]> Sergey Matveev's repositories - mmc.git/blobdiff - internal/users.go
internal package
[mmc.git] / internal / users.go
diff --git a/internal/users.go b/internal/users.go
new file mode 100644 (file)
index 0000000..83802e7
--- /dev/null
@@ -0,0 +1,49 @@
+// mmc -- Mattermost client
+// Copyright (C) 2023-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package mmc
+
+import (
+       "os"
+       "time"
+
+       "github.com/davecgh/go-spew/spew"
+       "github.com/mattermost/mattermost-server/v6/model"
+)
+
+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
+}