From ee2ca54d87c32399c6fcf6613f2bf64c9904aa39 Mon Sep 17 00:00:00 2001 From: Zambom Date: Fri, 17 Feb 2017 23:16:36 -0200 Subject: [PATCH] Updating mural comment notification --- amadeus/static/js/socket.js | 27 +++++++++++++++++++++------ mural/views.py | 25 +++++++++++++++++++------ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/amadeus/static/js/socket.js b/amadeus/static/js/socket.js index a5d7742..a6b5ae5 100644 --- a/amadeus/static/js/socket.js +++ b/amadeus/static/js/socket.js @@ -16,7 +16,7 @@ socket.onmessage = function(e) { muralNotificationMuralUpdate(content); } else if (content.subtype == "mural_delete") { muralNotificationMuralDelete(content); - } else if (content.subtype == "create_comment") { + } else if (content.subtype == "comment") { muralNotificationComment(content); } } @@ -103,11 +103,26 @@ function muralNotificationMuralDelete(content) { } function muralNotificationComment(content) { - if (window.location.pathname == content.pathname) { - if ($("#post-" + content.post_id).is(":visible")) { - var section = $("#post-" + content.post_id).find('.comment-section'); + var page = window.location.pathname, + render = (content.paths.indexOf(page) != -1), + checker = ""; + + switch (content.post_type) { + case "categorypost": + checker = "category"; + break; + case "subjectpost": + checker = "subject"; + break; + } + + if ((render && page.indexOf(checker) != -1) || (render && content.post_type == "generalpost")) { + var section = $(content.container); - section.append(content.complete); + if (section.is(":visible") || section.is(":hidden")) { + var comments = section.find('.comment-section'); + + comments.append(content.complete); } } else { $('.mural_badge').each(function () { @@ -130,7 +145,7 @@ function muralNotificationComment(content) { if (("Notification" in window)) { var options = { icon: content.user_icon, - body: content.simple + body: content.simple_notify } if (Notification.permission === "granted") { diff --git a/mural/views.py b/mural/views.py index 8f615d3..817dd9d 100644 --- a/mural/views.py +++ b/mural/views.py @@ -787,16 +787,29 @@ class CommentCreate(LoginRequiredMixin, generic.edit.CreateView): users = getSpaceUsers(self.request.user.id, post) entries = [] + + paths = [ + reverse("mural:manage_general"), + reverse("mural:manage_category"), + reverse("mural:manage_subject") + ] - notify_type = "mural" - user_icon = self.object.user.image_url - _view = render_to_string("mural/_view_comment.html", {"comment": self.object}, self.request) - simple_notify = _("%s has commented in a post")%(str(self.object.user)) - pathname = reverse("mural:manage_general") + notification = { + "type": "mural", + "subtype": "comment", + "paths": paths, + "user_icon": self.object.user.image_url, + "simple_notify": _("%s has commented in a post")%(str(self.object.user)), + "complete": render_to_string("mural/_view_comment.html", {"comment": self.object}, self.request), + "container": "#post-id" + str(post.get_id()), + "post_type": post._my_subclass + } + + notification = json.dumps(notification) for user in users: entries.append(MuralVisualizations(viewed = False, user = user, comment = self.object)) - Group("user-%s" % user.id).send({'text': json.dumps({"type": notify_type, "subtype": "create_comment", "user_icon": user_icon, "pathname": pathname, "simple": simple_notify, "complete": _view, "post_id": post.get_id()})}) + Group("user-%s" % user.id).send({'text': notification}) MuralVisualizations.objects.bulk_create(entries) -- libgit2 0.21.2