1 // mmc -- Mattermost client
2 // Copyright (C) 2023 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
27 "github.com/fsnotify/fsnotify"
28 "github.com/mattermost/mattermost-server/v6/model"
29 "go.cypherpunks.ru/recfile"
30 "go.stargrave.org/mmc"
33 func printPost(m map[string][]string) {
35 if len(m["Event"]) > 0 {
36 switch m["Event"][0] {
37 case model.WebsocketEventPostEdited:
39 case model.WebsocketEventPostDeleted:
43 fmt.Printf("\a%s <%s> %s%s\n", m["Created"][0], m["Sender"][0], tag, m["Text"][0])
45 for i, fileId := range m["File"] {
47 "\a%s <%s> %s%s (%s)\n",
48 m["Created"][0], m["Sender"][0], tag, fileId, m["FileName"][i],
54 lastNum := flag.Int("last", 10, "Only that number of messages")
57 lockPth := path.Join(where, mmc.OutRecLock)
58 unlock, err := mmc.Lock(lockPth)
62 pth := path.Join(where, mmc.OutRec)
63 fd, err := os.Open(pth)
68 r := recfile.NewReader(fd)
69 ms := make([]map[string][]string, 0)
71 m, err := r.NextMapWithSlice()
81 if len(ms) > *lastNum {
82 ms = ms[len(ms)-*lastNum:]
84 for _, m := range ms {
88 watcher, err := fsnotify.NewWatcher()
92 if err = watcher.Add(pth); err != nil {
97 case err = <-watcher.Errors:
99 case event := <-watcher.Events:
100 if !event.Has(fsnotify.Write) {
104 unlock, err = mmc.Lock(lockPth)
108 r = recfile.NewReader(fd)
110 m, err := r.NextMapWithSlice()