Skip to content

Commit

Permalink
Use EmptyResponse consistently for galley fed calls
Browse files Browse the repository at this point in the history
  • Loading branch information
elland committed Jun 21, 2023
1 parent ab79f33 commit 347f5a7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ type GalleyApi =
-- that are part of a conversation at creation time. Since MLS conversations
-- are always created empty (i.e. they only contain the creator), this RPC is
-- never invoked for such conversations.
FedEndpoint "on-conversation-created" (ConversationCreated ConvId) ()
FedEndpoint "on-conversation-created" (ConversationCreated ConvId) EmptyResponse
-- This endpoint is called the first time a user from this backend is
-- added to a remote conversation.
:<|> FedEndpoint "on-new-remote-conversation" NewRemoteConversation EmptyResponse
:<|> FedEndpoint "get-conversations" GetConversationsRequest GetConversationsResponse
-- used by the backend that owns a conversation to inform this backend of
-- changes to the conversation
:<|> FedEndpoint "on-conversation-updated" ConversationUpdate ()
:<|> FedEndpoint "on-conversation-updated" ConversationUpdate EmptyResponse
:<|> FedEndpointWithMods
'[ MakesFederatedCall 'Galley "on-conversation-updated",
MakesFederatedCall 'Galley "on-mls-message-sent",
Expand All @@ -72,7 +72,7 @@ type GalleyApi =
LeaveConversationResponse
-- used to notify this backend that a new message has been posted to a
-- remote conversation
:<|> FedEndpoint "on-message-sent" (RemoteMessage ConvId) ()
:<|> FedEndpoint "on-message-sent" (RemoteMessage ConvId) EmptyResponse
-- used by a remote backend to send a message to a conversation owned by
-- this backend
:<|> FedEndpointWithMods
Expand Down
9 changes: 6 additions & 3 deletions services/galley/src/Galley/API/Federation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ onConversationCreated ::
) =>
Domain ->
F.ConversationCreated ConvId ->
Sem r ()
Sem r EmptyResponse
onConversationCreated domain rc = do
let qrc = fmap (toRemoteUnsafe domain) rc
loc <- qualifyLocal ()
Expand Down Expand Up @@ -189,6 +189,7 @@ onConversationCreated domain rc = do
(F.ccTime qrcConnected)
(EdConversation c)
pushConversationEvent Nothing event (qualifyAs loc [qUnqualified . Public.memId $ mem]) []
pure EmptyResponse

onNewRemoteConversation ::
Member ConversationStore r =>
Expand Down Expand Up @@ -227,9 +228,10 @@ onConversationUpdated ::
) =>
Domain ->
F.ConversationUpdate ->
Sem r ()
Sem r EmptyResponse
onConversationUpdated requestingDomain cu =
updateLocalStateOfRemoteConv requestingDomain cu
>> pure EmptyResponse

-- as of now this will not generate the necessary events on the leaver's domain
leaveConversation ::
Expand Down Expand Up @@ -314,7 +316,7 @@ onMessageSent ::
) =>
Domain ->
F.RemoteMessage ConvId ->
Sem r ()
Sem r EmptyResponse
onMessageSent domain rmUnqualified = do
let rm = fmap (toRemoteUnsafe domain) rmUnqualified
convId = tUntagged $ F.rmConversation rm
Expand Down Expand Up @@ -351,6 +353,7 @@ onMessageSent domain rmUnqualified = do
mempty
msgMetadata
(Map.filterWithKey (\(uid, _) _ -> Set.member uid members) msgs)
pure EmptyResponse

sendMessage ::
( Member BrigAccess r,
Expand Down
22 changes: 11 additions & 11 deletions services/galley/test/integration/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2192,7 +2192,7 @@ paginateConvListIds = do
F.cuAlreadyPresentUsers = [],
F.cuAction = SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (pure qAlice) roleNameWireMember)
}
runFedClient @"on-conversation-updated" fedGalleyClient chadDomain cu
void $ runFedClient @"on-conversation-updated" fedGalleyClient chadDomain cu

remoteDee <- randomId
let deeDomain = Domain "dee.example.com"
Expand All @@ -2208,7 +2208,7 @@ paginateConvListIds = do
F.cuAlreadyPresentUsers = [],
F.cuAction = SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (pure qAlice) roleNameWireMember)
}
runFedClient @"on-conversation-updated" fedGalleyClient deeDomain cu
void $ runFedClient @"on-conversation-updated" fedGalleyClient deeDomain cu

