diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 0284574f..526c883c 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osichat/__pycache__/models.cpython-310.pyc b/osinaweb/osichat/__pycache__/models.cpython-310.pyc index 412b8c2f..a66f184e 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/models.py b/osinaweb/osichat/models.py index ad8e5c7f..b629a37e 100644 --- a/osinaweb/osichat/models.py +++ b/osinaweb/osichat/models.py @@ -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"