[Chat] Power conversation settings screen via useConvoQuery (#10853)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-06-10 23:23:47 +03:00
committed by GitHub
parent 3feea02548
commit 156903070b
@@ -19,9 +19,8 @@ import {
type NavigationProp, type NavigationProp,
} from '#/lib/routes/types' } from '#/lib/routes/types'
import {logger} from '#/logger' import {logger} from '#/logger'
import {ConvoProvider, isConvoActive, useConvo} from '#/state/messages/convo'
import {ConvoStatus} from '#/state/messages/convo/types'
import {useModerationOpts} from '#/state/preferences/moderation-opts' import {useModerationOpts} from '#/state/preferences/moderation-opts'
import {useConvoQuery} from '#/state/queries/messages/conversation'
import {useEditGroupChatName} from '#/state/queries/messages/edit-group-chat-name' import {useEditGroupChatName} from '#/state/queries/messages/edit-group-chat-name'
import {useLeaveConvo} from '#/state/queries/messages/leave-conversation' import {useLeaveConvo} from '#/state/queries/messages/leave-conversation'
import {useListConvoMembersQuery} from '#/state/queries/messages/list-convo-members' import {useListConvoMembersQuery} from '#/state/queries/messages/list-convo-members'
@@ -39,6 +38,7 @@ import {ReportConversationDialog} from '#/components/dms/ReportConversationDialo
import { import {
type ConvoWithDetails, type ConvoWithDetails,
type GroupConvoMember, type GroupConvoMember,
parseConvoView,
} from '#/components/dms/util' } from '#/components/dms/util'
import {Error} from '#/components/Error' import {Error} from '#/components/Error'
import {ArrowBoxLeft_Stroke2_Corner0_Rounded as ArrowBoxLeftIcon} from '#/components/icons/ArrowBoxLeft' import {ArrowBoxLeft_Stroke2_Corner0_Rounded as ArrowBoxLeftIcon} from '#/components/icons/ArrowBoxLeft'
@@ -113,30 +113,33 @@ export function MessagesConversationSettingsScreen({route}: Props) {
</Layout.Header.Content> </Layout.Header.Content>
<Layout.Header.Slot /> <Layout.Header.Slot />
</Layout.Header.Outer> </Layout.Header.Outer>
<ConvoProvider key={convoId} convoId={convoId}> <SettingsInner convoId={convoId} />
<SettingsInner />
</ConvoProvider>
</Layout.Screen> </Layout.Screen>
) )
} }
function SettingsInner() { function SettingsInner({convoId}: {convoId: string}) {
const {t: l} = useLingui() const {t: l} = useLingui()
const convoState = useConvo()
const navigation = useNavigation<NavigationProp>() const navigation = useNavigation<NavigationProp>()
const moderationOpts = useModerationOpts() const moderationOpts = useModerationOpts()
const {currentAccount} = useSession()
const {data: convoData, error, refetch} = useConvoQuery({convoId})
if (convoState.status === ConvoStatus.Error) { const convo = convoData
? parseConvoView(convoData, currentAccount?.did)
: null
if (error) {
return ( return (
<Error <Error
title={l`Something went wrong`} title={l`Something went wrong`}
message={l`We couldnt load this conversations settings`} message={l`We couldnt load this conversations settings`}
onRetry={() => convoState.error.retry()} onRetry={() => refetch()}
/> />
) )
} }
if (!convoState.convo || !moderationOpts) { if (!convo || !moderationOpts) {
return ( return (
<View style={[a.flex_1, a.align_center, a.justify_center]}> <View style={[a.flex_1, a.align_center, a.justify_center]}>
<Loader size="xl" /> <Loader size="xl" />
@@ -144,7 +147,7 @@ function SettingsInner() {
) )
} }
if (convoState.convo.kind !== 'group') { if (convo.kind !== 'group') {
return ( return (
<Error <Error
title={l`Wrong kind of conversation`} title={l`Wrong kind of conversation`}
@@ -160,13 +163,7 @@ function SettingsInner() {
) )
} }
return ( return <GroupSettings convo={convo} moderationOpts={moderationOpts} />
<GroupSettings
convo={convoState.convo}
moderationOpts={moderationOpts}
isReady={isConvoActive(convoState)}
/>
)
} }
function keyExtractor(item: Item) { function keyExtractor(item: Item) {
@@ -189,11 +186,9 @@ function isGroupMember(
function GroupSettings({ function GroupSettings({
convo, convo,
moderationOpts, moderationOpts,
isReady,
}: { }: {
convo: Extract<ConvoWithDetails, {kind: 'group'}> convo: Extract<ConvoWithDetails, {kind: 'group'}>
moderationOpts: ModerationOpts moderationOpts: ModerationOpts
isReady: boolean
}) { }) {
const [isPTRing, setIsPTRing] = useState(false) const [isPTRing, setIsPTRing] = useState(false)
@@ -279,7 +274,7 @@ function GroupSettings({
/> />
) )
case 'ADD_MEMBERS_LINK': case 'ADD_MEMBERS_LINK':
return <AddMembersLink convo={convo} disabled={!isReady} /> return <AddMembersLink convo={convo} />
case 'CHAT_MEMBER': case 'CHAT_MEMBER':
return ( return (
<Member <Member
@@ -320,7 +315,6 @@ function GroupSettings({
convo={convo} convo={convo}
isOwner={isOwner} isOwner={isOwner}
moderationOpts={moderationOpts} moderationOpts={moderationOpts}
isReady={isReady}
/> />
} }
renderItem={renderItem} renderItem={renderItem}
@@ -336,12 +330,10 @@ function SettingsHeader({
convo, convo,
isOwner, isOwner,
moderationOpts, moderationOpts,
isReady,
}: { }: {
convo: Extract<ConvoWithDetails, {kind: 'group'}> convo: Extract<ConvoWithDetails, {kind: 'group'}>
isOwner: boolean isOwner: boolean
moderationOpts: ModerationOpts moderationOpts: ModerationOpts
isReady: boolean
}) { }) {
const t = useTheme() const t = useTheme()
const {i18n, t: l} = useLingui() const {i18n, t: l} = useLingui()
@@ -516,7 +508,7 @@ function SettingsHeader({
]}> ]}>
<SettingsButton <SettingsButton
color={convo.view.muted ? 'negative_subtle' : 'secondary'} color={convo.view.muted ? 'negative_subtle' : 'secondary'}
disabled={!isReady || isMuting || lockStatus !== 'unlocked'} disabled={isMuting || lockStatus !== 'unlocked'}
icon={convo.view.muted ? BellOffIcon : BellIcon} icon={convo.view.muted ? BellOffIcon : BellIcon}
label={ label={
convo.view.muted convo.view.muted
@@ -528,7 +520,7 @@ function SettingsHeader({
/> />
{isOwner ? ( {isOwner ? (
<SettingsButton <SettingsButton
disabled={!isReady || isEditingName || lockStatus !== 'unlocked'} disabled={isEditingName || lockStatus !== 'unlocked'}
icon={EditIcon} icon={EditIcon}
label={l`Edit this group chats name`} label={l`Edit this group chats name`}
text={l`Edit name`} text={l`Edit name`}
@@ -540,7 +532,7 @@ function SettingsHeader({
) : null} ) : null}
{isJoinLinkEnabled ? ( {isJoinLinkEnabled ? (
<SettingsButton <SettingsButton
disabled={!isReady || lockStatus !== 'unlocked'} disabled={lockStatus !== 'unlocked'}
icon={ChainLinkIcon} icon={ChainLinkIcon}
label={ label={
isOwner isOwner
@@ -554,7 +546,7 @@ function SettingsHeader({
{canLockGroupChat ? ( {canLockGroupChat ? (
<SettingsButton <SettingsButton
color={lockStatus === 'locked' ? 'negative_subtle' : 'secondary'} color={lockStatus === 'locked' ? 'negative_subtle' : 'secondary'}
disabled={!isReady || isLocking} disabled={isLocking}
icon={LockIcon} icon={LockIcon}
label={ label={
lockStatus === 'locked' lockStatus === 'locked'
@@ -571,7 +563,6 @@ function SettingsHeader({
) : null} ) : null}
{!isOwner && reportSubjectDid ? ( {!isOwner && reportSubjectDid ? (
<SettingsButton <SettingsButton
disabled={!isReady}
icon={FlagIcon} icon={FlagIcon}
label={l`Report this group chat`} label={l`Report this group chat`}
text={l`Report`} text={l`Report`}
@@ -579,7 +570,7 @@ function SettingsHeader({
/> />
) : null} ) : null}
<SettingsButton <SettingsButton
disabled={!isReady || isLeaving || (isOwner && isLocking)} disabled={isLeaving || (isOwner && isLocking)}
icon={ArrowBoxLeftIcon} icon={ArrowBoxLeftIcon}
label={l`Leave this group chat`} label={l`Leave this group chat`}
text={l`Leave`} text={l`Leave`}