Restore link in Go Live prompt if status record present (#10636)
Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
@@ -1,7 +1,32 @@
|
||||
import {AppBskyActorStatus, AppBskyEmbedExternal} from '@atproto/api'
|
||||
import {type I18n} from '@lingui/core'
|
||||
import {plural} from '@lingui/core/macro'
|
||||
import psl from 'psl'
|
||||
|
||||
/**
|
||||
* Validates a raw status record and returns the typed record, or null if the
|
||||
* value is not a valid `app.bsky.actor.status` record.
|
||||
*/
|
||||
export function getValidLiveStatusRecord(
|
||||
statusRecord: unknown,
|
||||
): AppBskyActorStatus.Record | null {
|
||||
if (!AppBskyActorStatus.isRecord(statusRecord)) return null
|
||||
const validation = AppBskyActorStatus.validateRecord(statusRecord)
|
||||
if (!validation.success) return null
|
||||
return validation.value
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the external link URI from a status record, if present. Returns an
|
||||
* empty string when the record is invalid or has no external embed.
|
||||
*/
|
||||
export function getLiveLinkFromStatusRecord(statusRecord: unknown): string {
|
||||
const record = getValidLiveStatusRecord(statusRecord)
|
||||
if (!record) return ''
|
||||
if (!AppBskyEmbedExternal.isMain(record.embed)) return ''
|
||||
return record.embed.external.uri
|
||||
}
|
||||
|
||||
export function displayDuration(i18n: I18n, durationInMinutes: number) {
|
||||
const roundedDurationInMinutes = Math.round(durationInMinutes)
|
||||
const hours = Math.floor(roundedDurationInMinutes / 60)
|
||||
|
||||
Reference in New Issue
Block a user