Sort message-initiated timer updates before the initiating message
This commit is contained in:
parent
918616e6ab
commit
e62606361d
3 changed files with 18 additions and 22 deletions
|
@ -2618,13 +2618,10 @@ export async function startApp(): Promise<void> {
|
|||
const { expireTimer } = details;
|
||||
const isValidExpireTimer = typeof expireTimer === 'number';
|
||||
if (isValidExpireTimer) {
|
||||
const ourId = window.ConversationController.getOurConversationId();
|
||||
const receivedAt = Date.now();
|
||||
|
||||
await conversation.updateExpirationTimer(
|
||||
expireTimer,
|
||||
ourId,
|
||||
receivedAt,
|
||||
window.ConversationController.getOurConversationId(),
|
||||
undefined,
|
||||
{
|
||||
fromSync: true,
|
||||
}
|
||||
|
@ -2717,11 +2714,10 @@ export async function startApp(): Promise<void> {
|
|||
return;
|
||||
}
|
||||
|
||||
const receivedAt = Date.now();
|
||||
await conversation.updateExpirationTimer(
|
||||
expireTimer,
|
||||
window.ConversationController.getOurConversationId(),
|
||||
receivedAt,
|
||||
undefined,
|
||||
{
|
||||
fromSync: true,
|
||||
}
|
||||
|
|
|
@ -4396,11 +4396,13 @@ export class ConversationModel extends window.Backbone
|
|||
async updateExpirationTimer(
|
||||
providedExpireTimer: number | undefined,
|
||||
providedSource?: unknown,
|
||||
receivedAt?: number,
|
||||
initiatingMessage?: MessageModel,
|
||||
options: { fromSync?: unknown; fromGroupUpdate?: unknown } = {}
|
||||
): Promise<boolean | null | MessageModel | void> {
|
||||
const isSetByOther = providedSource || initiatingMessage;
|
||||
|
||||
if (isGroupV2(this.attributes)) {
|
||||
if (providedSource || receivedAt) {
|
||||
if (isSetByOther) {
|
||||
throw new Error(
|
||||
'updateExpirationTimer: GroupV2 timers are not updated this way'
|
||||
);
|
||||
|
@ -4444,7 +4446,7 @@ export class ConversationModel extends window.Backbone
|
|||
});
|
||||
|
||||
// if change wasn't made remotely, send it to the number/group
|
||||
if (!receivedAt) {
|
||||
if (!isSetByOther) {
|
||||
try {
|
||||
await conversationJobQueue.add({
|
||||
type: conversationQueueJobEnum.enum.DirectExpirationTimerUpdate,
|
||||
|
@ -4464,7 +4466,11 @@ export class ConversationModel extends window.Backbone
|
|||
|
||||
// When we add a disappearing messages notification to the conversation, we want it
|
||||
// to be above the message that initiated that change, hence the subtraction.
|
||||
const timestamp = (receivedAt || Date.now()) - 1;
|
||||
const receivedAt =
|
||||
initiatingMessage?.get('received_at') ||
|
||||
window.Signal.Util.incrementMessageCounter();
|
||||
const receivedAtMS = initiatingMessage?.get('received_at_ms') || Date.now();
|
||||
const sentAt = (initiatingMessage?.get('sent_at') || receivedAtMS) - 1;
|
||||
|
||||
this.set({ expireTimer });
|
||||
|
||||
|
@ -4480,9 +4486,9 @@ export class ConversationModel extends window.Backbone
|
|||
readStatus: ReadStatus.Unread,
|
||||
conversationId: this.id,
|
||||
// No type; 'incoming' messages are specially treated by conversation.markRead()
|
||||
sent_at: timestamp,
|
||||
received_at: window.Signal.Util.incrementMessageCounter(),
|
||||
received_at_ms: timestamp,
|
||||
sent_at: sentAt,
|
||||
received_at: receivedAt,
|
||||
received_at_ms: receivedAtMS,
|
||||
flags: Proto.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
|
||||
expirationTimerUpdate: {
|
||||
expireTimer,
|
||||
|
|
|
@ -2480,8 +2480,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
conversation.updateExpirationTimer(
|
||||
dataMessage.expireTimer,
|
||||
source,
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
message.getReceivedAt()!,
|
||||
message,
|
||||
{
|
||||
fromGroupUpdate: isGroupUpdate(message.attributes),
|
||||
}
|
||||
|
@ -2492,12 +2491,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
|||
// We only turn off timers if it's not a group update
|
||||
!isGroupUpdate(message.attributes)
|
||||
) {
|
||||
conversation.updateExpirationTimer(
|
||||
undefined,
|
||||
source,
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
message.getReceivedAt()!
|
||||
);
|
||||
conversation.updateExpirationTimer(undefined, source, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue