From 72992dfcae1caad4b42c7ffc64f66f7a5b2aa51c Mon Sep 17 00:00:00 2001 From: Zambom Date: Tue, 21 Mar 2017 23:17:30 -0300 Subject: [PATCH] Updating last message chat date when new arrives --- amadeus/static/js/socket.js | 5 ++++- chat/views.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/amadeus/static/js/socket.js b/amadeus/static/js/socket.js index 6d6d15d..54f3518 100644 --- a/amadeus/static/js/socket.js +++ b/amadeus/static/js/socket.js @@ -242,11 +242,14 @@ function messageReceived(content) { } else { var talk_line = $("#talk-" + content.container), talk_notifies = talk_line.find('.chat_notify'), - actual_count = talk_notifies.text(); + actual_count = talk_notifies.text(), + actual_date = talk_line.find(".talk-last_msg"); actual_count = parseInt(actual_count, 10) + 1; talk_notifies.text(actual_count); + + actual_date.html(content.last_date); $('.chat_badge').each(function () { var actual = $(this).text(); diff --git a/chat/views.py b/chat/views.py index 8bbf995..606cb93 100644 --- a/chat/views.py +++ b/chat/views.py @@ -7,6 +7,7 @@ from django.http import JsonResponse from django.template.loader import render_to_string from django.core.urlresolvers import reverse, reverse_lazy import textwrap +from django.utils import formats from django.utils.html import strip_tags from django.utils.translation import ugettext_lazy as _ from django.contrib.auth.mixins import LoginRequiredMixin @@ -193,7 +194,8 @@ class SendMessage(LoginRequiredMixin, generic.edit.CreateView): "notify_title": str(self.object.user), "simple_notify": simple_notify, "complete": render_to_string("chat/_message.html", {"talk_msg": self.object}, self.request), - "container": "chat-" + str(self.object.user.id) + "container": "chat-" + str(self.object.user.id), + "last_date": _("Last message in %s")%(formats.date_format(self.object.create_date, "SHORT_DATETIME_FORMAT")) } notification = json.dumps(notification) -- libgit2 0.21.2