fix: make the delete by author/hashes with adminSig work

pull/3052/head
Audric Ackermann 1 year ago
parent d4f3c7fdc1
commit d282875ac0

@ -19,7 +19,7 @@ import { ToastUtils, UserUtils } from '../../session/utils';
import { closeRightPanel, resetSelectedMessageIds } from '../../state/ducks/conversations';
import { updateConfirmModal } from '../../state/ducks/modalDialog';
import { resetRightOverlayMode } from '../../state/ducks/section';
import { MetaGroupWrapperActions } from '../../webworker/workers/browser/libsession_worker_interface';
import { UserGroupsWrapperActions } from '../../webworker/workers/browser/libsession_worker_interface';
async function unsendMessagesForEveryone1o1AndLegacy(
conversation: ConversationModel,
@ -66,16 +66,22 @@ async function unsendMessagesForEveryone1o1AndLegacy(
}
}
async function unsendMessagesForEveryoneGroupV2(
conversation: ConversationModel,
groupPk: GroupPubkeyType,
msgsToDelete: Array<MessageModel>
) {
async function unsendMessagesForEveryoneGroupV2({
allMessagesFrom,
conversation,
groupPk,
msgsToDelete,
}: {
conversation: ConversationModel;
groupPk: GroupPubkeyType;
msgsToDelete: Array<MessageModel>;
allMessagesFrom: Array<PubkeyType>;
}) {
const messageHashesToUnsend = await getMessageHashes(msgsToDelete);
const group = await MetaGroupWrapperActions.infoGet(groupPk);
const group = await UserGroupsWrapperActions.getGroup(groupPk);
if (!messageHashesToUnsend.length) {
window.log.info('unsendMessagesForEveryoneGroupV2: no hashes to remove');
if (!messageHashesToUnsend.length && !allMessagesFrom.length) {
window.log.info('unsendMessagesForEveryoneGroupV2: no hashes nor author to remove');
return;
}
@ -89,10 +95,10 @@ async function unsendMessagesForEveryoneGroupV2(
expirationType: 'unknown',
expireTimer: 0,
groupPk,
memberSessionIds: [],
memberSessionIds: allMessagesFrom,
messageHashes: messageHashesToUnsend,
sodium: await getSodiumRenderer(),
secretKey: group.secretKey,
secretKey: group?.secretKey || undefined,
}),
});
}
@ -127,7 +133,12 @@ async function unsendMessagesForEveryone(
if (!PubKey.is03Pubkey(destinationId)) {
throw new Error('invalid conversation id (03) for unsendMessageForEveryone');
}
await unsendMessagesForEveryoneGroupV2(conversation, destinationId, msgsToDelete);
await unsendMessagesForEveryoneGroupV2({
conversation,
groupPk: destinationId,
msgsToDelete,
allMessagesFrom: [], // currently we cannot remove all the messages from a specific pubkey
});
}
await deleteMessagesFromSwarmAndCompletelyLocally(conversation, msgsToDelete);
@ -392,9 +403,9 @@ const doDeleteSelectedMessages = async ({
}
// only lookup adminKey if we need to
if (!areAllOurs) {
const group = await MetaGroupWrapperActions.infoGet(convoId);
const weAreAdmin = !isEmpty(group.secretKey);
if (!weAreAdmin) {
const group = await UserGroupsWrapperActions.getGroup(convoId);
const weHaveAdminKey = !isEmpty(group?.secretKey);
if (!weHaveAdminKey) {
ToastUtils.pushMessageDeleteForbidden();
window.inboxStore?.dispatch(resetSelectedMessageIds());
return;

@ -1067,9 +1067,9 @@ function deleteAllMessageFromSendersInConversation(
}
return assertGlobalInstanceOrInstance(instance)
.prepare(
`DELETE FROM ${MESSAGES_TABLE} WHERE conversationId = $conversationId AND source IN ( ${toRemove.map(() => '?').join(', ')} ) RETURNING id`
`DELETE FROM ${MESSAGES_TABLE} WHERE conversationId = ? AND source IN ( ${toRemove.map(() => '?').join(', ')} ) RETURNING id`
)
.all(groupPk, toRemove)
.all(groupPk, ...toRemove)
.map(m => m.id);
}

@ -1,5 +1,5 @@
import { PubkeyType } from 'libsession_util_nodejs';
import { isEmpty } from 'lodash';
import _, { isEmpty } from 'lodash';
import { SignalService } from '../../../../../../protobuf';
import { SnodeNamespaces } from '../../../../../apis/snode_api/namespaces';
import { stringToUint8Array } from '../../../../../utils/String';
@ -55,7 +55,7 @@ export class GroupUpdateDeleteMemberContentMessage extends GroupUpdateMessage {
// If we have the secretKey, we can delete it for anyone `"DELETE_CONTENT" || timestamp || sessionId[0] || ... || messageHashes[0] || ...`
let adminSignature = new Uint8Array();
if (this.secretKey && this.sodium) {
if (this.secretKey && !_.isEmpty(this.secretKey) && this.sodium) {
adminSignature = this.sodium.crypto_sign_detached(
stringToUint8Array(
`DELETE_CONTENT${this.createAtNetworkTimestamp}${this.memberSessionIds.join('')}${this.messageHashes.join('')}`

Loading…
Cancel
Save