Use read sync timestamp to do unread bookkeeping
This commit is contained in:
parent
ed92d244b2
commit
fc34cd88b8
3 changed files with 19 additions and 4 deletions
|
@ -115,6 +115,7 @@ export async function onSync(sync: ReadSyncAttributesType): Promise<void> {
|
||||||
|
|
||||||
const message = window.MessageController.register(found.id, found);
|
const message = window.MessageController.register(found.id, found);
|
||||||
const readAt = Math.min(sync.readAt, Date.now());
|
const readAt = Math.min(sync.readAt, Date.now());
|
||||||
|
const newestSentAt = sync.timestamp;
|
||||||
|
|
||||||
// If message is unread, we mark it read. Otherwise, we update the expiration
|
// If message is unread, we mark it read. Otherwise, we update the expiration
|
||||||
// timer to the time specified by the read sync if it's earlier than
|
// timer to the time specified by the read sync if it's earlier than
|
||||||
|
@ -127,7 +128,11 @@ export async function onSync(sync: ReadSyncAttributesType): Promise<void> {
|
||||||
// onReadMessage may result in messages older than this one being
|
// onReadMessage may result in messages older than this one being
|
||||||
// marked read. We want those messages to have the same expire timer
|
// marked read. We want those messages to have the same expire timer
|
||||||
// start time as this one, so we pass the readAt value through.
|
// start time as this one, so we pass the readAt value through.
|
||||||
drop(message.getConversation()?.onReadMessage(message, readAt));
|
drop(
|
||||||
|
message
|
||||||
|
.getConversation()
|
||||||
|
?.onReadMessage(message, readAt, newestSentAt)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// only available during initialization
|
// only available during initialization
|
||||||
|
|
|
@ -3306,7 +3306,11 @@ export class ConversationModel extends window.Backbone
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async onReadMessage(message: MessageModel, readAt?: number): Promise<void> {
|
async onReadMessage(
|
||||||
|
message: MessageModel,
|
||||||
|
readAt?: number,
|
||||||
|
newestSentAt?: number
|
||||||
|
): Promise<void> {
|
||||||
// We mark as read everything older than this message - to clean up old stuff
|
// We mark as read everything older than this message - to clean up old stuff
|
||||||
// still marked unread in the database. If the user generally doesn't read in
|
// still marked unread in the database. If the user generally doesn't read in
|
||||||
// the desktop app, so the desktop app only gets read syncs, we can very
|
// the desktop app, so the desktop app only gets read syncs, we can very
|
||||||
|
@ -3321,7 +3325,7 @@ export class ConversationModel extends window.Backbone
|
||||||
return this.queueJob('onReadMessage', () =>
|
return this.queueJob('onReadMessage', () =>
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
this.markRead(message.get('received_at')!, {
|
this.markRead(message.get('received_at')!, {
|
||||||
newestSentAt: message.get('sent_at'),
|
newestSentAt: newestSentAt || message.get('sent_at'),
|
||||||
sendReadReceipts: false,
|
sendReadReceipts: false,
|
||||||
readAt,
|
readAt,
|
||||||
})
|
})
|
||||||
|
|
|
@ -19,6 +19,7 @@ import { SeenStatus } from '../MessageSeenStatus';
|
||||||
import { SendActionType, sendStateReducer } from '../messages/MessageSendState';
|
import { SendActionType, sendStateReducer } from '../messages/MessageSendState';
|
||||||
import { canConversationBeUnarchived } from './canConversationBeUnarchived';
|
import { canConversationBeUnarchived } from './canConversationBeUnarchived';
|
||||||
import { deleteForEveryone } from './deleteForEveryone';
|
import { deleteForEveryone } from './deleteForEveryone';
|
||||||
|
import { drop } from './drop';
|
||||||
import { handleEditMessage } from './handleEditMessage';
|
import { handleEditMessage } from './handleEditMessage';
|
||||||
import { isGroup } from './whatTypeOfConversation';
|
import { isGroup } from './whatTypeOfConversation';
|
||||||
import { isStory, isTapToView } from '../state/selectors/message';
|
import { isStory, isTapToView } from '../state/selectors/message';
|
||||||
|
@ -167,6 +168,7 @@ export async function modifyTargetMessage(
|
||||||
if (!isFirstRun && message.getPendingMarkRead()) {
|
if (!isFirstRun && message.getPendingMarkRead()) {
|
||||||
const markReadAt = message.getPendingMarkRead();
|
const markReadAt = message.getPendingMarkRead();
|
||||||
message.setPendingMarkRead(undefined);
|
message.setPendingMarkRead(undefined);
|
||||||
|
const newestSentAt = readSync?.timestamp;
|
||||||
|
|
||||||
// This is primarily to allow the conversation to mark all older
|
// This is primarily to allow the conversation to mark all older
|
||||||
// messages as read, as is done when we receive a read sync for
|
// messages as read, as is done when we receive a read sync for
|
||||||
|
@ -175,7 +177,11 @@ export async function modifyTargetMessage(
|
||||||
// We run message when `isFirstRun` is false so that it triggers when the
|
// We run message when `isFirstRun` is false so that it triggers when the
|
||||||
// message and the other ones accompanying it in the batch are fully in
|
// message and the other ones accompanying it in the batch are fully in
|
||||||
// the database.
|
// the database.
|
||||||
void message.getConversation()?.onReadMessage(message, markReadAt);
|
drop(
|
||||||
|
message
|
||||||
|
.getConversation()
|
||||||
|
?.onReadMessage(message, markReadAt, newestSentAt)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for out-of-order view once open syncs
|
// Check for out-of-order view once open syncs
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue