diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index fb277184..08fad1ba 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 adbe2657..fa12059b 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 eca95689..fc8adef4 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 b53f7a6d..c2be6fad 100644 --- a/osinaweb/osichat/consumers.py +++ b/osinaweb/osichat/consumers.py @@ -571,6 +571,11 @@ class OsitcomChatRoom(WebsocketConsumer): if self.client_type == 'mobile_admin': chat_room_data = model_to_dict(chat_room) + chat_room_data['visitor'] = { + 'id': chat_room.chatroomguest.visitor.id, + 'country_flag': chat_room.chatroomguest.visitor.flag_image_url, + 'is_online': chat_room.chatroomguest.visitor.is_online, + } chat_room_messages_data = [] for message in chat_room_messages: @@ -657,7 +662,6 @@ class OsitcomChatRoom(WebsocketConsumer): 'domain': self.domain } if self.client_type == 'mobile_admin': - member_data = None if member: member_data = model_to_dict(member) member_data['image'] = member.staffprofile.image.url if member.staffprofile and member.staffprofile.image else None diff --git a/osinaweb/osichat/migrations/0029_chatnotification_session_id.py b/osinaweb/osichat/migrations/0029_chatnotification_session_id.py new file mode 100644 index 00000000..3a7ede4c --- /dev/null +++ b/osinaweb/osichat/migrations/0029_chatnotification_session_id.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.5 on 2024-09-06 06:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('osichat', '0028_chatnotification_type_id'), + ] + + operations = [ + migrations.AddField( + model_name='chatnotification', + name='session_id', + field=models.CharField(max_length=200, null=True), + ), + ] diff --git a/osinaweb/osichat/migrations/__pycache__/0029_chatnotification_session_id.cpython-310.pyc b/osinaweb/osichat/migrations/__pycache__/0029_chatnotification_session_id.cpython-310.pyc new file mode 100644 index 00000000..3d77b1e5 Binary files /dev/null and b/osinaweb/osichat/migrations/__pycache__/0029_chatnotification_session_id.cpython-310.pyc differ diff --git a/osinaweb/osichat/models.py b/osinaweb/osichat/models.py index 36f9c5ec..ff5eb5ef 100644 --- a/osinaweb/osichat/models.py +++ b/osinaweb/osichat/models.py @@ -53,7 +53,7 @@ def send_notification(notification): body=notification_data['body'], image=notification.image if notification.image else None, ), - data={"id": str(notification.type_id), "type": notification.type}, + data={"id": str(notification.type_id), "type": notification.type, "session_id": notification.session_id}, android=android_config, apns=apns_config ) @@ -110,6 +110,7 @@ class ChatNotification(models.Model): created_at = models.DateTimeField(auto_now_add=True) type = models.CharField(max_length=8, choices=TYPES, null=True) type_id = models.IntegerField(null=True) + session_id = models.CharField(max_length=200, null=True) def save(self, *args, **kwargs): is_new = not self.pk super().save(*args, **kwargs) @@ -218,6 +219,7 @@ class VisitorLog(models.Model): def send_visitor_notification(self, is_repeat=False): type_id = self.visitor.id + session_id = self.visitor.session_id if is_repeat: title = "Existing visitor new acitivity on Ositcom!" if self.title: @@ -235,7 +237,9 @@ class VisitorLog(models.Model): message = body, image = self.visitor.notification_flag_image_url, type = "Visitor", - type_id = type_id + type_id = type_id, + session_id=session_id + ) @@ -282,6 +286,7 @@ class ChatRoomGuest(models.Model): self.send_chat_notification() def send_chat_notification(self): type_id = self.id + session_id = self.visitor.session_id title = "New chat on Ositcom!" body = f"Visitor {self.visitor.ip_address} started a new chat on Ositcom" notification = ChatNotification.objects.create( @@ -289,7 +294,8 @@ class ChatRoomGuest(models.Model): message = body, image = self.visitor.notification_flag_image_url, type = "Chat", - type_id = type_id + type_id = type_id, + session_id = session_id ) class ChatRoomReview(models.Model): @@ -331,6 +337,7 @@ class ChatMessage(models.Model): self.send_message_notification() def send_message_notification(self): type_id = self.id + session_id = self.room.chatroomguest.visitor.session_id title = f"Visitor {self.room.chatroomguest.visitor.ip_address} sent a new message on Ositcom!" body = f"{self.content}" notification = ChatNotification.objects.create( @@ -338,7 +345,8 @@ class ChatMessage(models.Model): message = body, image = self.room.chatroomguest.visitor.notification_flag_image_url, type = "Chat", - type_id = type_id + type_id = type_id, + session_id = session_id )