update quotes count after quoting
This commit is contained in:
@@ -1,4 +1,9 @@
|
|||||||
import {AppBskyActorDefs, AppBskyFeedGetQuotes} from '@atproto/api'
|
import {
|
||||||
|
AppBskyActorDefs,
|
||||||
|
AppBskyFeedGetPostThread,
|
||||||
|
AppBskyFeedGetQuotes,
|
||||||
|
BskyAgent,
|
||||||
|
} from '@atproto/api'
|
||||||
import {
|
import {
|
||||||
InfiniteData,
|
InfiniteData,
|
||||||
QueryClient,
|
QueryClient,
|
||||||
@@ -7,6 +12,7 @@ import {
|
|||||||
} from '@tanstack/react-query'
|
} from '@tanstack/react-query'
|
||||||
|
|
||||||
import {useAgent} from '#/state/session'
|
import {useAgent} from '#/state/session'
|
||||||
|
import {until} from 'lib/async/until'
|
||||||
import {getEmbeddedPost} from './util'
|
import {getEmbeddedPost} from './util'
|
||||||
|
|
||||||
const PAGE_SIZE = 30
|
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,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {useLingui} from '@lingui/react'
|
|||||||
import {POST_TOMBSTONE, Shadow, usePostShadow} from '#/state/cache/post-shadow'
|
import {POST_TOMBSTONE, Shadow, usePostShadow} from '#/state/cache/post-shadow'
|
||||||
import {useLanguagePrefs} from '#/state/preferences'
|
import {useLanguagePrefs} from '#/state/preferences'
|
||||||
import {useOpenLink} from '#/state/preferences/in-app-browser'
|
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 {ThreadPost} from '#/state/queries/post-thread'
|
||||||
import {useComposerControls} from '#/state/shell/composer'
|
import {useComposerControls} from '#/state/shell/composer'
|
||||||
import {MAX_POST_LINES} from 'lib/constants'
|
import {MAX_POST_LINES} from 'lib/constants'
|
||||||
@@ -26,7 +27,7 @@ import {countLines} from 'lib/strings/helpers'
|
|||||||
import {niceDate} from 'lib/strings/time'
|
import {niceDate} from 'lib/strings/time'
|
||||||
import {s} from 'lib/styles'
|
import {s} from 'lib/styles'
|
||||||
import {isWeb} from 'platform/detection'
|
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 {PostThreadFollowBtn} from 'view/com/post-thread/PostThreadFollowBtn'
|
||||||
import {atoms as a} from '#/alf'
|
import {atoms as a} from '#/alf'
|
||||||
import {RichText} from '#/components/RichText'
|
import {RichText} from '#/components/RichText'
|
||||||
@@ -174,6 +175,7 @@ let PostThreadItemLoaded = ({
|
|||||||
}): React.ReactNode => {
|
}): React.ReactNode => {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
const agent = useAgent()
|
||||||
const langPrefs = useLanguagePrefs()
|
const langPrefs = useLanguagePrefs()
|
||||||
const {openComposer} = useComposerControls()
|
const {openComposer} = useComposerControls()
|
||||||
const [limitLines, setLimitLines] = React.useState(
|
const [limitLines, setLimitLines] = React.useState(
|
||||||
@@ -232,6 +234,21 @@ let PostThreadItemLoaded = ({
|
|||||||
})
|
})
|
||||||
}, [openComposer, post, record, onPostReply, moderation])
|
}, [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(() => {
|
const onPressShowMore = React.useCallback(() => {
|
||||||
setLimitLines(false)
|
setLimitLines(false)
|
||||||
}, [setLimitLines])
|
}, [setLimitLines])
|
||||||
@@ -418,6 +435,7 @@ let PostThreadItemLoaded = ({
|
|||||||
record={record}
|
record={record}
|
||||||
richText={richText}
|
richText={richText}
|
||||||
onPressReply={onPressReply}
|
onPressReply={onPressReply}
|
||||||
|
onPostQuote={onPostQuote}
|
||||||
logContext="PostThreadItem"
|
logContext="PostThreadItem"
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
@@ -569,6 +587,7 @@ let PostThreadItemLoaded = ({
|
|||||||
record={record}
|
record={record}
|
||||||
richText={richText}
|
richText={richText}
|
||||||
onPressReply={onPressReply}
|
onPressReply={onPressReply}
|
||||||
|
onPostQuote={onPostQuote}
|
||||||
logContext="PostThreadItem"
|
logContext="PostThreadItem"
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ let PostCtrls = ({
|
|||||||
feedContext,
|
feedContext,
|
||||||
style,
|
style,
|
||||||
onPressReply,
|
onPressReply,
|
||||||
|
onPostQuote,
|
||||||
logContext,
|
logContext,
|
||||||
}: {
|
}: {
|
||||||
big?: boolean
|
big?: boolean
|
||||||
@@ -67,6 +68,7 @@ let PostCtrls = ({
|
|||||||
feedContext?: string | undefined
|
feedContext?: string | undefined
|
||||||
style?: StyleProp<ViewStyle>
|
style?: StyleProp<ViewStyle>
|
||||||
onPressReply: () => void
|
onPressReply: () => void
|
||||||
|
onPostQuote?: () => void
|
||||||
logContext: 'FeedItem' | 'PostThreadItem' | 'Post'
|
logContext: 'FeedItem' | 'PostThreadItem' | 'Post'
|
||||||
}): React.ReactNode => {
|
}): React.ReactNode => {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
@@ -169,16 +171,18 @@ let PostCtrls = ({
|
|||||||
author: post.author,
|
author: post.author,
|
||||||
indexedAt: post.indexedAt,
|
indexedAt: post.indexedAt,
|
||||||
},
|
},
|
||||||
|
onPost: onPostQuote,
|
||||||
})
|
})
|
||||||
}, [
|
}, [
|
||||||
openComposer,
|
sendInteraction,
|
||||||
post.uri,
|
post.uri,
|
||||||
post.cid,
|
post.cid,
|
||||||
post.author,
|
post.author,
|
||||||
post.indexedAt,
|
post.indexedAt,
|
||||||
record.text,
|
|
||||||
sendInteraction,
|
|
||||||
feedContext,
|
feedContext,
|
||||||
|
openComposer,
|
||||||
|
record.text,
|
||||||
|
onPostQuote,
|
||||||
])
|
])
|
||||||
|
|
||||||
const onShare = useCallback(() => {
|
const onShare = useCallback(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user