diff --git a/protocol/communities_events_utils_test.go b/protocol/communities_events_utils_test.go index 31f1f02b6..076ea2c05 100644 --- a/protocol/communities_events_utils_test.go +++ b/protocol/communities_events_utils_test.go @@ -1180,10 +1180,21 @@ func testAcceptMemberRequestToJoinResponseSharedWithOtherEventSenders(base Commu // user sends request to join requestID := testSendRequestToJoin(base, user, community.ID()) + checkRequestToJoin := func(r *MessengerResponse) bool { + if len(r.RequestsToJoinCommunity()) == 0 { + return false + } + for _, request := range r.RequestsToJoinCommunity() { + if request.PublicKey == user.IdentityPublicKeyString() { + return true + } + } + return false + } // event sender receives request to join _, err := WaitOnMessengerResponse( base.GetEventSender(), - func(r *MessengerResponse) bool { return len(r.RequestsToJoinCommunity()) > 0 }, + checkRequestToJoin, "event sender did not receive community request to join", ) s.Require().NoError(err) @@ -1191,7 +1202,7 @@ func testAcceptMemberRequestToJoinResponseSharedWithOtherEventSenders(base Commu // event sender 2 receives request to join _, err = WaitOnMessengerResponse( additionalEventSender, - func(r *MessengerResponse) bool { return len(r.RequestsToJoinCommunity()) > 0 }, + checkRequestToJoin, "event sender did not receive community request to join", ) s.Require().NoError(err) @@ -1245,27 +1256,36 @@ func testRejectMemberRequestToJoinResponseSharedWithOtherEventSenders(base Commu // user sends request to join requestID := testSendRequestToJoin(base, user, community.ID()) + checkRequestToJoin := func(r *MessengerResponse) bool { + if len(r.RequestsToJoinCommunity()) == 0 { + return false + } + for _, request := range r.RequestsToJoinCommunity() { + if request.PublicKey == user.IdentityPublicKeyString() { + return true + } + } + return false + } // event sender receives request to join - response, err := WaitOnMessengerResponse( + _, err := WaitOnMessengerResponse( base.GetEventSender(), - func(r *MessengerResponse) bool { return len(r.RequestsToJoinCommunity()) > 0 }, + checkRequestToJoin, "event sender did not receive community request to join", ) s.Require().NoError(err) - s.Require().Len(response.RequestsToJoinCommunity(), 1) // event sender 2 receives request to join - response, err = WaitOnMessengerResponse( + _, err = WaitOnMessengerResponse( additionalEventSender, - func(r *MessengerResponse) bool { return len(r.RequestsToJoinCommunity()) > 0 }, + checkRequestToJoin, "event sender did not receive community request to join", ) s.Require().NoError(err) - s.Require().Len(response.RequestsToJoinCommunity(), 1) rejectRequestToJoin := &requests.DeclineRequestToJoinCommunity{ID: requestID} - response, err = base.GetEventSender().DeclineRequestToJoinCommunity(rejectRequestToJoin) + response, err := base.GetEventSender().DeclineRequestToJoinCommunity(rejectRequestToJoin) s.Require().NoError(err) s.Require().NotNil(response) diff --git a/protocol/messenger_communities.go b/protocol/messenger_communities.go index 06e0b616e..37270009e 100644 --- a/protocol/messenger_communities.go +++ b/protocol/messenger_communities.go @@ -1498,8 +1498,10 @@ func (m *Messenger) RequestToJoinCommunity(request *requests.RequestToJoinCommun 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 + } } if !community.AutoAccept() { @@ -1514,6 +1516,9 @@ func (m *Messenger) RequestToJoinCommunity(request *requests.RequestToJoinCommun privMembersArray = append(privMembersArray, privilegedMembersSorted[protobuf.CommunityMember_ROLE_ADMIN]...) rawMessage.ResendMethod = common.ResendMethodSendPrivate + rawMessage.ResendType = common.ResendTypeDataSync + // MVDS only supports sending encrypted message + rawMessage.SkipEncryptionLayer = false rawMessage.ID = "" rawMessage.Recipients = privMembersArray @@ -1527,17 +1532,12 @@ func (m *Messenger) RequestToJoinCommunity(request *requests.RequestToJoinCommun rawMessage.Payload = payload for _, member := range rawMessage.Recipients { + rawMessage.Sender = nil _, err := m.sender.SendPrivate(context.Background(), member, rawMessage) if err != nil { return nil, err } } - - if len(rawMessage.Recipients) > 0 { - if _, err = m.AddRawMessageToWatch(rawMessage); err != nil { - return nil, err - } - } } response := &MessengerResponse{} @@ -3687,10 +3687,10 @@ func (m *Messenger) sendSharedAddressToControlNode(receiver *ecdsa.PublicKey, co rawMessage := common.RawMessage{ Payload: payload, CommunityID: community.ID(), - SkipEncryptionLayer: true, + SkipEncryptionLayer: false, MessageType: protobuf.ApplicationMetadataMessage_COMMUNITY_REQUEST_TO_JOIN, PubsubTopic: community.PubsubTopic(), // TODO: confirm if it should be sent in community pubsub topic - ResendType: common.ResendTypeRawMessage, + ResendType: common.ResendTypeDataSync, ResendMethod: common.ResendMethodSendPrivate, Recipients: []*ecdsa.PublicKey{receiver}, } @@ -3704,8 +3704,6 @@ func (m *Messenger) sendSharedAddressToControlNode(receiver *ecdsa.PublicKey, co return nil, err } - _, err = m.AddRawMessageToWatch(&rawMessage) - return requestToJoin, err } @@ -4869,7 +4867,11 @@ func (m *Messenger) CreateResponseWithACNotification(communityID string, acType // use pointer to rawMessage to get the message ID and other updated properties. func (m *Messenger) SendMessageToControlNode(community *communities.Community, rawMessage *common.RawMessage) ([]byte, error) { if !community.PublicKey().Equal(community.ControlNode()) { + m.logger.Debug("control node is different with community pubkey", zap.Any("control:", community.ControlNode()), zap.Any("communityPubkey:", community.PublicKey())) rawMessage.ResendMethod = common.ResendMethodSendPrivate + rawMessage.ResendType = common.ResendTypeDataSync + // MVDS only supports sending encrypted message + rawMessage.SkipEncryptionLayer = false rawMessage.Recipients = append(rawMessage.Recipients, community.ControlNode()) return m.sender.SendPrivate(context.Background(), community.ControlNode(), rawMessage) } diff --git a/protocol/messenger_raw_message_resend_test.go b/protocol/messenger_raw_message_resend_test.go index adb5bb87e..d6748fa21 100644 --- a/protocol/messenger_raw_message_resend_test.go +++ b/protocol/messenger_raw_message_resend_test.go @@ -101,22 +101,20 @@ func (s *MessengerRawMessageResendTest) waitForMessageSent(messageID string) { func (s *MessengerRawMessageResendTest) TestMessageSent() { ids, err := s.bobMessenger.RawMessagesIDsByType(protobuf.ApplicationMetadataMessage_COMMUNITY_REQUEST_TO_JOIN) s.Require().NoError(err) - // one request to join to control node and another to privileged member - s.Require().Len(ids, 2) + // one request to join to control node + s.Require().Len(ids, 1) s.waitForMessageSent(ids[0]) - s.waitForMessageSent(ids[1]) } // TestMessageResend tests if ApplicationMetadataMessage_COMMUNITY_REQUEST_TO_JOIN is resent func (s *MessengerRawMessageResendTest) TestMessageResend() { ids, err := s.bobMessenger.RawMessagesIDsByType(protobuf.ApplicationMetadataMessage_COMMUNITY_REQUEST_TO_JOIN) s.Require().NoError(err) - s.Require().Len(ids, 2) + s.Require().Len(ids, 1) // wait for Sent status for already sent message to make sure that sent message was delivered // before testing resend s.waitForMessageSent(ids[0]) - s.waitForMessageSent(ids[1]) rawMessage := s.GetRequestToJoinToControlNodeRawMessage(ids) s.Require().NotNil(rawMessage) @@ -145,10 +143,9 @@ func (s *MessengerRawMessageResendTest) TestMessageResend() { func (s *MessengerRawMessageResendTest) TestInvalidRawMessageToWatchDoesNotProduceResendLoop() { ids, err := s.bobMessenger.RawMessagesIDsByType(protobuf.ApplicationMetadataMessage_COMMUNITY_REQUEST_TO_JOIN) s.Require().NoError(err) - s.Require().Len(ids, 2) + s.Require().Len(ids, 1) s.waitForMessageSent(ids[0]) - s.waitForMessageSent(ids[1]) rawMessage := s.GetRequestToJoinToControlNodeRawMessage(ids) s.Require().NotNil(rawMessage)