Merge remote-tracking branch 'origin/main'

This commit is contained in:
2023-08-11 14:33:15 +03:00
8 changed files with 102 additions and 41 deletions

View File

@@ -66,6 +66,15 @@ def get_chat_receivers_for_user(user):
#
# return list(set(receivers_list))
def get_tickets_Dict_by_manager(user):
tickets = MsgGroup.objects.filter(enable=True, manager=user).order_by('-modifiedDT')
Dict = {
'tickets': tickets,
}
return Dict
def get_messages_for_ticket(ticket):
return ticket.rel_messages_for_group.filter(enable=True).order_by('-modifiedDT')

View File

@@ -76,8 +76,15 @@ def update_chat_ajax(request):
})
msgs = get_messages_for_ticket(ticket)
context_Dict = get_ticketsDict_for_staff(request.user)
tickets_list_html = render_to_string(
'blocks/profile/b_list_of_tickets_support_chat.html', context_Dict, request=request)
res_Dict.update({'tickets_list_html': tickets_list_html})
else:
msgs = get_msgs_for_chat_w_users(sender, receiver)
users_list_html = render_to_string(
'blocks/profile/b_list_of_users_messenger.html', res_Dict, request=request)
res_Dict.update({'users_list_html': users_list_html})
if not msgs or (request.user != msgs[0].receiver) or (not msgs and not last_message_modifiedDT) or (msgs and last_message_modifiedDT and msgs[0].modifiedDT <= last_message_modifiedDT):
Dict.update({
@@ -86,6 +93,7 @@ def update_chat_ajax(request):
return JsonResponse(Dict, status=200)
res_Dict.update({
'messages': msgs,
'cur_receiver': receiver,
@@ -94,11 +102,10 @@ def update_chat_ajax(request):
html = render_to_string(tpl_name, res_Dict, request=request)
res_Dict.update({'receivers': get_chat_receivers_for_user(request.user)})
users_list_html = render_to_string('blocks/profile/b_list_of_users_messenger.html', res_Dict, request=request)
Dict.update({
'html': html,
'users_list_html': users_list_html,
'required_beep': True,
})
return JsonResponse(Dict, status=200)

View File

@@ -1,36 +1,73 @@
window.onload = function () {
funcFocus()
}
//
// document.querySelector(".enter-message-inp").onload(
// funcFocus()
// )
function funcFocus(){
$(document).ready(
check_new_messages_timeout()
)
let inp = document.querySelector(".enter-message-inp")
if (inp !== null){
inp.focus()
}
}
var check_msg = null
var it = 0
function check_new_messages_timeout(){
// function initial_function (){
// var it_set_func = 0
// var it_func = 0
// check_new_messages_timeout(60000,it_set_func,it_func)
// }
function check_new_messages_timeout(timeout_time=1000){
let window = document.querySelector(".container-messages")
if (window !== null){
}
// if (window !== null){
//
//
// }
// if (it_set_func === 0){
// // clearInterval(check_msg)
// if (window === null){
// it_set_func++
// check_new_messages_timeout(60000,it_set_func,it_func)
// } else {
// let new_timeout_time = 1000
// it_set_func++
// check_new_messages_timeout(new_timeout_time,it_set_func,it_func)
// }
//
// }
check_msg = setInterval(function () {
// let new_message = getNewMessageSession()
// let user_online = userOnline('set')
window = document.querySelector(".container-messages")
if (window === null){
// let new_message = getNewMessageSession()
// let user_online = userOnline('set')
window = document.querySelector(".container-messages")
if (window === null){
// let new_timeout_time = 60000
//
} else {
it = 0
check_new_messages(window)
}
},
60000)
// check_new_messages_timeout(new_timeout_time,it_set_func,it_func)
} else {
// if (it_func === 0){
// let new_timeout_time = 1000
// it_func++
// check_new_messages_timeout(new_timeout_time,it_set_func,it_func)
// }
check_new_messages(window)
}
},
timeout_time)
}
@@ -114,6 +151,9 @@ function success_check_new_messages (data) {
if (data.users_list_html){
document.querySelector(".block-list-of-users").innerHTML = data.users_list_html
}
if (data.tickets_list_html){
document.querySelector(".block-list-of-users").innerHTML = data.tickets_list_html
}
// let updatedCookie = encodeURIComponent(name_cookie) + "=" + encodeURIComponent('');
// let search_cookie = document.cookie.match("(^|[^;]+)\s*" + name_cookie + "\s*=\s*([^;]+)")[0].substring(1)
// let search_cookie = getCookieValue('user_alerts')

View File

@@ -184,7 +184,9 @@ function selectedUserMessenger (ticket_id=null,user_id=null){
getNewMessageSession()
}
document.querySelector(".info_profile").innerHTML = data.html;
document.querySelector(".enter-message-inp").focus()
},
error: function (data){

View File

@@ -1,4 +1,4 @@
<section class="profile">
<section class="profile" >
{% csrf_token %}
<div

View File

@@ -58,7 +58,7 @@
<div class="footer-chat">
<div class="left-part-block-enter-message">
<input class="enter-message-inp" onkeypress="sendMessageEnter(event,null,{{ user.id }},{{ cur_receiver.id }})" placeholder="Отправить сообщение">
<input class="enter-message-inp" onfocus="check_new_messages_timeout()" onkeypress="sendMessageEnter(event,null,{{ user.id }},{{ cur_receiver.id }})" placeholder="Отправить сообщение">
</div>
<div class="right-part-block-enter-message">
<button class="attach-file-btn-message" onclick="attachFilemeassge()"></button>

View File

@@ -0,0 +1,19 @@
{% load static %}
<span class="title-list-of-users">Неразобранные тикеты</span>
<div class="insert_users">
{% if tickets_wo_manager %}
{% for item in tickets_wo_manager %}
{% include "widgets/w_chat_right_panel_tickets.html" %}
{% endfor %}
{% endif %}
</div>
<div class="block_tickets_in_work">
<span class="title-list-of-users">Тикеты в работе</span>
{% if tickets_for_manager %}
{% for item in tickets_for_manager %}
{% include "widgets/w_chat_right_panel_tickets.html" %}
{% endfor %}
{% endif %}
</div>

View File

@@ -48,7 +48,7 @@
<div class="footer-chat{% if not new_msg_allow %} hide{% endif %}">
<div class="left-part-block-enter-message">
<input class="enter-message-inp" onkeypress="sendMessageEnter(event,{{ ticket.id }},{{ user.id }},{{ ticket.owner.id }})" placeholder="Отправить сообщение">
<input class="enter-message-inp" onfocus="check_new_messages_timeout()" onkeypress="sendMessageEnter(event,{{ ticket.id }},{{ user.id }},{{ ticket.owner.id }})" placeholder="Отправить сообщение">
</div>
<div class="right-part-block-enter-message">
<button class="attach-file-btn-message" onclick="attachFilemeassge()"></button>
@@ -60,23 +60,7 @@
{% endif %}
{% if user.is_staff %}
<div class="block-list-of-users">
<span class="title-list-of-users">Неразобранные тикеты</span>
<div class="insert_users">
{% if tickets_wo_manager %}
{% for item in tickets_wo_manager %}
{% include "widgets/w_chat_right_panel_tickets.html" %}
{% endfor %}
{% endif %}
</div>
<div class="block_tickets_in_work">
<span class="title-list-of-users">Тикеты в работе</span>
{% if tickets_for_manager %}
{% for item in tickets_for_manager %}
{% include "widgets/w_chat_right_panel_tickets.html" %}
{% endfor %}
{% endif %}
</div>
{% include "blocks/profile/b_list_of_tickets_support_chat.html" %}
</div>
{% endif %}
</div>