Skip to content

Commit

Permalink
Merge pull request #610 from xmtp/ar/new-conversation-priorities
Browse files Browse the repository at this point in the history
fix: update priority in newConversation method
  • Loading branch information
alexrisch authored May 16, 2024
2 parents ff156df + aec9641 commit da4703e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-trains-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@xmtp/xmtp-js": patch
---

Updated priorities on newConversation method
23 changes: 12 additions & 11 deletions packages/js-sdk/src/conversations/Conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,18 @@ export default class Conversations<ContentTypes = any> {
context?: InvitationContext,
consentProof?: invitation.ConsentProofPayload
): Promise<Conversation<ContentTypes>> {
// Define a function for matching V2 conversations
const matcherFn = (convo: Conversation<ContentTypes>) =>
convo.peerAddress.toLowerCase() === peerAddress.toLowerCase() &&
isMatchingContext(context, convo.context ?? undefined)

// Check if we already have a V2 conversation with the peer in keystore
const existing = await this.getV2ConversationsFromKeystore()
const existingMatch = existing.find(matcherFn)
if (existingMatch) {
return existingMatch
}

let contact = await this.client.getUserContact(peerAddress)
if (!contact) {
throw new Error(`Recipient ${peerAddress} is not on the XMTP network`)
Expand Down Expand Up @@ -521,17 +533,6 @@ export default class Conversations<ContentTypes = any> {
contact = SignedPublicKeyBundle.fromLegacyBundle(contact)
}

// Define a function for matching V2 conversations
const matcherFn = (convo: Conversation<ContentTypes>) =>
convo.peerAddress.toLowerCase() === peerAddress.toLowerCase() &&
isMatchingContext(context, convo.context ?? undefined)

const existing = await this.getV2ConversationsFromKeystore()
const existingMatch = existing.find(matcherFn)
if (existingMatch) {
return existingMatch
}

return this.v2JobRunner.run(async (lastRun) => {
const newItems = await this.updateV2Conversations(lastRun)
const newItemMatch = newItems.find(matcherFn)
Expand Down

0 comments on commit da4703e

Please sign in to comment.