Skip to content

Commit 250d72b

Browse files
authored
Make conversation ID in on-conversation-created RPC unqualified (#1766)
* Make conv ID in register-conversation unqualified The conversation being created has to be in the backend which originated the RPC, therefore we can simply make its ID unqualified instead of checking if the two domains match.
1 parent b289dfe commit 250d72b

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make conversation ID of the on-conversation-created RPC unqualified

libs/wire-api-federation/src/Wire/API/Federation/API/Galley.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ data Api routes = Api
5353
:- "federation"
5454
:> Summary "Register users to be in a new remote conversation"
5555
:> "on-conversation-created"
56-
:> ReqBody '[JSON] NewRemoteConversation
56+
:> OriginDomainHeader
57+
:> ReqBody '[JSON] (NewRemoteConversation ConvId)
5758
:> Post '[JSON] (),
5859
getConversations ::
5960
routes
@@ -117,14 +118,13 @@ newtype GetConversationsResponse = GetConversationsResponse
117118
--
118119
-- FUTUREWORK: Think about extracting common conversation metadata into a
119120
-- separarate data type that can be reused in several data types in this module.
120-
data NewRemoteConversation = NewRemoteConversation
121+
data NewRemoteConversation conv = NewRemoteConversation
121122
{ -- | The time when the conversation was created
122123
rcTime :: UTCTime,
123124
-- | The user that created the conversation
124125
rcOrigUserId :: Qualified UserId,
125-
-- | The qualified conversation ID
126-
-- FUTUREWORK: Make this unqualified, assume the conversation is being hosted by OriginDomain
127-
rcCnvId :: Qualified ConvId,
126+
-- | The conversation ID, local to the backend invoking the RPC
127+
rcCnvId :: conv,
128128
-- | The conversation type
129129
rcCnvType :: ConvType,
130130
rcCnvAccess :: [Access],
@@ -136,8 +136,8 @@ data NewRemoteConversation = NewRemoteConversation
136136
rcMessageTimer :: Maybe Milliseconds,
137137
rcReceiptMode :: Maybe ReceiptMode
138138
}
139-
deriving stock (Eq, Show, Generic)
140-
deriving (ToJSON, FromJSON) via (CustomEncoded NewRemoteConversation)
139+
deriving stock (Eq, Show, Generic, Functor)
140+
deriving (ToJSON, FromJSON) via (CustomEncoded (NewRemoteConversation conv))
141141

142142
-- | A conversation membership update, as given by ' ConversationMemberUpdate',
143143
-- can be either a member addition or removal.

services/galley/src/Galley/API/Federation.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,22 @@ federationSitemap =
7575
FederationAPIGalley.sendMessage = sendMessage
7676
}
7777

78-
onConversationCreated :: NewRemoteConversation -> Galley ()
79-
onConversationCreated rc = do
78+
onConversationCreated :: Domain -> NewRemoteConversation ConvId -> Galley ()
79+
onConversationCreated domain rc = do
80+
let qrc = fmap (`Qualified` domain) rc
8081
localDomain <- viewFederationDomain
8182
let localUsers =
8283
foldMap (\om -> guard (qDomain (omQualifiedId om) == localDomain) $> omQualifiedId om)
8384
. rcMembers
8485
$ rc
8586
localUserIds = fmap qUnqualified localUsers
8687
unless (null localUsers) $ do
87-
Data.addLocalMembersToRemoteConv localUserIds (rcCnvId rc)
88-
forM_ (fromNewRemoteConversation localDomain rc) $ \(mem, c) -> do
88+
Data.addLocalMembersToRemoteConv localUserIds (rcCnvId qrc)
89+
forM_ (fromNewRemoteConversation localDomain qrc) $ \(mem, c) -> do
8990
let event =
9091
Event
9192
ConvCreate
92-
(rcCnvId rc)
93+
(rcCnvId qrc)
9394
(rcOrigUserId rc)
9495
(rcTime rc)
9596
(EdConversation c)

services/galley/src/Galley/API/Util.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,12 +478,12 @@ toNewRemoteConversation ::
478478
-- | The conversation to convert for sending to a remote Galley
479479
Data.Conversation ->
480480
-- | The resulting information to be sent to a remote Galley
481-
NewRemoteConversation
481+
NewRemoteConversation ConvId
482482
toNewRemoteConversation now localDomain Data.Conversation {..} =
483483
NewRemoteConversation
484484
{ rcTime = now,
485485
rcOrigUserId = Qualified convCreator localDomain,
486-
rcCnvId = Qualified convId localDomain,
486+
rcCnvId = convId,
487487
rcCnvType = convType,
488488
rcCnvAccess = convAccess,
489489
rcCnvAccessRole = convAccessRole,
@@ -521,7 +521,7 @@ toNewRemoteConversation now localDomain Data.Conversation {..} =
521521
-- conversation.
522522
fromNewRemoteConversation ::
523523
Domain ->
524-
NewRemoteConversation ->
524+
NewRemoteConversation (Qualified ConvId) ->
525525
[(Public.Member, Public.Conversation)]
526526
fromNewRemoteConversation d NewRemoteConversation {..} =
527527
let membersView = fmap (second Set.toList) . setHoles $ rcMembers
@@ -589,11 +589,11 @@ registerRemoteConversationMemberships now localDomain c = do
589589
$ c
590590
where
591591
registerRemoteConversations ::
592-
NewRemoteConversation ->
592+
NewRemoteConversation ConvId ->
593593
Domain ->
594594
Galley ()
595595
registerRemoteConversations rc domain = do
596-
let rpc = FederatedGalley.onConversationCreated FederatedGalley.clientRoutes rc
596+
let rpc = FederatedGalley.onConversationCreated FederatedGalley.clientRoutes localDomain rc
597597
runFederated domain rpc
598598

599599
-- | Notify remote backends about changes to the conversation memberships of the

services/galley/test/integration/API.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ emptyFederatedGalley =
224224
let e :: Text -> Handler a
225225
e s = throwError err501 {errBody = cs ("mock not implemented: " <> s)}
226226
in FederatedGalley.Api
227-
{ FederatedGalley.onConversationCreated = \_ -> e "onConversationCreated",
227+
{ FederatedGalley.onConversationCreated = \_ _ -> e "onConversationCreated",
228228
FederatedGalley.getConversations = \_ -> e "getConversations",
229229
FederatedGalley.onConversationMembershipsChanged = \_ _ -> e "onConversationMembershipsChanged",
230230
FederatedGalley.leaveConversation = \_ _ -> e "leaveConversation",

services/galley/test/integration/API/Util.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,10 +1165,11 @@ registerRemoteConv convId originUser name othMembers = do
11651165
now <- liftIO getCurrentTime
11661166
FederatedGalley.onConversationCreated
11671167
fedGalleyClient
1168+
(qDomain convId)
11681169
( FederatedGalley.NewRemoteConversation
11691170
{ rcTime = now,
11701171
rcOrigUserId = originUser,
1171-
rcCnvId = convId,
1172+
rcCnvId = qUnqualified convId,
11721173
rcCnvType = RegularConv,
11731174
rcCnvAccess = [],
11741175
rcCnvAccessRole = ActivatedAccessRole,

0 commit comments

Comments
 (0)