aboutsummaryrefslogtreecommitdiff
path: root/ui/commands.go
diff options
context:
space:
mode:
authorTulir Asokan <tulir@maunium.net>2019-06-16 19:32:57 +0300
committerTulir Asokan <tulir@maunium.net>2019-06-16 19:32:57 +0300
commit7f917f027127b46f219eaa8a6c696c4e078f6d04 (patch)
treec22ad66d7a96256abecbba81f9278efd83c4d690 /ui/commands.go
parent6eaee844654355d8d5d1dd1710f6c27a47069d0f (diff)
Add support for editing room tags
Diffstat (limited to 'ui/commands.go')
-rw-r--r--ui/commands.go54
1 files changed, 54 insertions, 0 deletions
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)