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:
parent
ff96822f67
commit
0f8559f22a
3 changed files with 27 additions and 0 deletions
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -10,6 +10,7 @@ const topics = [
|
|||
"CHANNEL_MEMBERS_NEW",
|
||||
"CHANNEL_MEMBERS_REMOVED",
|
||||
"CHANNEL_READ", // {endpoint, channel_id}
|
||||
"WINDOW_FOCUSED",
|
||||
];
|
||||
|
||||
let subscribers = Object.create(null);
|
||||
|
|
Loading…
Reference in a new issue