Discard invalid story replies

This commit is contained in:
Josh Perez 2022-11-09 22:52:53 -05:00 committed by GitHub
parent 42a1394039
commit cd1a1a00a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 0 deletions

View file

@ -109,6 +109,7 @@ export function sendStateReducer(
return newStatus === oldStatus
? state
: {
...state,
status: newStatus,
updatedAt: action.updatedAt,
};

View file

@ -2522,6 +2522,59 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
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,