Fix types in threadgates

This commit is contained in:
Eric Bailey
2025-01-02 17:21:51 -06:00
parent df51b486f2
commit 69b9b14898
3 changed files with 6 additions and 10 deletions
+1 -1
View File
@@ -138,7 +138,7 @@ export async function getThreadgateRecord({
}), }),
) )
if (data.value && AppBskyFeedThreadgate.isRecord(data.value)) { if (data.value && AppBskyFeedThreadgate.isValidRecord(data.value)) {
return data.value return data.value
} else { } else {
return null return null
+1 -1
View File
@@ -3,4 +3,4 @@ export type ThreadgateAllowUISetting =
| {type: 'nobody'} | {type: 'nobody'}
| {type: 'mention'} | {type: 'mention'}
| {type: 'following'} | {type: 'following'}
| {type: 'list'; list: unknown} | {type: 'list'; list: string}
+4 -8
View File
@@ -37,11 +37,11 @@ export function threadgateRecordToAllowUISetting(
const settings: ThreadgateAllowUISetting[] = threadgate.allow const settings: ThreadgateAllowUISetting[] = threadgate.allow
.map(allow => { .map(allow => {
let setting: ThreadgateAllowUISetting | undefined let setting: ThreadgateAllowUISetting | undefined
if (allow.$type === 'app.bsky.feed.threadgate#mentionRule') { if (AppBskyFeedThreadgate.isValidMentionRule(allow)) {
setting = {type: 'mention'} setting = {type: 'mention'}
} else if (allow.$type === 'app.bsky.feed.threadgate#followingRule') { } else if (AppBskyFeedThreadgate.isValidFollowingRule(allow)) {
setting = {type: 'following'} setting = {type: 'following'}
} else if (allow.$type === 'app.bsky.feed.threadgate#listRule') { } else if (AppBskyFeedThreadgate.isValidListRule(allow)) {
setting = {type: 'list', list: allow.list} setting = {type: 'list', list: allow.list}
} }
return setting return setting
@@ -65,11 +65,7 @@ export function threadgateAllowUISettingToAllowRecordValue(
return undefined return undefined
} }
let allow: ( let allow: Exclude<AppBskyFeedThreadgate.Record['allow'], undefined> = []
| AppBskyFeedThreadgate.MentionRule
| AppBskyFeedThreadgate.FollowingRule
| AppBskyFeedThreadgate.ListRule
)[] = []
if (!threadgate.find(v => v.type === 'nobody')) { if (!threadgate.find(v => v.type === 'nobody')) {
for (const rule of threadgate) { for (const rule of threadgate) {