aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
Diffstat (limited to 'ui')
-rw-r--r--ui/command-processor.go3
-rw-r--r--ui/commands.go54
-rw-r--r--ui/view-main.go5
3 files changed, 62 insertions, 0 deletions
diff --git a/ui/command-processor.go b/ui/command-processor.go
index 79faccc..ee975ad 100644
--- a/ui/command-processor.go
+++ b/ui/command-processor.go
@@ -111,6 +111,9 @@ func NewCommandProcessor(parent *MainView) *CommandProcessor {
"rainbow": cmdRainbow,
"rainbowme": cmdRainbowMe,
"notice": cmdNotice,
+ "tags": cmdTags,
+ "tag": cmdTag,
+ "untag": cmdUntag,
"invite": cmdInvite,
"hprof": cmdHeapProfile,
"cprof": cmdCPUProfile,
diff --git a/ui/commands.go b/ui/commands.go
index 3a55f32..0f7a2aa 100644
--- a/ui/commands.go
+++ b/ui/commands.go
@@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"io"
+ "math"
"os"
"runtime"
dbg "runtime/debug"
@@ -105,6 +106,59 @@ func cmdNotice(cmd *Command) {
cmd.UI.Render()
}
+func cmdTags(cmd *Command) {
+ tags := cmd.Room.MxRoom().RawTags
+ if len(tags) == 0 {
+ if cmd.Room.MxRoom().IsDirect {
+ cmd.Reply("This room has no tags, but it's marked as a direct chat.")
+ } else {
+ cmd.Reply("This room has no tags.")
+ }
+ return
+ }
+ var resp strings.Builder
+ resp.WriteString("Tags in this room:\n")
+ for _, tag := range tags {
+ if tag.Order != "" {
+ _, _ = fmt.Fprintf(&resp, "%s (order: %s)\n", tag.Tag, tag.Order)
+ } else {
+ _, _ = fmt.Fprintf(&resp, "%s (no order)\n", tag.Tag)
+ }
+ }
+ cmd.Reply(strings.TrimSpace(resp.String()))
+}
+
+func cmdTag(cmd *Command) {
+ if len(cmd.Args) == 0 {
+ cmd.Reply("Usage: /tag <tag> [order]")
+ return
+ }
+ order := math.NaN()
+ if len(cmd.Args) > 1 {
+ var err error
+ order, err = strconv.ParseFloat(cmd.Args[1], 64)
+ if err != nil {
+ cmd.Reply("%s is not a valid order: %v", cmd.Args[1], err)
+ return
+ }
+ }
+ err := cmd.Matrix.Client().AddTag(cmd.Room.MxRoom().ID, cmd.Args[0], order)
+ if err != nil {
+ cmd.Reply("Failed to add tag:", err)
+ }
+}
+
+func cmdUntag(cmd *Command) {
+ if len(cmd.Args) == 0 {
+ cmd.Reply("Usage: /untag <tag>")
+ return
+ }
+ err := cmd.Matrix.Client().RemoveTag(cmd.Room.MxRoom().ID, cmd.Args[0])
+ if err != nil {
+ cmd.Reply("Failed to remove tag:", err)
+ }
+}
+
func cmdRoomNick(cmd *Command) {
room := cmd.Room.MxRoom()
member := room.GetMember(room.SessionUserID)
diff --git a/ui/view-main.go b/ui/view-main.go
index 2a8a1fe..5357d24 100644
--- a/ui/view-main.go
+++ b/ui/view-main.go
@@ -370,8 +370,13 @@ func (view *MainView) UpdateTags(room *rooms.Room) {
if !view.roomList.Contains(room.ID) {
return
}
+ reselect := view.roomList.selected == room
view.roomList.Remove(room)
view.roomList.Add(room)
+ if reselect {
+ view.roomList.SetSelected(room.Tags()[0].Tag, room)
+ }
+ view.parent.Render()
}
func (view *MainView) SetTyping(roomID string, users []string) {