sendSyncMessage: Check timestamp, don't check sent status

This commit is contained in:
Scott Nonnenberg 2023-11-28 16:37:34 -08:00 committed by GitHub
parent 09ec45a125
commit c3a4a0bb31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 25 deletions

View file

@ -155,11 +155,8 @@ import { getSenderIdentifier } from '../util/getSenderIdentifier';
import { getNotificationDataForMessage } from '../util/getNotificationDataForMessage';
import { getNotificationTextForMessage } from '../util/getNotificationTextForMessage';
import { getMessageAuthorText } from '../util/getMessageAuthorText';
import {
getPropForTimestamp,
setPropForTimestamp,
hasEditBeenSent,
} from '../util/editHelpers';
import { getPropForTimestamp, setPropForTimestamp } from '../util/editHelpers';
import { getMessageSentTimestamp } from '../util/getMessageSentTimestamp';
/* eslint-disable more/no-then */
@ -1228,8 +1225,14 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
if (!dataMessage) {
return;
}
const wasEditSent = hasEditBeenSent(this);
const isUpdate = Boolean(this.get('synced')) && !wasEditSent;
const originalTimestamp = getMessageSentTimestamp(this.attributes, {
includeEdits: false,
log,
});
const isSendingEdit = targetTimestamp !== originalTimestamp;
const isUpdate = Boolean(this.get('synced')) && !isSendingEdit;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const conv = this.getConversation()!;
@ -1261,7 +1264,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
map(conversationsWithSealedSender, c => c.id)
);
const encodedContent = wasEditSent
const encodedContent = isSendingEdit
? {
encodedEditMessage: dataMessage,
}

View file

@ -4,28 +4,11 @@
import { isNumber, sortBy } from 'lodash';
import { strictAssert } from './assert';
import { isSent } from '../messages/MessageSendState';
import type { EditHistoryType } from '../model-types';
import type { MessageModel } from '../models/messages';
import type { LoggerType } from '../types/Logging';
export function hasEditBeenSent(message: MessageModel): boolean {
const originalTimestamp = message.get('timestamp');
const editHistory = message.get('editHistory') || [];
return Boolean(
editHistory.find(item => {
if (item.timestamp === originalTimestamp) {
return false;
}
return Object.values(item.sendStateByConversationId || {}).some(
sendState => isSent(sendState.status)
);
})
);
}
// The tricky bit for this function is if we are on our second+ attempt to send a given
// edit, we're still sending that edit.
export function getTargetOfThisEditTimestamp({