Skip to content

Commit

Permalink
Merge pull request #268 from xmtp/ar/groups-demo-fixes
Browse files Browse the repository at this point in the history
Groups Demo
  • Loading branch information
alexrisch authored Feb 16, 2024
2 parents 1e298e9 + c9e23bd commit 8505921
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions example/src/ConversationCreateScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ export default function ConversationCreateScreen({
return
}
if (groupsEnabled) {
const canMessage = (await client.canGroupMessage([toAddress]))[0]
const toAddresses = toAddress.split(',')
const canMessage = await client.canGroupMessage(toAddresses)
if (!canMessage) {
setAlert(`${toAddress} cannot be added to a group conversation yet`)
return
}
const group = await client.conversations.newGroup([toAddress])
const group = await client.conversations.newGroup(toAddresses)
navigation.navigate('group', { id: group.id })
} else {
const canMessage = await client.canMessage(toAddress)
Expand Down
2 changes: 1 addition & 1 deletion example/src/GroupScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default function GroupScreen({
)

return (
<SafeAreaView style={{ flex: 1 }}>
<SafeAreaView style={{ flexGrow: 1 }}>
<KeyboardAvoidingView
behavior="padding"
keyboardVerticalOffset={Platform.OS === 'ios' ? 100 : 0}
Expand Down
7 changes: 6 additions & 1 deletion example/src/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export function useGroupsList(): UseQueryResult<
const { client } = useXmtp()
return useQuery<Group<SupportedContentTypes>[]>(
['xmtp', 'groups', client?.address],
async () => (await client?.conversations.listGroups()) || [],
async () => {
await client?.conversations.syncGroups()
return (await client?.conversations.listGroups()) || []
},
{
enabled: !!client,
}
Expand Down Expand Up @@ -128,6 +131,8 @@ export function useGroupMessages({
['xmtp', 'groupMessages', client?.address, group?.id],
async () => {
await group!.sync()
const messages = await group!.messages()
console.log('messages', messages)
return group!.messages()
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export async function canMessage(
export async function canGroupMessage(
clientAddress: string,
peerAddresses: string[]
): Promise<boolean[]> {
): Promise<boolean> {
return await XMTPModule.canGroupMessage(clientAddress, peerAddresses)
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export class Client<
* @param {string[]} addresses - The addresses of the peers to check for messaging eligibility.
* @returns {Promise<boolean[]>} A Promise resolving to true for peers where group messaging is allowed, and false otherwise.
*/
async canGroupMessage(addresses: string[]): Promise<boolean[]> {
async canGroupMessage(addresses: string[]): Promise<boolean> {
return await XMTPModule.canGroupMessage(this.address, addresses)
}

Expand Down

0 comments on commit 8505921

Please sign in to comment.