perf_: return chats preview with optional filter
This commit is contained in:
parent
b0c90362d4
commit
a507bea8dc
|
@ -46,10 +46,19 @@ func (m *Messenger) Chats() []*Chat {
|
||||||
return chats
|
return chats
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Messenger) ChatsPreview() []*ChatPreview {
|
// ChatsPreview returns a list of chat previews.
|
||||||
|
// When onlyCommunityChats is nil, returns all chats
|
||||||
|
// When onlyCommunityChats is true, only returns community chats
|
||||||
|
// When onlyCommunityChats is false, returns all non-community chats
|
||||||
|
func (m *Messenger) ChatsPreview(onlyCommunityChats *bool) []*ChatPreview {
|
||||||
var chats []*ChatPreview
|
var chats []*ChatPreview
|
||||||
|
|
||||||
m.allChats.Range(func(chatID string, chat *Chat) (shouldContinue bool) {
|
m.allChats.Range(func(chatID string, chat *Chat) (shouldContinue bool) {
|
||||||
|
// Skip if chat doesn't match the filter
|
||||||
|
isCommunityChat := chat.ChatType == ChatTypeCommunityChat
|
||||||
|
if onlyCommunityChats != nil && isCommunityChat != *onlyCommunityChats {
|
||||||
|
return true
|
||||||
|
}
|
||||||
if chat.Active || chat.Muted {
|
if chat.Active || chat.Muted {
|
||||||
chatPreview := &ChatPreview{
|
chatPreview := &ChatPreview{
|
||||||
ID: chat.ID,
|
ID: chat.ID,
|
||||||
|
|
|
@ -291,8 +291,8 @@ func (api *PublicAPI) Chats(parent context.Context) []*protocol.Chat {
|
||||||
return api.service.messenger.Chats()
|
return api.service.messenger.Chats()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) ChatsPreview(parent context.Context) []*protocol.ChatPreview {
|
func (api *PublicAPI) ChatsPreview(parent context.Context, onlyCommunityChats *bool) []*protocol.ChatPreview {
|
||||||
return api.service.messenger.ChatsPreview()
|
return api.service.messenger.ChatsPreview(onlyCommunityChats)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) Chat(parent context.Context, chatID string) *protocol.Chat {
|
func (api *PublicAPI) Chat(parent context.Context, chatID string) *protocol.Chat {
|
||||||
|
|
Loading…
Reference in New Issue