"go.stargrave.org/mmc"
)
-const (
- PerPage = 100
- CmdFile = "/FILE "
-)
+const CmdFile = "/FILE "
var (
Newwin = flag.String("newwin", "cmd/newwin", "Path to newwin command")
}
Team := teams[0]
- Users := make(map[string]*model.User)
- for pageNum := 0; ; pageNum++ {
- time.Sleep(mmc.SleepTime)
- page, resp, err := c.GetUsers(pageNum, PerPage, "")
- if err != nil {
- if DebugFd != nil {
- spew.Fdump(DebugFd, resp)
- }
- log.Fatalln(err)
- }
- if DebugFd != nil {
- spew.Fdump(DebugFd, page)
- }
- for _, u := range page {
- Users[u.Id] = u
- }
- if len(page) < PerPage {
- break
- }
- }
-
var updateQueue []string
LastSent := time.Now()
+
+ Users, err := mmc.GetUsers(c, DebugFd)
+ if err != nil {
+ log.Fatalln(err)
+ }
for _, u := range Users {
pth := path.Join("users", strings.ReplaceAll(u.Username, ".", "_"))
os.MkdirAll(pth, 0777)
log.Println("OpenFile:", usersPth, err)
continue
}
- for pageNum := 0; ; pageNum++ {
- users, resp, err := c.GetUsersInChannel(ch.Id, pageNum, PerPage, "")
+ for n := 0; ; n++ {
+ users, resp, err := c.GetUsersInChannel(ch.Id, n, mmc.PerPage, "")
if err != nil {
if DebugFd != nil {
spew.Fdump(DebugFd, resp)
for _, u := range users {
fmt.Fprintf(fd, "%s\n", u.Username)
}
- if len(users) < PerPage {
+ if len(users) < mmc.PerPage {
break
}
}
if lastPostId == "" {
return nil
}
- for pageNum := 0; ; pageNum++ {
+ for n := 0; ; n++ {
time.Sleep(mmc.SleepTime)
- postList, resp, err := c.GetPostsAfter(
- chId, lastPostId, pageNum, PerPage, "", false,
+ list, resp, err := c.GetPostsAfter(
+ chId, lastPostId, n, mmc.PerPage, "", false,
)
if DebugFd != nil {
- spew.Fdump(DebugFd, postList, resp)
+ spew.Fdump(DebugFd, list, resp)
}
if resp.StatusCode == http.StatusNotFound {
break
return err
}
var posts []mmc.Post
- for _, post := range postList.ToSlice() {
+ for _, post := range list.ToSlice() {
posts = append(posts, mmc.Post{P: post, E: model.WebsocketEventPosted})
}
if err = writePosts(where, users, posts); err != nil {
return err
}
- if len(posts) < PerPage {
+ if len(posts) < mmc.PerPage {
break
}
}
"flag"
"log"
"os"
- "time"
"github.com/mattermost/mattermost-server/v6/model"
"go.cypherpunks.ru/recfile"
}
c := model.NewAPIv4Client("https://" + *entrypoint)
c.Login(login, password)
-
- users := make(map[string]*model.User)
- for pageNum := 0; ; pageNum++ {
- time.Sleep(mmc.SleepTime)
- page, _, err := c.GetUsers(pageNum, PerPage, "")
- if err != nil {
- log.Fatalln(err)
- }
- for _, u := range page {
- users[u.Id] = u
- }
- if len(page) < PerPage {
- break
- }
+ users, err := mmc.GetUsers(c, nil)
+ if err != nil {
+ log.Fatalln(err)
}
list, _, err := c.GetPostsBefore(chId, postId, 0, 200, "", false)
package mmc
import (
+ "os"
"strings"
"time"
+ "github.com/davecgh/go-spew/spew"
"github.com/mattermost/mattermost-server/v6/model"
"go.cypherpunks.ru/recfile"
)
const (
+ PerPage = 100
OutRec = "out.rec"
OutRecLock = "out.rec.lock"
Last = "last"
_, err = w.WriteFieldMultiline("Text", strings.Split(post.P.Message, "\n"))
return err
}
+
+func GetUsers(c *model.Client4, debugFd *os.File) (map[string]*model.User, error) {
+ users := make(map[string]*model.User)
+ for n := 0; ; n++ {
+ time.Sleep(SleepTime)
+ page, resp, err := c.GetUsers(n, PerPage, "")
+ if err != nil {
+ if debugFd != nil {
+ spew.Fdump(debugFd, resp)
+ }
+ return nil, err
+ }
+ if debugFd != nil {
+ spew.Fdump(debugFd, page)
+ }
+ for _, u := range page {
+ users[u.Id] = u
+ }
+ if len(page) < PerPage {
+ break
+ }
+ }
+ return users, nil
+}