diff options
Diffstat (limited to 'src/state/queries/threadgate/util.ts')
-rw-r--r-- | src/state/queries/threadgate/util.ts | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/state/queries/threadgate/util.ts b/src/state/queries/threadgate/util.ts index 4459eddbe..cbe8d4695 100644 --- a/src/state/queries/threadgate/util.ts +++ b/src/state/queries/threadgate/util.ts @@ -1,14 +1,15 @@ import {AppBskyFeedDefs, AppBskyFeedThreadgate} from '@atproto/api' import {ThreadgateAllowUISetting} from '#/state/queries/threadgate/types' +import * as bsky from '#/types/bsky' export function threadgateViewToAllowUISetting( threadgateView: AppBskyFeedDefs.ThreadgateView | undefined, ): ThreadgateAllowUISetting[] { + // Validate the record for clarity, since backwards compat code is a little confusing const threadgate = threadgateView && - AppBskyFeedThreadgate.isRecord(threadgateView.record) && - AppBskyFeedThreadgate.validateRecord(threadgateView.record).success + bsky.validate(threadgateView.record, AppBskyFeedThreadgate.validateRecord) ? threadgateView.record : undefined return threadgateRecordToAllowUISetting(threadgate) @@ -39,14 +40,14 @@ export function threadgateRecordToAllowUISetting( const settings: ThreadgateAllowUISetting[] = threadgate.allow .map(allow => { let setting: ThreadgateAllowUISetting | undefined - if (allow.$type === 'app.bsky.feed.threadgate#mentionRule') { + if (AppBskyFeedThreadgate.isMentionRule(allow)) { setting = {type: 'mention'} - } else if (allow.$type === 'app.bsky.feed.threadgate#followingRule') { + } else if (AppBskyFeedThreadgate.isFollowingRule(allow)) { setting = {type: 'following'} - } else if (allow.$type === 'app.bsky.feed.threadgate#followerRule') { - setting = {type: 'followers'} - } else if (allow.$type === 'app.bsky.feed.threadgate#listRule') { + } else if (AppBskyFeedThreadgate.isListRule(allow)) { setting = {type: 'list', list: allow.list} + } else if (AppBskyFeedThreadgate.isFollowerRule(allow)) { + setting = {type: 'followers'} } return setting }) @@ -69,11 +70,7 @@ export function threadgateAllowUISettingToAllowRecordValue( return undefined } - let allow: ( - | AppBskyFeedThreadgate.MentionRule - | AppBskyFeedThreadgate.FollowingRule - | AppBskyFeedThreadgate.ListRule - )[] = [] + let allow: Exclude<AppBskyFeedThreadgate.Record['allow'], undefined> = [] if (!threadgate.find(v => v.type === 'nobody')) { for (const rule of threadgate) { |