fix: track seen in notification settings

This commit is contained in:
prssanna 2019-11-12 15:28:28 +05:30
parent bb46bb0fa7
commit 643f185edc
5 changed files with 32 additions and 34 deletions

View file

@ -11,7 +11,6 @@
"column_break_4",
"document_type",
"read",
"seen",
"document_name",
"from_user"
],
@ -58,13 +57,6 @@
"read_only": 1,
"search_index": 1
},
{
"default": "0",
"fieldname": "seen",
"fieldtype": "Check",
"hidden": 1,
"label": "Seen"
},
{
"fieldname": "document_name",
"fieldtype": "Data",
@ -90,7 +82,7 @@
}
],
"in_create": 1,
"modified": "2019-11-07 20:42:07.548645",
"modified": "2019-11-12 15:22:35.283678",
"modified_by": "umair@erpnext.com",
"module": "Desk",
"name": "Notification Log",

View file

@ -112,13 +112,11 @@ def get_title_html(title):
return '<b class="subject-title">{0}</b>'.format(title)
@frappe.whitelist()
def set_all_values_for_field(docnames, fieldname):
def mark_all_as_read(docnames):
docnames = frappe.parse_json(docnames)
event_name = 'all_' + fieldname
if docnames:
filters = {'name': ['in', docnames]}
frappe.db.set_value('Notification Log', filters, fieldname, 1, update_modified=False)
frappe.publish_realtime(event_name, after_commit=True, user=frappe.session.user)
frappe.db.set_value('Notification Log', filters, 'read', 1, update_modified=False)
@frappe.whitelist()
def mark_as_read(docname):

View file

@ -13,7 +13,8 @@
"enable_email_assignment",
"enable_email_energy_point",
"enable_email_share",
"user"
"user",
"seen"
],
"fields": [
{
@ -75,11 +76,18 @@
"label": "User",
"options": "User",
"read_only": 1
},
{
"default": "0",
"fieldname": "seen",
"fieldtype": "Check",
"hidden": 1,
"label": "Seen"
}
],
"in_create": 1,
"modified": "2019-11-08 14:11:35.619306",
"modified_by": "frappetestuser2@gmail.com",
"modified": "2019-11-12 14:50:16.822761",
"modified_by": "Administrator",
"module": "Desk",
"name": "Notification Settings",
"owner": "Administrator",

View file

@ -60,3 +60,7 @@ def get_permission_query_conditions(user):
if not user: user = frappe.session.user
return '''(`tabNotification Settings`.user = '{user}')'''.format(user=user)
@frappe.whitelist()
def set_seen_value(value):
frappe.db.set_value('Notification Settings', frappe.session.user, 'seen', value, update_modified=False)

View file

@ -59,8 +59,7 @@ frappe.ui.Notifications = class Notifications {
this.get_notifications_list(this.max_length).then(list => {
this.dropdown_items = list;
this.render_notifications_dropdown();
if (this.$notifications.find('.unseen').length) {
if (this.notifications_settings.seen == 0) {
this.$notification_indicator.show();
}
});
@ -264,26 +263,17 @@ frappe.ui.Notifications = class Notifications {
.map(d => d.name);
if (!unread_docnames.length) return;
frappe.call(
'frappe.desk.doctype.notification_log.notification_log.set_all_values_for_field',
'frappe.desk.doctype.notification_log.notification_log.mark_all_as_read',
{
docnames: unread_docnames,
fieldname: 'read'
}
);
}
mark_all_as_seen() {
this.$dropdown_list.find('.unseen').removeClass('unseen');
let unseen_docnames = this.dropdown_items
.filter(item => item.seen === 0)
.map(d => d.name);
if (!unseen_docnames.length) return;
mark_as_seen() {
frappe.call(
'frappe.desk.doctype.notification_log.notification_log.set_all_values_for_field',
{
docnames: unseen_docnames,
fieldname: 'seen'
}
'frappe.desk.doctype.notification_settings.notification_settings.set_seen_value',
{ value: 1 }
);
}
@ -333,7 +323,6 @@ frappe.ui.Notifications = class Notifications {
field.document_name
);
let read_class = field.read ? '' : 'unread';
let seen_class = field.seen ? '' : 'unseen';
let mark_read_action = field.read ? '': 'data-action="mark_as_read"';
let message = field.subject;
let title = message.match(/<b class="subject-title">(.*?)<\/b>/);
@ -343,7 +332,7 @@ frappe.ui.Notifications = class Notifications {
let user_avatar = frappe.avatar(user, 'avatar-small user-avatar');
let timestamp = frappe.datetime.comment_when(field.creation, true);
let item_html =
`<a class="recent-item ${read_class} ${seen_class}"
`<a class="recent-item ${read_class}"
href="${doc_link}"
data-name="${field.name}"
${mark_read_action}
@ -451,6 +440,13 @@ frappe.ui.Notifications = class Notifications {
setup_notification_listeners() {
frappe.realtime.on('notification', () => {
if (this.notifications_settings.seen == 1) {
this.notifications_settings.seen = 0;
frappe.call(
'frappe.desk.doctype.notification_settings.notification_settings.set_seen_value',
{ value: 0 }
);
}
this.$dropdown.find('.notifications-indicator').show();
this.update_dropdown();
});
@ -475,7 +471,7 @@ frappe.ui.Notifications = class Notifications {
});
this.$dropdown.on('show.bs.dropdown', () => {
this.mark_all_as_seen();
this.mark_as_seen();
if (this.$notification_indicator.is(':visible')) {
this.$notification_indicator.hide();
frappe.call(