diff --git a/components/ConversationList/GroupConversationItem.tsx b/components/ConversationList/GroupConversationItem.tsx index 30a424325..b865dd35b 100644 --- a/components/ConversationList/GroupConversationItem.tsx +++ b/components/ConversationList/GroupConversationItem.tsx @@ -1,7 +1,8 @@ import { showActionSheetWithOptions } from "@components/StateHandlers/ActionSheetStateHandler"; import { useGroupConsent } from "@hooks/useGroupConsent"; import { translate } from "@i18n/index"; -import { useGroupQuery } from "@queries/useGroupQuery"; +import { useGroupNameQuery } from "@queries/useGroupNameQuery"; +import { useGroupPhotoQuery } from "@queries/useGroupPhotoQuery"; import { NativeStackScreenProps } from "@react-navigation/native-stack"; import { actionSheetColors } from "@styles/colors"; import { saveTopicsData } from "@utils/api"; @@ -14,8 +15,6 @@ import { useCurrentAccount, } from "../../data/store/accountsStore"; import { useSelect } from "../../data/store/storeHelpers"; -import { useGroupName } from "../../hooks/useGroupName"; -import { useGroupPhoto } from "../../hooks/useGroupPhoto"; import { NavigationParamList } from "../../screens/Navigation/Navigation"; import { ConversationWithLastMessagePreview } from "../../utils/conversation"; import { conversationName } from "../../utils/str"; @@ -34,14 +33,17 @@ export const GroupConversationItem: FC = ({ route, conversation, }) => { + const userAddress = useCurrentAccount() as string; const topic = conversation.topic; const lastMessagePreview = conversation.lastMessagePreview; - const { data: group } = useGroupQuery(currentAccount(), topic); - const { groupName } = useGroupName(topic); - const { groupPhoto } = useGroupPhoto(topic); + const { data: groupName } = useGroupNameQuery(userAddress, topic, { + refetchOnMount: false, + }); + const { data: groupPhoto } = useGroupPhotoQuery(userAddress, topic, { + refetchOnMount: false, + }); const { blockGroup } = useGroupConsent(topic); const colorScheme = useColorScheme(); - const userAddress = useCurrentAccount() as string; const { initialLoadDoneOnce, openedConversationTopic, @@ -64,7 +66,6 @@ export const GroupConversationItem: FC = ({ const handleDelete = useCallback( (defaultAction: () => void) => { - if (!group) return; showActionSheetWithOptions( { options: [ @@ -115,7 +116,7 @@ export const GroupConversationItem: FC = ({ } ); }, - [blockGroup, colorScheme, group, groupName, setTopicsData, topic] + [blockGroup, colorScheme, groupName, setTopicsData, topic] ); return ( diff --git a/components/PinnedConversations/PinnedConversation.tsx b/components/PinnedConversations/PinnedConversation.tsx index 8b9471fe0..98508c782 100644 --- a/components/PinnedConversations/PinnedConversation.tsx +++ b/components/PinnedConversations/PinnedConversation.tsx @@ -1,3 +1,5 @@ +import { useGroupNameQuery } from "@queries/useGroupNameQuery"; +import { useGroupPhotoQuery } from "@queries/useGroupPhotoQuery"; import { backgroundColor, textSecondaryColor } from "@styles/colors"; import { AvatarSizes } from "@styles/sizes"; import { FC, useCallback } from "react"; @@ -9,10 +11,12 @@ import { } from "react-native"; import Avatar from "..//Avatar"; -import { useChatStore, useProfilesStore } from "../../data/store/accountsStore"; +import { + useChatStore, + useCurrentAccount, + useProfilesStore, +} from "../../data/store/accountsStore"; import { XmtpConversation } from "../../data/store/chatStore"; -import { useGroupName } from "../../hooks/useGroupName"; -import { useGroupPhoto } from "../../hooks/useGroupPhoto"; import { navigate } from "../../utils/navigation"; import { getPreferredAvatar, getPreferredName } from "../../utils/profile"; import GroupAvatar from "../GroupAvatar"; @@ -22,10 +26,15 @@ interface Props { } export const PinnedConversation: FC = ({ conversation }) => { + const account = useCurrentAccount() as string; const profiles = useProfilesStore((s) => s.profiles); const { topic, isGroup } = conversation; - const { groupName } = useGroupName(topic); - const { groupPhoto } = useGroupPhoto(topic); + const { data: groupName } = useGroupNameQuery(account, topic, { + refetchOnMount: false, + }); + const { data: groupPhoto } = useGroupPhotoQuery(account, topic, { + refetchOnMount: false, + }); const title = isGroup ? groupName : conversation.conversationTitle; const socials = profiles[conversation.peerAddress as string]?.socials; const avatar = isGroup ? groupPhoto : getPreferredAvatar(socials); diff --git a/data/mappers.ts b/data/mappers.ts index 32ae9452a..6ccb38e27 100644 --- a/data/mappers.ts +++ b/data/mappers.ts @@ -82,7 +82,6 @@ export const xmtpConversationToDb = ( isGroup: xmtpConversation.isGroup, isActive: xmtpConversation.isGroup ? !!xmtpConversation.isActive : true, groupMembers: xmtpConversation.groupMembers, - groupAdmins: xmtpConversation.groupAdmins, groupName: xmtpConversation.isGroup ? xmtpConversation.groupName : undefined, groupPermissionLevel: xmtpConversation.groupPermissionLevel, lastNotificationsSubscribedPeriod: diff --git a/data/store/chatStore.ts b/data/store/chatStore.ts index 20abeb68f..f284c08b6 100644 --- a/data/store/chatStore.ts +++ b/data/store/chatStore.ts @@ -60,8 +60,6 @@ export type XmtpGroupConversation = XmtpConversationShared & { isGroup: true; peerAddress?: undefined; groupMembers: string[]; - groupAdmins: string[]; - groupSuperAdmins: string[]; groupPermissionLevel: "all_members" | "admin_only" | "custom_policy"; groupName?: string; groupCreator?: string; diff --git a/ios/ConverseNotificationExtension/Datatypes.swift b/ios/ConverseNotificationExtension/Datatypes.swift index 703700aaa..1d911b4dc 100644 --- a/ios/ConverseNotificationExtension/Datatypes.swift +++ b/ios/ConverseNotificationExtension/Datatypes.swift @@ -31,8 +31,6 @@ struct SavedNotificationConversation: Codable { var account: String var isGroup: Bool = false var groupMembers: [String?]? - var groupAdmins: [String?]? - var groupSuperAdmins: [String?]? var groupPermissionLevel: String? var groupName: String? var spamScore: Double? { diff --git a/queries/useGroupIsActive.ts b/queries/useGroupIsActive.ts index 3d3c42dc9..cc4a7a218 100644 --- a/queries/useGroupIsActive.ts +++ b/queries/useGroupIsActive.ts @@ -5,7 +5,7 @@ import { queryClient } from "./queryClient"; import { useGroupQuery } from "./useGroupQuery"; export const useGroupIsActiveQuery = (account: string, topic: string) => { - const { data: group } = useGroupQuery(account, topic); + const { data: group, dataUpdatedAt } = useGroupQuery(account, topic); return useQuery({ queryKey: groupIsActiveQueryKey(account, topic), queryFn: async () => { @@ -16,6 +16,7 @@ export const useGroupIsActiveQuery = (account: string, topic: string) => { }, enabled: !!group, initialData: group?.isGroupActive, + initialDataUpdatedAt: dataUpdatedAt, }); }; diff --git a/queries/useGroupNameQuery.ts b/queries/useGroupNameQuery.ts index a06b2007b..57bb299e6 100644 --- a/queries/useGroupNameQuery.ts +++ b/queries/useGroupNameQuery.ts @@ -1,11 +1,17 @@ -import { useQuery } from "@tanstack/react-query"; +import { useQuery, UseQueryOptions } from "@tanstack/react-query"; import { groupNameQueryKey } from "./QueryKeys"; import { queryClient } from "./queryClient"; import { useGroupQuery } from "./useGroupQuery"; -export const useGroupNameQuery = (account: string, topic: string) => { - const { data: group } = useGroupQuery(account, topic); +export const useGroupNameQuery = ( + account: string, + topic: string, + queryOptions?: Partial< + UseQueryOptions + > +) => { + const { data: group, dataUpdatedAt } = useGroupQuery(account, topic); return useQuery({ queryKey: groupNameQueryKey(account, topic), queryFn: async () => { @@ -14,8 +20,10 @@ export const useGroupNameQuery = (account: string, topic: string) => { } return group.groupName(); }, - enabled: !!group, + enabled: !!group && !!account, initialData: group?.name, + initialDataUpdatedAt: dataUpdatedAt, + ...queryOptions, }); }; diff --git a/queries/useGroupPhotoQuery.ts b/queries/useGroupPhotoQuery.ts index 4a269bb76..09e7f80b7 100644 --- a/queries/useGroupPhotoQuery.ts +++ b/queries/useGroupPhotoQuery.ts @@ -1,11 +1,17 @@ -import { useQuery } from "@tanstack/react-query"; +import { useQuery, UseQueryOptions } from "@tanstack/react-query"; import { groupPhotoQueryKey } from "./QueryKeys"; import { queryClient } from "./queryClient"; import { useGroupQuery } from "./useGroupQuery"; -export const useGroupPhotoQuery = (account: string, topic: string) => { - const { data: group } = useGroupQuery(account, topic); +export const useGroupPhotoQuery = ( + account: string, + topic: string, + queryOptions?: Partial< + UseQueryOptions + > +) => { + const { data: group, dataUpdatedAt } = useGroupQuery(account, topic); return useQuery({ queryKey: groupPhotoQueryKey(account, topic), queryFn: async () => { @@ -16,6 +22,8 @@ export const useGroupPhotoQuery = (account: string, topic: string) => { }, enabled: !!group, initialData: group?.imageUrlSquare, + initialDataUpdatedAt: dataUpdatedAt, + ...queryOptions, }); }; diff --git a/utils/xmtpRN/conversations.ts b/utils/xmtpRN/conversations.ts index ed72c9cf3..123644763 100644 --- a/utils/xmtpRN/conversations.ts +++ b/utils/xmtpRN/conversations.ts @@ -64,19 +64,11 @@ const protocolGroupToStateConversation = async ( ): Promise => { const groupMembers = await group.members(); const groupMembersAddresses: string[] = []; - const groupAdmins: string[] = []; - const groupSuperAdmins: string[] = []; const groupAddedByInboxId = await group.addedByInboxId(); let groupCreator: string | undefined; let groupAddedBy: string | undefined; groupMembers.forEach((m) => { - if (m.permissionLevel === "admin" || m.permissionLevel === "super_admin") { - groupAdmins.push(m.addresses[0]); - } - if (m.permissionLevel === "super_admin") { - groupSuperAdmins.push(m.addresses[0]); - } if (m.addresses[0]) { groupMembersAddresses.push(m.addresses[0]); } @@ -100,8 +92,6 @@ const protocolGroupToStateConversation = async ( pending: false, version: group.version, isGroup: true, - groupAdmins, - groupSuperAdmins, groupPermissionLevel: "custom_policy", groupName: group.name, groupCreator,