diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DmWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DmWrapper.kt index ba01da00e..eccc85725 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DmWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/DmWrapper.kt @@ -21,9 +21,6 @@ class DmWrapper { put("version", "DM") put("topic", dm.topic) put("peerInboxId", dm.peerInboxId) - if (dmParams.members) { - put("members", dm.members().map { MemberWrapper.encode(it) }) - } if (dmParams.creatorInboxId) put("creatorInboxId", dm.creatorInboxId()) if (dmParams.consentState) { put("consentState", consentStateToString(dm.consentState())) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt index 939d4ad25..961760fe1 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/wrappers/GroupWrapper.kt @@ -20,9 +20,6 @@ class GroupWrapper { put("createdAt", group.createdAt.time) put("version", "GROUP") put("topic", group.topic) - if (groupParams.members) { - put("members", group.members().map { MemberWrapper.encode(it) }) - } if (groupParams.creatorInboxId) put("creatorInboxId", group.creatorInboxId()) if (groupParams.isActive) put("isActive", group.isActive()) if (groupParams.addedByInboxId) put("addedByInboxId", group.addedByInboxId()) @@ -54,7 +51,6 @@ class GroupWrapper { } class ConversationParamsWrapper( - val members: Boolean = true, val creatorInboxId: Boolean = true, val isActive: Boolean = true, val addedByInboxId: Boolean = true, @@ -69,7 +65,6 @@ class ConversationParamsWrapper( if (conversationParams.isEmpty()) return ConversationParamsWrapper() val jsonOptions = JsonParser.parseString(conversationParams).asJsonObject return ConversationParamsWrapper( - if (jsonOptions.has("members")) jsonOptions.get("members").asBoolean else true, if (jsonOptions.has("creatorInboxId")) jsonOptions.get("creatorInboxId").asBoolean else true, if (jsonOptions.has("isActive")) jsonOptions.get("isActive").asBoolean else true, if (jsonOptions.has("addedByInboxId")) jsonOptions.get("addedByInboxId").asBoolean else true, diff --git a/example/src/tests/groupPerformanceTests.ts b/example/src/tests/groupPerformanceTests.ts index a08fbd7d2..48c5d3e12 100644 --- a/example/src/tests/groupPerformanceTests.ts +++ b/example/src/tests/groupPerformanceTests.ts @@ -72,6 +72,7 @@ let boClient: Client let davonV3Client: Client let initialPeers: Client[] let initialGroups: Group[] +let initialV3Peers: Client[] // let initialDms: Dm[] // let initialV2Convos: Conversation[] @@ -86,7 +87,7 @@ async function beforeAll( ;[davonV3Client] = await createV3Clients(1) initialPeers = await createClients(peersSize) - const initialV3Peers = await createV3Clients(peersSize) + initialV3Peers = await createV3Clients(peersSize) boClient = initialPeers[0] initialGroups = await createGroups( @@ -124,313 +125,337 @@ test('test compare V2 and V3 dms', async () => { console.log(`Davon synced ${v2Convos.length} Dms in ${end - start}ms`) start = Date.now() - const dms = await davonV3Client.conversations.listConversations() + let dms = await davonV3Client.conversations.listConversations() end = Date.now() console.log(`Davon loaded ${dms.length} Dms in ${end - start}ms`) - const v3Load = end - start - - assert( - v3Load < v2Load, - 'v3 conversations should load faster than v2 conversations' - ) - - return true -}) - -test('testing large group listings with ordering', async () => { - await beforeAll(1000, 10, 10) - - let start = Date.now() - let groups = await alixClient.conversations.listGroups() - let end = Date.now() - console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) - - await groups[5].send({ text: `Alix message` }) - await groups[50].send({ text: `Alix message` }) - await groups[150].send({ text: `Alix message` }) - await groups[500].send({ text: `Alix message` }) - await groups[700].send({ text: `Alix message` }) - await groups[900].send({ text: `Alix message` }) - - let start2 = Date.now() - let groups2 = await alixClient.conversations.listGroups( - { - members: false, - consentState: false, - description: false, - creatorInboxId: false, - addedByInboxId: false, - isActive: false, - lastMessage: true, - }, - 'lastMessage' - ) - let end2 = Date.now() - console.log(`Alix loaded ${groups2.length} groups in ${end2 - start2}ms`) - assert( - end2 - start2 < end - start, - 'listing 1000 groups without certain fields should take less time' - ) - - start = Date.now() - await alixClient.conversations.syncGroups() - end = Date.now() - console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) - assert( - end - start < 100, - 'syncing 1000 cached groups should take less than a .1 second' - ) - - start = Date.now() - await boClient.conversations.syncGroups() - end = Date.now() - console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) - - start = Date.now() - await boClient.conversations.syncAllGroups() - end = Date.now() - console.log(`Bo synced all ${groups.length} groups in ${end - start}ms`) - assert( - end - start < 30000, - 'Syncing all 1000 groups should take less than a 30 second' - ) - - start = Date.now() - groups = await boClient.conversations.listGroups() - end = Date.now() - console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) - - start2 = Date.now() - groups2 = await boClient.conversations.listGroups( - { - members: false, - consentState: false, - description: false, - creatorInboxId: false, - addedByInboxId: false, - isActive: false, - lastMessage: true, - }, - 'lastMessage' - ) - end2 = Date.now() - console.log(`Bo loaded ${groups2.length} groups in ${end2 - start2}ms`) - assert( - end2 - start2 < end - start, - 'listing 1000 groups without certain fields should take less time' - ) - - return true -}) - -test('testing large group listings', async () => { - await beforeAll(1000) - - let start = Date.now() - let groups = await alixClient.conversations.listGroups() - let end = Date.now() - console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) - assert( - end - start < 3000, - 'listing 1000 groups should take less than a 3 second' - ) - - start = Date.now() - await alixClient.conversations.syncGroups() - end = Date.now() - console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) - assert( - end - start < 100, - 'syncing 1000 cached groups should take less than a .1 second' - ) - - start = Date.now() - await boClient.conversations.syncGroups() - end = Date.now() - console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) - assert( - end - start < 6000, - 'syncing 1000 groups should take less than a 6 second' - ) - - start = Date.now() - groups = await boClient.conversations.listGroups() - end = Date.now() - console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) - assert( - end - start < 3000, - 'loading 1000 groups should take less than a 3 second' - ) - - return true -}) - -test('testing large message listings', async () => { - await beforeAll(1, 2000) - - const alixGroup = initialGroups[0] - let start = Date.now() - let messages = await alixGroup.messages() - let end = Date.now() - console.log(`Alix loaded ${messages.length} messages in ${end - start}ms`) - assert( - end - start < 1000, - 'listing 2000 self messages should take less than a 1 second' - ) - - start = Date.now() - await alixGroup.sync() - end = Date.now() - console.log(`Alix synced ${messages.length} messages in ${end - start}ms`) - assert( - end - start < 100, - 'syncing 2000 self messages should take less than a .1 second' - ) - - await boClient.conversations.syncGroups() - const boGroup = await boClient.conversations.findGroup(alixGroup.id) - start = Date.now() - await boGroup!.sync() - end = Date.now() - console.log(`Bo synced ${messages.length} messages in ${end - start}ms`) - assert( - end - start < 3000, - 'syncing 2000 messages should take less than a 3 second' - ) - - start = Date.now() - messages = await boGroup!.messages() - end = Date.now() - console.log(`Bo loaded ${messages.length} messages in ${end - start}ms`) - assert( - end - start < 1000, - 'loading 2000 messages should take less than a 1 second' - ) - - return true -}) - -test('testing large member listings', async () => { - await beforeAll(1, 1, 50) - - const alixGroup = initialGroups[0] - let start = Date.now() - let members = await alixGroup.members - let end = Date.now() - console.log(`Alix loaded ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'listing 50 members should take less than a .1 second' - ) - start = Date.now() - await alixGroup.sync() - end = Date.now() - console.log(`Alix synced ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'syncing 50 members should take less than a .1 second' - ) + await createDms(davonV3Client, await createV3Clients(5), 1) - await boClient.conversations.syncGroups() - const boGroup = await boClient.conversations.findGroup(alixGroup.id) - start = Date.now() - await boGroup!.sync() - end = Date.now() - console.log(`Bo synced ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'syncing 50 members should take less than a .1 second' - ) + await createV2Convos(alixClient, await createClients(5), 1) start = Date.now() - members = await boGroup!.members + v2Convos = await alixClient.conversations.list() end = Date.now() - console.log(`Bo loaded ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'loading 50 members should take less than a .1 second' - ) - - const [davonClient] = await createClients(1) + console.log(`Alix loaded ${v2Convos.length} v2Convos in ${end - start}ms`) start = Date.now() - await alixGroup.addMembers([davonClient.address]) + v2Convos = await alixClient.conversations.list() end = Date.now() - console.log(`Alix added 1 member in ${end - start}ms`) - assert(end - start < 100, 'adding 1 member should take less than a .1 second') + console.log(`Alix 2nd loaded ${v2Convos.length} v2Convos in ${end - start}ms`) start = Date.now() - members = await alixGroup.members + await davonV3Client.conversations.syncConversations() end = Date.now() - console.log(`Alix loaded ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'loading 50 member should take less than a .1 second' - ) + console.log(`Davon synced ${v2Convos.length} Dms in ${end - start}ms`) start = Date.now() - await boGroup!.sync() + dms = await davonV3Client.conversations.listConversations() end = Date.now() - console.log(`Bo synced ${members.length} members in ${end - start}ms`) - assert( - end - start < 100, - 'syncing 50 member should take less than a .1 second' - ) + console.log(`Davon loaded ${dms.length} Dms in ${end - start}ms`) + const v3Load = end - start - start = Date.now() - members = await boGroup!.members - end = Date.now() - console.log(`Bo loaded ${members.length} members in ${end - start}ms`) assert( - end - start < 100, - 'loading 50 member should take less than a .1 second' + v3Load < v2Load, + 'v3 conversations should load faster than v2 conversations' ) return true }) -test('testing sending message in large group', async () => { - await beforeAll(1, 2000, 100) - - const alixGroup = initialGroups[0] - let start = Date.now() - await alixGroup.send({ text: `Alix message` }) - let end = Date.now() - console.log(`Alix sent a message in ${end - start}ms`) - assert( - end - start < 200, - 'sending a message should take less than a .2 second' - ) - - await boClient.conversations.syncGroups() - const boGroup = await boClient.conversations.findGroup(alixGroup.id) - start = Date.now() - await boGroup!.prepareMessage({ text: `Bo message` }) - end = Date.now() - console.log(`Bo sent a message in ${end - start}ms`) - assert( - end - start < 100, - 'preparing a message should take less than a .1 second' - ) - - start = Date.now() - await boGroup!.sync() - end = Date.now() - console.log(`Bo synced messages in ${end - start}ms`) - assert( - end - start < 9000, - 'syncing 2000 messages should take less than a 9 second' - ) - - start = Date.now() - await boGroup!.send({ text: `Bo message 2` }) - end = Date.now() - console.log(`Bo sent a message in ${end - start}ms`) - assert( - end - start < 100, - 'sending a message should take less than a .1 second' - ) - - return true -}) +// test('testing large group listings with ordering', async () => { +// await beforeAll(1000, 10, 10) + +// let start = Date.now() +// let groups = await alixClient.conversations.listGroups() +// let end = Date.now() +// console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) + +// await groups[5].send({ text: `Alix message` }) +// await groups[50].send({ text: `Alix message` }) +// await groups[150].send({ text: `Alix message` }) +// await groups[500].send({ text: `Alix message` }) +// await groups[700].send({ text: `Alix message` }) +// await groups[900].send({ text: `Alix message` }) + +// let start2 = Date.now() +// let groups2 = await alixClient.conversations.listGroups( +// { +// members: false, +// consentState: false, +// description: false, +// creatorInboxId: false, +// addedByInboxId: false, +// isActive: false, +// lastMessage: true, +// }, +// 'lastMessage' +// ) +// let end2 = Date.now() +// console.log(`Alix loaded ${groups2.length} groups in ${end2 - start2}ms`) +// assert( +// end2 - start2 < end - start, +// 'listing 1000 groups without certain fields should take less time' +// ) + +// start = Date.now() +// await alixClient.conversations.syncGroups() +// end = Date.now() +// console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) +// assert( +// end - start < 100, +// 'syncing 1000 cached groups should take less than a .1 second' +// ) + +// start = Date.now() +// await boClient.conversations.syncGroups() +// end = Date.now() +// console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) + +// start = Date.now() +// await boClient.conversations.syncAllGroups() +// end = Date.now() +// console.log(`Bo synced all ${groups.length} groups in ${end - start}ms`) +// assert( +// end - start < 30000, +// 'Syncing all 1000 groups should take less than a 30 second' +// ) + +// start = Date.now() +// groups = await boClient.conversations.listGroups() +// end = Date.now() +// console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) + +// start2 = Date.now() +// groups2 = await boClient.conversations.listGroups( +// { +// members: false, +// consentState: false, +// description: false, +// creatorInboxId: false, +// addedByInboxId: false, +// isActive: false, +// lastMessage: true, +// }, +// 'lastMessage' +// ) +// end2 = Date.now() +// console.log(`Bo loaded ${groups2.length} groups in ${end2 - start2}ms`) +// assert( +// end2 - start2 < end - start, +// 'listing 1000 groups without certain fields should take less time' +// ) + +// return true +// }) + +// test('testing large group listings', async () => { +// await beforeAll(1000) + +// let start = Date.now() +// let groups = await alixClient.conversations.listGroups() +// let end = Date.now() +// console.log(`Alix loaded ${groups.length} groups in ${end - start}ms`) +// assert( +// end - start < 3000, +// 'listing 1000 groups should take less than a 3 second' +// ) + +// start = Date.now() +// await alixClient.conversations.syncGroups() +// end = Date.now() +// console.log(`Alix synced ${groups.length} groups in ${end - start}ms`) +// assert( +// end - start < 100, +// 'syncing 1000 cached groups should take less than a .1 second' +// ) + +// start = Date.now() +// await boClient.conversations.syncGroups() +// end = Date.now() +// console.log(`Bo synced ${groups.length} groups in ${end - start}ms`) +// assert( +// end - start < 6000, +// 'syncing 1000 groups should take less than a 6 second' +// ) + +// start = Date.now() +// groups = await boClient.conversations.listGroups() +// end = Date.now() +// console.log(`Bo loaded ${groups.length} groups in ${end - start}ms`) +// assert( +// end - start < 3000, +// 'loading 1000 groups should take less than a 3 second' +// ) + +// return true +// }) + +// test('testing large message listings', async () => { +// await beforeAll(1, 2000) + +// const alixGroup = initialGroups[0] +// let start = Date.now() +// let messages = await alixGroup.messages() +// let end = Date.now() +// console.log(`Alix loaded ${messages.length} messages in ${end - start}ms`) +// assert( +// end - start < 1000, +// 'listing 2000 self messages should take less than a 1 second' +// ) + +// start = Date.now() +// await alixGroup.sync() +// end = Date.now() +// console.log(`Alix synced ${messages.length} messages in ${end - start}ms`) +// assert( +// end - start < 100, +// 'syncing 2000 self messages should take less than a .1 second' +// ) + +// await boClient.conversations.syncGroups() +// const boGroup = await boClient.conversations.findGroup(alixGroup.id) +// start = Date.now() +// await boGroup!.sync() +// end = Date.now() +// console.log(`Bo synced ${messages.length} messages in ${end - start}ms`) +// assert( +// end - start < 3000, +// 'syncing 2000 messages should take less than a 3 second' +// ) + +// start = Date.now() +// messages = await boGroup!.messages() +// end = Date.now() +// console.log(`Bo loaded ${messages.length} messages in ${end - start}ms`) +// assert( +// end - start < 1000, +// 'loading 2000 messages should take less than a 1 second' +// ) + +// return true +// }) + +// test('testing large member listings', async () => { +// await beforeAll(1, 1, 50) + +// const alixGroup = initialGroups[0] +// let start = Date.now() +// let members = await alixGroup.members +// let end = Date.now() +// console.log(`Alix loaded ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'listing 50 members should take less than a .1 second' +// ) + +// start = Date.now() +// await alixGroup.sync() +// end = Date.now() +// console.log(`Alix synced ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'syncing 50 members should take less than a .1 second' +// ) + +// await boClient.conversations.syncGroups() +// const boGroup = await boClient.conversations.findGroup(alixGroup.id) +// start = Date.now() +// await boGroup!.sync() +// end = Date.now() +// console.log(`Bo synced ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'syncing 50 members should take less than a .1 second' +// ) + +// start = Date.now() +// members = await boGroup!.members +// end = Date.now() +// console.log(`Bo loaded ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'loading 50 members should take less than a .1 second' +// ) + +// const [davonClient] = await createClients(1) + +// start = Date.now() +// await alixGroup.addMembers([davonClient.address]) +// end = Date.now() +// console.log(`Alix added 1 member in ${end - start}ms`) +// assert(end - start < 100, 'adding 1 member should take less than a .1 second') + +// start = Date.now() +// members = await alixGroup.members +// end = Date.now() +// console.log(`Alix loaded ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'loading 50 member should take less than a .1 second' +// ) + +// start = Date.now() +// await boGroup!.sync() +// end = Date.now() +// console.log(`Bo synced ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'syncing 50 member should take less than a .1 second' +// ) + +// start = Date.now() +// members = await boGroup!.members +// end = Date.now() +// console.log(`Bo loaded ${members.length} members in ${end - start}ms`) +// assert( +// end - start < 100, +// 'loading 50 member should take less than a .1 second' +// ) + +// return true +// }) + +// test('testing sending message in large group', async () => { +// await beforeAll(1, 2000, 100) + +// const alixGroup = initialGroups[0] +// let start = Date.now() +// await alixGroup.send({ text: `Alix message` }) +// let end = Date.now() +// console.log(`Alix sent a message in ${end - start}ms`) +// assert( +// end - start < 200, +// 'sending a message should take less than a .2 second' +// ) + +// await boClient.conversations.syncGroups() +// const boGroup = await boClient.conversations.findGroup(alixGroup.id) +// start = Date.now() +// await boGroup!.prepareMessage({ text: `Bo message` }) +// end = Date.now() +// console.log(`Bo sent a message in ${end - start}ms`) +// assert( +// end - start < 100, +// 'preparing a message should take less than a .1 second' +// ) + +// start = Date.now() +// await boGroup!.sync() +// end = Date.now() +// console.log(`Bo synced messages in ${end - start}ms`) +// assert( +// end - start < 9000, +// 'syncing 2000 messages should take less than a 9 second' +// ) + +// start = Date.now() +// await boGroup!.send({ text: `Bo message 2` }) +// end = Date.now() +// console.log(`Bo sent a message in ${end - start}ms`) +// assert( +// end - start < 100, +// 'sending a message should take less than a .1 second' +// ) + +// return true +// }) diff --git a/ios/Wrappers/DmWrapper.swift b/ios/Wrappers/DmWrapper.swift index 72933339c..6994cc5b4 100644 --- a/ios/Wrappers/DmWrapper.swift +++ b/ios/Wrappers/DmWrapper.swift @@ -19,10 +19,7 @@ struct DmWrapper { "topic": dm.topic, "peerInboxId": try await dm.peerInboxId ] - - if conversationParams.members { - result["members"] = try await dm.members.compactMap { member in return try MemberWrapper.encode(member) } - } + if conversationParams.creatorInboxId { result["creatorInboxId"] = try dm.creatorInboxId() } diff --git a/ios/Wrappers/GroupWrapper.swift b/ios/Wrappers/GroupWrapper.swift index 7460db33a..4a3a943fd 100644 --- a/ios/Wrappers/GroupWrapper.swift +++ b/ios/Wrappers/GroupWrapper.swift @@ -18,10 +18,7 @@ struct GroupWrapper { "version": "GROUP", "topic": group.topic ] - - if conversationParams.members { - result["members"] = try await group.members.compactMap { member in return try MemberWrapper.encode(member) } - } + if conversationParams.creatorInboxId { result["creatorInboxId"] = try group.creatorInboxId() } @@ -63,7 +60,6 @@ struct GroupWrapper { } struct ConversationParamsWrapper { - let members: Bool let creatorInboxId: Bool let isActive: Bool let addedByInboxId: Bool @@ -74,7 +70,6 @@ struct ConversationParamsWrapper { let lastMessage: Bool init( - members: Bool = true, creatorInboxId: Bool = true, isActive: Bool = true, addedByInboxId: Bool = true, @@ -84,7 +79,6 @@ struct ConversationParamsWrapper { consentState: Bool = true, lastMessage: Bool = false ) { - self.members = members self.creatorInboxId = creatorInboxId self.isActive = isActive self.addedByInboxId = addedByInboxId @@ -103,7 +97,6 @@ struct ConversationParamsWrapper { } return ConversationParamsWrapper( - members: jsonDict["members"] as? Bool ?? true, creatorInboxId: jsonDict["creatorInboxId"] as? Bool ?? true, isActive: jsonDict["isActive"] as? Bool ?? true, addedByInboxId: jsonDict["addedByInboxId"] as? Bool ?? true, diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index a869a8309..105524f06 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -651,13 +651,19 @@ public class XMTPModule: Module { let params = ConversationParamsWrapper.conversationParamsFromJson(conversationParams ?? "") let order = getConversationSortOrder(order: sortOrder ?? "") + var start = Date() let conversations = try await client.conversations.listConversations(limit: limit, order: order) - + var end = Date() + print("Loaded \(conversations.count) conversations in \(end.timeIntervalSince(start) * 1000)ms from iOS") + var results: [String] = [] + start = Date() for conversation in conversations { let encodedConversationContainer = try await ConversationContainerWrapper.encode(conversation, client: client) results.append(encodedConversationContainer) } + end = Date() + print("Loaded \(results.count) conversationContainers in \(end.timeIntervalSince(start) * 1000)ms from iOS") return results } diff --git a/src/index.ts b/src/index.ts index f555f1977..f774f1a1b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -327,10 +327,7 @@ export async function findOrCreateDm< const dm = JSON.parse( await XMTPModule.findOrCreateDm(client.inboxId, peerAddress) ) - const members = dm['members']?.map((mem: string) => { - return Member.from(mem) - }) - return new Dm(client, dm, members) + return new Dm(client, dm) } export async function createGroup< @@ -359,10 +356,7 @@ export async function createGroup< ) ) - const members = group['members']?.map((mem: string) => { - return Member.from(mem) - }) - return new Group(client, group, members) + return new Group(client, group) } export async function createGroupCustomPermissions< @@ -390,10 +384,8 @@ export async function createGroupCustomPermissions< JSON.stringify(options) ) ) - const members = group['members']?.map((mem: string) => { - return Member.from(mem) - }) - return new Group(client, group, members) + + return new Group(client, group) } export async function listGroups< @@ -413,13 +405,11 @@ export async function listGroups< ) ).map((json: string) => { const group = JSON.parse(json) - const members = group['members']?.map((mem: string) => { - return Member.from(mem) - }) + const lastMessage = group['lastMessage'] ? DecodedMessage.from(group['lastMessage'], client) : undefined - return new Group(client, group, members, lastMessage) + return new Group(client, group, lastMessage) }) } @@ -440,13 +430,15 @@ export async function listV3Conversations< ) ).map((json: string) => { const jsonObj = JSON.parse(json) - const members = jsonObj.members.map((mem: string) => { - return Member.from(mem) - }) + + const lastMessage = jsonObj['lastMessage'] + ? DecodedMessage.from(jsonObj['lastMessage'], client) + : undefined + if (jsonObj.version === ConversationVersion.GROUP) { - return new Group(client, jsonObj, members) + return new Group(client, jsonObj, lastMessage) } else { - return new Dm(client, jsonObj, members) + return new Dm(client, jsonObj, lastMessage) } }) } @@ -544,11 +536,8 @@ export async function findGroup< if (!group || Object.keys(group).length === 0) { return undefined } - const members = - group['members']?.map((mem: string) => { - return Member.from(mem) - }) || [] - return new Group(client, group, members) + + return new Group(client, group) } export async function findConversation< @@ -562,15 +551,11 @@ export async function findConversation< if (!conversation || Object.keys(conversation).length === 0) { return undefined } - const members = - conversation['members']?.map((mem: string) => { - return Member.from(mem) - }) || [] if (conversation.version === ConversationVersion.GROUP) { - return new Group(client, conversation, members) + return new Group(client, conversation) } else { - return new Dm(client, conversation, members) + return new Dm(client, conversation) } } @@ -585,15 +570,11 @@ export async function findConversationByTopic< if (!conversation || Object.keys(conversation).length === 0) { return undefined } - const members = - conversation['members']?.map((mem: string) => { - return Member.from(mem) - }) || [] if (conversation.version === ConversationVersion.GROUP) { - return new Group(client, conversation, members) + return new Group(client, conversation) } else { - return new Dm(client, conversation, members) + return new Dm(client, conversation) } } @@ -608,11 +589,8 @@ export async function findDm< if (!dm || Object.keys(dm).length === 0) { return undefined } - const members = - dm['members']?.map((mem: string) => { - return Member.from(mem) - }) || [] - return new Dm(client, dm, members) + + return new Dm(client, dm) } export async function findV3Message< @@ -873,10 +851,7 @@ export async function listAll< return list.map((json: string) => { const jsonObj = JSON.parse(json) if (jsonObj.version === ConversationVersion.GROUP) { - const members = jsonObj.members.map((mem: string) => { - return Member.from(mem) - }) - return new Group(client, jsonObj, members) + return new Group(client, jsonObj) } else { return new Conversation(client, jsonObj) } @@ -1494,10 +1469,7 @@ export async function processWelcomeMessage< encryptedMessage ) const group = JSON.parse(json) - const members = group['members']?.map((mem: string) => { - return Member.from(mem) - }) - return new Group(client, group, members) + return new Group(client, group) } export async function processConversationWelcomeMessage< @@ -1511,14 +1483,11 @@ export async function processConversationWelcomeMessage< encryptedMessage ) const conversation = JSON.parse(json) - const members = conversation['members']?.map((mem: string) => { - return Member.from(mem) - }) if (conversation.version === ConversationVersion.GROUP) { - return new Group(client, conversation, members) + return new Group(client, conversation) } else { - return new Dm(client, conversation, members) + return new Dm(client, conversation) } } diff --git a/src/lib/Conversation.ts b/src/lib/Conversation.ts index 972ee5c7b..2bd9a1350 100644 --- a/src/lib/Conversation.ts +++ b/src/lib/Conversation.ts @@ -7,13 +7,13 @@ import { ConversationContainer, } from './ConversationContainer' import { DecodedMessage } from './DecodedMessage' +import { MessagesOptions } from './types' import { ConversationSendPayload } from './types/ConversationCodecs' import { DefaultContentTypes } from './types/DefaultContentType' import { EventTypes } from './types/EventTypes' import { SendOptions } from './types/SendOptions' import * as XMTP from '../index' import { ConversationContext, PreparedLocalMessage } from '../index' -import { MessagesOptions } from './types' export interface ConversationParams { createdAt: number @@ -38,7 +38,7 @@ export class Conversation conversationID?: string | undefined id: string state: ConsentState - + /** * Base64 encoded key material for the conversation. */ @@ -325,7 +325,12 @@ export class Conversation updateConsent(state: ConsentState): Promise { throw new Error('V3 only') } - processMessage(encryptedMessage: string): Promise> { + processMessage( + encryptedMessage: string + ): Promise> { + throw new Error('V3 only') + } + members(): Promise { throw new Error('V3 only') } } diff --git a/src/lib/ConversationContainer.ts b/src/lib/ConversationContainer.ts index a7037d78c..bc0f853f0 100644 --- a/src/lib/ConversationContainer.ts +++ b/src/lib/ConversationContainer.ts @@ -2,7 +2,7 @@ import { ConsentState } from './ConsentListEntry' import { ConversationSendPayload, MessagesOptions } from './types' import { DefaultContentTypes } from './types/DefaultContentType' import * as XMTP from '../index' -import { DecodedMessage } from '../index' +import { DecodedMessage, Member } from '../index' export enum ConversationVersion { DIRECT = 'DIRECT', @@ -34,4 +34,5 @@ export interface ConversationContainer< processMessage( encryptedMessage: string ): Promise> + members(): Promise } diff --git a/src/lib/Dm.ts b/src/lib/Dm.ts index dd9657148..d61609838 100644 --- a/src/lib/Dm.ts +++ b/src/lib/Dm.ts @@ -15,7 +15,6 @@ import * as XMTP from '../index' export interface DmParams { id: string createdAt: number - members: string[] creatorInboxId: InboxId topic: string consentState: ConsentState @@ -28,7 +27,6 @@ export class Dm client: XMTP.Client id: string createdAt: number - members: Member[] version = ConversationVersion.DM topic: string state: ConsentState @@ -37,13 +35,11 @@ export class Dm constructor( client: XMTP.Client, params: DmParams, - members: Member[], lastMessage?: DecodedMessage ) { this.client = client this.id = params.id this.createdAt = params.createdAt - this.members = members this.topic = params.topic this.state = params.consentState this.lastMessage = lastMessage @@ -252,7 +248,7 @@ export class Dm * @returns {Promise} A Promise that resolves to an array of Member objects. * To get the latest member list from the network, call sync() first. */ - async membersList(): Promise { + async members(): Promise { return await XMTP.listConversationMembers(this.client.inboxId, this.id) } } diff --git a/src/lib/Group.ts b/src/lib/Group.ts index 96558ec6b..7b9ac477b 100644 --- a/src/lib/Group.ts +++ b/src/lib/Group.ts @@ -37,7 +37,6 @@ export class Group< client: XMTP.Client id: string createdAt: number - members: Member[] version = ConversationVersion.GROUP topic: string creatorInboxId: InboxId @@ -53,13 +52,11 @@ export class Group< constructor( client: XMTP.Client, params: GroupParams, - members: Member[], lastMessage?: DecodedMessage ) { this.client = client this.id = params.id this.createdAt = params.createdAt - this.members = members this.topic = params.topic this.creatorInboxId = params.creatorInboxId this.name = params.name @@ -648,7 +645,7 @@ export class Group< * @returns {Promise} A Promise that resolves to an array of Member objects. * To get the latest member list from the network, call sync() first. */ - async membersList(): Promise { + async members(): Promise { return await XMTP.listConversationMembers(this.client.inboxId, this.id) } } diff --git a/src/lib/types/GroupOptions.ts b/src/lib/types/GroupOptions.ts index 9dad2ec2d..f084ac944 100644 --- a/src/lib/types/GroupOptions.ts +++ b/src/lib/types/GroupOptions.ts @@ -1,5 +1,4 @@ export type GroupOptions = { - members?: boolean creatorInboxId?: boolean isActive?: boolean addedByInboxId?: boolean