Skip to content

Commit

Permalink
Add space alt state
Browse files Browse the repository at this point in the history
  • Loading branch information
HitomaruKonpaku committed Mar 6, 2024
1 parent f920ba1 commit 26ab00e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/module/twitter/model/twitter-space.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Column, Entity, Index } from 'typeorm'
import { BaseExternalEntity } from '../../database/model/base-external.entity'
import { dbArrayTransformer } from '../../database/transformer/transformer'
import { AudioSpaceMetadataState } from '../api/enum/twitter-graphql.enum'
import { SpaceState } from '../enum/twitter-space.enum'
import { TwitterUser } from './twitter-user.entity'

Expand All @@ -16,6 +17,10 @@ export class TwitterSpace extends BaseExternalEntity {
@Column({ name: 'state', type: 'text', default: SpaceState.LIVE })
state: SpaceState

@Index()
@Column({ name: 'alt_state', type: 'text', nullable: true })
altState?: AudioSpaceMetadataState

@Column({ name: 'is_ticketed', type: 'boolean', nullable: true })
isTicketed?: boolean

Expand Down
1 change: 1 addition & 0 deletions src/module/twitter/util/twitter-entity.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export class TwitterEntityUtil {
modifiedAt: Date.now(),
creatorId: creator?.user_results?.result?.rest_id || creator?.user_results?.rest_id,
state: TwitterSpaceUtil.parseState(metadata.state),
altState: metadata.state,
scheduledStart: metadata.scheduled_start,
startedAt: metadata.start || metadata.started_at,
endedAt: NumberUtil.toNumberOrUndefined(metadata.ended_at),
Expand Down
20 changes: 8 additions & 12 deletions src/module/twitter/util/twitter-space.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,15 @@ export class TwitterSpaceUtil {
}

public static parseState(state: AudioSpaceMetadataState): SpaceState {
switch (state) {
case AudioSpaceMetadataState.NOT_STARTED:
return SpaceState.SCHEDULED
case AudioSpaceMetadataState.CANCELED:
return SpaceState.CANCELED
case AudioSpaceMetadataState.RUNNING:
return SpaceState.LIVE
case AudioSpaceMetadataState.ENDED:
case AudioSpaceMetadataState.TIMED_OUT:
return SpaceState.ENDED
default:
return null
const obj = {
[AudioSpaceMetadataState.NOT_STARTED]: SpaceState.SCHEDULED,
[AudioSpaceMetadataState.PRE_PUBLISHED]: SpaceState.SCHEDULED,
[AudioSpaceMetadataState.RUNNING]: SpaceState.LIVE,
[AudioSpaceMetadataState.TIMED_OUT]: SpaceState.ENDED,
[AudioSpaceMetadataState.ENDED]: SpaceState.ENDED,
[AudioSpaceMetadataState.CANCELED]: SpaceState.CANCELED,
}
return obj[state] || null
}

public static getMasterPlaylistUrl(url: string): string {
Expand Down

0 comments on commit 26ab00e

Please sign in to comment.