From ba307f9fde41d14c879018d8e1b5dd1d3a5b2bcb Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 12 Mar 2023 11:43:51 +0300 Subject: [PATCH 1/1] Sync user's history --- cmd/mmc/main.go | 45 +++++++++++++++++++++++++++++++-------------- doc/usage.texi | 20 ++++++++++++++++++-- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/cmd/mmc/main.go b/cmd/mmc/main.go index e1b2c29..b288a8d 100644 --- a/cmd/mmc/main.go +++ b/cmd/mmc/main.go @@ -116,6 +116,7 @@ func main() { if err != nil { log.Fatalln(err) } + UsersDC := make(map[string]*model.Channel, len(Users)) for _, u := range Users { pth := path.Join("users", strings.ReplaceAll(u.Username, ".", "_")) os.MkdirAll(pth, 0777) @@ -133,10 +134,23 @@ func main() { log.Fatalln(err) } } - updateQueue = append(updateQueue, - pth, u.Id+"__"+me.Id, - pth, me.Id+"__"+u.Id, - ) + + if fi, err := os.Stat(path.Join(pth, mmc.OutRec)); err == nil && fi.Size() > 0 { + time.Sleep(mmc.SleepTime) + dc, resp, err := c.CreateDirectChannel(me.Id, u.Id) + if err != nil { + if DebugFd != nil { + spew.Fdump(DebugFd, resp) + } + log.Println("CreateDirectChannel:", err) + continue + } + if DebugFd != nil { + spew.Fdump(DebugFd, dc) + } + UsersDC[u.Id] = dc + updateQueue = append(updateQueue, pth, dc.Id) + } statusPth := path.Join(pth, "status") os.Remove(statusPth) @@ -187,6 +201,7 @@ func main() { if err != nil { continue } + dc = UsersDC[u.Id] if dc == nil { dc, resp, err = c.CreateDirectChannel(me.Id, u.Id) if err != nil { @@ -196,6 +211,7 @@ func main() { log.Println("CreateDirectChannel:", err) continue } + UsersDC[u.Id] = dc if DebugFd != nil { spew.Fdump(DebugFd, dc) } @@ -307,17 +323,18 @@ func main() { }(ch) } - go func() { - log.Println("syncing", len(Chans)+len(Users), "rooms") - for len(updateQueue) > 0 { - err := updatePosts(c, Users, updateQueue[0], updateQueue[1]) - if err != nil { - log.Println("updatePosts:", err) - } - updateQueue = updateQueue[2:] + log.Println("syncing", len(updateQueue)/2, "rooms") + for len(updateQueue) > 0 { + err := updatePosts(c, Users, updateQueue[0], updateQueue[1]) + if err != nil { + log.Println("updatePosts:", err) } - log.Println("sync done") - }() + updateQueue = updateQueue[2:] + } + log.Println("sync done") + if *notifyCmd != "" { + exec.Command(*notifyCmd, "sync done").Run() + } go func() { os.MkdirAll("file", 0777) diff --git a/doc/usage.texi b/doc/usage.texi index d64b999..b8ebf78 100644 --- a/doc/usage.texi +++ b/doc/usage.texi @@ -6,6 +6,12 @@ @item Get the @url{git://git.stargrave.org/mmc.git, source code} and compile Go programs in @file{cmd} subdirectory. +@example +for c (cmd/rd cmd/mmc cmd/scrollback cmd/ch-leave) @{ + pushd $c ; go build -ldflags=-s ; popd +@} +@end example + @item Create and change to the directory where the state will be kept. @item Place your MM's credentials to @env{$NETRC} (@file{~/.netrc} by @@ -46,8 +52,9 @@ message at the bottom of the screen. @file{FILEID.tar} archive in current directory. @item After you just logged in, @command{cmd/mmc} checks for new -messages since you were offline. So some windows could be automatically -opened because of new messages. +messages since you were offline, if any messages were in the state's +history. So some windows could be automatically opened because of new +messages. @item By pressing @code{Prefix+Q} you will destroy the whole session and quit @command{tmux}. @@ -55,4 +62,13 @@ quit @command{tmux}. @item @command{cmd/mmc} heartbeats server each minute to tell that you are online, preventing you becoming away. +@item You can preliminary fill your history: + +@example +for c (users/*(/) chans/*(/)) @{ + cmd/scrollback -whole `cat $c/id` > $c/out.rec + cmd/last-update < $c/out.rec > $c/last +@} +@end example + @end enumerate -- 2.44.0