fix: add interactionNotification when we fail to leave 03 group

pull/3052/head
Audric Ackermann 12 months ago
parent c30fcfd013
commit 0dd0869348
No known key found for this signature in database

@ -444,6 +444,9 @@ export async function showLeaveGroupByConvoId(conversationId: string, name: stri
const admins = conversation.getGroupAdmins(); const admins = conversation.getGroupAdmins();
const isAdmin = admins.includes(UserUtils.getOurPubKeyStrFromCache()); const isAdmin = admins.includes(UserUtils.getOurPubKeyStrFromCache());
const showOnlyGroupAdminWarning = isClosedGroup && isAdmin; const showOnlyGroupAdminWarning = isClosedGroup && isAdmin;
const weAreLastAdmin =
PubKey.is05Pubkey(conversationId) ||
(PubKey.is03Pubkey(conversationId) && isAdmin && admins.length === 1);
const lastMessageInteractionType = conversation.get('lastMessageInteractionType'); const lastMessageInteractionType = conversation.get('lastMessageInteractionType');
const lastMessageInteractionStatus = conversation.get('lastMessageInteractionStatus'); const lastMessageInteractionStatus = conversation.get('lastMessageInteractionStatus');
@ -466,7 +469,7 @@ export async function showLeaveGroupByConvoId(conversationId: string, name: stri
await leaveGroupOrCommunityByConvoId({ await leaveGroupOrCommunityByConvoId({
conversationId, conversationId,
isPublic, isPublic,
sendLeaveMessage: true, sendLeaveMessage: !weAreLastAdmin, // we don't need to send a leave message when we are the last admin: the group is removed.
onClickClose, onClickClose,
}); });
}; };

@ -284,7 +284,11 @@ class ConvoController {
// send the leave message before we delete everything for this group (including the key!) // send the leave message before we delete everything for this group (including the key!)
// Note: if we were kicked, we already lost the authData/secretKey for it, so no need to try to send our message. // Note: if we were kicked, we already lost the authData/secretKey for it, so no need to try to send our message.
if (sendLeaveMessage && !groupInUserGroup?.kicked) { if (sendLeaveMessage && !groupInUserGroup?.kicked) {
await leaveClosedGroup(groupPk, fromSyncMessage); const failedToSendLeaveMessage = await leaveClosedGroup(groupPk, fromSyncMessage);
if (PubKey.is03Pubkey(groupPk) && failedToSendLeaveMessage) {
// this is caught and is adding an interaction notification message
throw new Error('Failed to send our leaving message to 03 group');
}
} }
// a group 03 can be removed fully or kept empty as kicked. // a group 03 can be removed fully or kept empty as kicked.
// when it was pendingInvite, we delete it fully, // when it was pendingInvite, we delete it fully,
@ -595,13 +599,15 @@ class ConvoController {
* *
* Note: `fromSyncMessage` is used to know if we need to send a leave group message to the group first. * Note: `fromSyncMessage` is used to know if we need to send a leave group message to the group first.
* So if the user made the action on this device, fromSyncMessage should be false, but if it happened from a linked device polled update, set this to true. * So if the user made the action on this device, fromSyncMessage should be false, but if it happened from a linked device polled update, set this to true.
*
* @returns true if the message failed to be sent.
*/ */
async function leaveClosedGroup(groupPk: PubkeyType | GroupPubkeyType, fromSyncMessage: boolean) { async function leaveClosedGroup(groupPk: PubkeyType | GroupPubkeyType, fromSyncMessage: boolean) {
const convo = ConvoHub.use().get(groupPk); const convo = ConvoHub.use().get(groupPk);
if (!convo || !convo.isClosedGroup()) { if (!convo || !convo.isClosedGroup()) {
window?.log?.error('Cannot leave non-existing group'); window?.log?.error('Cannot leave non-existing group');
return; return false;
} }
const ourNumber = UserUtils.getOurPubKeyStrFromCache(); const ourNumber = UserUtils.getOurPubKeyStrFromCache();
@ -630,7 +636,7 @@ async function leaveClosedGroup(groupPk: PubkeyType | GroupPubkeyType, fromSyncM
if (fromSyncMessage) { if (fromSyncMessage) {
// no need to send our leave message as our other device should already have sent it. // no need to send our leave message as our other device should already have sent it.
return; return false;
} }
if (PubKey.is03Pubkey(groupPk)) { if (PubKey.is03Pubkey(groupPk)) {
@ -656,6 +662,7 @@ async function leaveClosedGroup(groupPk: PubkeyType | GroupPubkeyType, fromSyncM
window?.log?.info( window?.log?.info(
`We are leaving the group ${ed25519Str(groupPk)}. Sending our leaving messages.` `We are leaving the group ${ed25519Str(groupPk)}. Sending our leaving messages.`
); );
let failedToSent03LeaveMessage = false;
// We might not be able to send our leaving messages (no encryption key pair, we were already removed, no network, etc). // We might not be able to send our leaving messages (no encryption key pair, we were already removed, no network, etc).
// If that happens, we should just remove everything from our current user. // If that happens, we should just remove everything from our current user.
try { try {
@ -683,11 +690,12 @@ async function leaveClosedGroup(groupPk: PubkeyType | GroupPubkeyType, fromSyncM
window?.log?.warn( window?.log?.warn(
`failed to send our leaving messages for ${ed25519Str(groupPk)}:${e.message}` `failed to send our leaving messages for ${ed25519Str(groupPk)}:${e.message}`
); );
failedToSent03LeaveMessage = true;
} }
// the rest of the cleaning of that conversation is done in the `deleteClosedGroup()` // the rest of the cleaning of that conversation is done in the `deleteClosedGroup()`
return; return failedToSent03LeaveMessage;
} }
// TODO remove legacy group support // TODO remove legacy group support
@ -695,7 +703,7 @@ async function leaveClosedGroup(groupPk: PubkeyType | GroupPubkeyType, fromSyncM
if (!keyPair || isEmpty(keyPair) || isEmpty(keyPair.publicHex) || isEmpty(keyPair.privateHex)) { if (!keyPair || isEmpty(keyPair) || isEmpty(keyPair.publicHex) || isEmpty(keyPair.privateHex)) {
// if we do not have a keyPair, we won't be able to send our leaving message neither, so just skip sending it. // if we do not have a keyPair, we won't be able to send our leaving message neither, so just skip sending it.
// this can happen when getting a group from a broken libsession user group wrapper, but not only. // this can happen when getting a group from a broken libsession user group wrapper, but not only.
return; return false;
} }
// Send the update to the group // Send the update to the group
@ -727,6 +735,7 @@ async function leaveClosedGroup(groupPk: PubkeyType | GroupPubkeyType, fromSyncM
)}. But still removing everything related to this group....` )}. But still removing everything related to this group....`
); );
} }
return wasSent;
} }
async function removeLegacyGroupFromWrappers(groupId: string) { async function removeLegacyGroupFromWrappers(groupId: string) {

@ -232,7 +232,7 @@ class GroupInviteJob extends PersistedJob<GroupInvitePersistedData> {
); );
} else { } else {
window?.inboxStore?.dispatch( window?.inboxStore?.dispatch(
groupInfoActions.setInvitePending({ groupPk, pubkey: member, sending: true }) groupInfoActions.setInvitePending({ groupPk, pubkey: member, sending: false })
); );
} }
window?.inboxStore?.dispatch( window?.inboxStore?.dispatch(

Loading…
Cancel
Save