don't mark message as read if app isn't focused

This commit is contained in:
Brice-W 2021-07-08 15:03:27 +10:00
parent bf76abacee
commit 936f9a3efc
5 changed files with 9 additions and 3 deletions

View File

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

View File

@ -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

View File

@ -713,7 +713,7 @@ class MessageInner extends React.PureComponent<MessageRegularProps, State> {
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) {

View File

@ -75,6 +75,7 @@ export class SessionMessagesList extends React.Component<Props, State> {
this.messageContainerRef = this.props.messageContainerRef;
this.ignoreScrollEvents = true;
window.setFocusListener(() => this.updateReadMessages());
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -378,7 +379,7 @@ export class SessionMessagesList extends React.Component<Props, State> {
return;
}
if (this.getScrollOffsetBottomPx() === 0) {
if (this.getScrollOffsetBottomPx() === 0 && window.isFocused()) {
void conversation.markRead(messages[0].attributes.received_at);
}
}

2
ts/window.d.ts vendored
View File

@ -40,6 +40,8 @@ declare global {
getFriendsFromContacts: any;
getSettingValue: any;
i18n: LocalizerType;
isFocused: any;
setFocusListener: (listener: any) => any;
libloki: Libloki;
libsignal: LibsignalProtocol;
log: any;