From 76e8b01335b8733fad96cc1090ee337c2c73252a Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Oct 2023 18:37:30 -0400 Subject: [PATCH 1/3] Fix notifications not showing up/being reset --- app/classes/shared/helpers.py | 13 ++++++++----- .../web/routes/api/crafty/announcements/index.py | 16 ++++++++++++++++ app/frontend/templates/notify.html | 6 +++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/classes/shared/helpers.py b/app/classes/shared/helpers.py index ba9c5a28..62ce8819 100644 --- a/app/classes/shared/helpers.py +++ b/app/classes/shared/helpers.py @@ -578,16 +578,19 @@ class Helpers: return version_data def get_announcements(self): - data = [] try: + data = [] response = requests.get("https://craftycontrol.com/notify", timeout=2) data = json.loads(response.content) + if self.update_available: + data.append(self.update_available) + return data except Exception as e: logger.error(f"Failed to fetch notifications with error: {e}") - - if self.update_available: - data.append(self.update_available) - return data + if self.update_available: + data = [self.update_available] + else: + return False def get_version_string(self): version_data = self.get_version() diff --git a/app/classes/web/routes/api/crafty/announcements/index.py b/app/classes/web/routes/api/crafty/announcements/index.py index 409aceed..b5286289 100644 --- a/app/classes/web/routes/api/crafty/announcements/index.py +++ b/app/classes/web/routes/api/crafty/announcements/index.py @@ -29,6 +29,14 @@ class ApiAnnounceIndexHandler(BaseApiHandler): ) = auth_data data = self.helper.get_announcements() + if not data: + return self.finish_json( + 418, + { + "status": "error", + "data": "Failed to get announcements", + }, + ) cleared = str( self.controller.users.get_user_by_id(auth_data[4]["user_id"])[ "cleared_notifs" @@ -84,6 +92,14 @@ class ApiAnnounceIndexHandler(BaseApiHandler): }, ) announcements = self.helper.get_announcements() + if not announcements: + return self.finish_json( + 418, + { + "status": "error", + "data": "Failed to get current announcements", + }, + ) res = [d.get("id", None) for d in announcements] cleared_notifs = str( self.controller.users.get_user_by_id(auth_data[4]["user_id"])[ diff --git a/app/frontend/templates/notify.html b/app/frontend/templates/notify.html index b7dd6dd9..83e80909 100644 --- a/app/frontend/templates/notify.html +++ b/app/frontend/templates/notify.html @@ -93,7 +93,7 @@ return true; } function updateAnnouncements(data) { - console.log(data) + console.log(data); let text = ""; for (let value of data) { text += `
  • ${value.title}

    ${value.date}

    ${value.desc}

  • ` @@ -138,12 +138,12 @@ console.log(responseData); setTimeout(function() { getAnnouncements(); - }, 1800); + }, 1800000); //Wait 30 minutes in miliseconds console.log("Registered annoucement fetch event in 30 minutes.") if (responseData.status === "ok") { updateAnnouncements(responseData.data) } else { - updateAnnouncements("
  • Trouble Getting Annoucements

  • ") + updateAnnouncements([]) } } async function send_clear(uuid) { From 645542b459639d502bea34fdd2e9aa3d3b48caf6 Mon Sep 17 00:00:00 2001 From: amcmanu3 Date: Sun, 29 Oct 2023 18:49:31 -0400 Subject: [PATCH 2/3] Move from 418 (i am a teapot) to 424 missing dep --- app/classes/web/routes/api/crafty/announcements/index.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/classes/web/routes/api/crafty/announcements/index.py b/app/classes/web/routes/api/crafty/announcements/index.py index b5286289..75f00f16 100644 --- a/app/classes/web/routes/api/crafty/announcements/index.py +++ b/app/classes/web/routes/api/crafty/announcements/index.py @@ -31,7 +31,7 @@ class ApiAnnounceIndexHandler(BaseApiHandler): data = self.helper.get_announcements() if not data: return self.finish_json( - 418, + 424, { "status": "error", "data": "Failed to get announcements", @@ -94,7 +94,7 @@ class ApiAnnounceIndexHandler(BaseApiHandler): announcements = self.helper.get_announcements() if not announcements: return self.finish_json( - 418, + 424, { "status": "error", "data": "Failed to get current announcements", From ec137db124dcdfd004531a4130516fd760481398 Mon Sep 17 00:00:00 2001 From: Zedifus Date: Wed, 1 Nov 2023 00:04:30 +0000 Subject: [PATCH 3/3] Update changelog !660 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b225b497..93cafab5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ TBD ### Bug fixes - Fix logic issue with `get_files` API permissions check ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/654)) +- Fix notifications not showing up/being reset #298 ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/660)) ### Tweaks - Auto refresh Crafty Announcements on 30m interval ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/653)) - Improve Crafty toggle buttons and Webhooks page ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/656))