diff --git a/src/store/modules/emojiSuggestionModule.js b/src/store/modules/emojiSuggestionModule.js index 50bc6ab..e95bba3 100644 --- a/src/store/modules/emojiSuggestionModule.js +++ b/src/store/modules/emojiSuggestionModule.js @@ -1,15 +1,9 @@ -import axios from 'axios' -import Vue from 'vue' -import { - bus -} from '../../main' -import VueRouter from 'vue-router'; -import NotificationSounds from '@/utils/notificationSound'; +import Vue from "vue"; const state = { array: null, - index: 0, -} + index: 0 +}; const getters = { emojiArray(state) { @@ -18,16 +12,16 @@ const getters = { getEmojiIndex(state) { return state.index; } -} +}; const actions = { setEmojiArray(context, array) { - context.commit('setEmojiArray', array) + context.commit("setEmojiArray", array); }, changeIndex(context, index) { - context.commit('changeIndex', index) + context.commit("changeIndex", index); } -} +}; const mutations = { setEmojiArray(state, array) { @@ -36,7 +30,7 @@ const mutations = { changeIndex(state, index) { Vue.set(state, "index", index); } -} +}; export default { namespace: true, @@ -44,4 +38,4 @@ export default { getters, actions, mutations -} \ No newline at end of file +}; diff --git a/src/store/modules/notificationsModule.js b/src/store/modules/notificationsModule.js index c645c0a..51b3957 100644 --- a/src/store/modules/notificationsModule.js +++ b/src/store/modules/notificationsModule.js @@ -1,65 +1,76 @@ -import {bus} from '../../main' -import {router} from './../../router' -import Vue from 'vue'; -import NotificationSounds from '@/utils/notificationSound'; +import Vue from "vue"; +import NotificationSounds from "@/utils/notificationSound"; const state = { notifications: [] -} +}; const getters = { notifications(state) { return state.notifications; } -} +}; const actions = { addAllNotifications(context, notifications) { - context.commit('addAllNotifications', notifications) + context.commit("addAllNotifications", notifications); }, messageCreatedNotification(context, notification) { - const {guildID, channelID, lastMessageID, sender} = notification; - + const { guildID, channelID, lastMessageID, sender } = notification; + const currentTab = context.rootGetters.currentTab; + // dont display a notification if the channel is selected. - if (context.rootState.channelModule.selectedChannelID !== channelID || !document.hasFocus()) { + if ( + context.rootState.channelModule.selectedChannelID !== channelID || + (currentTab !== 1 && currentTab !== 2) + ) { NotificationSounds.notification(); } let find = context.state.notifications.find(item => { - return item.channelID === channelID - }) + return item.channelID === channelID; + }); if (find) { - return context.commit('messageCreatedNotification', {exists: true, notification: {channelID, lastMessageID,sender}}); - } - context.commit('messageCreatedNotification', {exists: false, notification: {channelID, lastMessageID, sender, count: 1}}); - + return context.commit("messageCreatedNotification", { + exists: true, + notification: { channelID, lastMessageID, sender } + }); + } + context.commit("messageCreatedNotification", { + exists: false, + notification: { channelID, lastMessageID, sender, count: 1 } + }); }, dismissNotification(context, channelID) { - const notifications = context.state.notifications + const notifications = context.state.notifications; for (let index = 0; index < notifications.length; index++) { - if (notifications[index].channelID === channelID){ - context.commit('dismissNotification', index) + if (notifications[index].channelID === channelID) { + context.commit("dismissNotification", index); break; } } } -} +}; const mutations = { dismissNotification(state, index) { - Vue.delete(state.notifications, index) + Vue.delete(state.notifications, index); }, - addAllNotifications(state, notifications){ - Vue.set(state, 'notifications', notifications); + addAllNotifications(state, notifications) { + Vue.set(state, "notifications", notifications); }, messageCreatedNotification(state, data) { - const {exists, notification} = data; + const { exists, notification } = data; if (exists) { for (let i = 0; i < state.notifications.length; i++) { if (state.notifications[i].channelID === notification.channelID) { const count = state.notifications[i].count; - Vue.set(state.notifications[i], 'count', count + 1); - Vue.set(state.notifications[i], 'lastMessageID', data.notification.lastMessageID); - Vue.set(state.notifications[i], 'sender', data.notification.sender); + Vue.set(state.notifications[i], "count", count + 1); + Vue.set( + state.notifications[i], + "lastMessageID", + data.notification.lastMessageID + ); + Vue.set(state.notifications[i], "sender", data.notification.sender); break; } } @@ -67,7 +78,7 @@ const mutations = { } state.notifications.push(notification); } -} +}; export default { namespace: true, @@ -75,4 +86,4 @@ export default { actions, mutations, getters -} \ No newline at end of file +};