Skip to content

Commit f87769b

Browse files
committed
fix: remove redundant notification query
1 parent 2336a62 commit f87769b

File tree

1 file changed

+12
-49
lines changed

1 file changed

+12
-49
lines changed

src/gui/src/UI/UIDesktop.js

+12-49
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ async function UIDesktop(options){
163163
$(`.window[data-path="${html_encode(window.trash_path)}" i]`).find('.item-container').empty();
164164
})
165165

166+
/**
167+
* This event is triggered if a user receives a notification during
168+
* an active session.
169+
*/
166170
window.socket.on('notif.message', async ({ uid, notification }) => {
167171
let icon = window.icons[notification.icon];
168172
let round_icon = false;
@@ -207,6 +211,14 @@ async function UIDesktop(options){
207211
});
208212
});
209213

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+
*/
210222
window.__already_got_unreads = false;
211223
window.socket.on('notif.unreads', async ({ unreads }) => {
212224
if ( window.__already_got_unreads ) return;
@@ -1293,55 +1305,6 @@ async function UIDesktop(options){
12931305
})
12941306
}
12951307

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-
13451308
//--------------------------------------------------------------------------------------
13461309
// Trying to view a user's public folder?
13471310
// i.e. https://puter.com/@<username>

0 commit comments

Comments
 (0)