Skip to content

Commit

Permalink
preload chats
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer committed Aug 20, 2021
1 parent 45212b0 commit ab08042
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.83.15
0.83.16
12 changes: 12 additions & 0 deletions protocol/messenger_chats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions services/ext/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit ab08042

Please sign in to comment.