From a5676e5cb4f9166ee55bbd764b177e4549ce71dc Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 5 Aug 2024 10:06:01 -0500 Subject: [PATCH] Add opposite direction conversion --- src/state/queries/threadgate.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/state/queries/threadgate.ts b/src/state/queries/threadgate.ts index 4ccb2c8505..854fa4c768 100644 --- a/src/state/queries/threadgate.ts +++ b/src/state/queries/threadgate.ts @@ -49,6 +49,37 @@ export function threadgateViewToAllowUISetting( return settings } +/** + * Converts a list of {@link ThreadgateAllowUISetting} to the `allow` prop on + * {@link AppBskyFeedThreadgate.Record}, + */ +export function threadgateAllowUISettingToAllowType( + threadgate: ThreadgateAllowUISetting[], +) { + let allow: ( + | AppBskyFeedThreadgate.MentionRule + | AppBskyFeedThreadgate.FollowingRule + | AppBskyFeedThreadgate.ListRule + )[] = [] + + if (!threadgate.find(v => v.type === 'nobody')) { + for (const rule of threadgate) { + if (rule.type === 'mention') { + allow.push({$type: 'app.bsky.feed.threadgate#mentionRule'}) + } else if (rule.type === 'following') { + allow.push({$type: 'app.bsky.feed.threadgate#followingRule'}) + } else if (rule.type === 'list') { + allow.push({ + $type: 'app.bsky.feed.threadgate#listRule', + list: rule.list, + }) + } + } + } + + return allow +} + export const threadgateRecordQueryKeyRoot = 'threadgate-record' export const createThreadgateRecordQueryKey = (uri: string) => [ threadgateRecordQueryKeyRoot,