Send just sync message if we've already sent to all recipients

This commit is contained in:
Scott Nonnenberg 2022-05-31 16:20:45 -07:00 committed by GitHub
parent a88560183b
commit 16d180efac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View file

@ -108,6 +108,7 @@ export async function sendNormalMessage(
const {
allRecipientIdentifiers,
recipientIdentifiersWithoutMe,
sentRecipientIdentifiers,
untrustedUuids,
} = getMessageRecipients({
log,
@ -151,9 +152,13 @@ export async function sendNormalMessage(
let messageSendPromise: Promise<CallbackResultType | void>;
if (recipientIdentifiersWithoutMe.length === 0) {
if (!isMe(conversation.attributes) && !isGroup(conversation.attributes)) {
if (
!isMe(conversation.attributes) &&
!isGroup(conversation.attributes) &&
sentRecipientIdentifiers.length === 0
) {
log.info(
'No recipients, but we are not sending to ourselves or to group. Failing job.'
'No recipients; not sending to ourselves or to group, and no successful sends. Failing job.'
);
markMessageFailed(message, [new Error('No valid recipients')]);
return;
@ -337,20 +342,18 @@ function getMessageRecipients({
}>): {
allRecipientIdentifiers: Array<string>;
recipientIdentifiersWithoutMe: Array<string>;
sentRecipientIdentifiers: Array<string>;
untrustedUuids: Array<string>;
} {
const allRecipientIdentifiers: Array<string> = [];
const recipientIdentifiersWithoutMe: Array<string> = [];
const untrustedUuids: Array<string> = [];
const sentRecipientIdentifiers: Array<string> = [];
const currentConversationRecipients = conversation.getMemberConversationIds();
Object.entries(message.get('sendStateByConversationId') || {}).forEach(
([recipientConversationId, sendState]) => {
if (isSent(sendState.status)) {
return;
}
const recipient = window.ConversationController.get(
recipientConversationId
);
@ -387,6 +390,11 @@ function getMessageRecipients({
return;
}
if (isSent(sendState.status)) {
sentRecipientIdentifiers.push(recipientIdentifier);
return;
}
allRecipientIdentifiers.push(recipientIdentifier);
if (!isRecipientMe) {
recipientIdentifiersWithoutMe.push(recipientIdentifier);
@ -397,6 +405,7 @@ function getMessageRecipients({
return {
allRecipientIdentifiers,
recipientIdentifiersWithoutMe,
sentRecipientIdentifiers,
untrustedUuids,
};
}

View file

@ -1581,6 +1581,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
this.set({
// This is the same as a normal send()
expirationStartTimestamp: Date.now(),
errors: [],
});
const result = await this.sendSyncMessage();
this.set({