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:
parent
6e0d4e697f
commit
445135eb94
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue