feat(categories): Add muted type to category muting shortcut (#3534)
This commit is contained in:
parent
c1509637a5
commit
5935339c19
|
@ -57,6 +57,7 @@ const (
|
|||
MuteFor1Week
|
||||
MuteTillUnmuted
|
||||
MuteTill1Min
|
||||
Unmuted
|
||||
)
|
||||
|
||||
const pkStringLength = 68
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue