Fix assumption that every chat has an owner
This commit is contained in:
@@ -86,6 +86,9 @@ stats.json
|
||||
# VSCode
|
||||
.vscode
|
||||
|
||||
# Zed
|
||||
.zed
|
||||
|
||||
# gitignore and github actions
|
||||
!.gitignore
|
||||
!.github
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import {ScrollView, View} from 'react-native'
|
||||
import {moderateProfile, type ModerationOpts} from '@atproto/api'
|
||||
import {
|
||||
type ChatBskyActorDefs,
|
||||
moderateProfile,
|
||||
type ModerationOpts,
|
||||
} from '@atproto/api'
|
||||
import {msg} from '@lingui/core/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {Trans} from '@lingui/react/macro'
|
||||
@@ -66,8 +70,8 @@ export function RecentChats({
|
||||
if (!convo) return null
|
||||
|
||||
if (
|
||||
(convo.kind === 'direct' &&
|
||||
convo.primaryMember.handle === 'missing.invalid') ||
|
||||
!convo.primaryMember ||
|
||||
convo.primaryMember.handle === 'missing.invalid' ||
|
||||
convo.view.muted
|
||||
) {
|
||||
return null
|
||||
@@ -77,6 +81,7 @@ export function RecentChats({
|
||||
<RecentChatItem
|
||||
key={convo.view.id}
|
||||
convo={convo}
|
||||
primaryMember={convo.primaryMember}
|
||||
onPress={() => onSelectChat(convo.view.id)}
|
||||
moderationOpts={moderationOpts}
|
||||
/>
|
||||
@@ -103,15 +108,17 @@ function RecentChatItem({
|
||||
onPress,
|
||||
moderationOpts,
|
||||
convo,
|
||||
primaryMember,
|
||||
}: {
|
||||
onPress: () => void
|
||||
moderationOpts: ModerationOpts
|
||||
convo: ConvoWithDetails
|
||||
primaryMember: ChatBskyActorDefs.ProfileViewBasic
|
||||
}) {
|
||||
const {_} = useLingui()
|
||||
const t = useTheme()
|
||||
|
||||
const primaryProfile = useProfileShadow(convo.primaryMember)
|
||||
const primaryProfile = useProfileShadow(primaryMember)
|
||||
|
||||
const moderation = moderateProfile(primaryProfile, moderationOpts)
|
||||
const name =
|
||||
|
||||
@@ -479,14 +479,15 @@ function ExistingChatCard({
|
||||
const {t: l} = useLingui()
|
||||
const enabled =
|
||||
convo.kind === 'group' ? convo.details.lockStatus === 'unlocked' : true
|
||||
const moderation = moderateProfile(convo.primaryMember, moderationOpts)
|
||||
const name =
|
||||
convo.kind === 'group'
|
||||
? convo.details.name
|
||||
: createSanitizedDisplayName(
|
||||
convo.primaryMember,
|
||||
true,
|
||||
moderation.ui('displayName'),
|
||||
moderateProfile(convo.primaryMember, moderationOpts).ui(
|
||||
'displayName',
|
||||
),
|
||||
)
|
||||
|
||||
const handleOnPress = useCallback(() => {
|
||||
|
||||
@@ -69,7 +69,7 @@ export type ConvoWithDetails = {view: ChatBskyConvoDefs.ConvoView} & (
|
||||
| {
|
||||
kind: 'group'
|
||||
details: $Typed<ChatBskyConvoDefs.GroupConvo>
|
||||
primaryMember: GroupConvoMember // the owner
|
||||
primaryMember?: GroupConvoMember // the owner - may have left, thus optional
|
||||
members: Array<GroupConvoMember>
|
||||
}
|
||||
| {
|
||||
@@ -117,11 +117,6 @@ export function parseConvoView(
|
||||
}
|
||||
}
|
||||
|
||||
if (!owner) {
|
||||
logger.warn('No owner found in group convo')
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
view: convoView,
|
||||
kind: 'group',
|
||||
|
||||
@@ -47,7 +47,7 @@ export function Member({
|
||||
const displayName = isDeletedAccount
|
||||
? l`Deleted Account`
|
||||
: createSanitizedDisplayName(profile, true, moderation.ui('displayName'))
|
||||
const isProfileOwner = profile.did === convo.primaryMember.did
|
||||
const isProfileOwner = profile.did === convo.primaryMember?.did
|
||||
const isSelf = currentAccount?.did === profile.did
|
||||
let statusBadge: React.ReactNode | null = null
|
||||
if (isSelf) {
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import {useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {ChatBskyActorDefs, ChatBskyConvoDefs} from '@atproto/api'
|
||||
import {
|
||||
ChatBskyActorDefs,
|
||||
ChatBskyConvoDefs,
|
||||
ModerationOpts,
|
||||
} from '@atproto/api'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
|
||||
@@ -14,6 +18,7 @@ import {
|
||||
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 {useEditGroupChatName} from '#/state/queries/messages/edit-group-chat-name'
|
||||
import {useLeaveConvo} from '#/state/queries/messages/leave-conversation'
|
||||
import {useListConvoMembersQuery} from '#/state/queries/messages/list-convo-members'
|
||||
@@ -99,6 +104,7 @@ function SettingsInner() {
|
||||
const {t: l} = useLingui()
|
||||
const convoState = useConvo()
|
||||
const navigation = useNavigation<NavigationProp>()
|
||||
const moderationOpts = useModerationOpts()
|
||||
|
||||
if (convoState.status === ConvoStatus.Error) {
|
||||
return (
|
||||
@@ -111,7 +117,7 @@ function SettingsInner() {
|
||||
)
|
||||
}
|
||||
|
||||
if (!isConvoActive(convoState)) {
|
||||
if (!isConvoActive(convoState) || !moderationOpts) {
|
||||
return (
|
||||
<View style={[a.flex_1, a.align_center, a.justify_center]}>
|
||||
<Loader size="xl" />
|
||||
@@ -135,7 +141,9 @@ function SettingsInner() {
|
||||
)
|
||||
}
|
||||
|
||||
return <GroupSettings convo={convoState.convo} />
|
||||
return (
|
||||
<GroupSettings convo={convoState.convo} moderationOpts={moderationOpts} />
|
||||
)
|
||||
}
|
||||
|
||||
function keyExtractor(item: Item) {
|
||||
@@ -157,8 +165,10 @@ function isGroupMember(
|
||||
|
||||
function GroupSettings({
|
||||
convo,
|
||||
moderationOpts,
|
||||
}: {
|
||||
convo: Extract<ConvoWithDetails, {kind: 'group'}>
|
||||
moderationOpts: ModerationOpts
|
||||
}) {
|
||||
const initialNumToRender = useInitialNumToRender({minItemHeight: 68})
|
||||
const bottomBarOffset = useBottomBarOffset()
|
||||
@@ -166,7 +176,7 @@ function GroupSettings({
|
||||
const {currentAccount} = useSession()
|
||||
|
||||
const primaryMember = convo.primaryMember
|
||||
const isOwner = primaryMember.did === currentAccount?.did
|
||||
const isOwner = !!primaryMember && primaryMember.did === currentAccount?.did
|
||||
|
||||
const {data: memberListData = [], isPending} = useListConvoMembersQuery({
|
||||
convoId: convo.view.id,
|
||||
@@ -209,8 +219,8 @@ function GroupSettings({
|
||||
...memberListData
|
||||
.filter(isGroupMember)
|
||||
.sort((a, b) => {
|
||||
const aIsOwner = a.did === primaryMember.did
|
||||
const bIsOwner = b.did === primaryMember.did
|
||||
const aIsOwner = a.did === primaryMember?.did
|
||||
const bIsOwner = b.did === primaryMember?.did
|
||||
const aIsSelf = a.did === currentAccount?.did
|
||||
const bIsSelf = b.did === currentAccount?.did
|
||||
if (aIsOwner !== bIsOwner) return aIsOwner ? -1 : 1
|
||||
@@ -223,7 +233,7 @@ function GroupSettings({
|
||||
key: profile.did,
|
||||
profile,
|
||||
status:
|
||||
primaryMember.did === profile.did
|
||||
primaryMember?.did === profile.did
|
||||
? 'owner'
|
||||
: invites.includes(profile.did)
|
||||
? 'invited'
|
||||
@@ -271,7 +281,13 @@ function GroupSettings({
|
||||
desktopFixedHeight
|
||||
initialNumToRender={initialNumToRender}
|
||||
keyExtractor={keyExtractor}
|
||||
ListHeaderComponent={<SettingsHeader convo={convo} isOwner={isOwner} />}
|
||||
ListHeaderComponent={
|
||||
<SettingsHeader
|
||||
convo={convo}
|
||||
isOwner={isOwner}
|
||||
moderationOpts={moderationOpts}
|
||||
/>
|
||||
}
|
||||
renderItem={renderItem}
|
||||
sideBorders={false}
|
||||
windowSize={11}
|
||||
@@ -282,9 +298,11 @@ function GroupSettings({
|
||||
function SettingsHeader({
|
||||
convo,
|
||||
isOwner,
|
||||
moderationOpts,
|
||||
}: {
|
||||
convo: Extract<ConvoWithDetails, {kind: 'group'}>
|
||||
isOwner: boolean
|
||||
moderationOpts: ModerationOpts
|
||||
}) {
|
||||
const t = useTheme()
|
||||
const {i18n, t: l} = useLingui()
|
||||
@@ -517,11 +535,15 @@ function SettingsHeader({
|
||||
onChangeText={setNewGroupName}
|
||||
onConfirm={handleEditName}
|
||||
/>
|
||||
<InviteLinkDialog
|
||||
convo={convo}
|
||||
control={inviteLinkDialog}
|
||||
isOwner={isOwner}
|
||||
/>
|
||||
{convo.primaryMember && (
|
||||
<InviteLinkDialog
|
||||
convo={convo}
|
||||
owner={convo.primaryMember}
|
||||
control={inviteLinkDialog}
|
||||
isOwner={isOwner}
|
||||
moderationOpts={moderationOpts}
|
||||
/>
|
||||
)}
|
||||
<LockChatPrompt control={lockChatPrompt} onConfirm={handleConfirmLock} />
|
||||
<LeaveChatPrompt
|
||||
control={leaveChatPrompt}
|
||||
|
||||
@@ -14,7 +14,11 @@ import {useHaptics} from '#/lib/haptics'
|
||||
import {createSanitizedDisplayName} from '#/lib/moderation/create-sanitized-display-name'
|
||||
import {decrementBadgeCount} from '#/lib/notifications/notifications'
|
||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||
import {type Shadow, useProfileShadow} from '#/state/cache/profile-shadow'
|
||||
import {
|
||||
type Shadow,
|
||||
useMaybeProfileShadow,
|
||||
useProfileShadow,
|
||||
} from '#/state/cache/profile-shadow'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {
|
||||
precacheConvoQuery,
|
||||
@@ -167,10 +171,11 @@ function GroupChatItem({
|
||||
children?: React.ReactNode
|
||||
}) {
|
||||
const {t: l} = useLingui()
|
||||
const groupOwner = useProfileShadow(convo.primaryMember)
|
||||
const groupOwner = useMaybeProfileShadow(convo.primaryMember)
|
||||
|
||||
const moderation = useMemo(
|
||||
() => moderateProfile(groupOwner, moderationOpts),
|
||||
() =>
|
||||
groupOwner ? moderateProfile(groupOwner, moderationOpts) : undefined,
|
||||
[groupOwner, moderationOpts],
|
||||
)
|
||||
|
||||
@@ -215,8 +220,8 @@ function BaseChatItem({
|
||||
accessibilityHint: string
|
||||
isDeletedAccount: boolean
|
||||
isBlockedAccount: boolean
|
||||
primaryProfile: Shadow<bsky.profile.AnyProfileView>
|
||||
primaryProfileModeration: ModerationDecision
|
||||
primaryProfile?: Shadow<bsky.profile.AnyProfileView>
|
||||
primaryProfileModeration?: ModerationDecision
|
||||
showMenu?: boolean
|
||||
showProfileBadges: boolean
|
||||
postAlerts?: React.ReactNode
|
||||
@@ -236,6 +241,7 @@ function BaseChatItem({
|
||||
const hasUnread = convo.unreadCount > 0 && !isDeletedAccount
|
||||
|
||||
const blockInfo = useMemo(() => {
|
||||
if (!primaryProfileModeration) return {listBlocks: [], userBlock: undefined}
|
||||
const modui = primaryProfileModeration.ui('profileView')
|
||||
const blocks = modui.alerts.filter(alert => alert.type === 'blocking')
|
||||
const listBlocks = blocks.filter(alert => alert.source.type === 'list')
|
||||
@@ -455,7 +461,7 @@ function BaseChatItem({
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
{showProfileBadges && (
|
||||
{showProfileBadges && primaryProfile && (
|
||||
<ProfileBadges
|
||||
profile={primaryProfile}
|
||||
size="md"
|
||||
@@ -550,7 +556,8 @@ function BaseChatItem({
|
||||
|
||||
<ChatListItemPortal.Outlet />
|
||||
|
||||
{showMenu && (
|
||||
{/* TODO: Allow showing menu for groups where the owner has left! */}
|
||||
{showMenu && primaryProfile && (
|
||||
<ConvoMenu
|
||||
convo={convo}
|
||||
profile={primaryProfile}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {useEffect, useState} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {moderateProfile, type ModerationOpts} from '@atproto/api'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {useOpenComposer} from '#/lib/hooks/useOpenComposer'
|
||||
@@ -17,7 +18,10 @@ import {
|
||||
StackedButton,
|
||||
} from '#/components/Button'
|
||||
import * as Dialog from '#/components/Dialog'
|
||||
import {type ConvoWithDetails} from '#/components/dms/util'
|
||||
import {
|
||||
type ConvoWithDetails,
|
||||
type GroupConvoMember,
|
||||
} from '#/components/dms/util'
|
||||
import * as Toggle from '#/components/forms/Toggle'
|
||||
import {ArrowRight_Stroke2_Corner0_Rounded as ArrowRightIcon} from '#/components/icons/Arrow'
|
||||
import {ArrowShareRight_Stroke2_Corner2_Rounded as ArrowShareRightIcon} from '#/components/icons/ArrowShareRight'
|
||||
@@ -39,16 +43,24 @@ enum Step {
|
||||
export function InviteLinkDialog({
|
||||
convo,
|
||||
control,
|
||||
owner,
|
||||
isOwner,
|
||||
moderationOpts,
|
||||
}: {
|
||||
convo: Extract<ConvoWithDetails, {kind: 'group'}>
|
||||
control: Dialog.DialogOuterProps['control']
|
||||
owner: GroupConvoMember
|
||||
isOwner: boolean
|
||||
moderationOpts: ModerationOpts
|
||||
}) {
|
||||
const t = useTheme()
|
||||
const {t: l, i18n} = useLingui()
|
||||
|
||||
const ownerName = createSanitizedDisplayName(convo.primaryMember)
|
||||
const ownerName = createSanitizedDisplayName(
|
||||
owner,
|
||||
false,
|
||||
moderateProfile(owner, moderationOpts).ui('displayName'),
|
||||
)
|
||||
|
||||
const {joinLink} = convo.details
|
||||
const enabledStatus = joinLink?.enabledStatus
|
||||
|
||||
@@ -2,7 +2,9 @@ import {View} from 'react-native'
|
||||
import {Plural, Trans, useLingui} from '@lingui/react/macro'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {useAddGroupMembers} from '#/state/queries/messages/add-group-members'
|
||||
import {useListConvoMembersQuery} from '#/state/queries/messages/list-convo-members'
|
||||
import {useSession} from '#/state/session'
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
import {AvatarBubbles} from '#/components/AvatarBubbles'
|
||||
@@ -23,13 +25,16 @@ export function MessagesListInfoPanel({
|
||||
}) {
|
||||
const t = useTheme()
|
||||
const {t: l} = useLingui()
|
||||
const moderationOpts = useModerationOpts()
|
||||
const convoId = convo.view.id
|
||||
|
||||
const addMembersControl = Dialog.useDialogControl()
|
||||
const inviteLinkControl = Dialog.useDialogControl()
|
||||
|
||||
const {currentAccount} = useSession()
|
||||
|
||||
const convoId = convo.view.id
|
||||
const {data: fullMemberList} = useListConvoMembersQuery({convoId})
|
||||
|
||||
const {mutate: addGroupMembers} = useAddGroupMembers(convoId, {
|
||||
onSuccess: () => {
|
||||
addMembersControl.close()
|
||||
@@ -46,9 +51,9 @@ export function MessagesListInfoPanel({
|
||||
// (isOwner && groupConvo) ||
|
||||
// (!isOwner && groupConvo && joinLink?.enabledStatus === 'enabled')
|
||||
|
||||
const isOwner = convo?.primaryMember.did === currentAccount?.did
|
||||
const isOwner = convo.primaryMember?.did === currentAccount?.did
|
||||
|
||||
const members = (convo?.members ?? []).filter(
|
||||
const members = (convo.members ?? []).filter(
|
||||
profile => profile.did !== currentAccount?.did,
|
||||
)
|
||||
|
||||
@@ -81,7 +86,7 @@ export function MessagesListInfoPanel({
|
||||
return (
|
||||
<>
|
||||
<View style={[a.align_center, a.justify_center]}>
|
||||
<AvatarBubbles animate={true} profiles={convo?.members} />
|
||||
<AvatarBubbles animate={true} profiles={convo.members} />
|
||||
{convo.details.name ? (
|
||||
<Text style={[a.text_2xl, a.font_bold, a.mt_lg, t.atoms.text]}>
|
||||
{convo.details.name}
|
||||
@@ -139,11 +144,15 @@ export function MessagesListInfoPanel({
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
<InviteLinkDialog
|
||||
isOwner={isOwner}
|
||||
convo={convo}
|
||||
control={inviteLinkControl}
|
||||
/>
|
||||
{convo.primaryMember && moderationOpts && (
|
||||
<InviteLinkDialog
|
||||
convo={convo}
|
||||
owner={convo.primaryMember}
|
||||
moderationOpts={moderationOpts}
|
||||
isOwner={isOwner}
|
||||
control={inviteLinkControl}
|
||||
/>
|
||||
)}
|
||||
<Dialog.Outer
|
||||
control={addMembersControl}
|
||||
testID="addChatMembersDialog"
|
||||
|
||||
@@ -25,19 +25,22 @@ export function RequestListItem({
|
||||
return null
|
||||
}
|
||||
|
||||
const isDeletedAccount = convo.primaryMember.handle === 'missing.invalid'
|
||||
const isDeletedAccount =
|
||||
!convo.primaryMember || convo.primaryMember.handle === 'missing.invalid'
|
||||
|
||||
return (
|
||||
<View style={[a.relative, a.flex_1]}>
|
||||
<ChatListItem convo={convo.view} showMenu={false}>
|
||||
<View style={[a.pt_xs, a.pb_2xs]}>
|
||||
<KnownFollowers
|
||||
profile={convo.primaryMember}
|
||||
moderationOpts={moderationOpts}
|
||||
minimal
|
||||
showIfEmpty
|
||||
/>
|
||||
</View>
|
||||
{convo.primaryMember && (
|
||||
<View style={[a.pt_xs, a.pb_2xs]}>
|
||||
<KnownFollowers
|
||||
profile={convo.primaryMember}
|
||||
moderationOpts={moderationOpts}
|
||||
minimal
|
||||
showIfEmpty
|
||||
/>
|
||||
</View>
|
||||
)}
|
||||
{/* spacer, since you can't nest pressables */}
|
||||
<View style={[a.pt_md, a.pb_xs, a.w_full, {opacity: 0}]} aria-hidden>
|
||||
{/* Placeholder text so that it responds to the font height */}
|
||||
@@ -60,7 +63,7 @@ export function RequestListItem({
|
||||
paddingLeft: tokens.space.lg + 52 + tokens.space.md,
|
||||
},
|
||||
]}>
|
||||
{!isDeletedAccount ? (
|
||||
{convo.primaryMember && !isDeletedAccount ? (
|
||||
<>
|
||||
<AcceptChatButton convo={convo.view} currentScreen="list" />
|
||||
<RejectMenu
|
||||
|
||||
@@ -18,6 +18,7 @@ import {useCurrentConvoId} from '#/state/messages/current-convo-id'
|
||||
import {useMessagesEventBus} from '#/state/messages/events'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {parseConvoView} from '#/components/dms/util'
|
||||
import {useLeftConvos} from './leave-conversation'
|
||||
|
||||
export const RQKEY_ROOT = 'convo-list'
|
||||
@@ -408,6 +409,8 @@ export function useUnreadMessageCount() {
|
||||
numUnread?: string
|
||||
hasNew: boolean
|
||||
}>(() => {
|
||||
console.log('accepted', accepted)
|
||||
console.log('request', request)
|
||||
const acceptedCount = calculateCount(
|
||||
accepted,
|
||||
currentAccount?.did,
|
||||
@@ -453,19 +456,18 @@ function calculateCount(
|
||||
return (
|
||||
convos
|
||||
.filter(convo => convo.id !== currentConvoId)
|
||||
.reduce((acc, convo) => {
|
||||
const otherMember = convo.members.find(
|
||||
member => member.did !== currentAccountDid,
|
||||
)
|
||||
.reduce((acc, convoView) => {
|
||||
const convo = parseConvoView(convoView, currentAccountDid)
|
||||
|
||||
if (!otherMember || !moderationOpts) return acc
|
||||
if (!convo || !moderationOpts) return acc
|
||||
|
||||
const moderation = moderateProfile(otherMember, moderationOpts)
|
||||
const shouldIgnore =
|
||||
convo.muted ||
|
||||
moderation.blocked ||
|
||||
otherMember.handle === 'missing.invalid'
|
||||
const unreadCount = !shouldIgnore && convo.unreadCount > 0 ? 1 : 0
|
||||
convo.view.muted ||
|
||||
!convo.primaryMember ||
|
||||
moderateProfile(convo.primaryMember, moderationOpts).blocked ||
|
||||
convo.primaryMember.handle === 'missing.invalid' ||
|
||||
(convo.kind === 'group' && convo.details.lockStatus !== 'unlocked')
|
||||
const unreadCount = !shouldIgnore && convo.view.unreadCount > 0 ? 1 : 0
|
||||
|
||||
return acc + unreadCount
|
||||
}, 0) ?? 0
|
||||
|
||||
Reference in New Issue
Block a user