Skip to content

Commit

Permalink
fix(friends): remove conversation attached to friend (#4164)
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmcg authored Aug 9, 2022
1 parent 0db55af commit 0a8ea3c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 10 additions & 2 deletions libraries/Iridium/chat/ChatManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ export default class ChatManager extends Emitter<ConversationMessage> {
}

/**
* @param {string} name new item name
* @param {IridiumDirectory} parent empty string if root element
* @param {string} friendDid
* @description fetch direct conversation id based on friend did.
* significantly faster than Iridium.hash until about 5,000,000 conversation records
*/
Expand Down Expand Up @@ -228,6 +227,15 @@ export default class ChatManager extends Emitter<ConversationMessage> {
}
}

async deleteConversation(id: Conversation['id']) {
if (!this.hasConversation(id)) {
return
}
Vue.delete(this.state.conversations, id)
this.set('/conversations', this.state.conversations)
// todo - do we need to unsubscribe too?
}

getConversation(id: Conversation['id']): Conversation {
const conversation = this.state.conversations[id]
if (!conversation) {
Expand Down
13 changes: 6 additions & 7 deletions libraries/Iridium/friends/FriendsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,14 @@ export default class FriendsManager extends Emitter<IridiumFriendPubsub> {
throw new Error(FriendsError.FRIEND_NOT_FOUND)
}

Vue.delete(this.state.details, didUtils.didString(did))
const didString = didUtils.didString(did)

Vue.delete(this.state.details, didString)
await this.set(`/details`, this.state.details)
const id = await encoding.hash(
[friend.did, this.iridium.connector?.id].sort(),
)
if (id && this.iridium.chat.hasConversation(id)) {
Vue.delete(this.iridium.chat.state.conversations, id)
const id = this.iridium.chat.directConversationIdFromDid(didString)
if (id) {
this.iridium.chat.deleteConversation(id)
}

logger.info(this.loggerTag, 'friend removed', { did, friend })

// Announce to the remote user
Expand Down

0 comments on commit 0a8ea3c

Please sign in to comment.