Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Desktop notifications #252

Merged
merged 12 commits into from
Jan 29, 2022
14 changes: 2 additions & 12 deletions src/client/state/Notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class Notifications extends EventEmitter {

this.roomIdToNoti = new Map();

this._isSyncing = false;

this._initNoti();
this._listenEvents();

Expand Down Expand Up @@ -192,7 +190,7 @@ class Notifications extends EventEmitter {
body: mEvent.getContent().body,
icon: mEvent.sender?.getAvatarUrl(this.matrixClient.baseUrl, 36, 36, 'crop'),
});
noti.onclick = () => selectRoom(room.roomId);
noti.onclick = () => selectRoom(room.roomId, mEvent.getId());
}

_listenEvents() {
Expand All @@ -210,7 +208,7 @@ class Notifications extends EventEmitter {
const noti = this.getNoti(room.roomId);
this._setNoti(room.roomId, total - noti.total, highlight - noti.highlight);

if (this._isSyncing) {
if (this.matrixClient.getSyncState() === 'SYNCING') {
this._displayPopupNoti(mEvent, room);
}
});
Expand All @@ -231,14 +229,6 @@ class Notifications extends EventEmitter {
this.deleteNoti(room.roomId);
}
});

this.matrixClient.on('sync', (state) => {
if (state === 'SYNCING') {
this._isSyncing = true;
} else if (state === 'STOPPED' || state === 'ERROR') {
this._isSyncing = false;
}
});
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/client/state/userActivity.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import EventEmitter from 'events';

const recentlyActiveThreshold = 2 * 60 * 1000; // 2 minutes
ginnyTheCat marked this conversation as resolved.
Show resolved Hide resolved

class UserActivity extends EventEmitter {
constructor() {
super();
Expand All @@ -14,15 +16,14 @@ class UserActivity extends EventEmitter {
const inactivityEvent = () => { this.lastActive = 0; };

window.addEventListener('mousedown', activityEvent);
// window.addEventListener('mousemove', activityEvent);
window.addEventListener('keydown', activityEvent);
window.addEventListener('wheel', activityEvent, { passive: true, capture: true });
window.addEventListener('focus', activityEvent);
window.addEventListener('blur', inactivityEvent);
}

recentlyActive() {
return Date.now() - this.lastActive <= 2 * 60 * 1000;
return Date.now() - this.lastActive <= recentlyActiveThreshold;
}
}

Expand Down