mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Fix notifications not showing up/being reset
This commit is contained in:
parent
170750466c
commit
76e8b01335
@ -578,16 +578,19 @@ class Helpers:
|
|||||||
return version_data
|
return version_data
|
||||||
|
|
||||||
def get_announcements(self):
|
def get_announcements(self):
|
||||||
data = []
|
|
||||||
try:
|
try:
|
||||||
|
data = []
|
||||||
response = requests.get("https://craftycontrol.com/notify", timeout=2)
|
response = requests.get("https://craftycontrol.com/notify", timeout=2)
|
||||||
data = json.loads(response.content)
|
data = json.loads(response.content)
|
||||||
|
if self.update_available:
|
||||||
|
data.append(self.update_available)
|
||||||
|
return data
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to fetch notifications with error: {e}")
|
logger.error(f"Failed to fetch notifications with error: {e}")
|
||||||
|
if self.update_available:
|
||||||
if self.update_available:
|
data = [self.update_available]
|
||||||
data.append(self.update_available)
|
else:
|
||||||
return data
|
return False
|
||||||
|
|
||||||
def get_version_string(self):
|
def get_version_string(self):
|
||||||
version_data = self.get_version()
|
version_data = self.get_version()
|
||||||
|
@ -29,6 +29,14 @@ class ApiAnnounceIndexHandler(BaseApiHandler):
|
|||||||
) = auth_data
|
) = auth_data
|
||||||
|
|
||||||
data = self.helper.get_announcements()
|
data = self.helper.get_announcements()
|
||||||
|
if not data:
|
||||||
|
return self.finish_json(
|
||||||
|
418,
|
||||||
|
{
|
||||||
|
"status": "error",
|
||||||
|
"data": "Failed to get announcements",
|
||||||
|
},
|
||||||
|
)
|
||||||
cleared = str(
|
cleared = str(
|
||||||
self.controller.users.get_user_by_id(auth_data[4]["user_id"])[
|
self.controller.users.get_user_by_id(auth_data[4]["user_id"])[
|
||||||
"cleared_notifs"
|
"cleared_notifs"
|
||||||
@ -84,6 +92,14 @@ class ApiAnnounceIndexHandler(BaseApiHandler):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
announcements = self.helper.get_announcements()
|
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]
|
res = [d.get("id", None) for d in announcements]
|
||||||
cleared_notifs = str(
|
cleared_notifs = str(
|
||||||
self.controller.users.get_user_by_id(auth_data[4]["user_id"])[
|
self.controller.users.get_user_by_id(auth_data[4]["user_id"])[
|
||||||
|
@ -93,7 +93,7 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
function updateAnnouncements(data) {
|
function updateAnnouncements(data) {
|
||||||
console.log(data)
|
console.log(data);
|
||||||
let text = "";
|
let text = "";
|
||||||
for (let value of data) {
|
for (let value of data) {
|
||||||
text += `<li class="card-header header-sm justify-content-between align-items-center" id="${value.id}"><p style="float: right;"><i data-id="${value.id}"class="clear-button fa-regular fa-x"></i></p><a style="color: var(--purple);" href=${value.link} target="_blank"><h6>${value.title}</h6><small><p>${value.date}</p></small><p>${value.desc}</p></li></a>`
|
text += `<li class="card-header header-sm justify-content-between align-items-center" id="${value.id}"><p style="float: right;"><i data-id="${value.id}"class="clear-button fa-regular fa-x"></i></p><a style="color: var(--purple);" href=${value.link} target="_blank"><h6>${value.title}</h6><small><p>${value.date}</p></small><p>${value.desc}</p></li></a>`
|
||||||
@ -138,12 +138,12 @@
|
|||||||
console.log(responseData);
|
console.log(responseData);
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
getAnnouncements();
|
getAnnouncements();
|
||||||
}, 1800);
|
}, 1800000); //Wait 30 minutes in miliseconds
|
||||||
console.log("Registered annoucement fetch event in 30 minutes.")
|
console.log("Registered annoucement fetch event in 30 minutes.")
|
||||||
if (responseData.status === "ok") {
|
if (responseData.status === "ok") {
|
||||||
updateAnnouncements(responseData.data)
|
updateAnnouncements(responseData.data)
|
||||||
} else {
|
} else {
|
||||||
updateAnnouncements("<li><p>Trouble Getting Annoucements</p></li>")
|
updateAnnouncements([])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function send_clear(uuid) {
|
async function send_clear(uuid) {
|
||||||
|
Loading…
Reference in New Issue
Block a user