Commit ee2ca54d87c32399c6fcf6613f2bf64c9904aa39

Authored by Zambom
1 parent 5e7b5b97

Updating mural comment notification

Showing 2 changed files with 40 additions and 12 deletions   Show diff stats
amadeus/static/js/socket.js
@@ -16,7 +16,7 @@ socket.onmessage = function(e) { @@ -16,7 +16,7 @@ socket.onmessage = function(e) {
16 muralNotificationMuralUpdate(content); 16 muralNotificationMuralUpdate(content);
17 } else if (content.subtype == "mural_delete") { 17 } else if (content.subtype == "mural_delete") {
18 muralNotificationMuralDelete(content); 18 muralNotificationMuralDelete(content);
19 - } else if (content.subtype == "create_comment") { 19 + } else if (content.subtype == "comment") {
20 muralNotificationComment(content); 20 muralNotificationComment(content);
21 } 21 }
22 } 22 }
@@ -103,11 +103,26 @@ function muralNotificationMuralDelete(content) { @@ -103,11 +103,26 @@ function muralNotificationMuralDelete(content) {
103 } 103 }
104 104
105 function muralNotificationComment(content) { 105 function muralNotificationComment(content) {
106 - if (window.location.pathname == content.pathname) {  
107 - if ($("#post-" + content.post_id).is(":visible")) {  
108 - var section = $("#post-" + content.post_id).find('.comment-section'); 106 + var page = window.location.pathname,
  107 + render = (content.paths.indexOf(page) != -1),
  108 + checker = "";
  109 +
  110 + switch (content.post_type) {
  111 + case "categorypost":
  112 + checker = "category";
  113 + break;
  114 + case "subjectpost":
  115 + checker = "subject";
  116 + break;
  117 + }
  118 +
  119 + if ((render && page.indexOf(checker) != -1) || (render && content.post_type == "generalpost")) {
  120 + var section = $(content.container);
109 121
110 - section.append(content.complete); 122 + if (section.is(":visible") || section.is(":hidden")) {
  123 + var comments = section.find('.comment-section');
  124 +
  125 + comments.append(content.complete);
111 } 126 }
112 } else { 127 } else {
113 $('.mural_badge').each(function () { 128 $('.mural_badge').each(function () {
@@ -130,7 +145,7 @@ function muralNotificationComment(content) { @@ -130,7 +145,7 @@ function muralNotificationComment(content) {
130 if (("Notification" in window)) { 145 if (("Notification" in window)) {
131 var options = { 146 var options = {
132 icon: content.user_icon, 147 icon: content.user_icon,
133 - body: content.simple 148 + body: content.simple_notify
134 } 149 }
135 150
136 if (Notification.permission === "granted") { 151 if (Notification.permission === "granted") {
mural/views.py
@@ -787,16 +787,29 @@ class CommentCreate(LoginRequiredMixin, generic.edit.CreateView): @@ -787,16 +787,29 @@ class CommentCreate(LoginRequiredMixin, generic.edit.CreateView):
787 787
788 users = getSpaceUsers(self.request.user.id, post) 788 users = getSpaceUsers(self.request.user.id, post)
789 entries = [] 789 entries = []
  790 +
  791 + paths = [
  792 + reverse("mural:manage_general"),
  793 + reverse("mural:manage_category"),
  794 + reverse("mural:manage_subject")
  795 + ]
790 796
791 - notify_type = "mural"  
792 - user_icon = self.object.user.image_url  
793 - _view = render_to_string("mural/_view_comment.html", {"comment": self.object}, self.request)  
794 - simple_notify = _("%s has commented in a post")%(str(self.object.user))  
795 - pathname = reverse("mural:manage_general") 797 + notification = {
  798 + "type": "mural",
  799 + "subtype": "comment",
  800 + "paths": paths,
  801 + "user_icon": self.object.user.image_url,
  802 + "simple_notify": _("%s has commented in a post")%(str(self.object.user)),
  803 + "complete": render_to_string("mural/_view_comment.html", {"comment": self.object}, self.request),
  804 + "container": "#post-id" + str(post.get_id()),
  805 + "post_type": post._my_subclass
  806 + }
  807 +
  808 + notification = json.dumps(notification)
796 809
797 for user in users: 810 for user in users:
798 entries.append(MuralVisualizations(viewed = False, user = user, comment = self.object)) 811 entries.append(MuralVisualizations(viewed = False, user = user, comment = self.object))
799 - 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()})}) 812 + Group("user-%s" % user.id).send({'text': notification})
800 813
801 MuralVisualizations.objects.bulk_create(entries) 814 MuralVisualizations.objects.bulk_create(entries)
802 815