From 1b078478caefaf111cd647efae395b2edbc5c4eb Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 12 Mar 2023 16:05:45 +0300 Subject: [PATCH] Show thread mention --- cmd/rd/colourized | 1 + cmd/rd/main.go | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cmd/rd/colourized b/cmd/rd/colourized index 9ded197..6fb2945 100755 --- a/cmd/rd/colourized +++ b/cmd/rd/colourized @@ -4,4 +4,5 @@ dir="$(dirname "$(realpath -- "$0")")" "$dir"/rd $@ | spc \ -e blu,"^.?[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}" \ -e grn," <[^>]+> " \ + -e red," \[RE\]: " \ -e yel,"stargrave" diff --git a/cmd/rd/main.go b/cmd/rd/main.go index 0d7e70b..c7c6877 100644 --- a/cmd/rd/main.go +++ b/cmd/rd/main.go @@ -23,6 +23,8 @@ import ( "log" "os" "path" + "strings" + "unicode/utf8" "github.com/fsnotify/fsnotify" "github.com/mattermost/mattermost-server/v6/model" @@ -30,6 +32,20 @@ import ( "go.stargrave.org/mmc" ) +var Threads = make(map[string]string) + +func rememberPost(post map[string][]string) { + text := strings.Split(post["Text"][0], "\n")[0] + i := 60 + if len(text) > i { + for i > 0 && !utf8.Valid([]byte{text[i]}) { + i-- + } + text = text[:i] + "..." + } + Threads[post["Id"][0]] = text +} + func printPost(m map[string][]string) { var tag string if len(m["Event"]) > 0 { @@ -40,7 +56,19 @@ func printPost(m map[string][]string) { tag += "[DEL] " } } - fmt.Printf("\a%s <%s> %s%s\n", m["Created"][0], m["Sender"][0], tag, m["Text"][0]) + var re string + if len(m["RootId"]) > 0 { + thread := Threads[m["RootId"][0]] + if thread == "" { + thread = m["RootId"][0] + } + re = " [RE]: " + thread + } + fmt.Printf( + "\a%s <%s> %s%s%s\n", + m["Created"][0], m["Sender"][0], + tag, m["Text"][0], re, + ) tag += "[FILE] " for i, fileId := range m["File"] { fmt.Printf( @@ -82,6 +110,7 @@ func main() { ms = ms[len(ms)-*lastNum:] } for _, m := range ms { + rememberPost(m) printPost(m) } @@ -114,6 +143,7 @@ func main() { } log.Fatalln(err) } + rememberPost(m) printPost(m) } unlock() -- 2.48.1