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 { expireTimer } = details;
|
||||||
const isValidExpireTimer = typeof expireTimer === 'number';
|
const isValidExpireTimer = typeof expireTimer === 'number';
|
||||||
if (isValidExpireTimer) {
|
if (isValidExpireTimer) {
|
||||||
const ourId = window.ConversationController.getOurConversationId();
|
|
||||||
const receivedAt = Date.now();
|
|
||||||
|
|
||||||
await conversation.updateExpirationTimer(
|
await conversation.updateExpirationTimer(
|
||||||
expireTimer,
|
expireTimer,
|
||||||
ourId,
|
window.ConversationController.getOurConversationId(),
|
||||||
receivedAt,
|
undefined,
|
||||||
{
|
{
|
||||||
fromSync: true,
|
fromSync: true,
|
||||||
}
|
}
|
||||||
|
@ -2717,11 +2714,10 @@ export async function startApp(): Promise<void> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const receivedAt = Date.now();
|
|
||||||
await conversation.updateExpirationTimer(
|
await conversation.updateExpirationTimer(
|
||||||
expireTimer,
|
expireTimer,
|
||||||
window.ConversationController.getOurConversationId(),
|
window.ConversationController.getOurConversationId(),
|
||||||
receivedAt,
|
undefined,
|
||||||
{
|
{
|
||||||
fromSync: true,
|
fromSync: true,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4396,11 +4396,13 @@ export class ConversationModel extends window.Backbone
|
||||||
async updateExpirationTimer(
|
async updateExpirationTimer(
|
||||||
providedExpireTimer: number | undefined,
|
providedExpireTimer: number | undefined,
|
||||||
providedSource?: unknown,
|
providedSource?: unknown,
|
||||||
receivedAt?: number,
|
initiatingMessage?: MessageModel,
|
||||||
options: { fromSync?: unknown; fromGroupUpdate?: unknown } = {}
|
options: { fromSync?: unknown; fromGroupUpdate?: unknown } = {}
|
||||||
): Promise<boolean | null | MessageModel | void> {
|
): Promise<boolean | null | MessageModel | void> {
|
||||||
|
const isSetByOther = providedSource || initiatingMessage;
|
||||||
|
|
||||||
if (isGroupV2(this.attributes)) {
|
if (isGroupV2(this.attributes)) {
|
||||||
if (providedSource || receivedAt) {
|
if (isSetByOther) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'updateExpirationTimer: GroupV2 timers are not updated this way'
|
'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 change wasn't made remotely, send it to the number/group
|
||||||
if (!receivedAt) {
|
if (!isSetByOther) {
|
||||||
try {
|
try {
|
||||||
await conversationJobQueue.add({
|
await conversationJobQueue.add({
|
||||||
type: conversationQueueJobEnum.enum.DirectExpirationTimerUpdate,
|
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
|
// 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.
|
// 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 });
|
this.set({ expireTimer });
|
||||||
|
|
||||||
|
@ -4480,9 +4486,9 @@ export class ConversationModel extends window.Backbone
|
||||||
readStatus: ReadStatus.Unread,
|
readStatus: ReadStatus.Unread,
|
||||||
conversationId: this.id,
|
conversationId: this.id,
|
||||||
// No type; 'incoming' messages are specially treated by conversation.markRead()
|
// No type; 'incoming' messages are specially treated by conversation.markRead()
|
||||||
sent_at: timestamp,
|
sent_at: sentAt,
|
||||||
received_at: window.Signal.Util.incrementMessageCounter(),
|
received_at: receivedAt,
|
||||||
received_at_ms: timestamp,
|
received_at_ms: receivedAtMS,
|
||||||
flags: Proto.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
|
flags: Proto.DataMessage.Flags.EXPIRATION_TIMER_UPDATE,
|
||||||
expirationTimerUpdate: {
|
expirationTimerUpdate: {
|
||||||
expireTimer,
|
expireTimer,
|
||||||
|
|
|
@ -2480,8 +2480,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
|
||||||
conversation.updateExpirationTimer(
|
conversation.updateExpirationTimer(
|
||||||
dataMessage.expireTimer,
|
dataMessage.expireTimer,
|
||||||
source,
|
source,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
message,
|
||||||
message.getReceivedAt()!,
|
|
||||||
{
|
{
|
||||||
fromGroupUpdate: isGroupUpdate(message.attributes),
|
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
|
// We only turn off timers if it's not a group update
|
||||||
!isGroupUpdate(message.attributes)
|
!isGroupUpdate(message.attributes)
|
||||||
) {
|
) {
|
||||||
conversation.updateExpirationTimer(
|
conversation.updateExpirationTimer(undefined, source, message);
|
||||||
undefined,
|
|
||||||
source,
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
message.getReceivedAt()!
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue