Dmitry Novikov 8 years ago
parent
commit
657e8f6fe3
  1. 26
      msg_app/models.py
  2. 4
      msg_app/templates/msg_app/chat.html
  3. 2
      msg_app/views.py
  4. 6
      static/css/custom.css
  5. 6
      static/js/my.js

26
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):

4
msg_app/templates/msg_app/chat.html

@ -16,12 +16,12 @@
<small>{{ conv.participants.count }} {% trans 'peoples' %}</small>
</h3>
</div>
<div class="list-group">
<div class="list-group scroll-area">
{% with can_view_profile=perms.accounts_app.can_view_userprofile %}
{% for msg in msg_list %}
{% with author=msg.author %}
<div class="list-group-item clearfix">
<div class="list-group-item">
{% if msg.author == request.user %}
<a href="{% url 'msg_app:remove_msg' conv.pk msg.pk %}" class="btn btn-link pull-right" title="{% trans 'Delete' %}" data-toggle="tooltip">
<span class="glyphicon glyphicon-remove"></span>

2
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}

6
static/css/custom.css

@ -267,3 +267,9 @@ div#loading>div.gif {
border-style: ridge;
}
.scroll-area {
overflow-y: auto;
max-height: 65vh;
}

6
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);

Loading…
Cancel
Save