fixed more bugs with notification

This commit is contained in:
supertiger1234 2019-11-06 12:07:34 +00:00
parent 75871e4b61
commit 6c052ef208
2 changed files with 49 additions and 44 deletions

View file

@ -1,15 +1,9 @@
import axios from 'axios' import Vue from "vue";
import Vue from 'vue'
import {
bus
} from '../../main'
import VueRouter from 'vue-router';
import NotificationSounds from '@/utils/notificationSound';
const state = { const state = {
array: null, array: null,
index: 0, index: 0
} };
const getters = { const getters = {
emojiArray(state) { emojiArray(state) {
@ -18,16 +12,16 @@ const getters = {
getEmojiIndex(state) { getEmojiIndex(state) {
return state.index; return state.index;
} }
} };
const actions = { const actions = {
setEmojiArray(context, array) { setEmojiArray(context, array) {
context.commit('setEmojiArray', array) context.commit("setEmojiArray", array);
}, },
changeIndex(context, index) { changeIndex(context, index) {
context.commit('changeIndex', index) context.commit("changeIndex", index);
} }
} };
const mutations = { const mutations = {
setEmojiArray(state, array) { setEmojiArray(state, array) {
@ -36,7 +30,7 @@ const mutations = {
changeIndex(state, index) { changeIndex(state, index) {
Vue.set(state, "index", index); Vue.set(state, "index", index);
} }
} };
export default { export default {
namespace: true, namespace: true,
@ -44,4 +38,4 @@ export default {
getters, getters,
actions, actions,
mutations mutations
} };

View file

@ -1,65 +1,76 @@
import {bus} from '../../main' import Vue from "vue";
import {router} from './../../router' import NotificationSounds from "@/utils/notificationSound";
import Vue from 'vue';
import NotificationSounds from '@/utils/notificationSound';
const state = { const state = {
notifications: [] notifications: []
} };
const getters = { const getters = {
notifications(state) { notifications(state) {
return state.notifications; return state.notifications;
} }
} };
const actions = { const actions = {
addAllNotifications(context, notifications) { addAllNotifications(context, notifications) {
context.commit('addAllNotifications', notifications) context.commit("addAllNotifications", notifications);
}, },
messageCreatedNotification(context, notification) { 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. // 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(); NotificationSounds.notification();
} }
let find = context.state.notifications.find(item => { let find = context.state.notifications.find(item => {
return item.channelID === channelID return item.channelID === channelID;
}) });
if (find) { if (find) {
return context.commit('messageCreatedNotification', {exists: true, notification: {channelID, lastMessageID,sender}}); return context.commit("messageCreatedNotification", {
} exists: true,
context.commit('messageCreatedNotification', {exists: false, notification: {channelID, lastMessageID, sender, count: 1}}); notification: { channelID, lastMessageID, sender }
});
}
context.commit("messageCreatedNotification", {
exists: false,
notification: { channelID, lastMessageID, sender, count: 1 }
});
}, },
dismissNotification(context, channelID) { dismissNotification(context, channelID) {
const notifications = context.state.notifications const notifications = context.state.notifications;
for (let index = 0; index < notifications.length; index++) { for (let index = 0; index < notifications.length; index++) {
if (notifications[index].channelID === channelID){ if (notifications[index].channelID === channelID) {
context.commit('dismissNotification', index) context.commit("dismissNotification", index);
break; break;
} }
} }
} }
} };
const mutations = { const mutations = {
dismissNotification(state, index) { dismissNotification(state, index) {
Vue.delete(state.notifications, index) Vue.delete(state.notifications, index);
}, },
addAllNotifications(state, notifications){ addAllNotifications(state, notifications) {
Vue.set(state, 'notifications', notifications); Vue.set(state, "notifications", notifications);
}, },
messageCreatedNotification(state, data) { messageCreatedNotification(state, data) {
const {exists, notification} = data; const { exists, notification } = data;
if (exists) { if (exists) {
for (let i = 0; i < state.notifications.length; i++) { for (let i = 0; i < state.notifications.length; i++) {
if (state.notifications[i].channelID === notification.channelID) { if (state.notifications[i].channelID === notification.channelID) {
const count = state.notifications[i].count; const count = state.notifications[i].count;
Vue.set(state.notifications[i], 'count', count + 1); Vue.set(state.notifications[i], "count", count + 1);
Vue.set(state.notifications[i], 'lastMessageID', data.notification.lastMessageID); Vue.set(
Vue.set(state.notifications[i], 'sender', data.notification.sender); state.notifications[i],
"lastMessageID",
data.notification.lastMessageID
);
Vue.set(state.notifications[i], "sender", data.notification.sender);
break; break;
} }
} }
@ -67,7 +78,7 @@ const mutations = {
} }
state.notifications.push(notification); state.notifications.push(notification);
} }
} };
export default { export default {
namespace: true, namespace: true,
@ -75,4 +86,4 @@ export default {
actions, actions,
mutations, mutations,
getters getters
} };