]> Sergey Matveev's repositories - mmc.git/commitdiff
Sync user's history
authorSergey Matveev <stargrave@stargrave.org>
Sun, 12 Mar 2023 08:43:51 +0000 (11:43 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 12 Mar 2023 13:08:50 +0000 (16:08 +0300)
cmd/mmc/main.go
doc/usage.texi

index e1b2c2953b35fdebf25433651e403df40b263b1e..b288a8d5d11532bf0597fb926fb4a4e2ec94abe4 100644 (file)
@@ -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)
index d64b9990b05bdde021913e37194d34b9a9549f29..b8ebf7883bff6af3ed3c5c69afb04a7d2164053f 100644 (file)
@@ -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