From f145286e900a44a9ef3b44754129aaa4175c8550 Mon Sep 17 00:00:00 2001 From: Zambom Date: Tue, 28 Mar 2017 21:31:42 -0300 Subject: [PATCH] Making category notification update when new messages --- amadeus/static/js/chat.js | 2 +- amadeus/static/js/socket.js | 11 +++++++++++ chat/templates/chat/list_category.html | 2 +- chat/views.py | 12 ++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/amadeus/static/js/chat.js b/amadeus/static/js/chat.js index e783526..af7897e 100644 --- a/amadeus/static/js/chat.js +++ b/amadeus/static/js/chat.js @@ -440,7 +440,7 @@ $('.chat-collapse').on('shown.bs.collapse', function(e) { var url = $(".cat_url").val(); var new_li = $(li).clone(); - new_li.html($(this).parent().find('.panel-title span').text()); + new_li.html($(this).parent().find('.panel-title .item_name').text()); $(li).html("" + li_text + ""); $(li).append("/"); diff --git a/amadeus/static/js/socket.js b/amadeus/static/js/socket.js index 54f3518..1e46668 100644 --- a/amadeus/static/js/socket.js +++ b/amadeus/static/js/socket.js @@ -279,6 +279,17 @@ function messageReceived(content) { span.text(actual); } }); + + var item = $("#" + content.space); + + if (typeof(item) != "undefined") { + var span = item.parent().find('span:not(.item_name)'), + actual = span.text(); + + actual = parseInt(actual, 10) + 1; + + span.text(actual); + } } if (("Notification" in window)) { diff --git a/chat/templates/chat/list_category.html b/chat/templates/chat/list_category.html index b448483..c2a51ac 100644 --- a/chat/templates/chat/list_category.html +++ b/chat/templates/chat/list_category.html @@ -41,7 +41,7 @@

- {{ category.name }} ({{ category|notifies_category:request.user }}) + {{ category.name }} ({{ category|notifies_category:request.user }})

diff --git a/chat/views.py b/chat/views.py index 56ea3a8..78c6d50 100644 --- a/chat/views.py +++ b/chat/views.py @@ -277,9 +277,21 @@ class SendMessage(LoginRequiredMixin, generic.edit.CreateView): if self.object.image: simple_notify += " ".join(_("[Photo]")) + subclass = self.object.talk._my_subclass + + if subclass == "generaltalk": + space_type = "general" + elif subclass == "categorytalk": + space_type = "category" + space = self.object.talk.categorytalk.space.slug + else: + space_type = "subject" + space = self.object.talk.subjecttalk.space.slug + notification = { "type": "chat", "subtype": space_type, + "space": space, "user_icon": self.object.user.image_url, "notify_title": str(self.object.user), "simple_notify": simple_notify, -- libgit2 0.21.2