chat routines
This commit is contained in:
SDE
2023-08-06 13:53:28 +03:00
parent b3bee232c3
commit ec317aa8ba
9 changed files with 79 additions and 19 deletions

View File

@@ -15,7 +15,7 @@ urlpatterns = [
path('my_routes/', my_routes_ajax, name='my_routes_ajax'),
path('subscribe/', subscribe_ajax, name='subscribe_ajax'),
path('new_msg_to_user/', new_msg_to_user_ajax, name='new_msg_to_user' ),
path('chats/', chats_ajax, name='chats_ajax'),
path('support_tickets/', support_tickets_ajax, name='support_tickets_ajax'),

View File

@@ -25,14 +25,14 @@ def subscribe_ajax(request):
return JsonResponse({'html': html}, status=200)
@login_required(login_url='/profile/login/')
def new_msg_to_user_ajax(request):
def chats_ajax(request):
if request.method != 'POST':
raise Http404
Dict = {
}
html = render_to_string('blocks/profile/b_new_msg_to_user.html', Dict, request=request)
html = render_to_string('blocks/profile/b_chats.html', Dict, request=request)
return JsonResponse({'html': html}, status=200)
@login_required(login_url='/profile/login/')

View File

@@ -9,6 +9,8 @@ urlpatterns = [
path('registration/', registration_View, name='registration_page'),
path('', user_profile_View, name='user_profile'),
path('chat/<int:user_id>/', chat_w_user_View, name='chat_w_user'),
path('chat/', chat_w_user_View, name='chat_w_user_wo_user_id'),
path('login/', login_View, name='login_profile'),

View File

@@ -22,6 +22,34 @@ def registration_View(request):
return HttpResponse(t.render(Dict, request))
@login_required(login_url='/profile/login/')
def chat_w_user_View(request, user_id=None):
from ChatServiceApp.funcs import get_chat_receivers_for_user, get_msgs_for_chat_w_users
receivers = get_chat_receivers_for_user(request.user)
cur_chat_msgs = None
try:
cur_receiver = User.objects.get(id=user_id)
if not cur_receiver in receivers:
receivers.insert(0, cur_receiver)
cur_chat_msgs = get_msgs_for_chat_w_users(request.user, cur_receiver)
except User.DoesNotExist:
cur_receiver = None
Dict = {
'page': 'chat',
'cur_receiver': cur_receiver,
'receivers': receivers,
'cur_chat_msgs':cur_chat_msgs
}
t = loader.get_template('pages/profile/p_user_profile.html')
return HttpResponse(t.render(Dict, request))
@login_required(login_url='/profile/login/')
def user_profile_View(request):