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

Add subconversation ID to RemoteMLSMessage #3270

Merged
merged 4 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 changelog.d/6-federation/FS-1868
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add subconversation ID to onMLSMessageSent request payload.
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ data RemoteMLSMessage = RemoteMLSMessage
rmmMetadata :: MessageMetadata,
rmmSender :: Qualified UserId,
rmmConversation :: ConvId,
rmmSubConversation :: Maybe SubConvId,
rmmRecipients :: [(UserId, ClientId)],
rmmMessage :: Base64ByteString
}
Expand Down
2 changes: 1 addition & 1 deletion services/galley/src/Galley/API/Federation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ onMLSMessageSent domain rmm =
let recipients = filter (\(u, _) -> Set.member u members) (F.rmmRecipients rmm)
-- FUTUREWORK: support local bots
let e =
Event (tUntagged rcnv) Nothing (F.rmmSender rmm) (F.rmmTime rmm) $
Event (tUntagged rcnv) (F.rmmSubConversation rmm) (F.rmmSender rmm) (F.rmmTime rmm) $
EdMLSMessage (fromBase64ByteString (F.rmmMessage rmm))
let mkPush :: (UserId, ClientId) -> MessagePush 'NormalMessage
mkPush uc = newMessagePush loc mempty Nothing (F.rmmMetadata rmm) uc e
Expand Down
1 change: 1 addition & 0 deletions services/galley/src/Galley/API/MLS/Propagate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ propagateMessage qusr lConvOrSub con msg cm = do
rmmSender = qusr,
rmmMetadata = mm,
rmmConversation = qUnqualified qcnv,
rmmSubConversation = sconv,
rmmRecipients = rs >>= remoteMemberMLSClients,
rmmMessage = Base64ByteString msg.raw
}
Expand Down
61 changes: 61 additions & 0 deletions services/galley/test/integration/API/MLS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ tests s =
test s "delete subconversation as a remote member" (testRemoteMemberDeleteSubConv True),
test s "delete subconversation as a remote non-member" (testRemoteMemberDeleteSubConv False),
test s "delete parent conversation of a remote subconversation" testDeleteRemoteParentOfSubConv
],
testGroup
"Remote Sender/Remote SubConversation"
[ test s "on-mls-message-sent in subconversation" testRemoteToRemoteInSub
]
],
testGroup
Expand Down Expand Up @@ -1206,6 +1210,7 @@ testRemoteToRemote = do
rmmMetadata = defMessageMetadata,
rmmSender = qbob,
rmmConversation = conv,
rmmSubConversation = Nothing,
rmmRecipients = rcpts,
rmmMessage = Base64ByteString txt
}
Expand All @@ -1221,6 +1226,62 @@ testRemoteToRemote = do
-- eve should not receive the message
WS.assertNoEvent (1 # Second) [wsE]

testRemoteToRemoteInSub :: TestM ()
testRemoteToRemoteInSub = do
localDomain <- viewFederationDomain
c <- view tsCannon
alice <- randomUser
eve <- randomUser
bob <- randomId
conv <- randomId
let subConvId = SubConvId "conference"
aliceC1 = newClientId 0
aliceC2 = newClientId 1
eveC = newClientId 0
bdom = Domain "bob.example.com"
qconv = Qualified conv bdom
qbob = Qualified bob bdom
qalice = Qualified alice localDomain
now <- liftIO getCurrentTime
fedGalleyClient <- view tsFedGalleyClient

-- only add alice to the remote conversation
connectWithRemoteUser alice qbob
let cu =
ConversationUpdate
{ cuTime = now,
cuOrigUserId = qbob,
cuConvId = conv,
cuAlreadyPresentUsers = [],
cuAction =
SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (pure qalice) roleNameWireMember)
}
runFedClient @"on-conversation-updated" fedGalleyClient bdom cu

let txt = "Hello from another backend"
rcpts = [(alice, aliceC1), (alice, aliceC2), (eve, eveC)]
rm =
RemoteMLSMessage
{ rmmTime = now,
rmmMetadata = defMessageMetadata,
rmmSender = qbob,
rmmConversation = conv,
rmmSubConversation = Just subConvId,
rmmRecipients = rcpts,
rmmMessage = Base64ByteString txt
}

-- send message to alice and check reception
WS.bracketAsClientRN c [(alice, aliceC1), (alice, aliceC2), (eve, eveC)] $ \[wsA1, wsA2, wsE] -> do
void $ runFedClient @"on-mls-message-sent" fedGalleyClient bdom rm
liftIO $ do
-- alice should receive the message on her first client
WS.assertMatch_ (5 # Second) wsA1 $ \n -> wsAssertMLSMessage (fmap (flip SubConv subConvId) qconv) qbob txt n
WS.assertMatch_ (5 # Second) wsA2 $ \n -> wsAssertMLSMessage (fmap (flip SubConv subConvId) qconv) qbob txt n

-- eve should not receive the message
WS.assertNoEvent (1 # Second) [wsE]

testRemoteToLocal :: TestM ()
testRemoteToLocal = do
-- alice is local, bob is remote
Expand Down