]> Sergey Matveev's repositories - mmc.git/commitdiff
cmd/scrollback -whole
authorSergey Matveev <stargrave@stargrave.org>
Sun, 12 Mar 2023 11:12:06 +0000 (14:12 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sun, 12 Mar 2023 12:43:37 +0000 (15:43 +0300)
cmd/scrollback/main.go

index 733b5715391b1fcb19b6cd6339a7953eaa58487a..ddb29b68f44dc4c559de58d690bbee3dc2a93224 100644 (file)
@@ -20,21 +20,20 @@ import (
        "flag"
        "log"
        "os"
+       "time"
 
        "github.com/mattermost/mattermost-server/v6/model"
        "go.cypherpunks.ru/recfile"
        "go.stargrave.org/mmc"
 )
 
-const PerPage = 100
-
 func main() {
        entrypoint := flag.String("entrypoint", mmc.GetEntrypoint(), "Entrypoint")
        pageNum := flag.Int("page", 0, "Page number")
+       whole := flag.Bool("whole", false, "Whole history")
        direct := flag.Bool("direct", false, "Direct channel")
        flag.Parse()
        log.SetFlags(log.Lshortfile)
-       log.SetOutput(os.Stdout)
 
        chId := flag.Arg(0)
        postId := flag.Arg(1)
@@ -59,12 +58,29 @@ func main() {
                }
                chId = dc.Id
        }
-       list, _, err := c.GetPostsBefore(chId, postId, *pageNum, PerPage, "", false)
-       if err != nil {
-               log.Fatalln(err)
+       var slice []*model.Post
+       if *whole {
+               for n := 0; ; n++ {
+                       log.Println("page:", n)
+                       time.Sleep(mmc.SleepTime)
+                       list, _, err := c.GetPostsBefore(chId, postId, n, mmc.PerPage, "", false)
+                       if err != nil {
+                               log.Fatalln(err)
+                       }
+                       s := list.ToSlice()
+                       slice = append(slice, s...)
+                       if len(s) < mmc.PerPage {
+                               break
+                       }
+               }
+       } else {
+               list, _, err := c.GetPostsBefore(chId, postId, *pageNum, mmc.PerPage, "", false)
+               if err != nil {
+                       log.Fatalln(err)
+               }
+               slice = list.ToSlice()
        }
        w := recfile.NewWriter(os.Stdout)
-       slice := list.ToSlice()
        for i := len(slice) - 1; i >= 0; i-- {
                if err = mmc.PostToRec(
                        w, users,