From 20fbb4f57e2dce25d96cef9564874edd80d29a54 Mon Sep 17 00:00:00 2001 From: naskya Date: Sat, 8 Jul 2023 20:31:18 +0000 Subject: [PATCH] Don't show more then three announcement popups (because it can be annoying for new users) --- packages/client/src/init.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/packages/client/src/init.ts b/packages/client/src/init.ts index a0e99b9dcb..ff4dee309e 100644 --- a/packages/client/src/init.ts +++ b/packages/client/src/init.ts @@ -273,19 +273,26 @@ function checkForSplash() { } if ($i) { - api("announcements", { withUnreads: true }) + api("announcements", { withUnreads: true, limit: 10 }) .then((announcements) => { - announcements.forEach((announcement) => { - if (announcement.showPopup && announcement.isRead === false) - popup( - defineAsyncComponent( - () => import("@/components/MkAnnouncement.vue"), - ), - { announcement: announcement }, - {}, - "closed", - ); + const unreadAnnouncements = announcements.filter((item) => { + return !item.isRead; }); + if (unreadAnnouncements.length > 3) { + // TODO: navigate to the announcements page when there are too many unreads + } else { + unreadAnnouncements.forEach((item) => { + if (item.showPopup) + popup( + defineAsyncComponent( + () => import("@/components/MkAnnouncement.vue"), + ), + { announcement: item }, + {}, + "closed", + ); + }); + } }) .catch((err) => console.log(err)); }