fix(ui): check permissions in action list (#239)

This commit is contained in:
Dan Dryaev 2022-10-07 04:54:09 +00:00 • committed by GitHub
parent 4f4d03f90f
commit 4cb58e0edf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,8 +34,10 @@ func newActionsView(c *Core, m *discord.Message) *ActionsView {
c.App.SetFocus(c.MessagesView)
})
isDM := channelIsInDMCategory(c.ChannelsView.selectedChannel)
// If the client user has the `SEND_MESSAGES` permission, add "Reply" and "Mention Reply" actions.
if channelIsInDMCategory(c.ChannelsView.selectedChannel) || hasPermission(c.State, c.ChannelsView.selectedChannel.ID, discord.PermissionSendMessages) {
if isDM || !isDM && hasPermission(c.State, c.ChannelsView.selectedChannel.ID, discord.PermissionSendMessages) {
v.AddItem("Reply", "", 'r', v.replyAction)
v.AddItem("Mention Reply", "", 'R', v.mentionReplyAction)
}
@ -64,8 +66,10 @@ func newActionsView(c *Core, m *discord.Message) *ActionsView {
v.AddItem("Download Attachment", "", 'd', v.downloadAttachmentAction)
}
me, _ := c.State.MeStore.Me()
// If the client user has the `MANAGE_MESSAGES` permission, add a new action to delete the message.
if channelIsInDMCategory(c.ChannelsView.selectedChannel) || hasPermission(c.State, c.ChannelsView.selectedChannel.ID, discord.PermissionManageMessages) {
if (isDM && m.Author.ID == me.ID) || (!isDM && hasPermission(c.State, c.ChannelsView.selectedChannel.ID, discord.PermissionManageMessages)) {
v.AddItem("Delete", "", 'd', v.deleteAction)
}