From 4b8778d071806f6acdea08c38ce624f976f643b0 Mon Sep 17 00:00:00 2001 From: audric Date: Tue, 27 Jul 2021 11:16:23 +1000 Subject: [PATCH] fix markRead using timestamp of now when scroll to bottom --- app/sql.js | 1 - .../session/conversation/SessionMessagesListContainer.tsx | 4 ++-- ts/models/conversation.ts | 7 +++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/sql.js b/app/sql.js index 7ddb8a210..24d3a5fd7 100644 --- a/app/sql.js +++ b/app/sql.js @@ -1185,7 +1185,6 @@ function updateToLokiSchemaVersion15(currentVersion, db) { db.transaction(() => { db.exec(` DROP TABLE pairingAuthorisations; - DROP TABLE ${MESSAGES_FTS_TABLE}; DROP TRIGGER messages_on_delete; DROP TRIGGER messages_on_update; `); diff --git a/ts/components/session/conversation/SessionMessagesListContainer.tsx b/ts/components/session/conversation/SessionMessagesListContainer.tsx index 81adf29d3..f4c72bde0 100644 --- a/ts/components/session/conversation/SessionMessagesListContainer.tsx +++ b/ts/components/session/conversation/SessionMessagesListContainer.tsx @@ -174,7 +174,7 @@ class SessionMessagesListContainerInner extends React.Component { } if ((forceIsOnBottom || this.getScrollOffsetBottomPx() === 0) && isElectronWindowFocused()) { - void conversation.markRead(messagesProps[0].propsForMessage.receivedAt || 0).then(() => { + void conversation.markRead(Date.now()).then(() => { window.inboxStore?.dispatch(markConversationFullyRead(conversationKey)); }); } @@ -372,7 +372,7 @@ class SessionMessagesListContainerInner extends React.Component { const conversation = getConversationController().get(conversationKey); if (isElectronWindowFocused()) { - void conversation.markRead(messagesProps[0].propsForMessage.receivedAt || 0).then(() => { + void conversation.markRead(Date.now()).then(() => { window.inboxStore?.dispatch(markConversationFullyRead(conversationKey)); }); } diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 2bfb47f22..8d3edfab1 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -198,7 +198,10 @@ export class ConversationModel extends Backbone.Model { }); this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000, trailing: true }); //start right away the function is called, and wait 1sec before calling it again - const markReadDebounced = _.debounce(this.markReadBouncy, 1000, { leading: true }); + const markReadDebounced = _.debounce(this.markReadBouncy, 1000, { + leading: true, + trailing: true, + }); // tslint:disable-next-line: no-async-without-await this.markRead = async (newestUnreadDate: number) => { const lastReadTimestamp = this.lastReadTimestamp; @@ -972,7 +975,7 @@ export class ConversationModel extends Backbone.Model { let allUnreadMessagesInConvo = (await this.getUnread()).models; const oldUnreadNowRead = allUnreadMessagesInConvo.filter( - (message: any) => message.get('received_at') <= newestUnreadDate + message => (message.get('received_at') as number) <= newestUnreadDate ); let read = [];