Refactor target message for delivery receipt processing

This commit is contained in:
trevor-signal 2023-12-08 15:35:31 -05:00 committed by GitHub
parent e724f36b79
commit c2b1d76e6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 82 additions and 40 deletions

View file

@ -5,9 +5,10 @@ import { isNumber, sortBy } from 'lodash';
import { strictAssert } from './assert';
import type { EditHistoryType } from '../model-types';
import type { MessageModel } from '../models/messages';
import type { EditHistoryType, MessageAttributesType } from '../model-types';
import type { LoggerType } from '../types/Logging';
import { getMessageIdForLogging } from './idForLogging';
import type { MessageModel } from '../models/messages';
// 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.
@ -51,13 +52,18 @@ export function getPropForTimestamp<T extends keyof EditHistoryType>({
targetTimestamp,
}: {
log: LoggerType;
message: MessageModel;
message: MessageModel | MessageAttributesType;
prop: T;
targetTimestamp: number;
}): EditHistoryType[T] {
const logId = `getPropForTimestamp(${message.idForLogging()}, target=${targetTimestamp}})`;
const attributes =
message instanceof window.Whisper.Message ? message.attributes : message;
const editHistory = message.get('editHistory');
const logId = `getPropForTimestamp(${getMessageIdForLogging(
attributes
)}, target=${targetTimestamp}})`;
const { editHistory } = attributes;
const targetEdit = editHistory?.find(
item => item.timestamp === targetTimestamp
);
@ -65,7 +71,7 @@ export function getPropForTimestamp<T extends keyof EditHistoryType>({
if (editHistory) {
log.warn(`${logId}: No edit found, using top-level data`);
}
return message.get(prop);
return attributes[prop];
}
return targetEdit[prop];