diff --git a/protocol/messenger_chats.go b/protocol/messenger_chats.go index 28e38bc87..7d8c0147b 100644 --- a/protocol/messenger_chats.go +++ b/protocol/messenger_chats.go @@ -12,6 +12,14 @@ import ( "github.com/status-im/status-go/protocol/transport" ) +type ChatPreviewFilterType int + +const ( + ChatPreviewFilterTypeAll ChatPreviewFilterType = iota + ChatPreviewFilterTypeCommunity + ChatPreviewFilterTypeNonCommunity +) + func (m *Messenger) getOneToOneAndNextClock(contact *Contact) (*Chat, uint64, error) { chat, ok := m.allChats.Load(contact.ID) if !ok { @@ -50,13 +58,19 @@ func (m *Messenger) Chats() []*Chat { // 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 { +func (m *Messenger) ChatsPreview(filterPointer *ChatPreviewFilterType) []*ChatPreview { var chats []*ChatPreview - + filter := ChatPreviewFilterTypeAll + if filterPointer != nil { + filter = *filterPointer + } 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 { + if filter == ChatPreviewFilterTypeCommunity && !isCommunityChat { + return true + } + if filter == ChatPreviewFilterTypeNonCommunity && isCommunityChat { return true } if chat.Active || chat.Muted { diff --git a/services/ext/api.go b/services/ext/api.go index 3bd748272..0b1087d27 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -291,8 +291,8 @@ func (api *PublicAPI) Chats(parent context.Context) []*protocol.Chat { return api.service.messenger.Chats() } -func (api *PublicAPI) ChatsPreview(parent context.Context, onlyCommunityChats *bool) []*protocol.ChatPreview { - return api.service.messenger.ChatsPreview(onlyCommunityChats) +func (api *PublicAPI) ChatsPreview(parent context.Context, filterType *protocol.ChatPreviewFilterType) []*protocol.ChatPreview { + return api.service.messenger.ChatsPreview(filterType) } func (api *PublicAPI) Chat(parent context.Context, chatID string) *protocol.Chat {