From 7d2978af14aeb17fae0a8a1c01eaac12445fc4a8 Mon Sep 17 00:00:00 2001 From: Alex Risch Date: Wed, 7 Feb 2024 16:41:25 -0700 Subject: [PATCH 1/3] Group Messages Decode Group Messages --- src/index.ts | 24 +++++++++++++----------- src/lib/Group.ts | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 31dfa58e0..9c2ae0691 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,10 +6,10 @@ import { ConversationContext } from './XMTP.types' import XMTPModule from './XMTPModule' import { ConsentListEntry, ConsentState } from './lib/ConsentListEntry' import { + ContentCodec, DecryptedLocalAttachment, EncryptedLocalAttachment, PreparedLocalMessage, - ContentCodec, } from './lib/ContentCodec' import { Conversation } from './lib/Conversation' import { DecodedMessage } from './lib/DecodedMessage' @@ -17,14 +17,14 @@ import { Group } from './lib/Group' import type { Query } from './lib/Query' import { getAddress } from './utils/address' +export * from './context' +export * from './hooks' export { ReactionCodec } from './lib/NativeCodecs/ReactionCodec' -export { ReplyCodec } from './lib/NativeCodecs/ReplyCodec' export { ReadReceiptCodec } from './lib/NativeCodecs/ReadReceiptCodec' -export { StaticAttachmentCodec } from './lib/NativeCodecs/StaticAttachmentCodec' export { RemoteAttachmentCodec } from './lib/NativeCodecs/RemoteAttachmentCodec' +export { ReplyCodec } from './lib/NativeCodecs/ReplyCodec' +export { StaticAttachmentCodec } from './lib/NativeCodecs/StaticAttachmentCodec' export { TextCodec } from './lib/NativeCodecs/TextCodec' -export * from './hooks' -export * from './context' const EncodedContent = content.EncodedContent @@ -119,10 +119,13 @@ export async function sendMessageToGroup( } export async function groupMessages( - clientAddress: string, + client: Client, id: string ): Promise { - return await XMTPModule.groupMessages(clientAddress, id) + const messages = await XMTPModule.groupMessages(client.address, id) + return messages.map((json: string) => { + return DecodedMessage.from(json, client) + }) } export async function syncGroups(clientAddress: string) { @@ -484,11 +487,10 @@ export function preCreateIdentityCallbackCompleted() { export const emitter = new EventEmitter(XMTPModule ?? NativeModulesProxy.XMTP) -export * from './lib/ContentCodec' +export * from './XMTP.types' export { Client } from './lib/Client' +export * from './lib/ContentCodec' export { Conversation } from './lib/Conversation' -export * from './XMTP.types' export { Query } from './lib/Query' export { XMTPPush } from './lib/XMTPPush' -export { DecodedMessage } -export { ConsentListEntry } +export { ConsentListEntry, DecodedMessage } diff --git a/src/lib/Group.ts b/src/lib/Group.ts index 4cfd46064..7c5166c3f 100644 --- a/src/lib/Group.ts +++ b/src/lib/Group.ts @@ -62,7 +62,7 @@ export class Group { } async messages(): Promise { - return await XMTP.groupMessages(this.client.address, this.id) + return await XMTP.groupMessages(this.client, this.id) } async sync() { From 331f71c19801cbfeceb8ac4b6b75f0edcbfb1663 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Wed, 7 Feb 2024 21:30:18 -0600 Subject: [PATCH 2/3] Update group test now that we're decoding correctly --- example/package.json | 1 + example/src/tests.ts | 20 ++++++++------------ example/yarn.lock | 5 +++++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/example/package.json b/example/package.json index a2b4c2db5..9dc6f0b5e 100644 --- a/example/package.json +++ b/example/package.json @@ -47,6 +47,7 @@ "@types/node": "^18.16.3", "@types/react": "18.2.0", "@types/react-native": "0.71.8", + "@types/text-encoding": "^0.0.39", "@typescript-eslint/eslint-plugin": "^6.13.1", "@typescript-eslint/parser": "^6.13.1", "eslint": "^8.54.0", diff --git a/example/src/tests.ts b/example/src/tests.ts index 9bac29fae..6d97a9f39 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -182,13 +182,11 @@ test('can message in a group', async () => { if (bobMessages.length != 2) { throw new Error('num messages for bob should be 2, but it is' + bobMessages.length) } - let messageString: string = JSON.stringify(bobMessages[0]) - if (!messageString.includes("gm")) { - throw new Error('newest Message should include gm') + if (bobMessages[0].content() != "gm") { + throw new Error('newest message should be gm') } - let messageString2: string = JSON.stringify(bobMessages[1]) - if (!messageString2.includes("hello, world")) { - throw new Error('newest Message should include gm') + if (bobMessages[1].content() != "hello, world") { + throw new Error('newest message should be hello, world') } // Bob can send a message bobGroups[0].send("hey guys!") @@ -203,13 +201,11 @@ test('can message in a group', async () => { // Cam can read messages from Alice and Bob await camGroups[0].sync() let camMessages = await camGroups[0].messages() - let messageString3: string = JSON.stringify(camMessages[1]) - if (!messageString3.includes("gm")) { - throw new Error('second Message should include gm') + if (camMessages[1].content() != "gm") { + throw new Error('second Message should be gm') } - let messageString4: string = JSON.stringify(camMessages[0]) - if (!messageString4.includes("hey guys!")) { - throw new Error('newest Message should include hey guys!') + if (camMessages[0].content() != "hey guys!") { + throw new Error('newest Message should be hey guys!') } return true diff --git a/example/yarn.lock b/example/yarn.lock index 4a14f70fc..50b6cee3c 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -6321,6 +6321,11 @@ resolved "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz" integrity sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw== +"@types/text-encoding@^0.0.39": + version "0.0.39" + resolved "https://registry.yarnpkg.com/@types/text-encoding/-/text-encoding-0.0.39.tgz#6f6436ceb843d96a2306a87dc7e2286e62c2177c" + integrity sha512-gRPvgL1aMgP6Pv92Rs310cJvVQ86DSF62E7K30g1FoGmmYWXoNuXT8PV835iAVeiAZkRwr2IW37KuyDn9ljmeA== + "@types/trusted-types@^2.0.2": version "2.0.7" resolved "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz" From a3059dbe9d7e3227d5ba7fcc07709cdc1e595983 Mon Sep 17 00:00:00 2001 From: cameronvoell Date: Wed, 7 Feb 2024 21:34:14 -0600 Subject: [PATCH 3/3] fix: group messages decoded properly --- example/src/tests.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example/src/tests.ts b/example/src/tests.ts index 6d97a9f39..1ce1864ea 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -183,10 +183,10 @@ test('can message in a group', async () => { throw new Error('num messages for bob should be 2, but it is' + bobMessages.length) } if (bobMessages[0].content() != "gm") { - throw new Error('newest message should be gm') + throw new Error('newest message should be \'gm\'') } if (bobMessages[1].content() != "hello, world") { - throw new Error('newest message should be hello, world') + throw new Error('newest message should be \'hello, world\'') } // Bob can send a message bobGroups[0].send("hey guys!") @@ -202,10 +202,10 @@ test('can message in a group', async () => { await camGroups[0].sync() let camMessages = await camGroups[0].messages() if (camMessages[1].content() != "gm") { - throw new Error('second Message should be gm') + throw new Error('second Message should be \'gm\'') } if (camMessages[0].content() != "hey guys!") { - throw new Error('newest Message should be hey guys!') + throw new Error('newest Message should be \'hey guys!\'') } return true