diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index bf7d2f19..fb277184 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 a446714b..adbe2657 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 d696e423..d88258bf 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/api/__pycache__/views.cpython-310.pyc b/osinaweb/osichat/api/__pycache__/views.cpython-310.pyc index 7ca2bba6..2a0e81a6 100644 Binary files a/osinaweb/osichat/api/__pycache__/views.cpython-310.pyc and b/osinaweb/osichat/api/__pycache__/views.cpython-310.pyc differ diff --git a/osinaweb/osichat/migrations/0028_chatnotification_type_id.py b/osinaweb/osichat/migrations/0028_chatnotification_type_id.py new file mode 100644 index 00000000..3676f028 --- /dev/null +++ b/osinaweb/osichat/migrations/0028_chatnotification_type_id.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.5 on 2024-09-03 09:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('osichat', '0027_chatnotification_type'), + ] + + operations = [ + migrations.AddField( + model_name='chatnotification', + name='type_id', + field=models.IntegerField(null=True), + ), + ] diff --git a/osinaweb/osichat/migrations/__pycache__/0028_chatnotification_type_id.cpython-310.pyc b/osinaweb/osichat/migrations/__pycache__/0028_chatnotification_type_id.cpython-310.pyc new file mode 100644 index 00000000..6882a664 Binary files /dev/null and b/osinaweb/osichat/migrations/__pycache__/0028_chatnotification_type_id.cpython-310.pyc differ diff --git a/osinaweb/osichat/models.py b/osinaweb/osichat/models.py index 7c46e879..75267c0f 100644 --- a/osinaweb/osichat/models.py +++ b/osinaweb/osichat/models.py @@ -14,18 +14,22 @@ def send_notification(notification): notification_data = { 'title': notification.title, 'body': mark_safe(notification.message), + 'id': notification.type_id } - sound = 'default' - if notification.type == 'Visitor': - sound = 'https://osina.ositcom.com/static/notifications/new-visitor.mp3' + if notification.type == 'Chat': + sound = 'outside_chat.wav' + android_sound = 'outside_chat' + else: + sound = 'new_visitor.wav' + android_sound = 'new_visitor' android_config = AndroidConfig( notification=AndroidNotification( title=notification_data['title'], body=notification_data['body'], - sound=sound - ) + sound=android_sound + ) ) apns_config = APNSConfig( @@ -77,6 +81,7 @@ class ChatNotification(models.Model): image = models.TextField(blank=True,null=True) created_at = models.DateTimeField(auto_now_add=True) type = models.CharField(max_length=8, choices=TYPES, null=True) + type_id = models.IntegerField(null=True) def save(self, *args, **kwargs): is_new = not self.pk super().save(*args, **kwargs) @@ -184,6 +189,7 @@ class VisitorLog(models.Model): self.send_visitor_notification(is_repeat=True) def send_visitor_notification(self, is_repeat=False): + type_id = self.id if is_repeat: title = "Existing visitor new acitivity on Ositcom!" if self.title: @@ -200,7 +206,8 @@ class VisitorLog(models.Model): title=title, message = body, image = self.visitor.notification_flag_image_url, - type = "Visitor" + type = "Visitor", + type_id = type_id ) @@ -246,13 +253,15 @@ class ChatRoomGuest(models.Model): super().save(*args, **kwargs) self.send_chat_notification() def send_chat_notification(self): + type_id = self.id title = "New chat on Ositcom!" body = f"Visitor {self.visitor.ip_address} started a new chat on Ositcom" notification = ChatNotification.objects.create( title=title, message = body, image = self.visitor.notification_flag_image_url, - type = "Chat" + type = "Chat", + type_id = type_id ) class ChatRoomReview(models.Model): @@ -293,13 +302,15 @@ class ChatMessage(models.Model): if not self.member: self.send_message_notification() def send_message_notification(self): + type_id = self.id title = f"Visitor {self.room.chatroomguest.visitor.ip_address} sent a new message on Ositcom!" body = f"{self.content}" notification = ChatNotification.objects.create( title=title, message = body, image = self.room.chatroomguest.visitor.notification_flag_image_url, - type = "Chat" + type = "Chat", + type_id = type_id )