Commit 724a79a6dbf7afc8b6dcaa210ac2cbaeaaea6f0b
Exists in
master
and in
2 other branches
Merge branch 'refactoring' of https://github.com/amadeusproject/amadeuslms into refactoring
Showing
7 changed files
with
67 additions
and
3 deletions
Show diff stats
amadeus/static/js/chat.js
... | ... | @@ -79,6 +79,48 @@ function getModalInfo(btn, space, space_type) { |
79 | 79 | } |
80 | 80 | }); |
81 | 81 | |
82 | + var viewed = $(".messages-container").data('viewed'), | |
83 | + sub_badge = $(".messages-container").data('space'), | |
84 | + father = $(".messages-container").parent().parent().parent().parent(), | |
85 | + chat_list_item_id = "#talk-" + father.attr("id"); | |
86 | + | |
87 | + $('.chat_badge').each(function () { | |
88 | + var actual = $(this).text(); | |
89 | + | |
90 | + if (actual != "+99") { | |
91 | + actual = parseInt(actual, 10) - viewed; | |
92 | + | |
93 | + if (actual <= 0) { | |
94 | + $(this).text("0"); | |
95 | + $(this).hide(); | |
96 | + } else { | |
97 | + $(this).text(actual); | |
98 | + } | |
99 | + } | |
100 | + }); | |
101 | + | |
102 | + var counter = $(chat_list_item_id).find('.chat_notify_list').text(); | |
103 | + | |
104 | + counter = parseInt(counter, 10) - viewed; | |
105 | + | |
106 | + if (counter <= 0) { | |
107 | + counter = "0"; | |
108 | + } | |
109 | + | |
110 | + $(chat_list_item_id).find('.chat_notify_list').text(counter); | |
111 | + | |
112 | + var subject_cbadge = $("#subject_" + sub_badge).find('.chat_notify'), | |
113 | + actual = subject_cbadge.text(); | |
114 | + | |
115 | + if (actual != "+99") { | |
116 | + actual = parseInt(actual, 10) - viewed; | |
117 | + | |
118 | + if (actual <= 0) { | |
119 | + subject_cbadge.text("0"); | |
120 | + subject_cbadge.hide(); | |
121 | + } | |
122 | + } | |
123 | + | |
82 | 124 | setShortChatFormSubmit(); |
83 | 125 | setFiltersSubmitAndPagination(); |
84 | 126 | }); | ... | ... |
amadeus/static/js/mural_ungeneral.js
amadeus/static/js/socket.js
... | ... | @@ -241,9 +241,14 @@ function messageReceived(content) { |
241 | 241 | |
242 | 242 | $(this).hide(); |
243 | 243 | }); |
244 | + | |
245 | + $.ajax({ | |
246 | + type: 'GET', | |
247 | + url: content.view_url | |
248 | + }); | |
244 | 249 | } else { |
245 | 250 | var talk_line = $("#talk-" + content.container), |
246 | - talk_notifies = talk_line.find('.chat_notify'), | |
251 | + talk_notifies = talk_line.find('.chat_notify_list'), | |
247 | 252 | actual_count = talk_notifies.text(), |
248 | 253 | actual_date = talk_line.find(".talk-last_msg"); |
249 | 254 | ... | ... |
chat/templates/chat/_view.html
... | ... | @@ -9,7 +9,7 @@ |
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="user_{{ talking_to.id }}_status status {{ status }}" data-toggle="tooltip" title="{{ status|status_text }}"></a> {{ talking_to }} (<span class="chat_notify">{{ chat|notifies:request.user }}</span>)</h4> | |
12 | + <h4 class='talking-header'><a class="user_{{ talking_to.id }}_status status {{ status }}" data-toggle="tooltip" title="{{ status|status_text }}"></a> {{ talking_to }} (<span class="chat_notify_list">{{ 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/talk.html
... | ... | @@ -39,7 +39,7 @@ |
39 | 39 | </div> |
40 | 40 | </div> |
41 | 41 | <div class="row-fluid"> |
42 | - <div class="messages-container" data-talk="{{ talk_id }}" data-url="{% url 'chat:load_messages' talk_id %}" data-page="{{ page_obj.number }}" data-pages="{{ paginator.num_pages }}"> | |
42 | + <div class="messages-container" data-talk="{{ talk_id }}" data-url="{% url 'chat:load_messages' talk_id %}" data-page="{{ page_obj.number }}" data-pages="{{ paginator.num_pages }}" data-viewed="{{ messages_viewed }}" data-space="{{ subject }}"> | |
43 | 43 | <button type="button" class="btn btn-block btn-success btn-raised more-msgs" style="{% if paginator.num_pages == page_obj.number %}display:none;{% endif %}margin:0px"> |
44 | 44 | {% trans 'See old messages' %} |
45 | 45 | </button> | ... | ... |
chat/urls.py
... | ... | @@ -8,6 +8,7 @@ urlpatterns = [ |
8 | 8 | url(r'^subject/participants/(?P<subject>[\w_-]+)/$', views.SubjectParticipants.as_view(), name='participants_subject'), |
9 | 9 | url(r'^render_message/([\w_-]+)/([\w_-]+)/([\w_-]+)/([\w_-]+)/([\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/$', views.render_message, name='render_message'), |
10 | 10 | url(r'^favorite/([\w_-]+)/$', views.favorite, name='favorite'), |
11 | + url(r'^view_message/([\w_-]+)/$', views.message_viewed, name='view_message'), | |
11 | 12 | url(r'^load_messages/([\w_-]+)/$', views.load_messages, name='load_messages'), |
12 | 13 | url(r'^talk/(?P<email>[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/$', views.GetTalk.as_view(), name = 'talk'), |
13 | 14 | url(r'^send_message/(?P<email>[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})/(?P<talk_id>[\w_-]+)/(?P<space>[\w_-]+)/(?P<space_type>[\w_-]+)/$', views.SendMessage.as_view(), name = 'create'), | ... | ... |
chat/views.py
... | ... | @@ -258,6 +258,7 @@ class GetTalk(LoginRequiredMixin, LogMixin, generic.ListView): |
258 | 258 | template_name = 'chat/talk.html' |
259 | 259 | paginate_by = 20 |
260 | 260 | talk_id = "-1" |
261 | + n_viewed = 0 | |
261 | 262 | |
262 | 263 | def get_queryset(self): |
263 | 264 | user = self.request.user |
... | ... | @@ -274,6 +275,7 @@ class GetTalk(LoginRequiredMixin, LogMixin, generic.ListView): |
274 | 275 | messages = TalkMessages.objects.filter(talk = talk).order_by('-create_date') |
275 | 276 | |
276 | 277 | views = ChatVisualizations.objects.filter(Q(user = user) & Q(viewed = False) & (Q(message__talk = talk))) |
278 | + self.n_viewed = views.count() | |
277 | 279 | views.update(viewed = True, date_viewed = datetime.now()) |
278 | 280 | |
279 | 281 | return messages |
... | ... | @@ -283,6 +285,7 @@ class GetTalk(LoginRequiredMixin, LogMixin, generic.ListView): |
283 | 285 | |
284 | 286 | user_email = self.kwargs.get('email', '') |
285 | 287 | |
288 | + context['messages_viewed'] = self.n_viewed | |
286 | 289 | context['participant'] = get_object_or_404(User, email = user_email) |
287 | 290 | context['talk_id'] = self.talk_id |
288 | 291 | context['space'] = self.request.GET.get('space', '0') |
... | ... | @@ -290,6 +293,10 @@ class GetTalk(LoginRequiredMixin, LogMixin, generic.ListView): |
290 | 293 | context['form'] = ChatMessageForm() |
291 | 294 | context['form_url'] = reverse_lazy('chat:create', args = (), kwargs = {'email': self.kwargs.get('email', ''), 'talk_id': self.talk_id, 'space': self.request.GET.get('space', '0'), 'space_type': self.request.GET.get('space_type', 'general')}) |
292 | 295 | |
296 | + if context['space_type'] == "subject": | |
297 | + subject = get_object_or_404(Subject, id = context['space']) | |
298 | + context['subject'] = subject.slug | |
299 | + | |
293 | 300 | self.log_context['talk_id'] = self.talk_id |
294 | 301 | self.log_context['user_id'] = context['participant'].id |
295 | 302 | self.log_context['user_name'] = str(context['participant']) |
... | ... | @@ -352,6 +359,7 @@ class SendMessage(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
352 | 359 | "user_icon": self.object.user.image_url, |
353 | 360 | "notify_title": str(self.object.user), |
354 | 361 | "simple_notify": simple_notify, |
362 | + "view_url": reverse("chat:view_message", args = (self.object.id, ), kwargs = {}), | |
355 | 363 | "complete": render_to_string("chat/_message.html", {"talk_msg": self.object}, self.request), |
356 | 364 | "container": "chat-" + str(self.object.user.id), |
357 | 365 | "last_date": _("Last message in %s")%(formats.date_format(self.object.create_date, "SHORT_DATETIME_FORMAT")) |
... | ... | @@ -417,6 +425,13 @@ def favorite(request, message): |
417 | 425 | |
418 | 426 | return JsonResponse({'label': _('Favorite')}) |
419 | 427 | |
428 | +def message_viewed(request, message): | |
429 | + view = ChatVisualizations.objects.filter(message__id = message, user = request.user) | |
430 | + | |
431 | + view.update(viewed = True, date_viewed = datetime.now()) | |
432 | + | |
433 | + return JsonResponse({'msg': 'ok'}) | |
434 | + | |
420 | 435 | def load_messages(request, talk): |
421 | 436 | context = { |
422 | 437 | 'request': request, | ... | ... |