From 5a4cc503c6998707c943fe8ed4870cb573699525 Mon Sep 17 00:00:00 2001 From: Patryk Osmaczko Date: Tue, 26 Sep 2023 18:37:23 +0200 Subject: [PATCH] fix: ensure community channels are dehydrated on publish --- protocol/communities/community.go | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/protocol/communities/community.go b/protocol/communities/community.go index de3ff4a8d2..a4d163fa19 100644 --- a/protocol/communities/community.go +++ b/protocol/communities/community.go @@ -1231,7 +1231,11 @@ func (o *Community) Description() *protobuf.CommunityDescription { } func (o *Community) marshaledDescription() ([]byte, error) { - return proto.Marshal(o.config.CommunityDescription) + // This is only workaround to lower the size of the message that goes over the wire, + // see https://github.com/status-im/status-desktop/issues/12188 + clone := o.CreateDeepCopy() + clone.DehydrateChannelsMembers() + return proto.Marshal(clone.config.CommunityDescription) } func (o *Community) MarshaledDescription() ([]byte, error) { @@ -1241,14 +1245,14 @@ func (o *Community) MarshaledDescription() ([]byte, error) { } func (o *Community) toProtocolMessageBytes() ([]byte, error) { - // This should not happen, as we can only serialize on our side if we - // created the community - if !o.IsControlNode() && len(o.config.CommunityDescriptionProtocolMessage) == 0 { - return nil, ErrNotControlNode - } - // If we are not a control node, use the received serialized version if !o.IsControlNode() { + // This should not happen, as we can only serialize on our side if we + // created the community + if len(o.config.CommunityDescriptionProtocolMessage) == 0 { + return nil, ErrNotControlNode + } + return o.config.CommunityDescriptionProtocolMessage, nil } @@ -1265,15 +1269,6 @@ func (o *Community) toProtocolMessageBytes() ([]byte, error) { func (o *Community) ToProtocolMessageBytes() ([]byte, error) { o.mutex.Lock() defer o.mutex.Unlock() - - // This is only workaround to lower the size of the message that goes over the wire, - // see https://github.com/status-im/status-desktop/issues/12188 - if o.IsControlNode() { - clone := o.CreateDeepCopy() - clone.DehydrateChannelsMembers() - return clone.toProtocolMessageBytes() - } - return o.toProtocolMessageBytes() }