|
|
|
@ -242,7 +242,18 @@ class ChatRoom(models.Model):
|
|
|
|
|
class ChatRoomGuest(models.Model):
|
|
|
|
|
room = models.OneToOneField(ChatRoom, on_delete=models.CASCADE, null=True)
|
|
|
|
|
visitor = models.ForeignKey(Visitor, null=True, on_delete=models.CASCADE)
|
|
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
|
super().save(*args, **kwargs)
|
|
|
|
|
self.send_chat_notification()
|
|
|
|
|
def send_chat_notification(self):
|
|
|
|
|
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"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
class ChatRoomReview(models.Model):
|
|
|
|
|
REACTION_CHOICES = (
|
|
|
|
@ -279,6 +290,17 @@ class ChatMessage(models.Model):
|
|
|
|
|
'chatroom_id': self.room.id,
|
|
|
|
|
}
|
|
|
|
|
async_to_sync(channel_layer.group_send)("osichat", event)
|
|
|
|
|
if not self.member:
|
|
|
|
|
self.send_message_notification()
|
|
|
|
|
def send_message_notification(self):
|
|
|
|
|
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"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ChatMessageAttachment(models.Model):
|
|
|
|
|