fix activechats ordering

This commit is contained in:
andrey 2021-08-25 10:59:53 +02:00 committed by flexsurfer
parent 83394e0ed1
commit 20363e32ef
4 changed files with 16 additions and 13 deletions

View File

@ -1 +1 @@
0.84.1
0.84.2

View File

@ -93,6 +93,7 @@ type Messenger struct {
shouldPublishContactCode bool
systemMessagesTranslations *systemMessageTranslationsMap
allChats *chatMap
latestNActiveChats []*Chat
allContacts *contactMap
allInstallations *installationMap
modifiedInstallations *stringBoolMap
@ -981,6 +982,7 @@ func (m *Messenger) Init() error {
// Get chat IDs and public keys from the existing chats.
// TODO: Get only active chats by the query.
chats, err := m.persistence.Chats()
i := 0
if err != nil {
return err
}
@ -991,6 +993,15 @@ func (m *Messenger) Init() error {
}
m.allChats.Store(chat.ID, chat)
// if a user has thousands of chats
// we want to have quick access to the latest 60 sorted active chats, to show them first to the user
// 60 is the 3 screens of chats, so when user will scroll to the end we'll load all chats
if i < 60 {
m.latestNActiveChats = append(m.latestNActiveChats, chat)
i++
}
if !chat.Active || chat.Timeline() {
continue
}

View File

@ -20,16 +20,8 @@ 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) LatestActiveChats() []*Chat {
return m.latestNActiveChats
}
func (m *Messenger) ActiveChats() []*Chat {

View File

@ -267,8 +267,8 @@ 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) LatestActiveChats(parent context.Context) []*protocol.Chat {
return api.service.messenger.LatestActiveChats()
}
func (api *PublicAPI) ActiveChats(parent context.Context) []*protocol.Chat {