aboutsummaryrefslogtreecommitdiff
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
parent6eaee844654355d8d5d1dd1710f6c27a47069d0f (diff)
Add support for editing room tags
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--matrix/sync.go1
-rw-r--r--ui/command-processor.go3
-rw-r--r--ui/commands.go54
-rw-r--r--ui/view-main.go5
6 files changed, 66 insertions, 1 deletions
diff --git a/go.mod b/go.mod
index 8167018..12b9067 100644
--- a/go.mod
+++ b/go.mod
@@ -25,7 +25,7 @@ require (
gopkg.in/russross/blackfriday.v2 v2.0.1
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2
gopkg.in/yaml.v2 v2.2.2
- maunium.net/go/mautrix v0.1.0-alpha.3.0.20190616140407-62f6f484857e
+ maunium.net/go/mautrix v0.1.0-alpha.3.0.20190616163219-6b4bce05f314
maunium.net/go/mauview v0.0.0-20190606152754-de9e0a754a5d
maunium.net/go/tcell v0.0.0-20190606152714-9a88fc07b3ed
)
diff --git a/go.sum b/go.sum
index f0218f7..492f270 100644
--- a/go.sum
+++ b/go.sum
@@ -96,6 +96,8 @@ maunium.net/go/mautrix v0.1.0-alpha.3.0.20190616122434-35971ee5ad3c h1:FxaOZhImK
maunium.net/go/mautrix v0.1.0-alpha.3.0.20190616122434-35971ee5ad3c/go.mod h1:O+QWJP3H7BZEzIBSrECKpnpRnEKBwaoWVEu/yZwVwxg=
maunium.net/go/mautrix v0.1.0-alpha.3.0.20190616140407-62f6f484857e h1:W3NG02SHY4ldbLFyr0vQugKJQdONOb1lEjBPd3PTCrk=
maunium.net/go/mautrix v0.1.0-alpha.3.0.20190616140407-62f6f484857e/go.mod h1:O+QWJP3H7BZEzIBSrECKpnpRnEKBwaoWVEu/yZwVwxg=
+maunium.net/go/mautrix v0.1.0-alpha.3.0.20190616163219-6b4bce05f314 h1:wGlIqs/L+ErBbAHbkpM4AlFi+9+z9Bsle4xD4Gw+y3k=
+maunium.net/go/mautrix v0.1.0-alpha.3.0.20190616163219-6b4bce05f314/go.mod h1:O+QWJP3H7BZEzIBSrECKpnpRnEKBwaoWVEu/yZwVwxg=
maunium.net/go/mauview v0.0.0-20190606152754-de9e0a754a5d h1:H4wZ4vMVnOh5QFsb4xZtssgpv3DDEkBRzQ8iyEg2fX0=
maunium.net/go/mauview v0.0.0-20190606152754-de9e0a754a5d/go.mod h1:GL+akv58wNFzzX4IKLvryKx0F/AcYKHql35DiBzBc/w=
maunium.net/go/tcell v0.0.0-20190606152714-9a88fc07b3ed h1:sAcUrUZG2LFWBTkTtLKPQvHPHFM5d6huAhr5ZZuxtbQ=
diff --git a/matrix/sync.go b/matrix/sync.go
index 4489ea4..fd70980 100644
--- a/matrix/sync.go
+++ b/matrix/sync.go
@@ -214,6 +214,7 @@ func (s *GomuksSyncer) GetFilterJSON(userID string) json.RawMessage {
Timeline: mautrix.FilterPart{
Types: []string{
"m.room.message",
+ "m.room.redaction",
"m.room.encrypted",
"m.sticker",
"m.reaction",
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) {