Notification rework - Apprise v1 - working

This commit is contained in:
Jokob-sk
2023-10-08 14:52:22 +11:00
parent 79c47015f4
commit be4e0acdfc
11 changed files with 152 additions and 182 deletions

View File

@@ -40,11 +40,8 @@ class Notification_obj:
# Check if nothing to report, end
if JSON["internet"] == [] and JSON["new_devices"] == [] and JSON["down_devices"] == [] and JSON["events"] == [] and JSON["plugins"] == []:
self.HasNotifications = False
# end if nothing to report
return self.HasNotifications
# continue and save into DB if notifications available
self.HasNotifications = True
else:
self.HasNotifications = True
self.GUID = str(uuid.uuid4())
self.DateTimeCreated = timeNowTZ()
@@ -56,9 +53,10 @@ class Notification_obj:
self.PublishedVia = ""
self.Extra = Extra
self.upsert()
if self.HasNotifications:
self.upsert()
return self.HasNotifications
return self
# Only updates the status
def updateStatus(self, newStatus):
@@ -69,9 +67,7 @@ class Notification_obj:
def updatePublishedVia(self, newPublishedVia):
self.PublishedVia = newPublishedVia
self.DateTimePushed = timeNowTZ()
self.upsert()
# TODO Index vs hash to minimize SQL calls, finish CRUD operations, expose via API, use API in plugins
self.upsert()
# create or update a notification
def upsert(self):
@@ -82,6 +78,15 @@ class Notification_obj:
self.save()
# Remove notification object by GUID
def remove(self, GUID):
# Execute an SQL query to delete the notification with the specified GUID
self.db.sql.execute("""
DELETE FROM Notifications
WHERE GUID = ?
""", (GUID,))
self.save()
# Get all with the "new" status
def getNew(self):
self.db.sql.execute("""