Skip to content

Commit

Permalink
Handle chatroom deletions
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Jan 19, 2025
1 parent e93dfc8 commit 1ca633b
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions frontend/setupChelonia.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,41 @@ const handleDeletedContract = async (contractID: string) => {

switch (cheloniaState.type) {
case 'gi.contracts/chatroom': {
// TODO: Leave chatroom on our identity contract or our group, if we've
// joined.
const identityState = rootGetters.currentIdentityState
if (identityState.chatRooms?.[contractID]) {
// TODO
// Currently missing the ability to leave a DM
} else {
// This is a group chatroom. To determine which group the chatroom
// belongs to, we need to go over each group, since there isn't a
// chatroom->group relationship stored.
const cIDs = Object.entries(identityState.groups || {}).filter(([cID, state]) => {
return !state.hasLeft
}).map(([cID]) => {
return cID
})

for (const cID of cIDs) {
const groupState = await sbp('chelonia/contract/state', cID).catch(() => {})
// If the chatroom isn't part of this group, continue
if (!groupState?.chatRooms?.[contractID]) continue

if (!groupState.chatRooms[contractID].deletedDate) {
// If the chatroom hasn't been 'deleted' in the group, attempt to do
// so now.
await sbp('gi.actions/group/deleteChatRoom', {
contractID: cID,
data: { chatRoomID: contractID }
}).catch(e => {
console.warn(`[handleDeletedContract] ${e.name} thrown by gi.actions/group/deleteChatRoom ${cID} for ${contractID}:`, e)
})
}

// No need to continue in the loop, as chatrooms belong to a single
// group
break
}
}
break
}
case 'gi.contracts/group': {
Expand Down

0 comments on commit 1ca633b

Please sign in to comment.