go-tdlib/client/puller/chats.go

56 lines
901 B
Go
Raw Normal View History

2021-10-22 16:24:12 +02:00
package puller
import (
"math"
2021-10-22 16:31:26 +02:00
"git.zio.sh/astra/go-tdlib/client"
2021-10-22 16:24:12 +02:00
)
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
2021-12-08 13:43:22 +01:00
go chats(tdlibClient, chatChan, errChan, limit)
2021-10-22 16:24:12 +02:00
return chatChan, errChan
}
2021-12-08 13:43:22 +01:00
func chats(tdlibClient *client.Client, chatChan chan *client.Chat, errChan chan error, limit int32) {
2021-10-22 16:24:12 +02:00
defer func() {
close(chatChan)
close(errChan)
}()
for {
chats, err := tdlibClient.GetChats(&client.GetChatsRequest{
2021-12-08 13:43:22 +01:00
Limit: limit,
2021-10-22 16:24:12 +02:00
})
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
}
}
}