feat: show profile pics in sharing notifications

This commit is contained in:
jelveh 2024-11-18 07:22:13 -08:00
parent b11016dab3
commit 0e45132c05
3 changed files with 45 additions and 5 deletions

View File

@ -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;

View File

@ -25,7 +25,7 @@ function UINotification(options){
h += `<div id="ui-notification__${window.global_element_id}" data-uid="${html_encode(options.uid)}" data-el-id="${window.global_element_id}" class="notification antialiased animate__animated animate__fadeInRight animate__slow">`;
h += `<img class="notification-close disable-user-select" src="${html_encode(window.icons['close.svg'])}">`;
h += `<div class="notification-icon">`;
h += `<img src="${html_encode(options.icon ?? window.icons['bell.svg'])}">`;
h += `<img style="${options.round_icon ? 'border-radius: 50%;' : ''}" src="${html_encode(options.icon ?? window.icons['bell.svg'])}">`;
h += `</div>`;
h += `<div class="notification-content">`;
h += `<div class="notification-title">${html_encode(options.title)}</div>`;

View File

@ -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;
}