fix activechats ordering
This commit is contained in:
parent
83394e0ed1
commit
20363e32ef
|
@ -93,6 +93,7 @@ type Messenger struct {
|
||||||
shouldPublishContactCode bool
|
shouldPublishContactCode bool
|
||||||
systemMessagesTranslations *systemMessageTranslationsMap
|
systemMessagesTranslations *systemMessageTranslationsMap
|
||||||
allChats *chatMap
|
allChats *chatMap
|
||||||
|
latestNActiveChats []*Chat
|
||||||
allContacts *contactMap
|
allContacts *contactMap
|
||||||
allInstallations *installationMap
|
allInstallations *installationMap
|
||||||
modifiedInstallations *stringBoolMap
|
modifiedInstallations *stringBoolMap
|
||||||
|
@ -981,6 +982,7 @@ func (m *Messenger) Init() error {
|
||||||
// Get chat IDs and public keys from the existing chats.
|
// Get chat IDs and public keys from the existing chats.
|
||||||
// TODO: Get only active chats by the query.
|
// TODO: Get only active chats by the query.
|
||||||
chats, err := m.persistence.Chats()
|
chats, err := m.persistence.Chats()
|
||||||
|
i := 0
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -991,6 +993,15 @@ func (m *Messenger) Init() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
m.allChats.Store(chat.ID, chat)
|
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() {
|
if !chat.Active || chat.Timeline() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,16 +20,8 @@ func (m *Messenger) Chats() []*Chat {
|
||||||
return chats
|
return chats
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) LatestActiveNChats(num int) []*Chat {
|
func (m *Messenger) LatestActiveChats() []*Chat {
|
||||||
var chats []*Chat
|
return m.latestNActiveChats
|
||||||
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 {
|
func (m *Messenger) ActiveChats() []*Chat {
|
||||||
|
|
|
@ -267,8 +267,8 @@ func (api *PublicAPI) Chats(parent context.Context) []*protocol.Chat {
|
||||||
return api.service.messenger.Chats()
|
return api.service.messenger.Chats()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) LatestActiveNChats(parent context.Context, num int) []*protocol.Chat {
|
func (api *PublicAPI) LatestActiveChats(parent context.Context) []*protocol.Chat {
|
||||||
return api.service.messenger.LatestActiveNChats(num)
|
return api.service.messenger.LatestActiveChats()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) ActiveChats(parent context.Context) []*protocol.Chat {
|
func (api *PublicAPI) ActiveChats(parent context.Context) []*protocol.Chat {
|
||||||
|
|
Loading…
Reference in New Issue