feat: Add mute category methods (#2736)
This commit is contained in:
parent
76e2d843a6
commit
3e65e36fa6
|
@ -6,6 +6,22 @@ import (
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (o *Community) ChatsByCategoryID(categoryID string) []string {
|
||||||
|
o.mutex.Lock()
|
||||||
|
defer o.mutex.Unlock()
|
||||||
|
var chatIDs []string
|
||||||
|
if o == nil || o.config == nil || o.config.CommunityDescription == nil {
|
||||||
|
return chatIDs
|
||||||
|
}
|
||||||
|
|
||||||
|
for chatID, chat := range o.config.CommunityDescription.Chats {
|
||||||
|
if chat.CategoryId == categoryID {
|
||||||
|
chatIDs = append(chatIDs, chatID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return chatIDs
|
||||||
|
}
|
||||||
|
|
||||||
func (o *Community) CreateCategory(categoryID string, categoryName string, chatIDs []string) (*CommunityChanges, error) {
|
func (o *Community) CreateCategory(categoryID string, categoryName string, chatIDs []string) (*CommunityChanges, error) {
|
||||||
o.mutex.Lock()
|
o.mutex.Lock()
|
||||||
defer o.mutex.Unlock()
|
defer o.mutex.Unlock()
|
||||||
|
|
|
@ -1758,3 +1758,94 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunity_Leave() {
|
||||||
aoCom := mr.Communities()[0]
|
aoCom := mr.Communities()[0]
|
||||||
s.Equal(aCom, aoCom)
|
s.Equal(aCom, aoCom)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *MessengerCommunitiesSuite) TestSetMutePropertyOnChatsByCategory() {
|
||||||
|
// Create a community
|
||||||
|
createCommunityReq := &requests.CreateCommunity{
|
||||||
|
Membership: protobuf.CommunityPermissions_ON_REQUEST,
|
||||||
|
Name: "new community",
|
||||||
|
Color: "#000000",
|
||||||
|
Description: "new community description",
|
||||||
|
}
|
||||||
|
|
||||||
|
mr, err := s.alice.CreateCommunity(createCommunityReq)
|
||||||
|
s.Require().NoError(err, "s.alice.CreateCommunity")
|
||||||
|
var newCommunity *communities.Community
|
||||||
|
for _, com := range mr.Communities() {
|
||||||
|
if com.Name() == createCommunityReq.Name {
|
||||||
|
newCommunity = com
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s.Require().NotNil(newCommunity)
|
||||||
|
|
||||||
|
orgChat1 := &protobuf.CommunityChat{
|
||||||
|
Permissions: &protobuf.CommunityPermissions{
|
||||||
|
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
||||||
|
},
|
||||||
|
Identity: &protobuf.ChatIdentity{
|
||||||
|
DisplayName: "status-core",
|
||||||
|
Emoji: "😎",
|
||||||
|
Description: "status-core community chat",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
orgChat2 := &protobuf.CommunityChat{
|
||||||
|
Permissions: &protobuf.CommunityPermissions{
|
||||||
|
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
||||||
|
},
|
||||||
|
Identity: &protobuf.ChatIdentity{
|
||||||
|
DisplayName: "status-core2",
|
||||||
|
Emoji: "😎",
|
||||||
|
Description: "status-core community chat2",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
mr, err = s.alice.CreateCommunityChat(newCommunity.ID(), orgChat1)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().NotNil(mr)
|
||||||
|
s.Require().Len(mr.Communities(), 1)
|
||||||
|
s.Require().Len(mr.Chats(), 1)
|
||||||
|
|
||||||
|
mr, err = s.alice.CreateCommunityChat(newCommunity.ID(), orgChat2)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().NotNil(mr)
|
||||||
|
s.Require().Len(mr.Communities(), 1)
|
||||||
|
s.Require().Len(mr.Chats(), 1)
|
||||||
|
|
||||||
|
var chatIds []string
|
||||||
|
for k := range newCommunity.Chats() {
|
||||||
|
chatIds = append(chatIds, k)
|
||||||
|
}
|
||||||
|
category := &requests.CreateCommunityCategory{
|
||||||
|
CommunityID: newCommunity.ID(),
|
||||||
|
CategoryName: "category-name",
|
||||||
|
ChatIDs: chatIds,
|
||||||
|
}
|
||||||
|
|
||||||
|
mr, err = s.alice.CreateCommunityCategory(category)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().NotNil(mr)
|
||||||
|
s.Require().Len(mr.Communities(), 1)
|
||||||
|
s.Require().Len(mr.Communities()[0].Categories(), 1)
|
||||||
|
|
||||||
|
var categoryID string
|
||||||
|
for k := range mr.Communities()[0].Categories() {
|
||||||
|
categoryID = k
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.alice.SetMutePropertyOnChatsByCategory(newCommunity.IDString(), categoryID, true)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
for _, chat := range s.alice.Chats() {
|
||||||
|
if chat.CategoryID == categoryID {
|
||||||
|
s.Require().True(chat.Muted)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = s.alice.SetMutePropertyOnChatsByCategory(newCommunity.IDString(), categoryID, false)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
for _, chat := range s.alice.Chats() {
|
||||||
|
s.Require().False(chat.Muted)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -349,6 +349,26 @@ func (m *Messenger) SetMuted(communityID types.HexBytes, muted bool) error {
|
||||||
return m.communitiesManager.SetMuted(communityID, muted)
|
return m.communitiesManager.SetMuted(communityID, muted)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Messenger) SetMutePropertyOnChatsByCategory(communityID string, categoryID string, muted bool) error {
|
||||||
|
community, err := m.communitiesManager.GetByIDString(communityID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, chatID := range community.ChatsByCategoryID(categoryID) {
|
||||||
|
if muted {
|
||||||
|
err = m.MuteChat(communityID + chatID)
|
||||||
|
} else {
|
||||||
|
err = m.UnmuteChat(communityID + chatID)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Messenger) RequestToJoinCommunity(request *requests.RequestToJoinCommunity) (*MessengerResponse, error) {
|
func (m *Messenger) RequestToJoinCommunity(request *requests.RequestToJoinCommunity) (*MessengerResponse, error) {
|
||||||
logger := m.logger.Named("RequestToJoinCommunity")
|
logger := m.logger.Named("RequestToJoinCommunity")
|
||||||
if err := request.Validate(); err != nil {
|
if err := request.Validate(); err != nil {
|
||||||
|
|
|
@ -287,6 +287,14 @@ func (api *PublicAPI) DeleteChat(parent context.Context, chatID string) error {
|
||||||
return api.service.messenger.DeleteChat(chatID)
|
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) UnmuteCommunityCategory(communityID string, categoryID string) error {
|
||||||
|
return api.service.messenger.SetMutePropertyOnChatsByCategory(communityID, categoryID, false)
|
||||||
|
}
|
||||||
|
|
||||||
func (api *PublicAPI) MuteChat(parent context.Context, chatID string) error {
|
func (api *PublicAPI) MuteChat(parent context.Context, chatID string) error {
|
||||||
return api.service.messenger.MuteChat(chatID)
|
return api.service.messenger.MuteChat(chatID)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue