diff --git a/msg_app/models.py b/msg_app/models.py index 7d2142d..d69c4e6 100644 --- a/msg_app/models.py +++ b/msg_app/models.py @@ -2,6 +2,7 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ from accounts_app.models import UserProfile from chatbot.telebot import send_notify +from chatbot.models import ChatException class MessageError(Exception): @@ -147,7 +148,7 @@ class Conversation(models.Model): objects = ConversationManager() def get_messages(self): - return Message.objects.filter(conversation=self).order_by('sent_at')[:10] + return Message.objects.filter(conversation=self).order_by('sent_at') def get_messages_new_count(self, account): msgs = Message.objects.filter(conversation=self) @@ -159,16 +160,19 @@ class Conversation(models.Model): return messages[0] def new_message(self, text, attachment, author, with_status=True): - msg = Message.objects.create( - text=text, conversation=self, attachment=attachment, author=author - ) - if with_status: - for participant in self.participants.all(): - if participant == author: - continue - MessageStatus.objects.create(msg=msg, user=participant) - send_notify(msg_text=text,account=author, tag='msgapp') - return msg + try: + msg = Message.objects.create( + text=text, conversation=self, attachment=attachment, author=author + ) + if with_status: + for participant in self.participants.all(): + if participant == author: + continue + MessageStatus.objects.create(msg=msg, user=participant) + send_notify(msg_text=text, account=participant, tag='msgapp') + return msg + except ChatException as e: + raise MessageError(e) def remove_message(self, msg): if isinstance(msg, Message): diff --git a/msg_app/templates/msg_app/chat.html b/msg_app/templates/msg_app/chat.html index 5ee0394..89bf3fb 100644 --- a/msg_app/templates/msg_app/chat.html +++ b/msg_app/templates/msg_app/chat.html @@ -16,12 +16,12 @@ {{ conv.participants.count }} {% trans 'peoples' %} -
+
{% with can_view_profile=perms.accounts_app.can_view_userprofile %} {% for msg in msg_list %} {% with author=msg.author %} -
+
{% if msg.author == request.user %} diff --git a/msg_app/views.py b/msg_app/views.py index 2eafba9..2ffb87b 100644 --- a/msg_app/views.py +++ b/msg_app/views.py @@ -82,7 +82,7 @@ def check_news(request): r = { 'exist': True, 'content': msg, - 'title': _('Task') + 'title': "%s" % _('Message') } else: r = {'exist': False} diff --git a/static/css/custom.css b/static/css/custom.css index a96758d..d60c56c 100644 --- a/static/css/custom.css +++ b/static/css/custom.css @@ -267,3 +267,9 @@ div#loading>div.gif { border-style: ridge; } + + +.scroll-area { + overflow-y: auto; + max-height: 65vh; +} diff --git a/static/js/my.js b/static/js/my.js index 197400f..e1c82ff 100644 --- a/static/js/my.js +++ b/static/js/my.js @@ -181,6 +181,7 @@ $(document).ajaxError(function (ev, jqXHR, ajaxSettings, thrownError) { }, opt); var notifShow = function(title, content){ + if(!settings.news_url) return; var perm = Notification.permission.toLowerCase(); if(perm == "granted"){ curnotify = new Notification(title, { @@ -194,7 +195,7 @@ $(document).ajaxError(function (ev, jqXHR, ajaxSettings, thrownError) { } var on_ask_perm = function(r){ - notifShow("Thanks for letting notify you"); + console.log("Thanks for letting notify you"); } var check_news = function(){ @@ -203,6 +204,7 @@ $(document).ajaxError(function (ev, jqXHR, ajaxSettings, thrownError) { $.getJSON(settings.news_url, function(r){ if(r.exist){ notifShow(r.title, r.content); + /*console.log('News from '+settings.news_url+'. '+r.content);*/ }/*else console.log('No news from '+settings.news_url);*/ }); } @@ -212,7 +214,7 @@ $(document).ajaxError(function (ev, jqXHR, ajaxSettings, thrownError) { // прверяем новости раз в минуту var tiid = setInterval(check_news, settings.check_interval*1000); - Notification.requestPermission(on_ask_perm); + //Notification.requestPermission(on_ask_perm); } } })(jQuery);