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,17 +14,21 @@ 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
)
)
@ -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
)

Loading…
Cancel
Save