emile 8 months ago
parent 0080747dfd
commit 277b47a79a

Binary file not shown.

@ -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),
),
]

@ -14,18 +14,22 @@ def send_notification(notification):
notification_data = { notification_data = {
'title': notification.title, 'title': notification.title,
'body': mark_safe(notification.message), 'body': mark_safe(notification.message),
'id': notification.type_id
} }
sound = 'default' if notification.type == 'Chat':
if notification.type == 'Visitor': sound = 'outside_chat.wav'
sound = 'https://osina.ositcom.com/static/notifications/new-visitor.mp3' android_sound = 'outside_chat'
else:
sound = 'new_visitor.wav'
android_sound = 'new_visitor'
android_config = AndroidConfig( android_config = AndroidConfig(
notification=AndroidNotification( notification=AndroidNotification(
title=notification_data['title'], title=notification_data['title'],
body=notification_data['body'], body=notification_data['body'],
sound=sound sound=android_sound
) )
) )
apns_config = APNSConfig( apns_config = APNSConfig(
@ -77,6 +81,7 @@ class ChatNotification(models.Model):
image = models.TextField(blank=True,null=True) image = models.TextField(blank=True,null=True)
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
type = models.CharField(max_length=8, choices=TYPES, null=True) type = models.CharField(max_length=8, choices=TYPES, null=True)
type_id = models.IntegerField(null=True)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
is_new = not self.pk is_new = not self.pk
super().save(*args, **kwargs) super().save(*args, **kwargs)
@ -184,6 +189,7 @@ class VisitorLog(models.Model):
self.send_visitor_notification(is_repeat=True) self.send_visitor_notification(is_repeat=True)
def send_visitor_notification(self, is_repeat=False): def send_visitor_notification(self, is_repeat=False):
type_id = self.id
if is_repeat: if is_repeat:
title = "Existing visitor new acitivity on Ositcom!" title = "Existing visitor new acitivity on Ositcom!"
if self.title: if self.title:
@ -200,7 +206,8 @@ class VisitorLog(models.Model):
title=title, title=title,
message = body, message = body,
image = self.visitor.notification_flag_image_url, 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) super().save(*args, **kwargs)
self.send_chat_notification() self.send_chat_notification()
def send_chat_notification(self): def send_chat_notification(self):
type_id = self.id
title = "New chat on Ositcom!" title = "New chat on Ositcom!"
body = f"Visitor {self.visitor.ip_address} started a new chat on Ositcom" body = f"Visitor {self.visitor.ip_address} started a new chat on Ositcom"
notification = ChatNotification.objects.create( notification = ChatNotification.objects.create(
title=title, title=title,
message = body, message = body,
image = self.visitor.notification_flag_image_url, image = self.visitor.notification_flag_image_url,
type = "Chat" type = "Chat",
type_id = type_id
) )
class ChatRoomReview(models.Model): class ChatRoomReview(models.Model):
@ -293,13 +302,15 @@ class ChatMessage(models.Model):
if not self.member: if not self.member:
self.send_message_notification() self.send_message_notification()
def send_message_notification(self): def send_message_notification(self):
type_id = self.id
title = f"Visitor {self.room.chatroomguest.visitor.ip_address} sent a new message on Ositcom!" title = f"Visitor {self.room.chatroomguest.visitor.ip_address} sent a new message on Ositcom!"
body = f"{self.content}" body = f"{self.content}"
notification = ChatNotification.objects.create( notification = ChatNotification.objects.create(
title=title, title=title,
message = body, message = body,
image = self.room.chatroomguest.visitor.notification_flag_image_url, image = self.room.chatroomguest.visitor.notification_flag_image_url,
type = "Chat" type = "Chat",
type_id = type_id
) )

Loading…
Cancel
Save