Block posting of invalid chat invites (#10757)
Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
@@ -57,7 +57,7 @@ import {
|
||||
import {plural} from '@lingui/core/macro'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
import {useQueryClient} from '@tanstack/react-query'
|
||||
import {useQueries, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import * as apilib from '#/lib/api/index'
|
||||
import {EmbeddingDisabledError} from '#/lib/api/resolve'
|
||||
@@ -95,6 +95,7 @@ import {
|
||||
} from '#/state/preferences/languages'
|
||||
import {usePreferencesQuery} from '#/state/queries/preferences'
|
||||
import {useProfileQuery} from '#/state/queries/profile'
|
||||
import {resolveLinkQueryOptions} from '#/state/queries/resolve-link'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {useComposerControls} from '#/state/shell/composer'
|
||||
import {type ComposerOpts, type OnPostSuccessData} from '#/state/shell/composer'
|
||||
@@ -865,8 +866,25 @@ export const ComposePost = ({
|
||||
}
|
||||
}, [thread, requireAltTextEnabled, l])
|
||||
|
||||
// Subscribe to the resolve-link cache for any link URIs in the thread so we
|
||||
// can detect chat invites that resolved to no preview (revoked/expired) and
|
||||
// block publishing - otherwise the post would go out without the embed.
|
||||
const linkUris = thread.posts
|
||||
.filter(post => post.embed.link)
|
||||
.map(post => post.embed.link!.uri)
|
||||
const linkQueries = useQueries({
|
||||
queries: linkUris.map(uri => ({
|
||||
...resolveLinkQueryOptions(agent, uri),
|
||||
enabled: false,
|
||||
})),
|
||||
})
|
||||
const hasUnavailableChatInvite = linkQueries.some(
|
||||
q => q.data?.type === 'chat-invite' && !q.data.view,
|
||||
)
|
||||
|
||||
const canPost =
|
||||
!missingAltError &&
|
||||
!hasUnavailableChatInvite &&
|
||||
thread.posts.some(post => !isEmptyPost(post)) &&
|
||||
thread.posts.every(
|
||||
post =>
|
||||
|
||||
Reference in New Issue
Block a user