From e94620a60d5e8fea73e96725bd843a6f1c50dfb7 Mon Sep 17 00:00:00 2001 From: supertiger1234 Date: Tue, 12 Nov 2019 11:46:44 +0000 Subject: [PATCH] socket event for drag and drop, fixed some bugs --- src/components/app/Navigation.vue | 5 ++++- src/store/modules/socketIOModule.js | 33 ++++++++++++++++++++++++++++- src/utils/changelog.js | 3 ++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/components/app/Navigation.vue b/src/components/app/Navigation.vue index 41b9350..b255910 100644 --- a/src/components/app/Navigation.vue +++ b/src/components/app/Navigation.vue @@ -128,7 +128,10 @@ export default { )[serverID]; const defaultChannelID = server.default_channel_id; const channels = this.$store.getters.channels; - const channel = channels[lastSelectedChannel || defaultChannelID]; + let channel = channels[lastSelectedChannel || defaultChannelID]; + if (!channel) { + channel = channels[defaultChannelID]; + } this.dismissNotification(channel.channelID); this.$store.dispatch("servers/setSelectedServerID", serverID); diff --git a/src/store/modules/socketIOModule.js b/src/store/modules/socketIOModule.js index b0ef934..a828228 100644 --- a/src/store/modules/socketIOModule.js +++ b/src/store/modules/socketIOModule.js @@ -118,6 +118,7 @@ const actions = { s.channels = [...sortedServerChannels, ...tempServerChannels]; tempServerChannels = null; sortedServerChannels = null; + delete s.channel_position; return s; }) @@ -190,6 +191,11 @@ const actions = { context.commit("removeFriend", uniqueID); }, socket_receiveMessage(context, data) { + if (data.message.type === 1) { + if (context.getters.user.uniqueID === data.message.creator.uniqueID){ + return; + } + } if (context.getters.channels[data.message.channelID]) { context.dispatch("updateChannelLastMessage", data.message.channelID); } @@ -318,7 +324,28 @@ const actions = { ["socket_server:joined"](context, server) { context.dispatch("servers/setServer", server); - const channels = server.channels; + let channels = server.channels; + + + // sort server channels by order + if(server.channel_position) { + let tempServerChannels = [...channels]; + let sortedServerChannels = []; + for (let index = 0; index < server.channel_position.length; index++) { + const channelID = server.channel_position[index]; + const findIndex = tempServerChannels.findIndex((c) => c.channelID == channelID ); + if (tempServerChannels[findIndex]) { + sortedServerChannels = [...sortedServerChannels, ...[tempServerChannels[findIndex]]]; + tempServerChannels.splice(findIndex, 1) + } + } + channels = [...sortedServerChannels, ...tempServerChannels]; + tempServerChannels = null; + sortedServerChannels = null; + delete server.channel_position; + } + + for (let index = 0; index < channels.length; index++) { const element = channels[index]; @@ -358,6 +385,7 @@ const actions = { const selectedChannelID = context.rootState.channelModule.selectedChannelID; const serverChannelID = context.rootState.channelModule.serverChannelID; + const serverID = context.rootState.servers.selectedServerID; if (serverChannelIDs.includes(selectedChannelID)) { context.dispatch("selectedChannelID", null); @@ -365,6 +393,9 @@ const actions = { if (serverChannelIDs.includes(serverChannelID)) { context.dispatch("setServerChannelID", null); } + if (serverID === server_id) { + context.dispatch("servers/setSelectedServerID", null); + } context.dispatch("servers/removePresences", server_id); context.dispatch("servers/removeServer", server_id); context.dispatch("servers/removeNotifications", server_id); diff --git a/src/utils/changelog.js b/src/utils/changelog.js index 5be7605..47936b9 100644 --- a/src/utils/changelog.js +++ b/src/utils/changelog.js @@ -19,7 +19,8 @@ const config = [ "You can now move channels to make it more organized." ], fix: [ - "Fixed a bug where the notification sound would sometimes not work." + "Fixed a bug where the notification sound would sometimes not work.", + "Fixed a bug where join message would send twice." ], }, {