From cd1a1a00a2b057a9c4677bb9d305bcdbbc9805ce Mon Sep 17 00:00:00 2001 From: Josh Perez <60019601+josh-signal@users.noreply.github.com> Date: Wed, 9 Nov 2022 22:52:53 -0500 Subject: [PATCH] Discard invalid story replies --- ts/messages/MessageSendState.ts | 1 + ts/models/messages.ts | 53 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/ts/messages/MessageSendState.ts b/ts/messages/MessageSendState.ts index 4f0fb69b215..38e53f6705f 100644 --- a/ts/messages/MessageSendState.ts +++ b/ts/messages/MessageSendState.ts @@ -109,6 +109,7 @@ export function sendStateReducer( return newStatus === oldStatus ? state : { + ...state, status: newStatus, updatedAt: action.updatedAt, }; diff --git a/ts/models/messages.ts b/ts/models/messages.ts index b9bea5a3307..07752cb1063 100644 --- a/ts/models/messages.ts +++ b/ts/models/messages.ts @@ -2522,6 +2522,59 @@ export class MessageModel extends window.Backbone.Model { return; } + if (storyQuote) { + const sendStateByConversationId = + storyQuote.get('sendStateByConversationId') || {}; + const sendState = sendStateByConversationId[sender.id]; + + if (!sendState) { + log.warn( + `${idLog}: Received storyContext message but sender was not in sendStateByConversationId. Dropping.` + ); + + confirm(); + return; + } + + if (sendState.isAllowedToReplyToStory === false) { + log.warn( + `${idLog}: Received storyContext message but sender is not allowed to reply. Dropping.` + ); + + confirm(); + return; + } + + const storyDistributionListId = storyQuote.get( + 'storyDistributionListId' + ); + + if (storyDistributionListId) { + const storyDistribution = + await dataInterface.getStoryDistributionWithMembers( + storyDistributionListId + ); + + if (!storyDistribution) { + log.warn( + `${idLog}: Received storyContext message for story with no associated distribution list. Dropping.` + ); + + confirm(); + return; + } + + if (!storyDistribution.allowsReplies) { + log.warn( + `${idLog}: Received storyContext message but distribution list does not allow replies. Dropping.` + ); + + confirm(); + return; + } + } + } + const withQuoteReference = { ...message.attributes, ...initialMessage,