Skip to content

Commit

Permalink
remove creator inbox id from wrapper since its not performant
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 2, 2024
1 parent ad44835 commit 787ab2d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -752,11 +752,20 @@ class XMTPModule : Module() {
val params =
ConversationParamsWrapper.conversationParamsFromJson(conversationParams ?: "")
val order = getConversationSortOrder(sortOrder ?: "")
val start = Date()
val conversations =
client.conversations.listConversations(order = order, limit = limit)
conversations.map { conversation ->
val end = Date()
logV("LOPI Loaded ${conversations.size} DMs in ${end.time - start.time}ms")

val start2 = Date()
val convos = conversations.map { conversation ->
ConversationContainerWrapper.encode(client, conversation, params)
}
val end2 = Date()
logV("LOPI Encoded ${convos.size} DMs in ${end2.time - start2.time}ms")

convos
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class DmWrapper {
put("version", "DM")
put("topic", dm.topic)
put("peerInboxId", dm.peerInboxId)
if (dmParams.creatorInboxId) put("creatorInboxId", dm.creatorInboxId())
if (dmParams.consentState) {
put("consentState", consentStateToString(dm.consentState()))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class GroupWrapper {
put("createdAt", group.createdAt.time)
put("version", "GROUP")
put("topic", group.topic)
if (groupParams.creatorInboxId) put("creatorInboxId", group.creatorInboxId())
if (groupParams.isActive) put("isActive", group.isActive())
if (groupParams.addedByInboxId) put("addedByInboxId", group.addedByInboxId())
if (groupParams.name) put("name", group.name)
Expand Down Expand Up @@ -51,7 +50,6 @@ class GroupWrapper {
}

class ConversationParamsWrapper(
val creatorInboxId: Boolean = true,
val isActive: Boolean = true,
val addedByInboxId: Boolean = true,
val name: Boolean = true,
Expand All @@ -65,7 +63,6 @@ class ConversationParamsWrapper(
if (conversationParams.isEmpty()) return ConversationParamsWrapper()
val jsonOptions = JsonParser.parseString(conversationParams).asJsonObject
return ConversationParamsWrapper(
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,
if (jsonOptions.has("name")) jsonOptions.get("name").asBoolean else true,
Expand Down
2 changes: 1 addition & 1 deletion example/src/tests/groupPerformanceTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ test('test compare V2 and V3 dms', async () => {
let dms = await davonV3Client.conversations.listConversations()
end = Date.now()
console.log(`Davon loaded ${dms.length} Dms in ${end - start}ms`)
const v3Load = end - start

await createDms(davonV3Client, await createV3Clients(5), 1)

Expand All @@ -152,7 +153,6 @@ test('test compare V2 and V3 dms', async () => {
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,
Expand Down
3 changes: 0 additions & 3 deletions ios/Wrappers/DmWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ struct DmWrapper {
"peerInboxId": try await dm.peerInboxId
]

if conversationParams.creatorInboxId {
result["creatorInboxId"] = try dm.creatorInboxId()
}
if conversationParams.consentState {
result["consentState"] = ConsentWrapper.consentStateToString(state: try dm.consentState())
}
Expand Down
7 changes: 0 additions & 7 deletions ios/Wrappers/GroupWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ struct GroupWrapper {
"topic": group.topic
]

if conversationParams.creatorInboxId {
result["creatorInboxId"] = try group.creatorInboxId()
}
if conversationParams.isActive {
result["isActive"] = try group.isActive()
}
Expand Down Expand Up @@ -60,7 +57,6 @@ struct GroupWrapper {
}

struct ConversationParamsWrapper {
let creatorInboxId: Bool
let isActive: Bool
let addedByInboxId: Bool
let name: Bool
Expand All @@ -70,7 +66,6 @@ struct ConversationParamsWrapper {
let lastMessage: Bool

init(
creatorInboxId: Bool = true,
isActive: Bool = true,
addedByInboxId: Bool = true,
name: Bool = true,
Expand All @@ -79,7 +74,6 @@ struct ConversationParamsWrapper {
consentState: Bool = true,
lastMessage: Bool = false
) {
self.creatorInboxId = creatorInboxId
self.isActive = isActive
self.addedByInboxId = addedByInboxId
self.name = name
Expand All @@ -97,7 +91,6 @@ struct ConversationParamsWrapper {
}

return ConversationParamsWrapper(
creatorInboxId: jsonDict["creatorInboxId"] as? Bool ?? true,
isActive: jsonDict["isActive"] as? Bool ?? true,
addedByInboxId: jsonDict["addedByInboxId"] as? Bool ?? true,
name: jsonDict["name"] as? Bool ?? true,
Expand Down
15 changes: 9 additions & 6 deletions src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export interface GroupParams {
id: string
createdAt: number
members: string[]
creatorInboxId: InboxId
topic: string
name: string
isActive: boolean
Expand All @@ -39,15 +38,13 @@ export class Group<
createdAt: number
version = ConversationVersion.GROUP
topic: string
creatorInboxId: InboxId
name: string
isGroupActive: boolean
addedByInboxId: InboxId
imageUrlSquare: string
description: string
state: ConsentState
lastMessage?: DecodedMessage<ContentTypes>
// pinnedFrameUrl: string

constructor(
client: XMTP.Client<ContentTypes>,
Expand All @@ -58,26 +55,32 @@ export class Group<
this.id = params.id
this.createdAt = params.createdAt
this.topic = params.topic
this.creatorInboxId = params.creatorInboxId
this.name = params.name
this.isGroupActive = params.isActive
this.addedByInboxId = params.addedByInboxId
this.imageUrlSquare = params.imageUrlSquare
this.description = params.description
this.state = params.consentState
this.lastMessage = lastMessage
// this.pinnedFrameUrl = params.pinnedFrameUrl
}

/**
* This method returns an array of inbox ids associated with the group.
* To get the latest member inbox ids from the network, call sync() first.
* @returns {Promise<DecodedMessage<ContentTypes>[]>} A Promise that resolves to an array of DecodedMessage objects.
* @returns {Promise<InboxId[]>} A Promise that resolves to an array of InboxId objects.
*/
async memberInboxIds(): Promise<InboxId[]> {
return XMTP.listMemberInboxIds(this.client, this.id)
}

/**
* This method returns a inbox id associated with the creator of the group.
* @returns {Promise<InboxId>} A Promise that resolves to a InboxId.
*/
async creatorInboxId(): Promise<InboxId> {
return XMTP.creatorInboxId(this.client.inboxId, this.id)
}

/**
* Sends a message to the current group.
*
Expand Down

0 comments on commit 787ab2d

Please sign in to comment.