feat: create General channel with community creation (#2662)

This commit is contained in:
Anthony Laibe 2022-05-10 15:25:08 +02:00 committed by GitHub
parent d884749ebf
commit 6b9f9a896a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 9 deletions

View File

@ -147,6 +147,7 @@ func (s *MessengerCommunitiesSuite) TestRetrieveCommunity() {
s.Require().NotNil(response) s.Require().NotNil(response)
s.Require().Len(response.Communities(), 1) s.Require().Len(response.Communities(), 1)
s.Require().Len(response.CommunitiesSettings(), 1) s.Require().Len(response.CommunitiesSettings(), 1)
s.Require().Len(response.Chats(), 1)
community := response.Communities()[0] community := response.Communities()[0]
communitySettings := response.CommunitiesSettings()[0] communitySettings := response.CommunitiesSettings()[0]
@ -244,7 +245,6 @@ func (s *MessengerCommunitiesSuite) TestJoinCommunity() {
for k := range community.Chats() { for k := range community.Chats() {
chatIds = append(chatIds, k) chatIds = append(chatIds, k)
} }
category := &requests.CreateCommunityCategory{ category := &requests.CreateCommunityCategory{
CommunityID: community.ID(), CommunityID: community.ID(),
CategoryName: "category-name", CategoryName: "category-name",
@ -260,7 +260,7 @@ func (s *MessengerCommunitiesSuite) TestJoinCommunity() {
// Make sure the changes are reflect in the community // Make sure the changes are reflect in the community
community = response.Communities()[0] community = response.Communities()[0]
chats := community.Chats() chats := community.Chats()
s.Require().Len(chats, 1) s.Require().Len(chats, 2)
// Send an community message // Send an community message
chat := CreateOneToOneChat(common.PubkeyToHex(&s.alice.identity.PublicKey), &s.alice.identity.PublicKey, s.bob.transport) chat := CreateOneToOneChat(common.PubkeyToHex(&s.alice.identity.PublicKey), &s.alice.identity.PublicKey, s.bob.transport)
@ -301,7 +301,7 @@ func (s *MessengerCommunitiesSuite) TestJoinCommunity() {
s.Require().NotNil(response) s.Require().NotNil(response)
s.Require().Len(response.Communities(), 1) s.Require().Len(response.Communities(), 1)
s.Require().True(response.Communities()[0].Joined()) s.Require().True(response.Communities()[0].Joined())
s.Require().Len(response.Chats(), 1) s.Require().Len(response.Chats(), 2)
s.Require().Len(response.Communities()[0].Categories(), 1) s.Require().Len(response.Communities()[0].Categories(), 1)
var categoryID string var categoryID string
@ -310,7 +310,7 @@ func (s *MessengerCommunitiesSuite) TestJoinCommunity() {
} }
// The chat should be created // The chat should be created
createdChat = response.Chats()[0] createdChat = response.Chats()[1]
s.Require().Equal(community.IDString(), createdChat.CommunityID) s.Require().Equal(community.IDString(), createdChat.CommunityID)
s.Require().Equal(orgChat.Identity.DisplayName, createdChat.Name) s.Require().Equal(orgChat.Identity.DisplayName, createdChat.Name)
s.Require().Equal(orgChat.Identity.Emoji, createdChat.Emoji) s.Require().Equal(orgChat.Identity.Emoji, createdChat.Emoji)
@ -364,7 +364,6 @@ func (s *MessengerCommunitiesSuite) TestJoinCommunity() {
s.Require().Len(communities, 2) s.Require().Len(communities, 2)
s.Require().Len(response.Communities(), 1) s.Require().Len(response.Communities(), 1)
s.Require().NotNil(actualChat) s.Require().NotNil(actualChat)
s.Require().Equal(community.IDString(), actualChat.CommunityID) s.Require().Equal(community.IDString(), actualChat.CommunityID)
s.Require().Equal(orgChat.Identity.DisplayName, actualChat.Name) s.Require().Equal(orgChat.Identity.DisplayName, actualChat.Name)
s.Require().Equal(orgChat.Identity.Emoji, actualChat.Emoji) s.Require().Equal(orgChat.Identity.Emoji, actualChat.Emoji)
@ -380,7 +379,7 @@ func (s *MessengerCommunitiesSuite) TestJoinCommunity() {
s.Require().NotNil(response) s.Require().NotNil(response)
s.Require().Len(response.Communities(), 1) s.Require().Len(response.Communities(), 1)
s.Require().False(response.Communities()[0].Joined()) s.Require().False(response.Communities()[0].Joined())
s.Require().Len(response.RemovedChats(), 2) s.Require().Len(response.RemovedChats(), 3)
} }
func (s *MessengerCommunitiesSuite) TestInviteUsersToCommunity() { func (s *MessengerCommunitiesSuite) TestInviteUsersToCommunity() {
@ -508,9 +507,9 @@ func (s *MessengerCommunitiesSuite) TestPostToCommunityChat() {
s.Require().NotNil(response) s.Require().NotNil(response)
s.Require().Len(response.Communities(), 1) s.Require().Len(response.Communities(), 1)
s.Require().True(response.Communities()[0].Joined()) s.Require().True(response.Communities()[0].Joined())
s.Require().Len(response.Chats(), 1) s.Require().Len(response.Chats(), 2)
chatID := response.Chats()[0].ID chatID := response.Chats()[1].ID
inputMessage := &common.Message{} inputMessage := &common.Message{}
inputMessage.ChatId = chatID inputMessage.ChatId = chatID
inputMessage.ContentType = protobuf.ChatMessage_TEXT_PLAIN inputMessage.ContentType = protobuf.ChatMessage_TEXT_PLAIN
@ -1539,7 +1538,7 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunity_Leave() {
// Check that the joined community has the correct values // Check that the joined community has the correct values
s.Equal(community.ID(), aCom.ID()) s.Equal(community.ID(), aCom.ID())
s.Equal(community.Clock(), aCom.Clock()) s.Equal(uint64(0x2), aCom.Clock())
s.Equal(community.PublicKey(), aCom.PublicKey()) s.Equal(community.PublicKey(), aCom.PublicKey())
// Check alicesOtherDevice receives the sync join message // Check alicesOtherDevice receives the sync join message

View File

@ -659,9 +659,24 @@ func (m *Messenger) CreateCommunity(request *requests.CreateCommunity) (*Messeng
return nil, err 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
}
response := &MessengerResponse{} response := &MessengerResponse{}
response.AddCommunity(community) response.AddCommunity(community)
response.AddCommunitySettings(&communitySettings) response.AddCommunitySettings(&communitySettings)
response.AddChat(chatResponse.Chats()[0])
err = m.syncCommunity(context.Background(), community) err = m.syncCommunity(context.Background(), community)
if err != nil { if err != nil {
return nil, err return nil, err