|
|
|
@ -175,14 +175,28 @@ class VisitorLog(models.Model):
|
|
|
|
|
async_to_sync(channel_layer.group_send)("osichat", event)
|
|
|
|
|
if is_first_log:
|
|
|
|
|
self.send_visitor_notification()
|
|
|
|
|
def send_visitor_notification(self):
|
|
|
|
|
body = ""
|
|
|
|
|
if self.title:
|
|
|
|
|
body = f"New visitor navigated to {self.title}"
|
|
|
|
|
elif self.url:
|
|
|
|
|
body = f"New visitor navigated to {self.url}"
|
|
|
|
|
else:
|
|
|
|
|
last_log = self.visitor.visitorlog_set.exclude(id=self.id).order_by('-visit_date').first()
|
|
|
|
|
if last_log:
|
|
|
|
|
time_difference = self.visit_date - last_log.visit_date
|
|
|
|
|
if time_difference > timedelta(minutes=5):
|
|
|
|
|
self.send_visitor_notification(is_repeat=True)
|
|
|
|
|
|
|
|
|
|
def send_visitor_notification(self, is_repeat=False):
|
|
|
|
|
if is_repeat:
|
|
|
|
|
title = "Existing visitor new acitivity on Ositcom!"
|
|
|
|
|
if self.title:
|
|
|
|
|
body = f"Visitor navigated to {self.title}"
|
|
|
|
|
elif self.url:
|
|
|
|
|
body = f"Visitor returned to {self.url}"
|
|
|
|
|
else:
|
|
|
|
|
title = "New visitor on Ositcom!"
|
|
|
|
|
if self.title:
|
|
|
|
|
body = f"New visitor navigated to {self.title}"
|
|
|
|
|
elif self.url:
|
|
|
|
|
body = f"New visitor navigated to {self.url}"
|
|
|
|
|
notification = ChatNotification.objects.create(
|
|
|
|
|
title="New visitor on Ositcom!",
|
|
|
|
|
title=title,
|
|
|
|
|
message = body,
|
|
|
|
|
image = self.visitor.notification_flag_image_url,
|
|
|
|
|
type = "Visitor"
|
|
|
|
|