Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat_: accept community join request with mvds #5787

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions protocol/common/raw_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type RawMessage struct {
// don't wrap message into ProtocolMessage.
// when this is true, the message will not be resent via ResendTypeDataSync, but it's possible to
// resend it via ResendTypeRawMessage specified in ResendType
// MVDS only supports sending encrypted message.
SkipEncryptionLayer bool
SendPushNotification bool
MessageType protobuf.ApplicationMetadataMessage_Type
Expand Down
1 change: 1 addition & 0 deletions protocol/communities/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3520,6 +3520,7 @@ func (m *Manager) HandleCommunityRequestToJoinResponse(signer *ecdsa.PublicKey,

isControlNodeSigner := common.IsPubKeyEqual(community.ControlNode(), signer)
if !isControlNodeSigner {
m.logger.Debug("signer is not control node", zap.String("signer", common.PubkeyToHex(signer)), zap.String("controlNode", common.PubkeyToHex(community.ControlNode())))
return nil, ErrNotAuthorized
}

Expand Down
16 changes: 14 additions & 2 deletions protocol/messenger_communities.go
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,10 @@ func (m *Messenger) CancelRequestToJoinCommunity(ctx context.Context, request *r
}

func (m *Messenger) acceptRequestToJoinCommunity(requestToJoin *communities.RequestToJoin) (*MessengerResponse, error) {
m.logger.Debug("accept request to join community",
zap.String("community", requestToJoin.CommunityID.String()),
zap.String("pubkey", requestToJoin.PublicKey))

community, err := m.communitiesManager.AcceptRequestToJoin(requestToJoin)
if err != nil {
return nil, err
Expand Down Expand Up @@ -2019,6 +2023,12 @@ func (m *Messenger) acceptRequestToJoinCommunity(requestToJoin *communities.Requ
Priority: &common.HighPriority,
}

if !community.PublicKey().Equal(community.ControlNode()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be great if you can add a comment on this for future developer 🙂

rawMessage.ResendType = common.ResendTypeDataSync
rawMessage.SkipEncryptionLayer = false
rawMessage.Sender = nil
}

if community.Encrypted() {
rawMessage.HashRatchetGroupID = community.ID()
rawMessage.CommunityKeyExMsgType = common.KeyExMsgReuse
Expand All @@ -2029,8 +2039,10 @@ func (m *Messenger) acceptRequestToJoinCommunity(requestToJoin *communities.Requ
return nil, err
}

if _, err = m.AddRawMessageToWatch(rawMessage); err != nil {
return nil, err
if rawMessage.ResendType == common.ResendTypeRawMessage {
if _, err = m.AddRawMessageToWatch(rawMessage); err != nil {
return nil, err
}
}
}

Expand Down