@@ -163,6 +163,10 @@ async function UIDesktop(options){
163
163
$ ( `.window[data-path="${ html_encode ( window . trash_path ) } " i]` ) . find ( '.item-container' ) . empty ( ) ;
164
164
} )
165
165
166
+ /**
167
+ * This event is triggered if a user receives a notification during
168
+ * an active session.
169
+ */
166
170
window . socket . on ( 'notif.message' , async ( { uid, notification } ) => {
167
171
let icon = window . icons [ notification . icon ] ;
168
172
let round_icon = false ;
@@ -207,6 +211,14 @@ async function UIDesktop(options){
207
211
} ) ;
208
212
} ) ;
209
213
214
+ /**
215
+ * This event is triggered at the beginning of the session, after a websocket
216
+ * connection is established, because the backend informs the frontend of all
217
+ * unread notifications.
218
+ *
219
+ * It is not necessary to query unreads separately. If this stops working,
220
+ * then this event should be fixed rather than querying unreads separately.
221
+ */
210
222
window . __already_got_unreads = false ;
211
223
window . socket . on ( 'notif.unreads' , async ( { unreads } ) => {
212
224
if ( window . __already_got_unreads ) return ;
@@ -1293,55 +1305,6 @@ async function UIDesktop(options){
1293
1305
} )
1294
1306
}
1295
1307
1296
- // fetch notifications
1297
- fetch ( puter . APIOrigin + "/drivers/call" , {
1298
- "headers" : {
1299
- "Content-Type" : "application/json" ,
1300
- "Authorization" : `Bearer ${ puter . authToken } ` ,
1301
- } ,
1302
- "body" : JSON . stringify ( {
1303
- interface : 'puter-notifications' ,
1304
- method : 'select' ,
1305
- args : { }
1306
- } ) ,
1307
- "method" : "POST" ,
1308
- } )
1309
- . then ( response => response . json ( ) )
1310
- . then ( data => {
1311
- if ( data && data . result && data . result . length > 0 ) {
1312
- data . data ?. forEach ( async notification => {
1313
- let icon = window . icons [ 'puter-logo.svg' ] ;
1314
- let round_icon = false ;
1315
-
1316
- if ( notification . template === "file-shared-with-you" && notification . fields ?. username ) {
1317
- let profile_pic = await get_profile_picture ( notification . fields ?. username ) ;
1318
- if ( profile_pic ) {
1319
- icon = profile_pic ;
1320
- round_icon = true ;
1321
- notification . round_icon = round_icon ;
1322
- }
1323
- }
1324
- notification . icon = icon ;
1325
-
1326
- notification . click = async ( notif ) => {
1327
- if ( notification . template === "file-shared-with-you" ) {
1328
- let item_path = '/' + notification . fields ?. username ;
1329
- UIWindow ( {
1330
- path : '/' + notification . fields ?. username ,
1331
- title : path . basename ( item_path ) ,
1332
- icon : await item_icon ( { is_dir : true , path : item_path } ) ,
1333
- is_dir : true ,
1334
- app : 'explorer' ,
1335
- } ) ;
1336
- }
1337
- }
1338
-
1339
- UINotification ( notification ) ;
1340
- } )
1341
- }
1342
- } )
1343
-
1344
-
1345
1308
//--------------------------------------------------------------------------------------
1346
1309
// Trying to view a user's public folder?
1347
1310
// i.e. https://puter.com/@<username>
0 commit comments