preload chats

This commit is contained in:
andrey 2021-08-16 13:04:35 +02:00 committed by flexsurfer
parent 45212b0823
commit ab08042f21
3 changed files with 17 additions and 1 deletions

View File

@ -1 +1 @@
0.83.15
0.83.16

View File

@ -20,6 +20,18 @@ func (m *Messenger) Chats() []*Chat {
return chats
}
func (m *Messenger) LatestActiveNChats(num int) []*Chat {
var chats []*Chat
var i = 0
m.allChats.Range(func(chatID string, chat *Chat) (shouldContinue bool) {
chats = append(chats, chat)
i++
return i < num
})
return chats
}
func (m *Messenger) ActiveChats() []*Chat {
m.mutex.Lock()
defer m.mutex.Unlock()

View File

@ -267,6 +267,10 @@ func (api *PublicAPI) Chats(parent context.Context) []*protocol.Chat {
return api.service.messenger.Chats()
}
func (api *PublicAPI) LatestActiveNChats(parent context.Context, num int) []*protocol.Chat {
return api.service.messenger.LatestActiveNChats(num)
}
func (api *PublicAPI) ActiveChats(parent context.Context) []*protocol.Chat {
return api.service.messenger.ActiveChats()
}