mirror of
https://github.com/HeyPuter/puter.git
synced 2025-01-24 23:38:40 +08:00
fix: new sessions miss notifications
This commit is contained in:
parent
d0f16c8105
commit
b1ffb8eca1
@ -35,6 +35,10 @@ class NotificationService extends BaseService {
|
|||||||
express: require('express'),
|
express: require('express'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_construct () {
|
||||||
|
this.merged_on_user_connected_ = {};
|
||||||
|
}
|
||||||
|
|
||||||
async _init () {
|
async _init () {
|
||||||
const svc_database = this.services.get('database');
|
const svc_database = this.services.get('database');
|
||||||
this.db = svc_database.get(DB_WRITE, 'notification');
|
this.db = svc_database.get(DB_WRITE, 'notification');
|
||||||
@ -109,6 +113,13 @@ class NotificationService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async on_user_connected ({ user }) {
|
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
|
// query the users unread notifications
|
||||||
const notifications = await this.db.read(
|
const notifications = await this.db.read(
|
||||||
'SELECT * FROM `notification` ' +
|
'SELECT * FROM `notification` ' +
|
||||||
|
@ -183,9 +183,11 @@ class WebServerService extends BaseService {
|
|||||||
socket.on('trash.is_empty', (msg) => {
|
socket.on('trash.is_empty', (msg) => {
|
||||||
socket.broadcast.to(socket.user.id).emit('trash.is_empty', msg);
|
socket.broadcast.to(socket.user.id).emit('trash.is_empty', msg);
|
||||||
});
|
});
|
||||||
const svc_event = this.services.get('event');
|
socket.on('puter_is_actually_open', (msg) => {
|
||||||
svc_event.emit('web.socket.user-connected', {
|
const svc_event = this.services.get('event');
|
||||||
user: socket.user
|
svc_event.emit('web.socket.user-connected', {
|
||||||
|
user: socket.user
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -66,6 +66,7 @@ async function UIDesktop(options){
|
|||||||
|
|
||||||
window.socket.on('connect', function(){
|
window.socket.on('connect', function(){
|
||||||
// console.log('GUI Socket: Connected', window.socket.id);
|
// console.log('GUI Socket: Connected', window.socket.id);
|
||||||
|
window.socket.emit('puter_is_actually_open');
|
||||||
});
|
});
|
||||||
|
|
||||||
window.socket.on('reconnect', function(){
|
window.socket.on('reconnect', function(){
|
||||||
|
Loading…
Reference in New Issue
Block a user