Skip to content

Commit

Permalink
Expire Timer: If we generated change, don't mark unread
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Sep 6, 2022
1 parent 6a1b6f2 commit 56ffd7b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion ts/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2778,9 +2778,11 @@ export async function startApp(): Promise<void> {
}

await conversation.updateExpirationTimer(expireTimer, {
// Note: because it's our conversationId, this notification will be marked read. But
// setting this will make 'isSetByOther' check true.
source: window.ConversationController.getOurConversationId(),
fromSync: true,
receivedAt: ev.receivedAtCounter,
source: window.ConversationController.getOurConversationId(),
reason: 'group sync',
});
}
Expand Down
11 changes: 9 additions & 2 deletions ts/models/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4428,7 +4428,9 @@ export class ConversationModel extends window.Backbone
}
}

source = source || window.ConversationController.getOurConversationId();
const ourConversationId =
window.ConversationController.getOurConversationId();
source = source || ourConversationId;

this.set({ expireTimer });

Expand All @@ -4442,8 +4444,13 @@ export class ConversationModel extends window.Backbone
// to be above the message that initiated that change, hence the subtraction.
const sentAt = (providedSentAt || receivedAtMS) - 1;

const isFromSyncOperation =
reason === 'group sync' || reason === 'contact sync';
const isFromMe =
window.ConversationController.get(source)?.id === ourConversationId;
const isNoteToSelf = isMe(this.attributes);
const shouldBeRead = isNoteToSelf || isInitialSync;
const shouldBeRead =
(isInitialSync && isFromSyncOperation) || isFromMe || isNoteToSelf;

const model = new window.Whisper.Message({
conversationId: this.id,
Expand Down
4 changes: 2 additions & 2 deletions ts/models/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2663,7 +2663,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
// point and these calls will return early.
if (dataMessage.expireTimer) {
conversation.updateExpirationTimer(dataMessage.expireTimer, {
source,
source: sourceUuid || source,
receivedAt: message.get('received_at'),
receivedAtMS: message.get('received_at_ms'),
sentAt: message.get('sent_at'),
Expand All @@ -2676,7 +2676,7 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
!isEndSession(message.attributes)
) {
conversation.updateExpirationTimer(undefined, {
source,
source: sourceUuid || source,
receivedAt: message.get('received_at'),
receivedAtMS: message.get('received_at_ms'),
sentAt: message.get('sent_at'),
Expand Down
2 changes: 2 additions & 0 deletions ts/services/contactSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ async function updateConversationFromContactSync(

// expireTimer isn't in Storage Service so we have to rely on contact sync.
await conversation.updateExpirationTimer(details.expireTimer, {
// Note: because it's our conversationId, this notification will be marked read. But
// setting this will make 'isSetByOther' check true.
source: window.ConversationController.getOurConversationId(),
receivedAt: receivedAtCounter,
fromSync: true,
Expand Down

0 comments on commit 56ffd7b

Please sign in to comment.