commit: d74d5a8ce29311bc4b5c79527558f84c59965932
parent fa69034020078ed0b100bd6b99d79ec07f97c58a
Author: tusooa <tusooa@kazv.moe>
Date: Thu, 24 Nov 2022 18:39:42 -0500
Detect backend support for announcements
Diffstat:
6 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/src/components/nav_panel/nav_panel.js b/src/components/nav_panel/nav_panel.js
@@ -88,6 +88,7 @@ const NavPanel = {
privateMode: state => state.instance.private,
federating: state => state.instance.federating,
pleromaChatMessagesAvailable: state => state.instance.pleromaChatMessagesAvailable,
+ supportsAnnouncements: state => state.announcements.supportsAnnouncements,
pinnedItems: state => new Set(state.serverSideStorage.prefsStorage.collections.pinnedNavItems),
collapsed: state => state.serverSideStorage.prefsStorage.simple.collapseNav
}),
@@ -98,6 +99,7 @@ const NavPanel = {
.map(([k, v]) => ({ ...v, name: k })),
{
hasChats: this.pleromaChatMessagesAvailable,
+ hasAnnouncements: this.supportsAnnouncements,
isFederating: this.federating,
isPrivate: this.privateMode,
currentUser: this.currentUser
diff --git a/src/components/navigation/filter.js b/src/components/navigation/filter.js
@@ -1,4 +1,4 @@
-export const filterNavigation = (list = [], { hasChats, isFederating, isPrivate, currentUser }) => {
+export const filterNavigation = (list = [], { hasChats, hasAnnouncements, isFederating, isPrivate, currentUser }) => {
return list.filter(({ criteria, anon, anonRoute }) => {
const set = new Set(criteria || [])
if (!isFederating && set.has('federating')) return false
@@ -6,6 +6,7 @@ export const filterNavigation = (list = [], { hasChats, isFederating, isPrivate,
if (!currentUser && !(anon || anonRoute)) return false
if ((!currentUser || !currentUser.locked) && set.has('lockedUser')) return false
if (!hasChats && set.has('chats')) return false
+ if (!hasAnnouncements && set.has('announcements')) return false
return true
})
}
diff --git a/src/components/navigation/navigation.js b/src/components/navigation/navigation.js
@@ -76,6 +76,7 @@ export const ROOT_ITEMS = {
route: 'announcements',
icon: 'bullhorn',
label: 'nav.announcements',
- badgeGetter: 'unreadAnnouncementCount'
+ badgeGetter: 'unreadAnnouncementCount',
+ criteria: ['announcements']
}
}
diff --git a/src/components/side_drawer/side_drawer.js b/src/components/side_drawer/side_drawer.js
@@ -95,7 +95,8 @@ const SideDrawer = {
}
},
...mapState({
- pleromaChatMessagesAvailable: state => state.instance.pleromaChatMessagesAvailable
+ pleromaChatMessagesAvailable: state => state.instance.pleromaChatMessagesAvailable,
+ supportsAnnouncements: state => state.announcements.supportsAnnouncements
}),
...mapGetters(['unreadChatCount', 'unreadAnnouncementCount'])
},
diff --git a/src/components/side_drawer/side_drawer.vue b/src/components/side_drawer/side_drawer.vue
@@ -192,6 +192,7 @@
</a>
</li>
<li
+ v-if="currentUser && supportsAnnouncements"
@click="toggleDrawer"
>
<router-link
diff --git a/src/modules/announcements.js b/src/modules/announcements.js
@@ -2,6 +2,7 @@ const FETCH_ANNOUNCEMENT_INTERVAL_MS = 1000 * 60 * 5
export const defaultState = {
announcements: [],
+ supportsAnnouncements: true,
fetchAnnouncementsTimer: undefined
}
@@ -20,6 +21,9 @@ export const mutations = {
},
setFetchAnnouncementsTimer (state, timer) {
state.fetchAnnouncementsTimer = timer
+ },
+ setSupportsAnnouncements (state, supportsAnnouncements) {
+ state.supportsAnnouncements = supportsAnnouncements
}
}
@@ -40,6 +44,10 @@ const announcements = {
getters,
actions: {
fetchAnnouncements (store) {
+ if (!store.state.supportsAnnouncements) {
+ return Promise.resolve()
+ }
+
const currentUser = store.rootState.users.currentUser
const isAdmin = currentUser && currentUser.role === 'admin'
@@ -72,6 +80,15 @@ const announcements = {
.then(announcements => {
store.commit('setAnnouncements', announcements)
})
+ .catch(error => {
+ // If and only if backend does not support announcements, it would return 404.
+ // In this case, silently ignores it.
+ if (error && error.statusCode === 404) {
+ store.commit('setSupportsAnnouncements', false)
+ } else {
+ throw error
+ }
+ })
},
markAnnouncementAsRead (store, id) {
return store.rootState.api.backendInteractor.dismissAnnouncement({ id })