feat(messenger): add `createDefaultChannel` flag to `CreateCommunity` API
This introduces a flag to configure whether `Messenger.CreateCommunity` should create a default channel. As discussed in https://github.com/status-im/status-go/issues/2758, this is needed for the upcoming functionality to import discord communities. Closes #2758
This commit is contained in:
parent
17efc5e782
commit
1ac88975b0
|
@ -142,6 +142,37 @@ func (s *MessengerCommunitiesSuite) newMessenger() *Messenger {
|
|||
return s.newMessengerWithKey(s.shh, privateKey)
|
||||
}
|
||||
|
||||
func (s *MessengerCommunitiesSuite) TestCreateCommunity() {
|
||||
description := &requests.CreateCommunity{
|
||||
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
||||
Name: "status",
|
||||
Color: "#ffffff",
|
||||
Description: "status community description",
|
||||
}
|
||||
response, err := s.bob.CreateCommunity(description, true)
|
||||
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
s.Require().Len(response.Chats(), 1)
|
||||
}
|
||||
|
||||
func (s *MessengerCommunitiesSuite) TestCreateCommunity_WithoutDefaultChannel() {
|
||||
|
||||
description := &requests.CreateCommunity{
|
||||
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
||||
Name: "status",
|
||||
Color: "#ffffff",
|
||||
Description: "status community description",
|
||||
}
|
||||
response, err := s.bob.CreateCommunity(description, false)
|
||||
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
s.Require().Len(response.Chats(), 0)
|
||||
}
|
||||
|
||||
func (s *MessengerCommunitiesSuite) TestRetrieveCommunity() {
|
||||
alice := s.newMessenger()
|
||||
|
||||
|
@ -152,7 +183,7 @@ func (s *MessengerCommunitiesSuite) TestRetrieveCommunity() {
|
|||
Description: "status community description",
|
||||
}
|
||||
|
||||
response, err := s.bob.CreateCommunity(description)
|
||||
response, err := s.bob.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
|
@ -210,7 +241,7 @@ func (s *MessengerCommunitiesSuite) TestJoinCommunity() {
|
|||
}
|
||||
|
||||
// Create an community chat
|
||||
response, err := s.bob.CreateCommunity(description)
|
||||
response, err := s.bob.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
|
@ -408,7 +439,7 @@ func (s *MessengerCommunitiesSuite) TestCommunityContactCodeAdvertisement() {
|
|||
}
|
||||
|
||||
// Create an community chat
|
||||
response, err := s.bob.CreateCommunity(description)
|
||||
response, err := s.bob.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
|
||||
|
@ -494,7 +525,7 @@ func (s *MessengerCommunitiesSuite) TestInviteUsersToCommunity() {
|
|||
}
|
||||
|
||||
// Create an community chat
|
||||
response, err := s.bob.CreateCommunity(description)
|
||||
response, err := s.bob.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
|
@ -548,7 +579,7 @@ func (s *MessengerCommunitiesSuite) TestPostToCommunityChat() {
|
|||
}
|
||||
|
||||
// Create an community chat
|
||||
response, err := s.bob.CreateCommunity(description)
|
||||
response, err := s.bob.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
|
@ -669,7 +700,7 @@ func (s *MessengerCommunitiesSuite) TestImportCommunity() {
|
|||
}
|
||||
|
||||
// Create an community chat
|
||||
response, err := s.bob.CreateCommunity(description)
|
||||
response, err := s.bob.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
|
@ -740,7 +771,7 @@ func (s *MessengerCommunitiesSuite) TestRequestAccess() {
|
|||
}
|
||||
|
||||
// Create an community chat
|
||||
response, err := s.bob.CreateCommunity(description)
|
||||
response, err := s.bob.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
|
@ -903,7 +934,7 @@ func (s *MessengerCommunitiesSuite) TestRequestAccessAgain() {
|
|||
}
|
||||
|
||||
// Create an community chat
|
||||
response, err := s.bob.CreateCommunity(description)
|
||||
response, err := s.bob.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
|
@ -1156,7 +1187,7 @@ func (s *MessengerCommunitiesSuite) TestShareCommunity() {
|
|||
}
|
||||
|
||||
// Create an community chat
|
||||
response, err := s.bob.CreateCommunity(description)
|
||||
response, err := s.bob.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
|
@ -1204,7 +1235,7 @@ func (s *MessengerCommunitiesSuite) TestBanUser() {
|
|||
}
|
||||
|
||||
// Create an community chat
|
||||
response, err := s.bob.CreateCommunity(description)
|
||||
response, err := s.bob.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
|
@ -1274,7 +1305,7 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunitySettings() {
|
|||
Description: "new community description",
|
||||
}
|
||||
|
||||
mr, err := s.alice.CreateCommunity(createCommunityReq)
|
||||
mr, err := s.alice.CreateCommunity(createCommunityReq, true)
|
||||
s.Require().NoError(err, "s.alice.CreateCommunity")
|
||||
var newCommunity *communities.Community
|
||||
for _, com := range mr.Communities() {
|
||||
|
@ -1335,7 +1366,7 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunitySettings_EditCommunity() {
|
|||
Description: "new community description",
|
||||
}
|
||||
|
||||
mr, err := s.alice.CreateCommunity(createCommunityReq)
|
||||
mr, err := s.alice.CreateCommunity(createCommunityReq, true)
|
||||
s.Require().NoError(err, "s.alice.CreateCommunity")
|
||||
var newCommunity *communities.Community
|
||||
for _, com := range mr.Communities() {
|
||||
|
@ -1436,7 +1467,7 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunity() {
|
|||
Description: "new community description",
|
||||
}
|
||||
|
||||
mr, err := s.alice.CreateCommunity(createCommunityReq)
|
||||
mr, err := s.alice.CreateCommunity(createCommunityReq, true)
|
||||
s.Require().NoError(err, "s.alice.CreateCommunity")
|
||||
var newCommunity *communities.Community
|
||||
for _, com := range mr.Communities() {
|
||||
|
@ -1531,7 +1562,7 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunity_RequestToJoin() {
|
|||
Color: "#000000",
|
||||
Description: "new community description",
|
||||
}
|
||||
mr, err := s.bob.CreateCommunity(createCommunityReq)
|
||||
mr, err := s.bob.CreateCommunity(createCommunityReq, true)
|
||||
s.Require().NoError(err, "CreateCommunity")
|
||||
s.Require().NotNil(mr)
|
||||
s.Len(mr.Communities(), 1)
|
||||
|
@ -1767,7 +1798,7 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunity_Leave() {
|
|||
Color: "#000000",
|
||||
Description: "new community description",
|
||||
}
|
||||
mr, err := s.bob.CreateCommunity(createCommunityReq)
|
||||
mr, err := s.bob.CreateCommunity(createCommunityReq, true)
|
||||
s.Require().NoError(err, "CreateCommunity")
|
||||
s.Require().NotNil(mr)
|
||||
s.Len(mr.Communities(), 1)
|
||||
|
@ -1863,7 +1894,7 @@ func (s *MessengerCommunitiesSuite) TestSetMutePropertyOnChatsByCategory() {
|
|||
Description: "new community description",
|
||||
}
|
||||
|
||||
mr, err := s.alice.CreateCommunity(createCommunityReq)
|
||||
mr, err := s.alice.CreateCommunity(createCommunityReq, true)
|
||||
s.Require().NoError(err, "s.alice.CreateCommunity")
|
||||
var newCommunity *communities.Community
|
||||
for _, com := range mr.Communities() {
|
||||
|
|
|
@ -404,7 +404,7 @@ func (s *MessengerBackupSuite) TestBackupCommunities() {
|
|||
}
|
||||
|
||||
// Create a community chat
|
||||
response, err := bob1.CreateCommunity(description)
|
||||
response, err := bob1.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
|
|
|
@ -739,11 +739,13 @@ func (m *Messenger) DeleteCommunityChat(communityID types.HexBytes, chatID strin
|
|||
return response, nil
|
||||
}
|
||||
|
||||
func (m *Messenger) CreateCommunity(request *requests.CreateCommunity) (*MessengerResponse, error) {
|
||||
func (m *Messenger) CreateCommunity(request *requests.CreateCommunity, createDefaultChannel bool) (*MessengerResponse, error) {
|
||||
if err := request.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := &MessengerResponse{}
|
||||
|
||||
community, err := m.communitiesManager.CreateCommunity(request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -770,22 +772,25 @@ func (m *Messenger) CreateCommunity(request *requests.CreateCommunity) (*Messeng
|
|||
return nil, err
|
||||
}
|
||||
|
||||
chatResponse, err := m.CreateCommunityChat(community.ID(), &protobuf.CommunityChat{
|
||||
Identity: &protobuf.ChatIdentity{
|
||||
DisplayName: "general",
|
||||
Description: "General channel for the community",
|
||||
Color: community.Description().Identity.Color,
|
||||
},
|
||||
Permissions: &protobuf.CommunityPermissions{
|
||||
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if createDefaultChannel {
|
||||
chatResponse, err := m.CreateCommunityChat(community.ID(), &protobuf.CommunityChat{
|
||||
Identity: &protobuf.ChatIdentity{
|
||||
DisplayName: "general",
|
||||
Description: "General channel for the community",
|
||||
Color: community.Description().Identity.Color,
|
||||
},
|
||||
Permissions: &protobuf.CommunityPermissions{
|
||||
Access: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// updating community so it contains the general chat
|
||||
community = chatResponse.Communities()[0]
|
||||
// updating community so it contains the general chat
|
||||
community = chatResponse.Communities()[0]
|
||||
response.AddChat(chatResponse.Chats()[0])
|
||||
}
|
||||
|
||||
if request.Encrypted {
|
||||
// Init hash ratchet for community
|
||||
|
@ -796,10 +801,8 @@ func (m *Messenger) CreateCommunity(request *requests.CreateCommunity) (*Messeng
|
|||
}
|
||||
}
|
||||
|
||||
response := &MessengerResponse{}
|
||||
response.AddCommunity(community)
|
||||
response.AddCommunitySettings(&communitySettings)
|
||||
response.AddChat(chatResponse.Chats()[0])
|
||||
err = m.syncCommunity(context.Background(), community)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -906,7 +906,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationCommunityReq
|
|||
Description: "status community description",
|
||||
}
|
||||
|
||||
response, err := bob.CreateCommunity(description)
|
||||
response, err := bob.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
|
|
|
@ -385,7 +385,7 @@ func (api *PublicAPI) LeaveCommunity(parent context.Context, communityID types.H
|
|||
|
||||
// CreateCommunity creates a new community with the provided description
|
||||
func (api *PublicAPI) CreateCommunity(request *requests.CreateCommunity) (*protocol.MessengerResponse, error) {
|
||||
return api.service.messenger.CreateCommunity(request)
|
||||
return api.service.messenger.CreateCommunity(request, true)
|
||||
}
|
||||
|
||||
// EditCommunity edits an existing community with the provided description
|
||||
|
|
Loading…
Reference in New Issue