go-tdlib/client/puller/supergroup.go

54 lines
1.2 KiB
Go
Raw Normal View History

2018-10-09 03:46:15 +00:00
package puller
import (
2022-01-26 20:48:37 +00:00
"github.com/c0re100/gotdlib/client"
2018-10-09 03:46:15 +00:00
)
2021-12-30 05:55:02 +00:00
func SupergroupMembers(tdlibClient *client.Client, supergroupId int64) (chan *client.ChatMember, chan error) {
2018-10-23 12:49:10 +00:00
chatMemberChan := make(chan *client.ChatMember, 10)
errChan := make(chan error, 1)
2018-10-09 03:46:15 +00:00
2018-10-23 12:49:10 +00:00
var filter client.SupergroupMembersFilter = nil
var offset int32 = 0
var limit int32 = 200
2018-10-09 03:46:15 +00:00
2018-10-23 12:49:10 +00:00
go supergroupMembers(tdlibClient, chatMemberChan, errChan, supergroupId, filter, offset, limit)
2018-10-09 03:46:15 +00:00
2018-10-23 12:49:10 +00:00
return chatMemberChan, errChan
2018-10-09 03:46:15 +00:00
}
2021-12-30 05:55:02 +00:00
func supergroupMembers(tdlibClient *client.Client, chatMemberChan chan *client.ChatMember, errChan chan error, supergroupId int64, filter client.SupergroupMembersFilter, offset int32, limit int32) {
2018-10-23 12:49:10 +00:00
defer func() {
close(chatMemberChan)
close(errChan)
}()
var page int32 = 0
for {
chatMembers, err := tdlibClient.GetSupergroupMembers(&client.GetSupergroupMembersRequest{
SupergroupId: supergroupId,
Filter: filter,
Offset: page*limit + offset,
Limit: limit,
})
if err != nil {
errChan <- err
return
}
if len(chatMembers.Members) == 0 {
errChan <- EOP
break
}
for _, member := range chatMembers.Members {
chatMemberChan <- member
}
page++
}
2018-10-09 03:46:15 +00:00
}