Przeglądaj źródła

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

Dan Dryaev 3 lat temu
rodzic
commit
4f4d03f90f
3 zmienionych plików z 10 dodań i 4 usunięć
  1. 2 2
      ui/actions_view.go
  2. 3 1
      ui/input_view.go
  3. 5 1
      ui/util.go

+ 2 - 2
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)
 	}
 

+ 3 - 1
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},
 		}
 

+ 5 - 1
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 {