diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 33eb2928..95194055 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osichat/__pycache__/consumers.cpython-310.pyc b/osinaweb/osichat/__pycache__/consumers.cpython-310.pyc index dfd9a270..56ea9268 100644 Binary files a/osinaweb/osichat/__pycache__/consumers.cpython-310.pyc and b/osinaweb/osichat/__pycache__/consumers.cpython-310.pyc differ diff --git a/osinaweb/osichat/__pycache__/models.cpython-310.pyc b/osinaweb/osichat/__pycache__/models.cpython-310.pyc index 559378f9..0a006e4c 100644 Binary files a/osinaweb/osichat/__pycache__/models.cpython-310.pyc and b/osinaweb/osichat/__pycache__/models.cpython-310.pyc differ diff --git a/osinaweb/osichat/consumers.py b/osinaweb/osichat/consumers.py index cd16fbd1..81a37092 100644 --- a/osinaweb/osichat/consumers.py +++ b/osinaweb/osichat/consumers.py @@ -95,8 +95,6 @@ class OsitcomChatRoom(WebsocketConsumer): ) if event_type == 'typing': - print(text_data_json.get('typing_status')) - print(text_data_json.get('user_id')) event = { 'type': 'typing_handler', 'user_id': text_data_json.get('user_id'), @@ -204,6 +202,16 @@ class OsitcomChatRoom(WebsocketConsumer): } self.update_read_messages_handler(event) + if event_type == 'end_chat': + event = { + 'type': 'end_chat_handler', + 'user_id': text_data_json.get('user_id') + } + async_to_sync(self.channel_layer.group_send)( + self.session_id, event + ) + + @@ -239,9 +247,12 @@ class OsitcomChatRoom(WebsocketConsumer): html = render_to_string("chat-widget.html", context=context) else: if chat_room: - html = render_to_string("chat-room.html", context=context) + if chat_room.date_terminated: + html = render_to_string("ended-chat.html", context=context) + else: + html = render_to_string("chat-room.html", context=context) else: - html = render_to_string("start-conversation.html", context=context) + html = render_to_string("start-chat.html", context=context) self.send(text_data=json.dumps({ 'event_type': 'load_chat', 'html': html, @@ -340,7 +351,33 @@ class OsitcomChatRoom(WebsocketConsumer): else: latest_unread_message = None + def uploaded_file_handler(self, event): + message_attachment = get_object_or_404(ChatMessageAttachment, id=event['message_attachment_id']) + context = { + 'message_attachment': message_attachment, + 'file_type': event['file_type'] + } + html = render_to_string("partials/message-attachment.html", context=context) + self.send(text_data=json.dumps({ + 'event_type': 'uploaded_file', + 'file_name': event['file_name'], + 'html': html, + })) - - - + def end_chat_handler(self, event): + if event['user_id']: + member = get_object_or_404(User, id=event['user_id']) + else: + member = None + self.chat_room.date_terminated = datetime.now() + self.chat_room.terminated_by = member + self.chat_room.save() + context = { + 'chat_room': self.chat_room, + 'chat_room_messages': ChatMessage.objects.filter(room=self.chat_room).order_by('date_sent'), + } + html = render_to_string("ended-chat.html", context=context) + self.send(text_data=json.dumps({ + 'event_type': 'ended_chat', + 'html': html, + })) \ No newline at end of file diff --git a/osinaweb/osichat/migrations/0017_chatroom_date_terminated_chatroom_terminated_by.py b/osinaweb/osichat/migrations/0017_chatroom_date_terminated_chatroom_terminated_by.py new file mode 100644 index 00000000..58229955 --- /dev/null +++ b/osinaweb/osichat/migrations/0017_chatroom_date_terminated_chatroom_terminated_by.py @@ -0,0 +1,26 @@ +# Generated by Django 4.2.5 on 2024-08-01 16:49 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('osichat', '0016_chatmessageseen_seen_date'), + ] + + operations = [ + migrations.AddField( + model_name='chatroom', + name='date_terminated', + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AddField( + model_name='chatroom', + name='terminated_by', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='terminated_chatrooms', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/osinaweb/osichat/migrations/__pycache__/0017_chatroom_date_terminated_chatroom_terminated_by.cpython-310.pyc b/osinaweb/osichat/migrations/__pycache__/0017_chatroom_date_terminated_chatroom_terminated_by.cpython-310.pyc new file mode 100644 index 00000000..6cbfecac Binary files /dev/null and b/osinaweb/osichat/migrations/__pycache__/0017_chatroom_date_terminated_chatroom_terminated_by.cpython-310.pyc differ diff --git a/osinaweb/osichat/models.py b/osinaweb/osichat/models.py index fffb4856..35eaa056 100644 --- a/osinaweb/osichat/models.py +++ b/osinaweb/osichat/models.py @@ -17,6 +17,8 @@ class ChatRoom(models.Model): name = models.CharField(max_length=300) created_by = models.ForeignKey(User, null=True, on_delete=models.SET_NULL, blank=True) date_created = models.DateTimeField() + terminated_by = models.ForeignKey(User, null=True, on_delete=models.SET_NULL, blank=True, related_name='terminated_chatrooms') + date_terminated = models.DateTimeField(null=True, blank=True) @property def last_updated(self): last_message = ChatMessage.objects.filter(room=self).order_by('-date_sent').first() @@ -31,6 +33,7 @@ class ChatRoom(models.Model): else: return last_updated_time.strftime('%d-%m-%Y') + class ChatRoomGuest(models.Model): room = models.OneToOneField(ChatRoom, on_delete=models.CASCADE, null=True) name = models.CharField(max_length=300) diff --git a/osinaweb/osichat/templates/chat-room.html b/osinaweb/osichat/templates/chat-room.html index cf27f59d..f63ce930 100644 --- a/osinaweb/osichat/templates/chat-room.html +++ b/osinaweb/osichat/templates/chat-room.html @@ -49,7 +49,7 @@ class="w-[25px] h-[25px] rounded-full shadow-md text-white flex justify-center items-center bg-osiblue uppercase text-xs"> {% if message.member.staffprofile.image %} + src="http://192.168.1.111:8000{{message.member.staffprofile.image.url}}"> {% else %}

{{message.member.first_name.0}}{{message.member.last_name.0}}

{% endif %} @@ -99,7 +99,7 @@ {% if message.chatmessageattachment.is_image %}
- +
{% else %} @@ -125,7 +125,7 @@ {% endfor %} - + @@ -161,7 +161,7 @@
- +

Osichat 2.0 by Ositcom

diff --git a/osinaweb/osichat/templates/chat-widget.html b/osinaweb/osichat/templates/chat-widget.html index a53914bb..952cf388 100644 --- a/osinaweb/osichat/templates/chat-widget.html +++ b/osinaweb/osichat/templates/chat-widget.html @@ -28,50 +28,49 @@
- - - - + - diff --git a/osinaweb/osichat/templates/ended-chat.html b/osinaweb/osichat/templates/ended-chat.html new file mode 100644 index 00000000..dd2a078d --- /dev/null +++ b/osinaweb/osichat/templates/ended-chat.html @@ -0,0 +1,134 @@ +{%load static%} + + + +
+
+ +
+
+
+ + + + + + + + + + + + +
+
+
+

{% if chat_room.chatroomguest.name %}Hello {{chat_room.chatroomguest.name}},{% else %}Hello,{% endif %} thank you for contacting us. Please bear with us while we + connect you with the next available agent as soon as possible.

+
+
+ + +
+ + {% for message in chat_room_messages %} + + {% if message.member %} +
+
+
+ {% if message.member.staffprofile.image %} + + {% else %} +

{{message.member.first_name.0}}{{message.member.last_name.0}}

+ {% endif %} +
+
+ {% if not message.chatmessageattachment %} +
+

{{message.content}}

+
+ {% else %} + {% if message.chatmessageattachment.is_image %} +
+ +
+ {% else %} +
+
+
+ + + + + +
+
+ {{message.chatmessageattachment.file_name}} +
+
+
+ {% endif %} + {% endif %} +
+ + + {% else %} + {% if not message.chatmessageattachment %} +
+
+

{{message.content}}

+
+
+ {% else %} + {% if message.chatmessageattachment.is_image %} +
+
+ +
+
+ {% else %} +
+
+
+
+ + + + + +
+
+ {{message.chatmessageattachment.file_name}} +
+
+
+
+ {% endif %} + {% endif %} + {% endif %} + {% endfor %} +
+ + + + +
+ + +
\ No newline at end of file diff --git a/osinaweb/osichat/templates/partials/message-attachment.html b/osinaweb/osichat/templates/partials/message-attachment.html index 1a969319..ce0c2812 100644 --- a/osinaweb/osichat/templates/partials/message-attachment.html +++ b/osinaweb/osichat/templates/partials/message-attachment.html @@ -5,7 +5,7 @@ class="w-[25px] h-[25px] rounded-full shadow-md text-white flex justify-center items-center bg-osiblue uppercase text-xs"> {% if message_attachment.message.member.staffprofile.image %} + src="http://192.168.1.111:8000{{message_attachment.message.member.staffprofile.image.url}}"> {% else %}

{{message_attachment.message.member.first_name.0}}{{message_attachment.message.member.last_name.0}}

{% endif %} @@ -14,7 +14,7 @@ {% if file_type == 'image' %}
- +
{% else %}
- +
{% else %} diff --git a/osinaweb/osichat/templates/partials/message.html b/osinaweb/osichat/templates/partials/message.html index 2ba53375..6bb6ea85 100644 --- a/osinaweb/osichat/templates/partials/message.html +++ b/osinaweb/osichat/templates/partials/message.html @@ -1,11 +1,11 @@ {% if chat_message.member %} -
+
{% if chat_message.member.staffprofile.image %} + src="http://192.168.1.111:8000{{chat_message.member.staffprofile.image.url}}"> {% else %}

{{chat_message.member.first_name.0}}{{chat_message.member.last_name.0}}

{% endif %} @@ -20,7 +20,7 @@ {% if chat_message.chatmessageattachment.is_image %}
- +
{% else %}
{% else %} {% if not chat_message.chatmessageattachment %} -
+

{{chat_message.content}}

@@ -53,13 +53,13 @@
{% else %} {% if chat_message.chatmessageattachment.is_image %} -
+
- +
{% else %} -
+
@@ -77,4 +77,15 @@
{% endif %} {% endif %} -{% endif %} \ No newline at end of file +{% endif %} + + + \ No newline at end of file diff --git a/osinaweb/osichat/templates/partials/typing.html b/osinaweb/osichat/templates/partials/typing.html index be843fae..dff0a3dc 100644 --- a/osinaweb/osichat/templates/partials/typing.html +++ b/osinaweb/osichat/templates/partials/typing.html @@ -3,7 +3,7 @@ class="w-[30px] h-[30px] rounded-full shadow-md text-white flex justify-center items-center bg-osiblue uppercase text-xs"> {% if member.staffprofile.image %} + src="http://192.168.1.111:8000{{member.staffprofile.image.url}}"> {% else %}

{{member.first_name.0}}{{member.last_name.0}}

{% endif %} diff --git a/osinaweb/osichat/templates/partials/unread-messages.html b/osinaweb/osichat/templates/partials/unread-messages.html index 5f5653d8..bbd0a743 100644 --- a/osinaweb/osichat/templates/partials/unread-messages.html +++ b/osinaweb/osichat/templates/partials/unread-messages.html @@ -7,7 +7,7 @@ class="w-[30px] h-[30px] rounded-full shadow-md text-white flex justify-center items-center bg-osiblue uppercase text-xs"> {% if latest_unread_message.member.staffprofile.image %} + src="http://192.168.1.111:8000{{latest_unread_message.member.staffprofile.image.url}}"> {% else %}

{{latest_unread_message.member.first_name.0}}{{latest_unread_message.member.last_name.0}}

{% endif %} @@ -45,7 +45,7 @@
{% else %}
- +
{% endif %} diff --git a/osinaweb/osichat/templates/start-chat.html b/osinaweb/osichat/templates/start-chat.html index 3ce60920..52282795 100644 --- a/osinaweb/osichat/templates/start-chat.html +++ b/osinaweb/osichat/templates/start-chat.html @@ -62,7 +62,7 @@
- +

Osichat 2.0 by Ositcom

diff --git a/osinaweb/static/images/uploaded_chat_files/4d198000-d76e-440e-af50-e6b16a21eada.jpeg b/osinaweb/static/images/uploaded_chat_files/4d198000-d76e-440e-af50-e6b16a21eada.jpeg new file mode 100644 index 00000000..2c7b114b Binary files /dev/null and b/osinaweb/static/images/uploaded_chat_files/4d198000-d76e-440e-af50-e6b16a21eada.jpeg differ diff --git a/osinaweb/static/images/uploaded_chat_files/5178d421-0fed-470e-a643-8cf5669aade6.jpeg b/osinaweb/static/images/uploaded_chat_files/5178d421-0fed-470e-a643-8cf5669aade6.jpeg new file mode 100644 index 00000000..44837dcc Binary files /dev/null and b/osinaweb/static/images/uploaded_chat_files/5178d421-0fed-470e-a643-8cf5669aade6.jpeg differ diff --git a/osinaweb/static/images/uploaded_chat_files/IMG_1918.webp b/osinaweb/static/images/uploaded_chat_files/IMG_1918.webp new file mode 100644 index 00000000..66e4f7fa Binary files /dev/null and b/osinaweb/static/images/uploaded_chat_files/IMG_1918.webp differ diff --git a/osinaweb/static/images/uploaded_chat_files/WSM_LOG_20240731_0751.log b/osinaweb/static/images/uploaded_chat_files/WSM_LOG_20240731_0751.log new file mode 100644 index 00000000..e69de29b diff --git a/osinaweb/static/images/uploaded_chat_files/image.jpg b/osinaweb/static/images/uploaded_chat_files/image.jpg new file mode 100644 index 00000000..a75a2374 Binary files /dev/null and b/osinaweb/static/images/uploaded_chat_files/image.jpg differ diff --git a/osinaweb/static/js/osichat-admin/conversation.js b/osinaweb/static/js/osichat-admin/conversation.js index 58aaa7fb..5bf06ffa 100644 --- a/osinaweb/static/js/osichat-admin/conversation.js +++ b/osinaweb/static/js/osichat-admin/conversation.js @@ -1,5 +1,5 @@ const admin_chat_ws_scheme = window.location.protocol === "https:" ? "wss" : "ws"; -const admin_chat_domain = "192.168.1.106:8000"; +const admin_chat_domain = "192.168.1.111:8000"; let chatWebSocket = null; diff --git a/osinaweb/static/js/osichat/conversation.js b/osinaweb/static/js/osichat/conversation.js index 5e38fa01..c75a45aa 100644 --- a/osinaweb/static/js/osichat/conversation.js +++ b/osinaweb/static/js/osichat/conversation.js @@ -1,5 +1,5 @@ const chat_ws_scheme = window.location.protocol === "https:" ? "wss" : "ws"; -const domain = "192.168.1.106:8000"; +const domain = "192.168.1.111:8000"; let osichatSocket; let isOpen = false; let chatLoaded = false; @@ -12,7 +12,7 @@ async function fetchSessionID() { let session_id = 'Unknown'; while (session_id === 'Unknown') { try { - const response = await fetch('http://192.168.1.106:3000/get-client-session/'); + const response = await fetch('http://192.168.1.111:3000/get-client-session/'); const data = await response.json(); if (data.session_id) { session_id = data.session_id; @@ -82,12 +82,12 @@ function handleLoadChatEvent(data, osichatSocket) { chatDiv.appendChild(script); } - const startChatContainer = document.getElementById('startChat'); + const startChatContainer = document.getElementById('startChat'); //Case where returned is start-conversation.html if (startChatContainer) { handleFormSubmission(startChatContainer, 'start_conversation', osichatSocket); } - const sendMessageContainer = document.getElementById('sendMessage'); + const sendMessageContainer = document.getElementById('sendMessage'); //Case where returned is chat-room.html if (sendMessageContainer) { appendTextAreaScript(domain, chatDiv); handleFormSubmission(sendMessageContainer, 'send_message', osichatSocket); @@ -96,6 +96,14 @@ function handleLoadChatEvent(data, osichatSocket) { uploadScript.type = 'text/javascript'; uploadScript.src = `http://${domain}/static/js/osichat/upload-file.js`; chatDiv.appendChild(uploadScript); + + const endChatScript = document.createElement('script'); + endChatScript.type = 'text/javascript'; + endChatScript.src = `http://${domain}/static/js/osichat/end-chat.js`; + chatDiv.appendChild(endChatScript); + + const endChatButton = document.getElementById('endChat'); + endChatButton.classList.remove('hidden') } } @@ -162,6 +170,14 @@ async function initializeChatWebSocket() { unreadMessages.classList.add('hidden'); } break; + case 'ended_chat': + const currentChat = document.getElementById(`roomContainer`); + if (currentChat) { + currentChat.innerHTML = data.html; + } + document.getElementById(`endChatConfirmationContainer`).classList.add('hidden'); + document.getElementById(`endChat`).classList.add('hidden'); + break; default: console.log('Unknown event type:', data.event_type); } @@ -192,6 +208,3 @@ window.addEventListener('offline', () => { // INITIALIZE CHAT WEB SOCKET initializeChatWebSocket(); - - - diff --git a/osinaweb/static/js/osichat/end-chat.js b/osinaweb/static/js/osichat/end-chat.js new file mode 100644 index 00000000..c7732c19 --- /dev/null +++ b/osinaweb/static/js/osichat/end-chat.js @@ -0,0 +1,29 @@ +(function() { + const endChat = document.getElementById('endChat'); + const endChatConfirmationContainer = document.getElementById("endChatConfirmationContainer"); + const closeConfirmationMessage = document.getElementById('closeConfirmationMessage'); + const endChatConfirmed = document.getElementById('endChatComfirmed'); + + + endChat.addEventListener("click", function() { + if (endChatConfirmationContainer) { + endChatConfirmationContainer.classList.remove("hidden"); + } + }); + + closeConfirmationMessage.addEventListener("click", function() { + if (closeConfirmationMessage) { + endChatConfirmationContainer.classList.add("hidden"); + } + }); + + endChatConfirmed.addEventListener("click", function() { + const eventMessage = { + event_type: 'end_chat', + }; + + osichatSocket.send(JSON.stringify(eventMessage)); + + }); + +})(); diff --git a/osinaweb/static/js/osichat/upload-file.js b/osinaweb/static/js/osichat/upload-file.js index a618ce46..04bdf8e6 100644 --- a/osinaweb/static/js/osichat/upload-file.js +++ b/osinaweb/static/js/osichat/upload-file.js @@ -1,5 +1,5 @@ (function () { - const imageDomain = "http://192.168.1.106:8000"; + const imageDomain = "http://192.168.1.111:8000"; // TO TRIGGER TEH FILE UPLOADER WHEN CLICKING ON THE UPLOAD FILE SVG document.getElementById('svgFileUpload').addEventListener('click', function () {