From c03eda8425e88f96053e592841d73469f3d660e1 Mon Sep 17 00:00:00 2001 From: davelopez <46503462+davelopez@users.noreply.github.com> Date: Fri, 17 Nov 2023 16:19:58 +0100 Subject: [PATCH] Fix filtering of active broadcasts Admin users get all the broadcasts notifications regardless of their "activation" status so we need to apply the filtering also in the client. Regular users are not affected because they can only get active broadcasts. --- client/src/stores/broadcastsStore.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/client/src/stores/broadcastsStore.ts b/client/src/stores/broadcastsStore.ts index 8395b591521..d465aeb81f8 100644 --- a/client/src/stores/broadcastsStore.ts +++ b/client/src/stores/broadcastsStore.ts @@ -16,7 +16,7 @@ export const useBroadcastsStore = defineStore( const dismissedBroadcasts = ref<{ [key: string]: Expirable }>({}); const activeBroadcasts = computed(() => { - return broadcasts.value.filter((b) => !dismissedBroadcasts.value[b.id]); + return broadcasts.value.filter(isActive); }); async function loadBroadcasts() { @@ -40,6 +40,14 @@ export const useBroadcastsStore = defineStore( Vue.set(dismissedBroadcasts.value, broadcast.id, { expiration_time: broadcast.expiration_time }); } + function isActive(broadcast: BroadcastNotification) { + return ( + !dismissedBroadcasts.value[broadcast.id] && + !hasExpired(broadcast.expiration_time) && + hasBeenPublished(broadcast) + ); + } + function hasExpired(expirationTimeStr?: string) { if (!expirationTimeStr) { return false; @@ -49,6 +57,12 @@ export const useBroadcastsStore = defineStore( return now > expirationTime; } + function hasBeenPublished(broadcast: BroadcastNotification) { + const publicationTime = new Date(`${broadcast.publication_time}Z`); + const now = new Date(); + return now >= publicationTime; + } + function clearExpiredDismissedBroadcasts() { for (const key in dismissedBroadcasts.value) { if (hasExpired(dismissedBroadcasts.value[key]?.expiration_time)) {