go-tdlib/client/puller/chat.go
Aleksandr Zelenin 0dc94fc121 add pullers
2018-10-09 06:46:15 +03:00

47 lines
1.1 KiB
Go

package puller
import (
"github.com/zelenin/go-tdlib/client"
)
func ChatHistory(tdlibClient *client.Client, chatId int64) (chan *client.Message, chan error) {
messageChan := make(chan *client.Message, 10)
errChan := make(chan error, 1)
var fromMessageId int64 = 0
var offset int32 = 0
var limit int32 = 100
go chatHistory(tdlibClient, messageChan, errChan, chatId, fromMessageId, offset, limit, false)
return messageChan, errChan
}
func chatHistory(tdlibClient *client.Client, messageChan chan *client.Message, errChan chan error, chatId int64, fromMessageId int64, offset int32, limit int32, onlyLocal bool) {
defer func() {
close(messageChan)
close(errChan)
}()
for {
messages, err := tdlibClient.GetChatHistory(chatId, fromMessageId, offset, limit, onlyLocal)
if err != nil {
errChan <- err
return
}
if len(messages.Messages) == 0 {
errChan <- EOP
break
}
for _, message := range messages.Messages {
fromMessageId = message.Id
messageChan <- message
}
}
}