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(); }