-- 1 Proteus self conv + 1 MLS self conv + 2 convs with bob and eve + 196
-- local convs + 25 convs on chad.example.com + 31 on dee.example = 256 convs.
Expand Down Expand Up @@ -2253,7 +2253,7 @@ paginateConvListIdsPageEndingAtLocalsAndDomain = do
F.cuAlreadyPresentUsers = [],
F.cuAction = SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (pure qAlice) roleNameWireMember)
}
runFedClient @"on-conversation-updated" fedGalleyClient chadDomain cu
void $ runFedClient @"on-conversation-updated" fedGalleyClient chadDomain cu

remoteDee <- randomId
let deeDomain = Domain "dee.example.com"
Expand All @@ -2271,7 +2271,7 @@ paginateConvListIdsPageEndingAtLocalsAndDomain = do
F.cuAlreadyPresentUsers = [],
F.cuAction = SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (pure qAlice) roleNameWireMember)
}
runFedClient @"on-conversation-updated" fedGalleyClient deeDomain cu
void $ runFedClient @"on-conversation-updated" fedGalleyClient deeDomain cu

foldM_ (getChunkedConvs 16 0 alice) Nothing [4, 3, 2, 1, 0 :: Int]

Expand Down Expand Up @@ -3922,7 +3922,7 @@ putRemoteConvMemberOk update = do
cuAction =
SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (pure qalice) roleNameWireMember)
}
runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cu
void $ runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cu

-- Expected member state
let memberAlice =
Expand Down Expand Up @@ -4067,7 +4067,7 @@ putRemoteReceiptModeOk = do
cuAction =
SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (pure qalice) roleNameWireAdmin)
}
runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cuAddAlice
void $ runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cuAddAlice

-- add another user adam as member
qadam <- randomQualifiedUser
Expand All @@ -4082,7 +4082,7 @@ putRemoteReceiptModeOk = do
cuAction =
SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (pure qadam) roleNameWireMember)
}
runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cuAddAdam
void $ runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cuAddAdam

let newReceiptMode = ReceiptMode 42
let action = ConversationReceiptModeUpdate newReceiptMode
Expand Down Expand Up @@ -4398,10 +4398,10 @@ removeUser = do
F.ccReceiptMode = Nothing,
F.ccProtocol = ProtocolProteus
}
runFedClient @"on-conversation-created" fedGalleyClient bDomain $ nc convB1 bart [alice, alexDel]
runFedClient @"on-conversation-created" fedGalleyClient bDomain $ nc convB2 bart [alexDel]
runFedClient @"on-conversation-created" fedGalleyClient cDomain $ nc convC1 carl [alexDel]
runFedClient @"on-conversation-created" fedGalleyClient dDomain $ nc convD1 dory [alexDel]
void $ runFedClient @"on-conversation-created" fedGalleyClient bDomain $ nc convB1 bart [alice, alexDel]
void $ runFedClient @"on-conversation-created" fedGalleyClient bDomain $ nc convB2 bart [alexDel]
void $ runFedClient @"on-conversation-created" fedGalleyClient cDomain $ nc convC1 carl [alexDel]
void $ runFedClient @"on-conversation-created" fedGalleyClient dDomain $ nc convD1 dory [alexDel]

