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.
This commit is contained in:
davelopez
2023-11-17 17:47:00 +01:00
parent 427677a540
commit c03eda8425
+15 -1
View File
@@ -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)) {