go-tdlib/client/puller/chats.go

56 lines
901 B
Go

package puller
import (
"math"
"git.zio.sh/astra/go-tdlib/client"
)
func Chats(tdlibClient *client.Client) (chan *client.Chat, chan error) {
chatChan := make(chan *client.Chat, 10)
errChan := make(chan error, 1)
var limit int32 = 100
go chats(tdlibClient, chatChan, errChan, limit)
return chatChan, errChan
}
func chats(tdlibClient *client.Client, chatChan chan *client.Chat, errChan chan error, limit int32) {
defer func() {
close(chatChan)
close(errChan)
}()
for {
chats, err := tdlibClient.GetChats(&client.GetChatsRequest{
Limit: limit,
})
if err != nil {
errChan <- err
return
}
if len(chats.ChatIds) == 0 {
errChan <- EOP
break
}
for _, chatId := range chats.ChatIds {
chat, err := tdlibClient.GetChat(&client.GetChatRequest{
ChatId: chatId,
})
if err != nil {
errChan <- err
return
}
chatChan <- chat
}
}
}