You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-desktop/ts/session/apis/snode_api/factories/DeleteGroupHashesRequestFac...

36 lines
1.1 KiB
TypeScript

import { UserGroupsGet } from 'libsession_util_nodejs';
import { isEmpty } from 'lodash';
import { ed25519Str } from '../../../utils/String';
import { DeleteHashesFromGroupNodeSubRequest } from '../SnodeRequestTypes';
function makeGroupHashesToDeleteSubRequest({
messagesHashes,
group,
}: {
group: Pick<UserGroupsGet, 'secretKey' | 'pubkeyHex'>;
messagesHashes: Set<string>;
}) {
const groupPk = group.pubkeyHex;
const messagesHashesArr = [...messagesHashes];
if (messagesHashesArr.length) {
if (!group.secretKey || isEmpty(group.secretKey)) {
window.log.debug(
`makeGroupHashesToDeleteSubRequest: ${ed25519Str(groupPk)}: messagesHashesArr not empty but we do not have the secretKey`
);
throw new Error(
'makeGroupHashesToDeleteSubRequest: messagesHashesArr not empty but we do not have the secretKey'
);
}
return new DeleteHashesFromGroupNodeSubRequest({
messagesHashes: messagesHashesArr,
groupPk,
secretKey: group.secretKey,
});
}
return undefined;
}
export const DeleteGroupHashesFactory = { makeGroupHashesToDeleteSubRequest };