chore_: add ChatPreviewFilterType
This commit is contained in:
parent
502d4f3734
commit
42023d34b6
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue