Skip to content

Commit

Permalink
Merge pull request #245 from xmtp/ar/group-messages
Browse files Browse the repository at this point in the history
Group Messages Decoding
  • Loading branch information
cameronvoell authored Feb 8, 2024
2 parents dd6b260 + a3059db commit 2e532b4
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 8 additions & 12 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 13 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ 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'
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

Expand Down Expand Up @@ -119,10 +119,13 @@ export async function sendMessageToGroup(
}

export async function groupMessages(
clientAddress: string,
client: Client<any>,
id: string
): Promise<DecodedMessage[]> {
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) {
Expand Down Expand Up @@ -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 }
2 changes: 1 addition & 1 deletion src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Group<ContentTypes> {
}

async messages(): Promise<DecodedMessage[]> {
return await XMTP.groupMessages(this.client.address, this.id)
return await XMTP.groupMessages(this.client, this.id)
}

async sync() {
Expand Down

0 comments on commit 2e532b4

Please sign in to comment.