From 0e45132c05aa1106503fef02b7e4c97ecc675e10 Mon Sep 17 00:00:00 2001 From: jelveh Date: Mon, 18 Nov 2024 07:22:13 -0800 Subject: [PATCH] feat: show profile pics in sharing notifications --- src/gui/src/UI/UIDesktop.js | 19 +++++++++++++++---- src/gui/src/UI/UINotification.js | 2 +- src/gui/src/helpers.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/gui/src/UI/UIDesktop.js b/src/gui/src/UI/UIDesktop.js index eec8c38bf..549028b5a 100644 --- a/src/gui/src/UI/UIDesktop.js +++ b/src/gui/src/UI/UIDesktop.js @@ -123,12 +123,23 @@ async function UIDesktop(options){ $(`.window[data-path="${html_encode(window.trash_path)}" i]`).find('.item-container').empty(); }) - window.socket.on('notif.message', ({ uid, notification }) => { - const icon = window.icons[notification.icon]; + window.socket.on('notif.message', async ({ uid, notification }) => { + let icon = window.icons[notification.icon]; + let round_icon = false; + + if(notification.template === "file-shared-with-you" && notification.fields?.username){ + let profile_pic = await get_profile_picture(notification.fields.username); + if(profile_pic){ + icon = profile_pic; + round_icon = true; + } + } + UINotification({ title: notification.title, text: notification.text, icon: icon, + round_icon: round_icon, value: notification, uid, close: async () => { @@ -1756,5 +1767,5 @@ window.reset_window_size_and_position = (el_window)=>{ left: 'calc(50% - 340px)', }); } - -export default UIDesktop; + +export default UIDesktop; \ No newline at end of file diff --git a/src/gui/src/UI/UINotification.js b/src/gui/src/UI/UINotification.js index c5b64fe52..127007ab4 100644 --- a/src/gui/src/UI/UINotification.js +++ b/src/gui/src/UI/UINotification.js @@ -25,7 +25,7 @@ function UINotification(options){ h += `
`; h += ``; h += `
`; - h += ``; + h += ``; h += `
`; h += `
`; h += `
${html_encode(options.title)}
`; diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index a968f59fe..afec23e07 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2651,4 +2651,33 @@ window.update_profile = function(username, key_vals){ // Ignored console.log(e); }); +} + +window.blob2str = (blob) => { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => resolve(reader.result); + reader.onerror = reject; + reader.readAsText(blob); + }); +} + +window.get_profile_picture = async function(username){ + let icon; + // try getting profile pic + try{ + let stat = await puter.fs.stat('/' + username + '/Public/.profile'); + if(stat.size > 0 && stat.is_dir === false && stat.size < 1000000){ + let profile_json = await puter.fs.read('/' + username + '/Public/.profile'); + profile_json = await blob2str(profile_json); + const profile = JSON.parse(profile_json); + + if(profile.picture && profile.picture.startsWith('data:image')){ + icon = profile.picture; + } + } + }catch(e){ + } + + return icon; } \ No newline at end of file