Bluesky app fork with some witchin' additions 💫

Fix threadgate read after write (#4577)

* Fix threadgate read-after-write problem

* Fix React key (drive-by)

authored by danabra.mov and committed by

GitHub 75aec192 7d8fca56

+39 -4
+39 -4
src/view/com/threadgate/WhoCanReply.tsx
··· 1 1 import React from 'react' 2 2 import {Keyboard, StyleProp, View, ViewStyle} from 'react-native' 3 - import {AppBskyFeedDefs, AppBskyGraphDefs, AtUri} from '@atproto/api' 3 + import { 4 + AppBskyFeedDefs, 5 + AppBskyFeedGetPostThread, 6 + AppBskyGraphDefs, 7 + AtUri, 8 + BskyAgent, 9 + } from '@atproto/api' 4 10 import {msg, Trans} from '@lingui/macro' 5 11 import {useLingui} from '@lingui/react' 6 12 import {useQueryClient} from '@tanstack/react-query' 7 13 8 14 import {useAnalytics} from '#/lib/analytics/analytics' 9 15 import {createThreadgate} from '#/lib/api' 16 + import {until} from '#/lib/async/until' 10 17 import {useColorSchemeStyle} from '#/lib/hooks/useColorSchemeStyle' 11 18 import {usePalette} from '#/lib/hooks/usePalette' 12 19 import {makeListLink, makeProfileLink} from '#/lib/routes/links' ··· 85 92 rkey: new AtUri(post.uri).rkey, 86 93 }) 87 94 } 95 + await whenAppViewReady(agent, post.uri, res => { 96 + const thread = res.data.thread 97 + if (AppBskyFeedDefs.isThreadViewPost(thread)) { 98 + const fetchedSettings = threadgateViewToSettings( 99 + thread.post.threadgate, 100 + ) 101 + return ( 102 + JSON.stringify(fetchedSettings) === JSON.stringify(newSettings) 103 + ) 104 + } 105 + return false 106 + }) 88 107 Toast.show('Thread settings updated') 89 108 queryClient.invalidateQueries({ 90 109 queryKey: [POST_THREAD_RQKEY_ROOT], ··· 133 152 <Trans> 134 153 Only{' '} 135 154 {settings.map((rule, i) => ( 136 - <> 155 + <React.Fragment key={`rule-${i}`}> 137 156 <Rule 138 - key={`rule-${i}`} 139 157 rule={rule} 140 158 post={post} 141 159 lists={post.threadgate!.lists} 142 160 /> 143 161 <Separator key={`sep-${i}`} i={i} length={settings.length} /> 144 - </> 162 + </React.Fragment> 145 163 ))}{' '} 146 164 can reply. 147 165 </Trans> ··· 227 245 } 228 246 return <>, </> 229 247 } 248 + 249 + async function whenAppViewReady( 250 + agent: BskyAgent, 251 + uri: string, 252 + fn: (res: AppBskyFeedGetPostThread.Response) => boolean, 253 + ) { 254 + await until( 255 + 5, // 5 tries 256 + 1e3, // 1s delay between tries 257 + fn, 258 + () => 259 + agent.app.bsky.feed.getPostThread({ 260 + uri, 261 + depth: 0, 262 + }), 263 + ) 264 + }