fix: ensure receivedMessage.CommunityID in chat message handler is set

This enables clients to obtain invitation's community ID even when
description processing is queued.

part of: status-im/status-desktop#12481
This commit is contained in:
Patryk Osmaczko 2023-10-25 17:01:33 +02:00 committed by osmaczko
parent 6e0d4e697f
commit 445135eb94
2 changed files with 12 additions and 25 deletions

View File

@ -431,7 +431,7 @@ func (m *Manager) runOwnerVerificationLoop() {
m.logger.Info("validating communities", zap.String("id", id), zap.Int("count", len(communities))) m.logger.Info("validating communities", zap.String("id", id), zap.Int("count", len(communities)))
for _, communityToValidate := range communities { for _, communityToValidate := range communities {
signer, description, err := m.unwrapCommunityDescriptionMessage(communityToValidate.payload) signer, description, err := UnwrapCommunityDescriptionMessage(communityToValidate.payload)
if err != nil { if err != nil {
m.logger.Error("failed to unwrap community", zap.Error(err)) m.logger.Error("failed to unwrap community", zap.Error(err))
continue continue
@ -2856,7 +2856,7 @@ func (m *Manager) HandleCommunityRequestToLeave(signer *ecdsa.PublicKey, proto *
return nil 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{} applicationMetadataMessage := &protobuf.ApplicationMetadataMessage{}
err := proto.Unmarshal(payload, applicationMetadataMessage) err := proto.Unmarshal(payload, applicationMetadataMessage)
@ -2881,16 +2881,6 @@ func (m *Manager) unwrapCommunityDescriptionMessage(payload []byte) (*ecdsa.Publ
return signer, description, nil 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) { func (m *Manager) JoinCommunity(id types.HexBytes, forceJoin bool) (*Community, error) {
community, err := m.GetByID(id) community, err := m.GetByID(id)
if err != nil { if err != nil {

View File

@ -1689,11 +1689,6 @@ func (m *Messenger) HandleCommunityRequestToLeave(state *ReceivedMessageState, r
return nil 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 { func (m *Messenger) handleEditMessage(state *ReceivedMessageState, editMessage EditMessage) error {
if err := ValidateEditMessage(editMessage.EditMessage); err != nil { if err := ValidateEditMessage(editMessage.EditMessage); err != nil {
return err return err
@ -2282,20 +2277,22 @@ func (m *Messenger) handleChatMessage(state *ReceivedMessageState, forceSeen boo
if receivedMessage.ContentType == protobuf.ChatMessage_COMMUNITY { if receivedMessage.ContentType == protobuf.ChatMessage_COMMUNITY {
m.logger.Debug("Handling community content type") 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 { if err != nil {
return err return err
} }
if communityResponse == nil { err = m.handleCommunityDescription(state, signer, description, receivedMessage.GetCommunity())
return nil if err != nil {
return err
} }
community := communityResponse.Community if len(description.ID) != 0 {
receivedMessage.CommunityID = community.IDString() receivedMessage.CommunityID = description.ID
} else {
state.Response.AddCommunity(community) // Backward compatibility
state.Response.CommunityChanges = append(state.Response.CommunityChanges, communityResponse.Changes) receivedMessage.CommunityID = types.EncodeHex(crypto.CompressPubkey(signer))
}
} }
receivedMessage.New = true receivedMessage.New = true