Detect backend support for announcements
This commit is contained in:
parent
fa69034020
commit
d74d5a8ce2
@ -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
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ export const ROOT_ITEMS = {
|
||||
route: 'announcements',
|
||||
icon: 'bullhorn',
|
||||
label: 'nav.announcements',
|
||||
badgeGetter: 'unreadAnnouncementCount'
|
||||
badgeGetter: 'unreadAnnouncementCount',
|
||||
criteria: ['announcements']
|
||||
}
|
||||
}
|
||||
|
@ -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'])
|
||||
},
|
||||
|
@ -192,6 +192,7 @@
|
||||
</a>
|
||||
</li>
|
||||
<li
|
||||
v-if="currentUser && supportsAnnouncements"
|
||||
@click="toggleDrawer"
|
||||
>
|
||||
<router-link
|
||||
|
@ -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 })
|
||||
|
Loading…
Reference in New Issue
Block a user