Assert that retried UUID is still part of dlist

This commit is contained in:
Josh Perez 2022-08-23 12:37:16 -04:00 committed by GitHub
parent a52bb25731
commit 413b6dbd5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,6 +8,7 @@ import {
import { isBoolean, isNumber } from 'lodash';
import * as Bytes from '../Bytes';
import dataInterface from '../sql/Client';
import { isProduction } from './version';
import { strictAssert } from './assert';
import { getSendOptions } from './getSendOptions';
@ -143,6 +144,38 @@ export async function onRetryRequest(event: RetryRequestEvent): Promise<void> {
timestamp,
});
// Assert that the requesting UUID is still part of a distribution list that
// the message was sent to.
if (contentProto.storyMessage) {
const { storyDistributionLists } = window.reduxStore.getState();
const membersByListId = new Map<string, Set<string>>();
storyDistributionLists.distributionLists.forEach(list => {
membersByListId.set(list.id, new Set(list.memberUuids));
});
const messages = await dataInterface.getMessagesBySentAt(timestamp);
const isInDistributionList = messages.some(message => {
if (!message.storyDistributionListId) {
return false;
}
const members = membersByListId.get(message.storyDistributionListId);
if (!members) {
return false;
}
return members.has(requesterUuid);
});
if (!isInDistributionList) {
log.warn(
`onRetryRequest/${logId}: requesterUuid is not in distribution list`
);
confirm();
return;
}
}
const recipientConversation = window.ConversationController.getOrCreate(
requesterUuid,
'private'