X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=cmd%2Frd%2Fmain.go;h=c7c68772c53b727203b36e7aa5a0204203eff1d6;hb=1b078478caefaf111cd647efae395b2edbc5c4eb;hp=0d7e70b65e9280fef79d140c3ff71deb134e62fe;hpb=ba307f9fde41d14c879018d8e1b5dd1d3a5b2bcb;p=mmc.git 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()