Commit 269127a9729d055258625c95ed791fa834c8bf9f

Authored by Zambom
1 parent 79740dd7

Adding chat notification badges

amadeus/context_processors.py
... ... @@ -3,6 +3,7 @@ from datetime import datetime
3 3 from themes.models import Themes
4 4 from notifications.models import Notification
5 5 from mural.models import MuralVisualizations
  6 +from chat.models import ChatVisualizations
6 7  
7 8 def theme(request):
8 9 context = {}
... ... @@ -35,4 +36,16 @@ def mural_notifies(request):
35 36  
36 37 context['mural_notifications_count'] = notifications
37 38  
  39 + return context
  40 +
  41 +def chat_notifies(request):
  42 + context = {}
  43 +
  44 + notifications = 0
  45 +
  46 + if request.user.is_authenticated:
  47 + notifications = ChatVisualizations.objects.filter(viewed = False, user = request.user).count()
  48 +
  49 + context['chat_notifications_count'] = notifications
  50 +
38 51 return context
39 52 \ No newline at end of file
... ...
amadeus/settings.py
... ... @@ -118,6 +118,7 @@ TEMPLATES = [
118 118 'amadeus.context_processors.theme',
119 119 'amadeus.context_processors.notifies',
120 120 'amadeus.context_processors.mural_notifies',
  121 + 'amadeus.context_processors.chat_notifies',
121 122 ],
122 123 },
123 124 },
... ...
amadeus/static/css/base/amadeus.css
... ... @@ -1468,6 +1468,7 @@ div.dataTables_wrapper div.dataTables_paginate {
1468 1468 #msg_editable {
1469 1469 width: 100%;
1470 1470 z-index: 1;
  1471 + min-height: 20px;
1471 1472 }
1472 1473  
1473 1474 .action-button {
... ...
amadeus/static/js/socket.js
... ... @@ -239,6 +239,43 @@ function messageReceived(content) {
239 239  
240 240 $(this).hide();
241 241 });
  242 + } else {
  243 + var talk_line = $("#talk-" + content.container),
  244 + talk_notifies = talk_line.find('.chat_notify'),
  245 + actual_count = talk_notifies.text();
  246 +
  247 + actual_count = parseInt(actual_count, 10) + 1;
  248 +
  249 + talk_notifies.text(actual_count);
  250 +
  251 + $('.chat_badge').each(function () {
  252 + var actual = $(this).text();
  253 +
  254 + if (actual != "+99") {
  255 + actual = parseInt(actual, 10) + 1;
  256 +
  257 + if (actual > 99) {
  258 + actual = "+99";
  259 + }
  260 +
  261 + $(this).text(actual);
  262 + }
  263 +
  264 + $(this).show();
  265 + });
  266 +
  267 + $('.chat-tabs').find('li').each(function () {
  268 + var identity = $(this).data('chat');
  269 +
  270 + if (identity == content.subtype) {
  271 + var span = $(this).find('span'),
  272 + actual = span.text();
  273 +
  274 + actual = parseInt(actual, 10) + 1;
  275 +
  276 + span.text(actual);
  277 + }
  278 + });
242 279 }
243 280  
244 281 if (("Notification" in window)) {
... ...
amadeus/templates/base.html
... ... @@ -209,6 +209,7 @@
209 209 <li class="item {{ chat_menu_active }} action_icon" data-toggle="tooltip" data-placement="right" title="{% trans "Messages" %}">
210 210 <a href="{% url 'chat:manage_general' %}">
211 211 <i class="fa fa-envelope-o" aria-hidden="true"></i>
  212 + <span class="badge notify_badge chat_badge" {% if chat_notifications_count == 0 %} style="display:none" {% endif %}>{% if chat_notifications_count > 99 %} +99 {% else %} {{ chat_notifications_count }} {% endif %}</span>
212 213 </a>
213 214 </li>
214 215 <li class="item {{ pendencies_menu_active }} action_icon" data-toggle="tooltip" data-placement="right" title="{% trans "Pendencies" %}">
... ... @@ -263,6 +264,7 @@
263 264 <li class="item {{ chat_menu_active }} action_icon" data-toggle="tooltip" data-placement="top" title="{% trans "Messages" %}">
264 265 <a href="{% url 'chat:manage_general' %}">
265 266 <i class="fa fa-envelope-o" aria-hidden="true"></i>
  267 + <span class="badge notify_badge chat_badge" {% if chat_notifications_count == 0 %} style="display:none" {% endif %}>{% if chat_notifications_count > 99 %} +99 {% else %} {{ chat_notifications_count }} {% endif %}</span>
266 268 </a>
267 269 </li>
268 270 <li class="item {{ pendencies_menu_active }} action_icon" data-toggle="tooltip" data-placement="top" title="{% trans "Pendencies" %}">
... ...
chat/templates/chat/_view.html
... ... @@ -4,12 +4,12 @@
4 4  
5 5 {% is_online talking_to as status %}
6 6  
7   -<div class="col-md-12 participant panel">
  7 +<div id="talk-chat-{{ talking_to.id }}" class="col-md-12 participant panel">
8 8 <div class="col-md-1 user-img">
9 9 <img src="{{ talking_to.image_url }}" class="img-responsive" />
10 10 </div>
11 11 <div class="col-md-6 user-info">
12   - <h4 class='talking-header'><a class="status {{ status }}" data-toggle="tooltip" title="{{ status|status_text }}"></a> {{ talking_to }}</h4>
  12 + <h4 class='talking-header'><a class="status {{ status }}" data-toggle="tooltip" title="{{ status|status_text }}"></a> {{ talking_to }} (<span class="chat_notify">{{ chat|notifies:request.user }}</span>)</h4>
13 13 <p class="talk-last_msg">{% trans 'Last message in' %} {{ chat|last_message }}</p>
14 14 </div>
15 15 <div class="col-md-4 buttons pull-right text-center">
... ...
chat/templates/chat/list.html
... ... @@ -13,10 +13,10 @@
13 13  
14 14 {% block content %}
15 15 <div id="core-subjects-options-div">
16   - <ul class="core-subjects-options mural-tabs">
  16 + <ul class="core-subjects-options chat-tabs">
17 17 <a href="{% url 'chat:manage_general' %}"><li data-chat="general" class="active">{% trans "General" %} (<span>{{ totals.general }}</span>)</li></a>
18   - <a href=""><li data-chat="categories">{% trans "Per Category" %} (<span>{{ totals.category }}</span>)</li></a>
19   - <a href=""><li data-chat="subjects">{% trans "Per Subject" %} (<span>{{ totals.subject }}</span>)</li></a>
  18 + <a href=""><li data-chat="category">{% trans "Per Category" %} (<span>{{ totals.category }}</span>)</li></a>
  19 + <a href=""><li data-chat="subject">{% trans "Per Subject" %} (<span>{{ totals.subject }}</span>)</li></a>
20 20 </ul>
21 21 </div>
22 22  
... ...
chat/templatetags/chat_tags.py
... ... @@ -7,7 +7,7 @@ from django.contrib.sessions.models import Session
7 7  
8 8 from log.models import Log
9 9  
10   -from chat.models import TalkMessages
  10 +from chat.models import TalkMessages, ChatVisualizations
11 11  
12 12 register = template.Library()
13 13  
... ... @@ -49,4 +49,10 @@ def chat_user(user, chat):
49 49 def last_message(chat):
50 50 last_message = TalkMessages.objects.filter(talk = chat).order_by('-create_date')[0]
51 51  
52   - return last_message.create_date
53 52 \ No newline at end of file
  53 + return last_message.create_date
  54 +
  55 +@register.filter(name = 'notifies')
  56 +def notifies(chat, user):
  57 + total = ChatVisualizations.objects.filter(message__talk = chat, user = user).count()
  58 +
  59 + return total
54 60 \ No newline at end of file
... ...