From 936f9a3efcc45ddc4af12aa5ce09ff33cc545459 Mon Sep 17 00:00:00 2001 From: Brice-W Date: Thu, 8 Jul 2021 15:03:27 +1000 Subject: [PATCH 01/13] don't mark message as read if app isn't focused --- js/focus_listener.js | 3 +++ js/read_syncs.js | 2 +- ts/components/conversation/Message.tsx | 2 +- ts/components/session/conversation/SessionMessagesList.tsx | 3 ++- ts/window.d.ts | 2 ++ 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/js/focus_listener.js b/js/focus_listener.js index c9a728233..29b027598 100644 --- a/js/focus_listener.js +++ b/js/focus_listener.js @@ -3,12 +3,15 @@ 'use strict'; let windowFocused = false; + let windowFocusedListener = function() {} window.addEventListener('blur', () => { windowFocused = false; }); window.addEventListener('focus', () => { windowFocused = true; + windowFocusedListener(); }); window.isFocused = () => windowFocused; + window.setFocusListener = (listener) => windowFocusedListener = listener; })(); diff --git a/js/read_syncs.js b/js/read_syncs.js index 70aebf1c4..c7337ec07 100644 --- a/js/read_syncs.js +++ b/js/read_syncs.js @@ -59,7 +59,7 @@ // 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 // the previous read time. - if (message.isUnread()) { + if (message.isUnread() && window.isFocused()) { await message.markRead(readAt); // onReadMessage may result in messages older than this one being diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index 2fd928ccf..6a4ba4c98 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -713,7 +713,7 @@ class MessageInner extends React.PureComponent { const isShowingImage = this.isShowingImage(); const isIncoming = direction === 'incoming'; - const shouldMarkReadWhenVisible = isIncoming && isUnread; + const shouldMarkReadWhenVisible = isIncoming && isUnread && window.isFocused(); const divClasses = ['session-message-wrapper']; if (selected) { diff --git a/ts/components/session/conversation/SessionMessagesList.tsx b/ts/components/session/conversation/SessionMessagesList.tsx index e3af18792..20c7dc350 100644 --- a/ts/components/session/conversation/SessionMessagesList.tsx +++ b/ts/components/session/conversation/SessionMessagesList.tsx @@ -75,6 +75,7 @@ export class SessionMessagesList extends React.Component { this.messageContainerRef = this.props.messageContainerRef; this.ignoreScrollEvents = true; + window.setFocusListener(() => this.updateReadMessages()); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -378,7 +379,7 @@ export class SessionMessagesList extends React.Component { return; } - if (this.getScrollOffsetBottomPx() === 0) { + if (this.getScrollOffsetBottomPx() === 0 && window.isFocused()) { void conversation.markRead(messages[0].attributes.received_at); } } diff --git a/ts/window.d.ts b/ts/window.d.ts index 5f43a4e83..70c74c782 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -40,6 +40,8 @@ declare global { getFriendsFromContacts: any; getSettingValue: any; i18n: LocalizerType; + isFocused: any; + setFocusListener: (listener: any) => any; libloki: Libloki; libsignal: LibsignalProtocol; log: any; From 2af9d9e15d1538fd87db970f4152747024e4bc52 Mon Sep 17 00:00:00 2001 From: Brice-W Date: Mon, 12 Jul 2021 14:35:43 +1000 Subject: [PATCH 02/13] use of a custom hook to detect focus --- js/focus_listener.js | 3 --- ts/components/conversation/Message.tsx | 21 ++++++++----------- .../conversation/SessionMessagesList.tsx | 1 - ts/window.d.ts | 3 +-- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/js/focus_listener.js b/js/focus_listener.js index 29b027598..c9a728233 100644 --- a/js/focus_listener.js +++ b/js/focus_listener.js @@ -3,15 +3,12 @@ 'use strict'; let windowFocused = false; - let windowFocusedListener = function() {} window.addEventListener('blur', () => { windowFocused = false; }); window.addEventListener('focus', () => { windowFocused = true; - windowFocusedListener(); }); window.isFocused = () => windowFocused; - window.setFocusListener = (listener) => windowFocusedListener = listener; })(); diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index 6a4ba4c98..c3010a3d9 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -42,6 +42,7 @@ import { MessageInteraction } from '../../interactions'; import autoBind from 'auto-bind'; import { AudioPlayerWithEncryptedFile } from './H5AudioPlayer'; import { ClickToTrustSender } from './message/ClickToTrustSender'; +import { ReadableMessage } from './ReadableMessage'; // Same as MIN_WIDTH in ImageGrid.tsx const MINIMUM_LINK_PREVIEW_IMAGE_WIDTH = 200; @@ -713,7 +714,7 @@ class MessageInner extends React.PureComponent { const isShowingImage = this.isShowingImage(); const isIncoming = direction === 'incoming'; - const shouldMarkReadWhenVisible = isIncoming && isUnread && window.isFocused(); + const shouldMarkReadWhenVisible = isIncoming && isUnread; const divClasses = ['session-message-wrapper']; if (selected) { @@ -729,7 +730,7 @@ class MessageInner extends React.PureComponent { } const onVisible = (inView: boolean) => { - if (inView && shouldMarkReadWhenVisible) { + if (inView && shouldMarkReadWhenVisible && window.isFocused()) { // mark the message as read. // this will trigger the expire timer. void markRead(Date.now()); @@ -737,15 +738,11 @@ class MessageInner extends React.PureComponent { }; return ( - {this.renderAvatar()}
{ {this.renderError(!isIncoming)} {this.renderContextMenu()}
-
+ ); } diff --git a/ts/components/session/conversation/SessionMessagesList.tsx b/ts/components/session/conversation/SessionMessagesList.tsx index 20c7dc350..922a40d31 100644 --- a/ts/components/session/conversation/SessionMessagesList.tsx +++ b/ts/components/session/conversation/SessionMessagesList.tsx @@ -75,7 +75,6 @@ export class SessionMessagesList extends React.Component { this.messageContainerRef = this.props.messageContainerRef; this.ignoreScrollEvents = true; - window.setFocusListener(() => this.updateReadMessages()); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/ts/window.d.ts b/ts/window.d.ts index 70c74c782..5a7b1e7d5 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -40,8 +40,7 @@ declare global { getFriendsFromContacts: any; getSettingValue: any; i18n: LocalizerType; - isFocused: any; - setFocusListener: (listener: any) => any; + isFocused: () => boolean; libloki: Libloki; libsignal: LibsignalProtocol; log: any; From c98fdec10eda3a31525effde41705d7816a01403 Mon Sep 17 00:00:00 2001 From: Brice-W Date: Mon, 12 Jul 2021 15:03:30 +1000 Subject: [PATCH 03/13] adding new files --- .../conversation/ReadableMessage.tsx | 28 +++++++++++++++++++ ts/hooks/useFocus.ts | 11 ++++++++ 2 files changed, 39 insertions(+) create mode 100644 ts/components/conversation/ReadableMessage.tsx create mode 100644 ts/hooks/useFocus.ts diff --git a/ts/components/conversation/ReadableMessage.tsx b/ts/components/conversation/ReadableMessage.tsx new file mode 100644 index 000000000..d5288e221 --- /dev/null +++ b/ts/components/conversation/ReadableMessage.tsx @@ -0,0 +1,28 @@ +import React from 'react'; +import { useFocus } from "../../hooks/useFocus" +import { InView } from 'react-intersection-observer'; + +type ReadableMessageProps = { + children: React.ReactNode; + id: string; + className: string; + onChange: (inView: boolean) => void; + onContextMenu: (e: any) => void +} + +export const ReadableMessage = (props: ReadableMessageProps) => { + + const { onChange } = props; + useFocus(onChange); + + return ( + + {props.children} + ); +} diff --git a/ts/hooks/useFocus.ts b/ts/hooks/useFocus.ts new file mode 100644 index 000000000..e3d3d510c --- /dev/null +++ b/ts/hooks/useFocus.ts @@ -0,0 +1,11 @@ +import { useEffect } from "react"; + +export const useFocus = (action: (param: any) => void) => { + + useEffect(() => { + window.addEventListener("focus", action); + return () => { + window.removeEventListener("focus", action); + }; + }); +} \ No newline at end of file From 151fc758c05d69fef7eb70d7fb1641536f434632 Mon Sep 17 00:00:00 2001 From: Brice-W Date: Mon, 12 Jul 2021 16:44:31 +1000 Subject: [PATCH 04/13] format --- ts/components/conversation/Message.tsx | 8 ++--- .../conversation/ReadableMessage.tsx | 36 ++++++++----------- ts/hooks/useFocus.ts | 9 +++-- ts/models/message.ts | 2 ++ 4 files changed, 25 insertions(+), 30 deletions(-) diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index c3010a3d9..c33845f76 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -739,10 +739,10 @@ class MessageInner extends React.PureComponent { return ( {this.renderAvatar()}
void; - onContextMenu: (e: any) => void -} + children: React.ReactNode; + id: string; + className: string; + onChange: (inView: boolean) => void; + onContextMenu: (e: any) => void; +}; export const ReadableMessage = (props: ReadableMessageProps) => { + const { onChange } = props; + useFocus(onChange); - const { onChange } = props; - useFocus(onChange); - - return ( - - {props.children} - ); -} + return ( + + {props.children} + + ); +}; diff --git a/ts/hooks/useFocus.ts b/ts/hooks/useFocus.ts index e3d3d510c..8f62de92e 100644 --- a/ts/hooks/useFocus.ts +++ b/ts/hooks/useFocus.ts @@ -1,11 +1,10 @@ -import { useEffect } from "react"; +import { useEffect } from 'react'; export const useFocus = (action: (param: any) => void) => { - useEffect(() => { - window.addEventListener("focus", action); + window.addEventListener('focus', action); return () => { - window.removeEventListener("focus", action); + window.removeEventListener('focus', action); }; }); -} \ No newline at end of file +}; diff --git a/ts/models/message.ts b/ts/models/message.ts index 339058372..380c2ec50 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -1047,6 +1047,8 @@ export class MessageModel extends Backbone.Model { public async markRead(readAt: number) { this.markReadNoCommit(readAt); + this.getConversation()?.markRead(readAt); + await this.commit(); } From 14ef4cd39a0b356b767d998ff06eb8ccd64bee02 Mon Sep 17 00:00:00 2001 From: Brice-W Date: Tue, 13 Jul 2021 13:08:46 +1000 Subject: [PATCH 05/13] adding lastReadTimestamp property --- ts/models/conversation.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 5dae6d3c5..c17c94566 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -92,6 +92,7 @@ export interface ConversationAttributes { triggerNotificationsFor: ConversationNotificationSettingType; isTrustedForAttachmentDownload: boolean; isPinned: boolean; + lastReadTimestamp: number; } export interface ConversationAttributesOptionals { @@ -160,6 +161,7 @@ export const fillConvoAttributesWithDefaults = ( triggerNotificationsFor: 'all', // if the settings is not set in the db, this is the default isTrustedForAttachmentDownload: false, // we don't trust a contact until we say so isPinned: false, + lastReadTimestamp: 0, }); }; @@ -188,7 +190,13 @@ export class ConversationModel extends Backbone.Model { this.updateLastMessage = _.throttle(this.bouncyUpdateLastMessage.bind(this), 1000); this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 }); //start right away the function is called, and wait 1sec before calling it again - this.markRead = _.debounce(this.markReadBouncy, 1000, { leading: true }); + this.markRead = (readAt: number) => { + const lastReadTimestamp = this.get('lastReadTimestamp'); + if (readAt > lastReadTimestamp) { + this.set('lastReadTimestamp', readAt); + } + _.debounce(this.markReadBouncy, 1000, { leading: true }); + } // Listening for out-of-band data updates this.typingRefreshTimer = null; @@ -902,6 +910,10 @@ export class ConversationModel extends Backbone.Model { } public async markReadBouncy(newestUnreadDate: number, providedOptions: any = {}) { + if (this.get('lastReadTimestamp') >= 0) { + return; + } + const options = providedOptions || {}; _.defaults(options, { sendReadReceipts: true }); From c38d2a5ea7d357668fab54b4c3689495e4c89da6 Mon Sep 17 00:00:00 2001 From: Brice-W Date: Thu, 15 Jul 2021 16:48:54 +1000 Subject: [PATCH 06/13] revert prev changes + marking read now based on received_at --- ts/components/conversation/Message.tsx | 4 ++-- ts/components/conversation/ReadableMessage.tsx | 18 +++++++++++++++++- ts/models/conversation.ts | 13 +------------ ts/models/message.ts | 2 +- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index c33845f76..7bcf81e95 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -729,8 +729,8 @@ class MessageInner extends React.PureComponent { divClasses.push('flash-green-once'); } - const onVisible = (inView: boolean) => { - if (inView && shouldMarkReadWhenVisible && window.isFocused()) { + const onVisible = (inView: boolean | Object) => { + if (inView === true && shouldMarkReadWhenVisible && window.isFocused()) { // mark the message as read. // this will trigger the expire timer. void markRead(Date.now()); diff --git a/ts/components/conversation/ReadableMessage.tsx b/ts/components/conversation/ReadableMessage.tsx index d6cc6be4b..f907ca1b8 100644 --- a/ts/components/conversation/ReadableMessage.tsx +++ b/ts/components/conversation/ReadableMessage.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { useFocus } from '../../hooks/useFocus'; -import { InView } from 'react-intersection-observer'; +import { InView, useInView } from 'react-intersection-observer'; type ReadableMessageProps = { children: React.ReactNode; @@ -11,6 +11,22 @@ type ReadableMessageProps = { }; export const ReadableMessage = (props: ReadableMessageProps) => { + /*const { ref, inView, entry } = useInView({ + threshold: 1, + delay: 200, + triggerOnce: true, + trackVisibility: true, + }); + + const { onChange } = props; + useFocus(() => onChange(inView)); + + return ( +
+ {props.children} +
+ )*/ + const { onChange } = props; useFocus(onChange); diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index c17c94566..dd3dcf64e 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -92,7 +92,6 @@ export interface ConversationAttributes { triggerNotificationsFor: ConversationNotificationSettingType; isTrustedForAttachmentDownload: boolean; isPinned: boolean; - lastReadTimestamp: number; } export interface ConversationAttributesOptionals { @@ -161,7 +160,6 @@ export const fillConvoAttributesWithDefaults = ( triggerNotificationsFor: 'all', // if the settings is not set in the db, this is the default isTrustedForAttachmentDownload: false, // we don't trust a contact until we say so isPinned: false, - lastReadTimestamp: 0, }); }; @@ -190,13 +188,7 @@ export class ConversationModel extends Backbone.Model { this.updateLastMessage = _.throttle(this.bouncyUpdateLastMessage.bind(this), 1000); this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 }); //start right away the function is called, and wait 1sec before calling it again - this.markRead = (readAt: number) => { - const lastReadTimestamp = this.get('lastReadTimestamp'); - if (readAt > lastReadTimestamp) { - this.set('lastReadTimestamp', readAt); - } - _.debounce(this.markReadBouncy, 1000, { leading: true }); - } + this.markRead = _.debounce(this.markReadBouncy, 1000, { leading: true }); // Listening for out-of-band data updates this.typingRefreshTimer = null; @@ -910,9 +902,6 @@ export class ConversationModel extends Backbone.Model { } public async markReadBouncy(newestUnreadDate: number, providedOptions: any = {}) { - if (this.get('lastReadTimestamp') >= 0) { - return; - } const options = providedOptions || {}; _.defaults(options, { sendReadReceipts: true }); diff --git a/ts/models/message.ts b/ts/models/message.ts index 380c2ec50..ec58ecf97 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -1047,7 +1047,7 @@ export class MessageModel extends Backbone.Model { public async markRead(readAt: number) { this.markReadNoCommit(readAt); - this.getConversation()?.markRead(readAt); + this.getConversation()?.markRead(this.attributes.received_at); await this.commit(); } From db46c2960be5a549ed59bc0e4cee3a005b7fcfb1 Mon Sep 17 00:00:00 2001 From: Brice-W Date: Fri, 16 Jul 2021 13:32:58 +1000 Subject: [PATCH 07/13] update in marking read message --- .../conversation/ReadableMessage.tsx | 2 +- ts/models/conversation.ts | 20 +++++++++++++++++-- ts/test/test-utils/utils/message.ts | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ts/components/conversation/ReadableMessage.tsx b/ts/components/conversation/ReadableMessage.tsx index f907ca1b8..2dc6ed992 100644 --- a/ts/components/conversation/ReadableMessage.tsx +++ b/ts/components/conversation/ReadableMessage.tsx @@ -31,7 +31,7 @@ export const ReadableMessage = (props: ReadableMessageProps) => { useFocus(onChange); return ( - + {props.children} ); diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index dd3dcf64e..0d035be28 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -92,6 +92,7 @@ export interface ConversationAttributes { triggerNotificationsFor: ConversationNotificationSettingType; isTrustedForAttachmentDownload: boolean; isPinned: boolean; + lastReadTimestamp: number; } export interface ConversationAttributesOptionals { @@ -160,6 +161,7 @@ export const fillConvoAttributesWithDefaults = ( triggerNotificationsFor: 'all', // if the settings is not set in the db, this is the default isTrustedForAttachmentDownload: false, // we don't trust a contact until we say so isPinned: false, + lastReadTimestamp: 0, }); }; @@ -188,7 +190,16 @@ export class ConversationModel extends Backbone.Model { this.updateLastMessage = _.throttle(this.bouncyUpdateLastMessage.bind(this), 1000); this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 }); //start right away the function is called, and wait 1sec before calling it again - this.markRead = _.debounce(this.markReadBouncy, 1000, { leading: true }); + //this.markRead = _.debounce(this.markReadBouncy, 1000, { leading: true }); + const markReadBouncy = _.debounce(this.markReadBouncy, 1000, { leading: true }) + this.markRead = (newestUnreadDate: number) => { + const lastReadTimestamp = this.get('lastReadTimestamp'); + if (newestUnreadDate > lastReadTimestamp) + this.set({ + lastReadTimestamp: newestUnreadDate, + }); + markReadBouncy(newestUnreadDate); + } // Listening for out-of-band data updates this.typingRefreshTimer = null; @@ -903,6 +914,11 @@ export class ConversationModel extends Backbone.Model { public async markReadBouncy(newestUnreadDate: number, providedOptions: any = {}) { + const lastReadTimestamp = this.get('lastReadTimestamp'); + if (newestUnreadDate < lastReadTimestamp) { + return; + } + const options = providedOptions || {}; _.defaults(options, { sendReadReceipts: true }); @@ -948,7 +964,7 @@ export class ConversationModel extends Backbone.Model { const cachedUnreadCountOnConvo = this.get('unreadCount'); if (cachedUnreadCountOnConvo !== read.length) { // reset the unreadCount on the convo to the real one coming from markRead messages on the db - this.set({ unreadCount: 0 }); + this.set({ unreadCount: realUnreadCount }); await this.commit(); } else { // window?.log?.info('markRead(): nothing newly read.'); diff --git a/ts/test/test-utils/utils/message.ts b/ts/test/test-utils/utils/message.ts index 4d0cdf6f2..809a0a96e 100644 --- a/ts/test/test-utils/utils/message.ts +++ b/ts/test/test-utils/utils/message.ts @@ -89,6 +89,7 @@ export class MockConversation { triggerNotificationsFor: 'all', isTrustedForAttachmentDownload: false, isPinned: false, + lastReadTimestamp: 0, }; } From 1397107dff0c86883b1f95f241eff554a3afe9ba Mon Sep 17 00:00:00 2001 From: Brice-W Date: Fri, 16 Jul 2021 13:48:08 +1000 Subject: [PATCH 08/13] fix issues --- ts/models/conversation.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 0d035be28..1df311e82 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -191,15 +191,16 @@ export class ConversationModel extends Backbone.Model { this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 }); //start right away the function is called, and wait 1sec before calling it again //this.markRead = _.debounce(this.markReadBouncy, 1000, { leading: true }); - const markReadBouncy = _.debounce(this.markReadBouncy, 1000, { leading: true }) + const markReadBouncy = _.debounce(this.markReadBouncy, 1000, { leading: true }); this.markRead = (newestUnreadDate: number) => { const lastReadTimestamp = this.get('lastReadTimestamp'); - if (newestUnreadDate > lastReadTimestamp) - this.set({ - lastReadTimestamp: newestUnreadDate, - }); - markReadBouncy(newestUnreadDate); - } + if (newestUnreadDate > lastReadTimestamp) { + this.set({ + lastReadTimestamp: newestUnreadDate, + }); + } + void markReadBouncy(newestUnreadDate); + }; // Listening for out-of-band data updates this.typingRefreshTimer = null; @@ -913,7 +914,6 @@ export class ConversationModel extends Backbone.Model { } public async markReadBouncy(newestUnreadDate: number, providedOptions: any = {}) { - const lastReadTimestamp = this.get('lastReadTimestamp'); if (newestUnreadDate < lastReadTimestamp) { return; From 4f98917eaf33f71b3c3a002fdfdbe8f6eee24a26 Mon Sep 17 00:00:00 2001 From: Brice-W Date: Fri, 16 Jul 2021 13:49:32 +1000 Subject: [PATCH 09/13] clean --- ts/models/conversation.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index 1df311e82..dacdc2327 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -190,7 +190,6 @@ export class ConversationModel extends Backbone.Model { this.updateLastMessage = _.throttle(this.bouncyUpdateLastMessage.bind(this), 1000); this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 }); //start right away the function is called, and wait 1sec before calling it again - //this.markRead = _.debounce(this.markReadBouncy, 1000, { leading: true }); const markReadBouncy = _.debounce(this.markReadBouncy, 1000, { leading: true }); this.markRead = (newestUnreadDate: number) => { const lastReadTimestamp = this.get('lastReadTimestamp'); From 9a420f85cebebaa62ece63ecba3030a5fc4030b5 Mon Sep 17 00:00:00 2001 From: Brice-W Date: Fri, 16 Jul 2021 16:20:34 +1000 Subject: [PATCH 10/13] fixes --- ts/components/conversation/ReadableMessage.tsx | 16 ---------------- ts/models/conversation.ts | 16 +++++++--------- ts/test/test-utils/utils/message.ts | 1 - 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/ts/components/conversation/ReadableMessage.tsx b/ts/components/conversation/ReadableMessage.tsx index 2dc6ed992..d56fa2c4e 100644 --- a/ts/components/conversation/ReadableMessage.tsx +++ b/ts/components/conversation/ReadableMessage.tsx @@ -11,22 +11,6 @@ type ReadableMessageProps = { }; export const ReadableMessage = (props: ReadableMessageProps) => { - /*const { ref, inView, entry } = useInView({ - threshold: 1, - delay: 200, - triggerOnce: true, - trackVisibility: true, - }); - - const { onChange } = props; - useFocus(() => onChange(inView)); - - return ( -
- {props.children} -
- )*/ - const { onChange } = props; useFocus(onChange); diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index b9867bd86..7b879d0a4 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -92,7 +92,6 @@ export interface ConversationAttributes { triggerNotificationsFor: ConversationNotificationSettingType; isTrustedForAttachmentDownload: boolean; isPinned: boolean; - lastReadTimestamp: number; } export interface ConversationAttributesOptionals { @@ -161,7 +160,6 @@ export const fillConvoAttributesWithDefaults = ( triggerNotificationsFor: 'all', // if the settings is not set in the db, this is the default isTrustedForAttachmentDownload: false, // we don't trust a contact until we say so isPinned: false, - lastReadTimestamp: 0, }); }; @@ -175,6 +173,7 @@ export class ConversationModel extends Backbone.Model { private typingRefreshTimer?: NodeJS.Timeout | null; private typingPauseTimer?: NodeJS.Timeout | null; private typingTimer?: NodeJS.Timeout | null; + private lastReadTimestamp: number; private pending: any; @@ -190,20 +189,19 @@ export class ConversationModel extends Backbone.Model { this.updateLastMessage = _.throttle(this.bouncyUpdateLastMessage.bind(this), 1000); this.throttledNotify = _.debounce(this.notify, 500, { maxWait: 1000 }); //start right away the function is called, and wait 1sec before calling it again - const markReadBouncy = _.debounce(this.markReadBouncy, 1000, { leading: true }); + const markReadDebounced = _.debounce(this.markReadBouncy, 1000, { leading: true }); this.markRead = (newestUnreadDate: number) => { - const lastReadTimestamp = this.get('lastReadTimestamp'); + const lastReadTimestamp = this.lastReadTimestamp; if (newestUnreadDate > lastReadTimestamp) { - this.set({ - lastReadTimestamp: newestUnreadDate, - }); + this.lastReadTimestamp = newestUnreadDate; } - void markReadBouncy(newestUnreadDate); + void markReadDebounced(newestUnreadDate); }; // Listening for out-of-band data updates this.typingRefreshTimer = null; this.typingPauseTimer = null; + this.lastReadTimestamp = 0; window.inboxStore?.dispatch(conversationActions.conversationChanged(this.id, this.getProps())); } @@ -925,7 +923,7 @@ export class ConversationModel extends Backbone.Model { } public async markReadBouncy(newestUnreadDate: number, providedOptions: any = {}) { - const lastReadTimestamp = this.get('lastReadTimestamp'); + const lastReadTimestamp = this.lastReadTimestamp; if (newestUnreadDate < lastReadTimestamp) { return; } diff --git a/ts/test/test-utils/utils/message.ts b/ts/test/test-utils/utils/message.ts index 809a0a96e..4d0cdf6f2 100644 --- a/ts/test/test-utils/utils/message.ts +++ b/ts/test/test-utils/utils/message.ts @@ -89,7 +89,6 @@ export class MockConversation { triggerNotificationsFor: 'all', isTrustedForAttachmentDownload: false, isPinned: false, - lastReadTimestamp: 0, }; } From e9f70d8c828b590f210d63c259213a6668353455 Mon Sep 17 00:00:00 2001 From: Brice-W Date: Mon, 19 Jul 2021 09:31:24 +1000 Subject: [PATCH 11/13] fix issue --- ts/components/session/registration/RegistrationTabs.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ts/components/session/registration/RegistrationTabs.tsx b/ts/components/session/registration/RegistrationTabs.tsx index d3128df43..9c94ec543 100644 --- a/ts/components/session/registration/RegistrationTabs.tsx +++ b/ts/components/session/registration/RegistrationTabs.tsx @@ -17,7 +17,7 @@ import { import { fromHex } from '../../../session/utils/String'; import { TaskTimedOutError } from '../../../session/utils/Promise'; import { mn_decode } from '../../../session/crypto/mnemonic'; -import { SwarmPolling } from '../../../session/snode_api/swarmPolling'; +import { getSwarmPollingInstance } from '../../../session/snode_api/swarmPolling'; export const MAX_USERNAME_LENGTH = 20; // tslint:disable: use-simple-attributes @@ -191,11 +191,9 @@ export async function signInWithLinking(signInDetails: { try { await resetRegistration(); await window.setPassword(password); - const pubkeyStr = await signInByLinkingDevice(userRecoveryPhrase, 'english'); - + await signInByLinkingDevice(userRecoveryPhrase, 'english'); let displayNameFromNetwork = ''; - SwarmPolling.getInstance().addPubkey(pubkeyStr); - SwarmPolling.getInstance().start(); + await getSwarmPollingInstance().start(); await PromiseUtils.waitForTask(done => { window.Whisper.events.on('configurationMessageReceived', (displayName: string) => { From 829fd1c19974a0964e1e839a3cd4c9566d7a267c Mon Sep 17 00:00:00 2001 From: Brice-W Date: Mon, 19 Jul 2021 10:23:20 +1000 Subject: [PATCH 12/13] menu fixes --- ts/components/ConversationListItem.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index b17f00bbd..c23db163a 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -63,6 +63,8 @@ const ConversationListItem = (props: Props) => { isMe, isPinned, isTyping, + isPublic, + left, type, lastMessage, memberAvatars, @@ -126,6 +128,8 @@ const ConversationListItem = (props: Props) => { triggerId={triggerId} type={type} isMe={isMe} + isPublic={isPublic} + left={left} notificationForConvo={notificationForConvo} currentNotificationSetting={currentNotificationSetting} /> From 8256451ec684f8c28fc73f67bbd104eb0cb906ad Mon Sep 17 00:00:00 2001 From: Brice-W Date: Tue, 20 Jul 2021 15:06:58 +1000 Subject: [PATCH 13/13] enable pinning conversations --- preload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preload.js b/preload.js index 87b3d051b..b9f6206c9 100644 --- a/preload.js +++ b/preload.js @@ -56,7 +56,7 @@ window.lokiFeatureFlags = { useFileOnionRequests: true, useFileOnionRequestsV2: true, // more compact encoding of files in response padOutgoingAttachments: true, - enablePinConversations: false, + enablePinConversations: true, }; if (typeof process.env.NODE_ENV === 'string' && process.env.NODE_ENV.includes('test-integration')) {