WS.bracketR3 c alice' alexDel' amy' $ \(wsAlice, wsAlexDel, wsAmy) -> do
let handler = do
Expand Down
27 changes: 13 additions & 14 deletions services/galley/test/integration/API/Federation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ addLocalUser = do
SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (qalice :| [qdee]) roleNameWireMember)
}
WS.bracketRN c [alice, charlie, dee] $ \[wsA, wsC, wsD] -> do
runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cu
void $ runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cu
liftIO $ do
WS.assertMatch_ (5 # Second) wsA $
wsAssertMemberJoinWithRole qconv qbob [qalice] roleNameWireMember
Expand Down Expand Up @@ -308,7 +308,7 @@ addUnconnectedUsersOnly = do
SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (qCharlie :| []) roleNameWireMember)
}
-- Alice receives no notifications from this
runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cu
void $ runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cu
WS.assertNoEvent (5 # Second) [wsA]

-- | This test invokes the federation endpoint:
Expand Down Expand Up @@ -353,9 +353,9 @@ removeLocalUser = do

connectWithRemoteUser alice qBob
WS.bracketR c alice $ \ws -> do
runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cuAdd
void $ runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cuAdd
afterAddition <- listRemoteConvs remoteDomain alice
runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cuRemove
void $ runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain cuRemove
liftIO $ do
void . WS.assertMatch (3 # Second) ws $
wsAssertMemberJoinWithRole qconv qBob [qAlice] roleNameWireMember
Expand Down Expand Up @@ -416,21 +416,21 @@ removeRemoteUser = do
}

WS.bracketRN c [alice, charlie, dee, flo] $ \[wsA, wsC, wsD, wsF] -> do
runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain (cuRemove qEve)
void $ runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain (cuRemove qEve)
liftIO $ do
WS.assertMatchN_ (3 # Second) [wsA, wsD] $
wsAssertMembersLeave qconv qBob [qEve]
WS.assertNoEvent (1 # Second) [wsC, wsF]

WS.bracketRN c [alice, charlie, dee, flo] $ \[wsA, wsC, wsD, wsF] -> do
runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain (cuRemove qDee)
void $ runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain (cuRemove qDee)
liftIO $ do
WS.assertMatchN_ (3 # Second) [wsA, wsD] $
wsAssertMembersLeave qconv qBob [qDee]
WS.assertNoEvent (1 # Second) [wsC, wsF]

WS.bracketRN c [alice, charlie, dee, flo] $ \[wsA, wsC, wsD, wsF] -> do
runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain (cuRemove qFlo)
void $ runFedClient @"on-conversation-updated" fedGalleyClient remoteDomain (cuRemove qFlo)
liftIO $ do
WS.assertMatchN_ (3 # Second) [wsA] $
wsAssertMembersLeave qconv qBob [qFlo]
Expand Down Expand Up @@ -467,7 +467,7 @@ notifyUpdate extras action etype edata = do
FedGalley.cuAction = action
}
WS.bracketR2 c alice charlie $ \(wsA, wsC) -> do
runFedClient @"on-conversation-updated" fedGalleyClient bdom cu
void $ runFedClient @"on-conversation-updated" fedGalleyClient bdom cu
liftIO $ do
WS.assertMatch_ (5 # Second) wsA $ \n -> do
let e = List1.head (WS.unpackPayload n)
Expand Down Expand Up @@ -511,8 +511,7 @@ notifyUpdateUnavailable extras action etype edata = do
WS.bracketR2 c alice charlie $ \(wsA, wsC) -> do
((), _fedRequests) <-
withTempMockFederator' (throw $ MockErrorResponse Http.status500 "Down for maintenance") $
void $
runFedClient @"on-conversation-updated" fedGalleyClient bdom cu
void $ runFedClient @"on-conversation-updated" fedGalleyClient bdom cu
liftIO $ do
WS.assertMatch_ (5 # Second) wsA $ \n -> do
let e = List1.head (WS.unpackPayload n)
Expand Down Expand Up @@ -644,7 +643,7 @@ notifyDeletedConversation = do
FedGalley.cuAlreadyPresentUsers = [alice],
FedGalley.cuAction = SomeConversationAction (sing @'ConversationDeleteTag) ()
}
runFedClient @"on-conversation-updated" fedGalleyClient bobDomain cu
void $ runFedClient @"on-conversation-updated" fedGalleyClient bobDomain cu

liftIO $ do
WS.assertMatch_ (5 # Second) wsAlice $ \n -> do
Expand Down Expand Up @@ -702,7 +701,7 @@ addRemoteUser = do
SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (qdee :| [qeve, qflo]) roleNameWireMember)
}
WS.bracketRN c (map qUnqualified [qalice, qcharlie, qdee, qflo]) $ \[wsA, wsC, wsD, wsF] -> do
runFedClient @"on-conversation-updated" fedGalleyClient bdom cu
void $ runFedClient @"on-conversation-updated" fedGalleyClient bdom cu
void . liftIO $ do
WS.assertMatchN_ (5 # Second) [wsA, wsD] $
wsAssertMemberJoinWithRole qconv qbob [qeve, qdee] roleNameWireMember
Expand Down Expand Up @@ -847,7 +846,7 @@ onMessageSent = do
FedGalley.cuAction =
SomeConversationAction (sing @'ConversationJoinTag) (ConversationJoin (pure qalice) roleNameWireMember)
}
runFedClient @"on-conversation-updated" fedGalleyClient bdom cu
void $ runFedClient @"on-conversation-updated" fedGalleyClient bdom cu

let txt = "Hello from another backend"
msg client = Map.fromList [(client, txt)]
Expand All @@ -869,7 +868,7 @@ onMessageSent = do

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

0 comments on commit 347f5a7

Please sign in to comment.