@@ -35,6 +35,10 @@ class NotificationService extends BaseService {
35
35
express : require ( 'express' ) ,
36
36
}
37
37
38
+ _construct ( ) {
39
+ this . merged_on_user_connected_ = { } ;
40
+ }
41
+
38
42
async _init ( ) {
39
43
const svc_database = this . services . get ( 'database' ) ;
40
44
this . db = svc_database . get ( DB_WRITE , 'notification' ) ;
@@ -109,14 +113,21 @@ class NotificationService extends BaseService {
109
113
}
110
114
111
115
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 } ) {
112
123
// query the users unread notifications
113
124
const notifications = await this . db . read (
114
125
'SELECT * FROM `notification` ' +
115
126
'WHERE user_id=? AND shown IS NULL AND acknowledged IS NULL ' +
116
127
'ORDER BY created_at ASC' ,
117
128
[ user . id ]
118
129
) ;
119
-
130
+
120
131
// set all the notifications to "shown"
121
132
const shown_ts = Math . floor ( Date . now ( ) / 1000 ) ;
122
133
await this . db . write (
@@ -140,7 +151,7 @@ class NotificationService extends BaseService {
140
151
notification : notif . value ,
141
152
} )
142
153
}
143
-
154
+
144
155
// send the unread notifications to gui
145
156
const svc_event = this . services . get ( 'event' ) ;
146
157
svc_event . emit ( 'outer.gui.notif.unreads' , {
0 commit comments