update quotes count after quoting

This commit is contained in:
Hailey
2024-08-19 13:30:25 -07:00
parent 23d00d6d2b
commit 1f1887730a
3 changed files with 51 additions and 5 deletions
+24 -1
View File
@@ -1,4 +1,9 @@
import {AppBskyActorDefs, AppBskyFeedGetQuotes} from '@atproto/api'
import {
AppBskyActorDefs,
AppBskyFeedGetPostThread,
AppBskyFeedGetQuotes,
BskyAgent,
} from '@atproto/api'
import {
InfiniteData,
QueryClient,
@@ -7,6 +12,7 @@ import {
} from '@tanstack/react-query'
import {useAgent} from '#/state/session'
import {until} from 'lib/async/until'
import {getEmbeddedPost} from './util'
const PAGE_SIZE = 30
@@ -66,3 +72,20 @@ export function* findAllProfilesInQueryData(
}
}
}
export async function whenAppViewReady(
agent: BskyAgent,
uri: string,
fn: (res: AppBskyFeedGetPostThread.Response) => boolean,
) {
await until(
3, // 5 tries
1e3, // 1s delay between tries
fn,
() =>
agent.app.bsky.feed.getPostThread({
uri,
depth: 0,
}),
)
}
+20 -1
View File
@@ -14,6 +14,7 @@ import {useLingui} from '@lingui/react'
import {POST_TOMBSTONE, Shadow, usePostShadow} from '#/state/cache/post-shadow'
import {useLanguagePrefs} from '#/state/preferences'
import {useOpenLink} from '#/state/preferences/in-app-browser'
import {whenAppViewReady as whenAppViewReadyQuote} from '#/state/queries/post-quotes'
import {ThreadPost} from '#/state/queries/post-thread'
import {useComposerControls} from '#/state/shell/composer'
import {MAX_POST_LINES} from 'lib/constants'
@@ -26,7 +27,7 @@ import {countLines} from 'lib/strings/helpers'
import {niceDate} from 'lib/strings/time'
import {s} from 'lib/styles'
import {isWeb} from 'platform/detection'
import {useSession} from 'state/session'
import {useAgent, useSession} from 'state/session'
import {PostThreadFollowBtn} from 'view/com/post-thread/PostThreadFollowBtn'
import {atoms as a} from '#/alf'
import {RichText} from '#/components/RichText'
@@ -174,6 +175,7 @@ let PostThreadItemLoaded = ({
}): React.ReactNode => {
const pal = usePalette('default')
const {_} = useLingui()
const agent = useAgent()
const langPrefs = useLanguagePrefs()
const {openComposer} = useComposerControls()
const [limitLines, setLimitLines] = React.useState(
@@ -232,6 +234,21 @@ let PostThreadItemLoaded = ({
})
}, [openComposer, post, record, onPostReply, moderation])
const onPostQuote = React.useCallback(() => {
// We need to wait until the quote count is updated before we can show the new total. We'll wait for the appview
// here. Worst case scenario - someone deletes a quote right as you make yours - this will fail after 3 retries
whenAppViewReadyQuote(agent, post.uri, res => {
const thread = res.data.thread
if (AppBskyFeedDefs.isThreadViewPost(thread)) {
if (thread.post.quoteCount !== post.quoteCount) {
onPostReply(undefined)
return true
}
}
return false
})
}, [agent, post.uri, post.quoteCount, onPostReply])
const onPressShowMore = React.useCallback(() => {
setLimitLines(false)
}, [setLimitLines])
@@ -418,6 +435,7 @@ let PostThreadItemLoaded = ({
record={record}
richText={richText}
onPressReply={onPressReply}
onPostQuote={onPostQuote}
logContext="PostThreadItem"
/>
</View>
@@ -569,6 +587,7 @@ let PostThreadItemLoaded = ({
record={record}
richText={richText}
onPressReply={onPressReply}
onPostQuote={onPostQuote}
logContext="PostThreadItem"
/>
</View>
+7 -3
View File
@@ -58,6 +58,7 @@ let PostCtrls = ({
feedContext,
style,
onPressReply,
onPostQuote,
logContext,
}: {
big?: boolean
@@ -67,6 +68,7 @@ let PostCtrls = ({
feedContext?: string | undefined
style?: StyleProp<ViewStyle>
onPressReply: () => void
onPostQuote?: () => void
logContext: 'FeedItem' | 'PostThreadItem' | 'Post'
}): React.ReactNode => {
const t = useTheme()
@@ -169,16 +171,18 @@ let PostCtrls = ({
author: post.author,
indexedAt: post.indexedAt,
},
onPost: onPostQuote,
})
}, [
openComposer,
sendInteraction,
post.uri,
post.cid,
post.author,
post.indexedAt,
record.text,
sendInteraction,
feedContext,
openComposer,
record.text,
onPostQuote,
])
const onShare = useCallback(() => {