diff --git a/protocol/chat.go b/protocol/chat.go index fcdae635b..7be7d7127 100644 --- a/protocol/chat.go +++ b/protocol/chat.go @@ -57,6 +57,7 @@ const ( MuteFor1Week MuteTillUnmuted MuteTill1Min + Unmuted ) const pkStringLength = 68 diff --git a/protocol/communities_messenger_test.go b/protocol/communities_messenger_test.go index 3fe2203e8..87429056e 100644 --- a/protocol/communities_messenger_test.go +++ b/protocol/communities_messenger_test.go @@ -3093,7 +3093,11 @@ func (s *MessengerCommunitiesSuite) TestSetMutePropertyOnChatsByCategory() { categoryID = k } - err = s.alice.SetMutePropertyOnChatsByCategory(newCommunity.IDString(), categoryID, true) + err = s.alice.SetMutePropertyOnChatsByCategory(&requests.MuteCategory{ + CommunityID: newCommunity.IDString(), + CategoryID: categoryID, + MutedType: MuteTillUnmuted, + }, true) s.Require().NoError(err) for _, chat := range s.alice.Chats() { @@ -3102,7 +3106,11 @@ func (s *MessengerCommunitiesSuite) TestSetMutePropertyOnChatsByCategory() { } } - err = s.alice.SetMutePropertyOnChatsByCategory(newCommunity.IDString(), categoryID, false) + err = s.alice.SetMutePropertyOnChatsByCategory(&requests.MuteCategory{ + CommunityID: newCommunity.IDString(), + CategoryID: categoryID, + MutedType: Unmuted, + }, false) s.Require().NoError(err) for _, chat := range s.alice.Chats() { diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index f7972c7f6..2ba19bc0a 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -532,17 +532,20 @@ func (m *Messenger) SetMuted(communityID types.HexBytes, muted bool) error { return m.communitiesManager.SetMuted(communityID, muted) } -func (m *Messenger) SetMutePropertyOnChatsByCategory(communityID string, categoryID string, muted bool) error { - community, err := m.communitiesManager.GetByIDString(communityID) +func (m *Messenger) SetMutePropertyOnChatsByCategory(request *requests.MuteCategory, muted bool) error { + if err := request.Validate(); err != nil { + return err + } + community, err := m.communitiesManager.GetByIDString(request.CommunityID) if err != nil { return err } - for _, chatID := range community.ChatsByCategoryID(categoryID) { + for _, chatID := range community.ChatsByCategoryID(request.CategoryID) { if muted { - _, err = m.MuteChat(&requests.MuteChat{ChatID: communityID + chatID, MutedType: MuteTillUnmuted}) + _, err = m.MuteChat(&requests.MuteChat{ChatID: request.CommunityID + chatID, MutedType: request.MutedType}) } else { - err = m.UnmuteChat(communityID + chatID) + err = m.UnmuteChat(request.CommunityID + chatID) } if err != nil { return err diff --git a/protocol/requests/mute_category_request.go b/protocol/requests/mute_category_request.go new file mode 100644 index 000000000..b3c223cab --- /dev/null +++ b/protocol/requests/mute_category_request.go @@ -0,0 +1,25 @@ +package requests + +import ( + "errors" +) + +var ErrInvalidMuteCategoryParams = errors.New("mute-category: invalid params") + +type MuteCategory struct { + CommunityID string + CategoryID string + MutedType MutingVariation +} + +func (a *MuteCategory) Validate() error { + if len(a.CommunityID) == 0 || len(a.CategoryID) == 0 { + return ErrInvalidMuteCategoryParams + } + + if a.MutedType < 0 { + return ErrInvalidMuteCategoryParams + } + + return nil +} diff --git a/services/ext/api.go b/services/ext/api.go index a55da1ae8..507b62ed9 100644 --- a/services/ext/api.go +++ b/services/ext/api.go @@ -295,12 +295,12 @@ func (api *PublicAPI) DeleteChat(parent context.Context, chatID string) error { return api.service.messenger.DeleteChat(chatID) } -func (api *PublicAPI) MuteCommunityCategory(communityID string, categoryID string) error { - return api.service.messenger.SetMutePropertyOnChatsByCategory(communityID, categoryID, true) +func (api *PublicAPI) MuteCommunityCategory(request *requests.MuteCategory) error { + return api.service.messenger.SetMutePropertyOnChatsByCategory(request, true) } func (api *PublicAPI) UnmuteCommunityCategory(communityID string, categoryID string) error { - return api.service.messenger.SetMutePropertyOnChatsByCategory(communityID, categoryID, false) + return api.service.messenger.SetMutePropertyOnChatsByCategory(&requests.MuteCategory{CommunityID: communityID, CategoryID: categoryID, MutedType: protocol.Unmuted}, false) } func (api *PublicAPI) MuteChatV2(parent context.Context, request *requests.MuteChat) (time.Time, error) {