diff --git a/api/views.py b/api/views.py index 0ce545b..a05e91a 100755 --- a/api/views.py +++ b/api/views.py @@ -1,5 +1,5 @@ from django.conf import settings -from django.db.models import Q +from django.db.models import Q, F from rest_framework import permissions from rest_framework.pagination import PageNumberPagination from rest_framework.viewsets import ModelViewSet @@ -124,7 +124,9 @@ class MessageViewSet(ModelViewSet): if search_param: # import code; code.interact(local=dict(globals(), **locals())) if search_param == 'in': - queryset = queryset.filter(Q(sender__in=[sender_id,recipent_id]),Q(recipent__in=[sender_id,recipent_id])).filter(order__isnull=True).order_by('created') + queryset = queryset.filter(Q(sender__in=[sender_id,recipent_id]),Q(recipent__in=[sender_id,recipent_id])).\ + filter(order__isnull=True).\ + filter(~Q(sender=F('recipent'))).order_by('created') return queryset diff --git a/assets/js/chat.js b/assets/js/chat.js index 744d209..0d5dbda 100644 --- a/assets/js/chat.js +++ b/assets/js/chat.js @@ -100,14 +100,29 @@ $(function () { $("#orderBlock" + ordHashId).trigger('click'); $("a[href='#tab2']").trigger('click'); }, 100); - } else if (currentHash.indexOf("#team") == 0) { + } else if(currentHash.indexOf("#user") == 0){ + var userHashId = currentHash.replace("#user", ""); + setTimeout(function () { + $("#userBlock" + userHashId).trigger('click'); + //$("a[href='#tab1']").trigger('click'); + }, 100); + } else if (currentHash.indexOf("#teamorder") == 0) { + var teamHashId = currentHash.replace("#teamorder", ""); + $("#teamOrderBlock" + teamHashId).trigger('click'); + $("a[href='#tab3']").trigger('click'); + } else if (currentHash.indexOf("#myteam") == 0){ + var teamHashId = currentHash.replace("#myteam", ""); + $("#teamMyBlock" + teamHashId).trigger('click'); + $("a[href='#tab3']").trigger('click'); } else { setTimeout(function () { $(".user-block").first().trigger('click'); + location.hash = ''; }, 10); setTimeout(function () { $(".order-block").first().trigger('click'); + location.hash = ''; }, 500); } // Информация о заказе @@ -231,6 +246,7 @@ $(function () { // Вытащить сообщения для конактов $('.user-block').on('click', function () { var contactId = $(this).attr('data-id'); + location.hash = '#user' + contactId; $("#contact-chat-form #recipentContactId").val(contactId); $("#add-form-contractor-note #recipentNoteContractor").val(contactId); diff --git a/assets/js/chat_contractor.js b/assets/js/chat_contractor.js index a1c0b8d..4602b75 100644 --- a/assets/js/chat_contractor.js +++ b/assets/js/chat_contractor.js @@ -142,6 +142,7 @@ $(function () { $(this).addClass('orAct'); var teamId = $(this).attr('data-team-id'); + location.hash = '#teamorder' + teamId; var orderId = $(this).attr('data-order-id'); $("#team-chat-form #teamId").val(teamId); $("#team-chat-form #orderTeamId").val(orderId); @@ -229,6 +230,7 @@ $(function () { docList.innerHTML = ''; var teamId = $(this).attr('data-team-id'); + location.hash = '#myteam' + teamId; $("#team-chat-form #teamId").val(teamId); $("#add-form-team-note #teamNote").val(teamId); $("#team-chat-form #orderTeamId").val(""); @@ -301,6 +303,7 @@ $(function () { }); $(this).addClass('orAct'); var orderId = $(this).attr('data-id'); + location.hash = '#order' + orderId; var recipentId = $(this).attr('data-recipent-id'); var projectId = $(this).attr('data-project-id'); diff --git a/chat/chat.py b/chat/chat.py index c3d2f4a..4b79f5d 100644 --- a/chat/chat.py +++ b/chat/chat.py @@ -54,6 +54,7 @@ class ChatHandler(websocket.WebSocketHandler): @gen.coroutine def add_message(self, message_data): + sender_id = message_data['data']['sender_id'] recipent_id = message_data['data']['recipent_id'] order_id = message_data['data'].get('order_id', None) diff --git a/chat/templates/chat_contractor.html b/chat/templates/chat_contractor.html index 4e15818..3084f02 100644 --- a/chat/templates/chat_contractor.html +++ b/chat/templates/chat_contractor.html @@ -39,7 +39,7 @@