Skip to content

Commit b1ffb8e

Browse files
committed
fix: new sessions miss notifications
1 parent d0f16c8 commit b1ffb8e

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/backend/src/services/NotificationService.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class NotificationService extends BaseService {
3535
express: require('express'),
3636
}
3737

38+
_construct () {
39+
this.merged_on_user_connected_ = {};
40+
}
41+
3842
async _init () {
3943
const svc_database = this.services.get('database');
4044
this.db = svc_database.get(DB_WRITE, 'notification');
@@ -109,14 +113,21 @@ class NotificationService extends BaseService {
109113
}
110114

111115
async on_user_connected ({ user }) {
116+
if ( this.merged_on_user_connected_[user.uuid] ) {
117+
clearTimeout(this.merged_on_user_connected_[user.uuid]);
118+
}
119+
this.merged_on_user_connected_[user.uuid] =
120+
setTimeout(() => this.do_on_user_connected({ user }), 2000);
121+
}
122+
async do_on_user_connected ({ user }) {
112123
// query the users unread notifications
113124
const notifications = await this.db.read(
114125
'SELECT * FROM `notification` ' +
115126
'WHERE user_id=? AND shown IS NULL AND acknowledged IS NULL ' +
116127
'ORDER BY created_at ASC',
117128
[user.id]
118129
);
119-
130+
120131
// set all the notifications to "shown"
121132
const shown_ts = Math.floor(Date.now() / 1000);
122133
await this.db.write(
@@ -140,7 +151,7 @@ class NotificationService extends BaseService {
140151
notification: notif.value,
141152
})
142153
}
143-
154+
144155
// send the unread notifications to gui
145156
const svc_event = this.services.get('event');
146157
svc_event.emit('outer.gui.notif.unreads', {

src/backend/src/services/WebServerService.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,11 @@ class WebServerService extends BaseService {
183183
socket.on('trash.is_empty', (msg) => {
184184
socket.broadcast.to(socket.user.id).emit('trash.is_empty', msg);
185185
});
186-
const svc_event = this.services.get('event');
187-
svc_event.emit('web.socket.user-connected', {
188-
user: socket.user
186+
socket.on('puter_is_actually_open', (msg) => {
187+
const svc_event = this.services.get('event');
188+
svc_event.emit('web.socket.user-connected', {
189+
user: socket.user
190+
});
189191
});
190192
});
191193

src/gui/src/UI/UIDesktop.js

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ async function UIDesktop(options){
6666

6767
window.socket.on('connect', function(){
6868
// console.log('GUI Socket: Connected', window.socket.id);
69+
window.socket.emit('puter_is_actually_open');
6970
});
7071

7172
window.socket.on('reconnect', function(){

0 commit comments

Comments
 (0)