diff --git a/src/components/nav_panel/nav_panel.js b/src/components/nav_panel/nav_panel.js index 8f7edb7f..23acbc95 100644 --- a/src/components/nav_panel/nav_panel.js +++ b/src/components/nav_panel/nav_panel.js @@ -1,4 +1,4 @@ -import { mapState } from 'vuex' +import { mapState, mapGetters } from 'vuex' const NavPanel = { created () { @@ -6,13 +6,16 @@ const NavPanel = { this.$store.dispatch('startFetchingFollowRequests') } }, - computed: mapState({ - currentUser: state => state.users.currentUser, - chat: state => state.chat.channel, - followRequestCount: state => state.api.followRequests.length, - privateMode: state => state.instance.private, - federating: state => state.instance.federating - }) + computed: { + ...mapState({ + currentUser: state => state.users.currentUser, + chat: state => state.chat.channel, + followRequestCount: state => state.api.followRequests.length, + privateMode: state => state.instance.private, + federating: state => state.instance.federating + }), + ...mapGetters(['unreadChatCount', 'currentChat']) + } } export default NavPanel diff --git a/src/components/nav_panel/nav_panel.vue b/src/components/nav_panel/nav_panel.vue index 5c35cf31..69a885d6 100644 --- a/src/components/nav_panel/nav_panel.vue +++ b/src/components/nav_panel/nav_panel.vue @@ -19,6 +19,12 @@
  • +
    + {{ unreadChatCount(currentChat) }} +
    {{ $t("nav.chats") }}
  • diff --git a/src/components/side_drawer/side_drawer.js b/src/components/side_drawer/side_drawer.js index 2181ecc7..47510179 100644 --- a/src/components/side_drawer/side_drawer.js +++ b/src/components/side_drawer/side_drawer.js @@ -1,3 +1,4 @@ +import { mapGetters } from 'vuex' import UserCard from '../user_card/user_card.vue' import { unseenNotificationsFromStore } from '../../services/notification_utils/notification_utils' import GestureService from '../../services/gesture_service/gesture_service' @@ -47,7 +48,8 @@ const SideDrawer = { }, federating () { return this.$store.state.instance.federating - } + }, + ...mapGetters(['unreadChatCount', 'currentChat']) }, methods: { toggleDrawer () { diff --git a/src/components/side_drawer/side_drawer.vue b/src/components/side_drawer/side_drawer.vue index 6d38a1af..58bb4e37 100644 --- a/src/components/side_drawer/side_drawer.vue +++ b/src/components/side_drawer/side_drawer.vue @@ -46,8 +46,14 @@ {{ $t("nav.dms") }} - + {{ $t("nav.chats") }} + + {{ unreadChatCount(currentChat) }} +
  • {{ $t("nav.twkn") }}
  • -
  • - - {{ $t("nav.chat") }} - -
    • n.chatMessage && n.chatMessage.chat_id === id && !n.seen + }) rootState.api.backendInteractor.readChat({ id }).then(() => { // dispatch('refreshCurrentUser') }) @@ -124,11 +127,10 @@ const chats = { updateChat (state, { _dispatch, chat: updatedChat, _rootGetters }) { let chat = find(state.chatList.data, { id: updatedChat.id }) if (chat) { - state.chatList.data = state.chatList.data.filter(d => { - return d.id !== updatedChat.id - }) + chat.lastMessage = updatedChat.lastMessage + chat.unread = updatedChat.unread } - state.chatList.data.unshift(updatedChat) + if (!chat) { state.chatList.data.unshift(updatedChat) } state.chatList.idStore[updatedChat.id] = updatedChat }, deleteChat (state, { _dispatch, id, _rootGetters }) { diff --git a/src/modules/statuses.js b/src/modules/statuses.js index ed78cffd..2b93b995 100644 --- a/src/modules/statuses.js +++ b/src/modules/statuses.js @@ -335,6 +335,7 @@ const addNewNotifications = (state, { dispatch, notifications, older, visibleNot if (notification.type === 'pleroma:chat_mention') { dispatch('addChatMessages', { chatId: notification.chatMessage.chat_id, messages: [notification.chatMessage] }) dispatch('updateChatByAccountId', { accountId: notification.from_profile.id }) + // dispatch('updateUnreadChatCount', { userId, unreadChatCount }) } // Only add a new notification if we don't have one for the same action @@ -540,6 +541,9 @@ export const mutations = { dismissNotification (state, { id }) { state.notifications.data = state.notifications.data.filter(n => n.id !== id) }, + dismissNotifications (state, { finder }) { + state.notifications.data = state.notifications.data.filter(n => finder) + }, updateNotification (state, { id, updater }) { const notification = find(state.notifications.data, n => n.id === id) notification && updater(notification) @@ -616,6 +620,22 @@ export const mutations = { const statuses = { state: defaultState(), + getters: { + unreadChatCount: state => currentChat => { + let res = 0 + state.notifications.data.forEach(n => { + let isMsg = !n.seen && n.chatMessage + if (!isMsg) { return } + + if (currentChat) { + if (currentChat.id !== n.chatMessage.chat_id) { res++ } + } else { + res++ + } + }) + return res + } + }, actions: { addNewStatuses ({ rootState, commit }, { statuses, showImmediately = false, timeline = false, noIdUpdate = false, userId }) { commit('addNewStatuses', { statuses, showImmediately, timeline, noIdUpdate, user: rootState.users.currentUser, userId }) @@ -718,6 +738,14 @@ const statuses = { commit('dismissNotification', { id }) rootState.api.backendInteractor.dismissNotification({ id }) }, + markMultipleNotificationsAsSeen ({ rootState, commit }, { finder }) { + const notifications = rootState.statuses.notifications.data.filter(finder) + + notifications.forEach(n => { + commit('markSingleNotificationAsSeen', { id: n.id }) + rootState.api.backendInteractor.markNotificationsAsSeen({ id: n.id, single: true }) + }) + }, updateNotification ({ rootState, commit }, { id, updater }) { commit('updateNotification', { id, updater }) }, diff --git a/src/modules/users.js b/src/modules/users.js index f9329f2a..2c69fe37 100644 --- a/src/modules/users.js +++ b/src/modules/users.js @@ -225,6 +225,12 @@ export const mutations = { signUpFailure (state, errors) { state.signUpPending = false state.signUpErrors = errors + }, + updateUnreadChatCount (state, { userId, unreadChatCount }) { + const user = state.usersObject[userId] + if (user) { + user.unread_chat_count = unreadChatCount + } } } @@ -259,6 +265,9 @@ const users = { mutations, getters, actions: { + updateUnreadChatCount (store, { userId, unreadChatCount }) { + store.commit('updateUnreadChatCount', { userId, unreadChatCount }) + }, fetchUser (store, id) { return store.rootState.api.backendInteractor.fetchUser({ id }) .then((user) => { diff --git a/src/services/notification_utils/notification_utils.js b/src/services/notification_utils/notification_utils.js index d73f747c..eb479227 100644 --- a/src/services/notification_utils/notification_utils.js +++ b/src/services/notification_utils/notification_utils.js @@ -9,8 +9,7 @@ export const visibleTypes = store => ([ store.state.config.notificationVisibility.follows && 'follow', store.state.config.notificationVisibility.followRequest && 'follow_request', store.state.config.notificationVisibility.moves && 'move', - store.state.config.notificationVisibility.emojiReactions && 'pleroma:emoji_reaction', - store.state.config.notificationVisibility.chatMention && 'pleroma:chat_mention' + store.state.config.notificationVisibility.emojiReactions && 'pleroma:emoji_reaction' ].filter(_ => _)) const statusNotifications = ['like', 'mention', 'repeat', 'pleroma:emoji_reaction']