diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index d61642b97..f4a1b4a4e 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -431,7 +431,7 @@ func (m *Manager) runOwnerVerificationLoop() { m.logger.Info("validating communities", zap.String("id", id), zap.Int("count", len(communities))) for _, communityToValidate := range communities { - signer, description, err := m.unwrapCommunityDescriptionMessage(communityToValidate.payload) + signer, description, err := UnwrapCommunityDescriptionMessage(communityToValidate.payload) if err != nil { m.logger.Error("failed to unwrap community", zap.Error(err)) continue @@ -2856,7 +2856,7 @@ func (m *Manager) HandleCommunityRequestToLeave(signer *ecdsa.PublicKey, proto * return nil } -func (m *Manager) unwrapCommunityDescriptionMessage(payload []byte) (*ecdsa.PublicKey, *protobuf.CommunityDescription, error) { +func UnwrapCommunityDescriptionMessage(payload []byte) (*ecdsa.PublicKey, *protobuf.CommunityDescription, error) { applicationMetadataMessage := &protobuf.ApplicationMetadataMessage{} err := proto.Unmarshal(payload, applicationMetadataMessage) @@ -2881,16 +2881,6 @@ func (m *Manager) unwrapCommunityDescriptionMessage(payload []byte) (*ecdsa.Publ return signer, description, nil } -func (m *Manager) HandleWrappedCommunityDescriptionMessage(payload []byte, shard *common.Shard) (*CommunityResponse, error) { - m.logger.Debug("Handling wrapped community description message") - signer, description, err := m.unwrapCommunityDescriptionMessage(payload) - if err != nil { - return nil, err - } - - return m.HandleCommunityDescriptionMessage(signer, description, payload, shard, nil) -} - func (m *Manager) JoinCommunity(id types.HexBytes, forceJoin bool) (*Community, error) { community, err := m.GetByID(id) if err != nil { diff --git a/protocol/messenger_handler.go b/protocol/messenger_handler.go index 8b92bbb3b..2dfabb1b7 100644 --- a/protocol/messenger_handler.go +++ b/protocol/messenger_handler.go @@ -1689,11 +1689,6 @@ func (m *Messenger) HandleCommunityRequestToLeave(state *ReceivedMessageState, r return nil } -// handleWrappedCommunityDescriptionMessage handles a wrapped community description -func (m *Messenger) handleWrappedCommunityDescriptionMessage(payload []byte, shard *common.Shard) (*communities.CommunityResponse, error) { - return m.communitiesManager.HandleWrappedCommunityDescriptionMessage(payload, shard) -} - func (m *Messenger) handleEditMessage(state *ReceivedMessageState, editMessage EditMessage) error { if err := ValidateEditMessage(editMessage.EditMessage); err != nil { return err @@ -2282,20 +2277,22 @@ func (m *Messenger) handleChatMessage(state *ReceivedMessageState, forceSeen boo if receivedMessage.ContentType == protobuf.ChatMessage_COMMUNITY { m.logger.Debug("Handling community content type") - communityResponse, err := m.handleWrappedCommunityDescriptionMessage(receivedMessage.GetCommunity(), common.ShardFromProtobuff(receivedMessage.Shard)) + signer, description, err := communities.UnwrapCommunityDescriptionMessage(receivedMessage.GetCommunity()) if err != nil { return err } - if communityResponse == nil { - return nil + err = m.handleCommunityDescription(state, signer, description, receivedMessage.GetCommunity()) + if err != nil { + return err } - community := communityResponse.Community - receivedMessage.CommunityID = community.IDString() - - state.Response.AddCommunity(community) - state.Response.CommunityChanges = append(state.Response.CommunityChanges, communityResponse.Changes) + if len(description.ID) != 0 { + receivedMessage.CommunityID = description.ID + } else { + // Backward compatibility + receivedMessage.CommunityID = types.EncodeHex(crypto.CompressPubkey(signer)) + } } receivedMessage.New = true