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..1ce1864ea 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" 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() {