From f888e58005a24fa682e811dc651a93959de5e3a1 Mon Sep 17 00:00:00 2001 From: supertiger1234 Date: Thu, 19 Sep 2019 16:03:28 +0100 Subject: [PATCH] hide edit and delete when not available --- .../Popouts/Popouts/messageContextMenu.vue | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/components/app/Popouts/Popouts/messageContextMenu.vue b/src/components/app/Popouts/Popouts/messageContextMenu.vue index 3c6e326..fe562aa 100644 --- a/src/components/app/Popouts/Popouts/messageContextMenu.vue +++ b/src/components/app/Popouts/Popouts/messageContextMenu.vue @@ -1,8 +1,8 @@ @@ -58,14 +58,42 @@ export default { }, computed: { contextDetails() { - const { x, y, messageID, message, channelID } = this.$store.getters.popouts.messageContextMenu; + const { x, y, messageID, message, channelID, uniqueID } = this.$store.getters.popouts.messageContextMenu; return { x, y, messageID, message, - channelID + channelID, + uniqueID } + }, + serverID() { + const serverChannelIDs = Object.entries(this.$store.getters['servers/channelsIDs']); + const find = serverChannelIDs.find(c => { + return c[1].includes(this.contextDetails.channelID) + }); + return find ? find[0] : undefined; + }, + serverMember () { + const serverMembers = this.$store.getters['servers/serverMembers']; + return serverMembers.find(m => + m.uniqueID === this.user.uniqueID && m.server_id === this.serverID && m.type === "OWNER" + ) + }, + user() { + return this.$store.getters.user; + }, + showEditOption() { + // Only show edit option if the user is us. + return this.user.uniqueID === this.contextDetails.uniqueID + }, + showDeleteOption() { + // Only show delete option if the user is us or server owner is us. + if (this.user.uniqueID === this.contextDetails.uniqueID){ + return true; + } + return !!this.serverMember; } },