fix(ui): reply action not displayed for DM channels (#237)

This commit is contained in:
Dan Dryaev 2022-10-06 13:00:43 +00:00 • committed by GitHub
parent 99a7bbf2ae
commit 4f4d03f90f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View file

@ -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)
}

View file

@ -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},
}

View file

@ -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 {