-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Members Query on Conversation List #1343
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||||
import { | ||||||
QueryObserverOptions, | ||||||
SetDataOptions, | ||||||
useQuery, | ||||||
UseQueryOptions, | ||||||
} from "@tanstack/react-query"; | ||||||
import { getCleanAddress } from "@utils/evm/getCleanAddress"; | ||||||
import { ConversationTopic, Member } from "@xmtp/react-native-sdk"; | ||||||
|
@@ -11,65 +11,69 @@ import { groupMembersQueryKey } from "./QueryKeys"; | |||||
import { EntityObjectWithAddress, entifyWithAddress } from "./entify"; | ||||||
import { queryClient } from "./queryClient"; | ||||||
import { useGroupQuery } from "./useGroupQuery"; | ||||||
import { GroupWithCodecsType } from "@/utils/xmtpRN/client.types"; | ||||||
|
||||||
export type GroupMembersSelectData = EntityObjectWithAddress<Member, InboxId>; | ||||||
|
||||||
const fetchGroupMembers = async ( | ||||||
group: GroupWithCodecsType | undefined | null | ||||||
) => { | ||||||
if (!group) { | ||||||
return { | ||||||
byId: {}, | ||||||
byAddress: {}, | ||||||
ids: [], | ||||||
}; | ||||||
} | ||||||
const members = await group.members(); | ||||||
|
||||||
return entifyWithAddress( | ||||||
members, | ||||||
(member) => member.inboxId, | ||||||
(member) => getCleanAddress(member.addresses[0]) | ||||||
); | ||||||
}; | ||||||
|
||||||
const groupMembersQueryConfig = ( | ||||||
account: string, | ||||||
group: GroupWithCodecsType | undefined | null, | ||||||
enabled: boolean | ||||||
): UseQueryOptions<GroupMembersSelectData> => ({ | ||||||
queryKey: groupMembersQueryKey(account, group?.topic!), | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove non-null assertion operator The non-null assertion on - queryKey: groupMembersQueryKey(account, group?.topic!),
+ queryKey: groupMembersQueryKey(account, group?.topic ?? ''), 📝 Committable suggestion
Suggested change
|
||||||
queryFn: () => fetchGroupMembers(group!), | ||||||
enabled, | ||||||
}); | ||||||
|
||||||
export const useGroupMembersQuery = ( | ||||||
account: string, | ||||||
topic: ConversationTopic, | ||||||
queryOptions?: Partial<QueryObserverOptions<GroupMembersSelectData>> | ||||||
topic: ConversationTopic | ||||||
) => { | ||||||
const { data: group } = useGroupQuery(account, topic); | ||||||
return useQuery<GroupMembersSelectData>({ | ||||||
queryKey: groupMembersQueryKey(account, topic!), | ||||||
queryFn: async () => { | ||||||
if (!group) { | ||||||
return { | ||||||
byId: {}, | ||||||
byAddress: {}, | ||||||
ids: [], | ||||||
}; | ||||||
} | ||||||
const updatedMembers = await group.members(); | ||||||
return entifyWithAddress( | ||||||
updatedMembers, | ||||||
(member) => member.inboxId, | ||||||
// TODO: Multiple addresses support | ||||||
(member) => getCleanAddress(member.addresses[0]) | ||||||
); | ||||||
}, | ||||||
enabled: !!group && !!topic, | ||||||
...queryOptions, | ||||||
}); | ||||||
const enabled = !!group && !!topic; | ||||||
return useQuery<GroupMembersSelectData>( | ||||||
groupMembersQueryConfig(account, group, enabled) | ||||||
); | ||||||
}; | ||||||
|
||||||
export const useGroupMembersConversationScreenQuery = ( | ||||||
account: string, | ||||||
topic: ConversationTopic, | ||||||
queryOptions?: Partial<QueryObserverOptions<GroupMembersSelectData>> | ||||||
topic: ConversationTopic | ||||||
) => { | ||||||
const { data: group } = useGroupQuery(account, topic); | ||||||
return useQuery<GroupMembersSelectData>({ | ||||||
queryKey: groupMembersQueryKey(account, topic), | ||||||
queryFn: async () => { | ||||||
if (!group) { | ||||||
return { | ||||||
byId: {}, | ||||||
byAddress: {}, | ||||||
ids: [], | ||||||
}; | ||||||
} | ||||||
const members = await group.members(); | ||||||
return entifyWithAddress( | ||||||
members, | ||||||
(member) => member.inboxId, | ||||||
// TODO: Multiple addresses support | ||||||
(member) => getCleanAddress(member.addresses[0]) | ||||||
); | ||||||
}, | ||||||
enabled: !!group, | ||||||
...queryOptions, | ||||||
}); | ||||||
const enabled = !!group && !!topic; | ||||||
return useQuery<GroupMembersSelectData>( | ||||||
groupMembersQueryConfig(account, group, enabled) | ||||||
); | ||||||
}; | ||||||
|
||||||
export const useConversationListMembersQuery = ( | ||||||
account: string, | ||||||
group: GroupWithCodecsType | undefined | null | ||||||
) => { | ||||||
const enabled = !!group && !group.imageUrlSquare; | ||||||
return useQuery<GroupMembersSelectData>( | ||||||
groupMembersQueryConfig(account, group, enabled) | ||||||
); | ||||||
}; | ||||||
|
||||||
export const getGroupMembersQueryData = ( | ||||||
|
@@ -84,7 +88,7 @@ export const setGroupMembersQueryData = ( | |||||
members: GroupMembersSelectData, | ||||||
options?: SetDataOptions | ||||||
) => { | ||||||
queryClient.setQueryData( | ||||||
queryClient.setQueryData<GroupMembersSelectData>( | ||||||
groupMembersQueryKey(account, topic), | ||||||
members, | ||||||
options | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Query enabled condition could prevent member data fetching
The verification reveals that
useConversationListMembersQuery
is indeed conditionally enabled based on!!group && !group.imageUrlSquare
. This means the query will not fetch member data when:group
is null/undefined, orgroup.imageUrlSquare
existsThis could be problematic as member data might be needed regardless of whether a group has an image URL or not, especially since the hook
useGroupConversationListAvatarInfo
appears to use this data for avatar-related functionality.queries/useGroupMembersQuery.ts
: Consider removing the!group.imageUrlSquare
condition from the enabled check unless there's a specific reason why member data is not needed when a group image exists.🔗 Analysis chain
Verify query enabled condition
This query's enabled condition is tied to the absence of
imageUrlSquare
. Ensure this doesn't prevent necessary member data fetching.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 40
Script:
Length of output: 2432