fix: new sessions miss notifications

This commit is contained in:
KernelDeimos 2024-11-14 19:25:57 -05:00
parent d0f16c8105
commit b1ffb8eca1
3 changed files with 19 additions and 5 deletions

View File

@ -35,6 +35,10 @@ class NotificationService extends BaseService {
express: require('express'),
}
_construct () {
this.merged_on_user_connected_ = {};
}
async _init () {
const svc_database = this.services.get('database');
this.db = svc_database.get(DB_WRITE, 'notification');
@ -109,6 +113,13 @@ class NotificationService extends BaseService {
}
async on_user_connected ({ user }) {
if ( this.merged_on_user_connected_[user.uuid] ) {
clearTimeout(this.merged_on_user_connected_[user.uuid]);
}
this.merged_on_user_connected_[user.uuid] =
setTimeout(() => this.do_on_user_connected({ user }), 2000);
}
async do_on_user_connected ({ user }) {
// query the users unread notifications
const notifications = await this.db.read(
'SELECT * FROM `notification` ' +

View File

@ -183,11 +183,13 @@ class WebServerService extends BaseService {
socket.on('trash.is_empty', (msg) => {
socket.broadcast.to(socket.user.id).emit('trash.is_empty', msg);
});
socket.on('puter_is_actually_open', (msg) => {
const svc_event = this.services.get('event');
svc_event.emit('web.socket.user-connected', {
user: socket.user
});
});
});
this.server_ = server;
await this.services.emit('install.websockets');

View File

@ -66,6 +66,7 @@ async function UIDesktop(options){
window.socket.on('connect', function(){
// console.log('GUI Socket: Connected', window.socket.id);
window.socket.emit('puter_is_actually_open');
});
window.socket.on('reconnect', function(){