Mark incoming messages in current channel as read

but only if tab is focused. When tab gets focus, mark channel as read.
This commit is contained in:
Midgard 2022-06-09 15:14:40 +02:00
parent ff96822f67
commit 0f8559f22a
Signed by: midgard
GPG key ID: 511C112F1331BBB4
3 changed files with 27 additions and 0 deletions

View file

@ -207,3 +207,20 @@ function checkKeyPress(event) {
}
return false;
}
pubsub.subscribe("MESSAGES_NEW", post => {
if (!window.hasFocus) {
return;
}
const curChan = currentChannel();
if (post.endpoint === curChan.endpoint && post.channel_id === curChan.channel_id) {
mm_client.getOrCreate(post.endpoint).markChannelRead(post.channel_id);
}
});
pubsub.subscribe("WINDOW_FOCUSED", () => {
const curChan = currentChannel();
if (!curChan.channel_id) return;
mm_client.getOrCreate(curChan.endpoint).markChannelRead(curChan.channel_id);
});

View file

@ -21,3 +21,12 @@ localstorage_credentials.getServers()
.forEach(mm_client.getOrCreate);
populateChannelList();
window.hasFocus = true;
window.addEventListener("focus", _ => {
window.hasFocus = true;
pubsub.publish("WINDOW_FOCUSED");
});
window.addEventListener("blur", _ => {
window.hasFocus = false;
});

View file

@ -10,6 +10,7 @@ const topics = [
"CHANNEL_MEMBERS_NEW",
"CHANNEL_MEMBERS_REMOVED",
"CHANNEL_READ", // {endpoint, channel_id}
"WINDOW_FOCUSED",
];
let subscribers = Object.create(null);