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
1 changed files with 33 additions and 0 deletions

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'