From 4f4d03f90fd0c308a3ca8f2e136192f72dcb756d Mon Sep 17 00:00:00 2001 From: Dan Dryaev <48590492+ShadiestGoat@users.noreply.github.com> Date: Thu, 6 Oct 2022 13:00:43 +0000 Subject: [PATCH] fix(ui): reply action not displayed for DM channels (#237) --- ui/actions_view.go | 4 ++-- ui/input_view.go | 4 +++- ui/util.go | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ui/actions_view.go b/ui/actions_view.go index c2d36ca..894aa93 100644 --- a/ui/actions_view.go +++ b/ui/actions_view.go @@ -35,7 +35,7 @@ func newActionsView(c *Core, m *discord.Message) *ActionsView { }) // If the client user has the `SEND_MESSAGES` permission, add "Reply" and "Mention Reply" actions. - if hasPermission(c.State, c.ChannelsView.selectedChannel.ID, discord.PermissionSendMessages) { + if channelIsInDMCategory(c.ChannelsView.selectedChannel) || hasPermission(c.State, c.ChannelsView.selectedChannel.ID, discord.PermissionSendMessages) { v.AddItem("Reply", "", 'r', v.replyAction) v.AddItem("Mention Reply", "", 'R', v.mentionReplyAction) } @@ -65,7 +65,7 @@ func newActionsView(c *Core, m *discord.Message) *ActionsView { } // If the client user has the `MANAGE_MESSAGES` permission, add a new action to delete the message. - if hasPermission(c.State, c.ChannelsView.selectedChannel.ID, discord.PermissionManageMessages) { + if channelIsInDMCategory(c.ChannelsView.selectedChannel) || hasPermission(c.State, c.ChannelsView.selectedChannel.ID, discord.PermissionManageMessages) { v.AddItem("Delete", "", 'd', v.deleteAction) } diff --git a/ui/input_view.go b/ui/input_view.go index 01d0d17..7d8e64b 100644 --- a/ui/input_view.go +++ b/ui/input_view.go @@ -84,7 +84,9 @@ func (v *InputView) sendMessage() *tcell.EventKey { _, m := findMessageByID(ms, discord.MessageID(mID)) d := api.SendMessageData{ Content: t, - Reference: m.Reference, + Reference: &discord.MessageReference{ + MessageID: m.ID, + }, AllowedMentions: &api.AllowedMentions{RepliedUser: option.False}, } diff --git a/ui/util.go b/ui/util.go index c99bcfb..043c5fc 100644 --- a/ui/util.go +++ b/ui/util.go @@ -42,7 +42,7 @@ func channelToString(c discord.Channel) string { for i, r := range c.DMRecipients { rps[i] = r.Username + "#" + r.Discriminator } - + repr = strings.Join(rps, ", ") } default: @@ -62,6 +62,10 @@ func findMessageByID(ms []discord.Message, mID discord.MessageID) (int, *discord return -1, nil } +func channelIsInDMCategory(c *discord.Channel) bool { + return c.Type == discord.DirectMessage || c.Type == discord.GroupDM +} + func hasPermission(s *state.State, cID discord.ChannelID, p discord.Permissions) bool { perm, err := s.Permissions(cID, s.Ready().User.ID) if err != nil {