fix: load avatars of user in notification dropdown (#17630)
This commit is contained in:
parent
84c6c09b80
commit
0b9a9ebfac
3 changed files with 37 additions and 9 deletions
|
|
@ -133,6 +133,22 @@ def get_email_header(doc):
|
|||
return header_map[doc.type or "Default"]
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_notification_logs(limit=20):
|
||||
notification_logs = frappe.db.get_list(
|
||||
"Notification Log", fields=["*"], limit=limit, order_by="creation desc"
|
||||
)
|
||||
|
||||
users = [log.from_user for log in notification_logs]
|
||||
users = [*set(users)] # remove duplicates
|
||||
user_info = frappe._dict()
|
||||
|
||||
for user in users:
|
||||
frappe.utils.add_user_info(user, user_info)
|
||||
|
||||
return {"notification_logs": notification_logs, "user_info": user_info}
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def mark_all_as_read():
|
||||
unread_docs_list = frappe.db.get_all(
|
||||
|
|
|
|||
|
|
@ -189,19 +189,22 @@ class NotificationsView extends BaseNotificationsView {
|
|||
);
|
||||
|
||||
this.setup_notification_listeners();
|
||||
this.get_notifications_list(this.max_length).then(list => {
|
||||
this.dropdown_items = list;
|
||||
this.get_notifications_list(this.max_length).then(r => {
|
||||
if (!r.message) return;
|
||||
this.dropdown_items = r.message.notification_logs;
|
||||
frappe.update_user_info(r.message.user_info);
|
||||
this.render_notifications_dropdown();
|
||||
if (this.settings.seen == 0) {
|
||||
this.toggle_notification_icon(false);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
update_dropdown() {
|
||||
this.get_notifications_list(1).then(r => {
|
||||
let new_item = r[0];
|
||||
if (!r.message) return;
|
||||
let new_item = r.message.notification_logs[0];
|
||||
frappe.update_user_info(r.message.user_info);
|
||||
this.dropdown_items.unshift(new_item);
|
||||
if (this.dropdown_items.length > this.max_length) {
|
||||
this.container
|
||||
|
|
@ -322,11 +325,10 @@ class NotificationsView extends BaseNotificationsView {
|
|||
}
|
||||
|
||||
get_notifications_list(limit) {
|
||||
return frappe.db.get_list('Notification Log', {
|
||||
fields: ['*'],
|
||||
limit: limit,
|
||||
order_by: 'creation desc'
|
||||
});
|
||||
return frappe.call(
|
||||
'frappe.desk.doctype.notification_log.notification_log.get_notification_logs',
|
||||
{ limit: limit }
|
||||
);
|
||||
}
|
||||
|
||||
get_item_link(notification_doc) {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,16 @@ frappe.user_info = function(uid) {
|
|||
return user_info;
|
||||
};
|
||||
|
||||
frappe.update_user_info = function(user_info) {
|
||||
for (let user in user_info) {
|
||||
if (frappe.boot.user_info[user]) {
|
||||
Object.assign(frappe.boot.user_info[user], user_info[user]);
|
||||
} else {
|
||||
frappe.boot.user_info[user] = user_info[user];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
frappe.provide('frappe.user');
|
||||
|
||||
$.extend(frappe.user, {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue