@@ -58,13 +58,17 @@ data CreateClients = CreateWithoutKey | CreateWithKey | DontCreateClients
58
58
data CreateConv = CreateConv | CreateProteusConv | DontCreateConv
59
59
deriving (Eq )
60
60
61
+ data CreatorOrigin = LocalCreator | RemoteCreator Domain
62
+
61
63
createNewConv :: CreateConv -> Maybe NewConv
62
64
createNewConv CreateConv = Just defNewMLSConv
63
65
createNewConv CreateProteusConv = Just defNewProteusConv
64
66
createNewConv DontCreateConv = Nothing
65
67
68
+
66
69
data SetupOptions = SetupOptions
67
70
{ createClients :: CreateClients ,
71
+ creatorOrigin :: CreatorOrigin ,
68
72
createConv :: CreateConv ,
69
73
makeConnections :: Bool
70
74
}
@@ -73,6 +77,7 @@ instance Default SetupOptions where
73
77
def =
74
78
SetupOptions
75
79
{ createClients = CreateWithKey ,
80
+ creatorOrigin = LocalCreator ,
76
81
createConv = DontCreateConv ,
77
82
makeConnections = True
78
83
}
@@ -152,41 +157,31 @@ setupParticipants ::
152
157
[Int ] ->
153
158
State. StateT [LastPrekey ] TestM (Participant , [Participant ])
154
159
setupParticipants tmp SetupOptions {.. } ns = do
155
- creator <- lift randomQualifiedUser >>= setupParticipant tmp DontCreateClients 1
160
+ creator <- lift (creatorUserOrId creatorOrigin) >>= setupParticipant tmp DontCreateClients 1
156
161
others <- for ns $ \ n ->
157
162
lift randomQualifiedUser >>= setupParticipant tmp createClients n
158
- lift . when makeConnections $
159
- traverse_
160
- ( connectUsers (qUnqualified (pUserId creator))
161
- . List1
162
- . fmap (qUnqualified . pUserId)
163
- )
164
- (nonEmpty others)
163
+ lift . when makeConnections $ case creatorOrigin of
164
+ LocalCreator ->
165
+ traverse_
166
+ ( connectUsers (qUnqualified (pUserId creator))
167
+ . List1
168
+ . fmap (qUnqualified . pUserId)
169
+ )
170
+ (nonEmpty others)
171
+ RemoteCreator _ ->
172
+ traverse_
173
+ ( \ u ->
174
+ connectWithRemoteUser
175
+ (qUnqualified . pUserId $ u)
176
+ (pUserId creator)
177
+ )
178
+ others
165
179
pure (creator, others)
166
-
167
- -- | Just like 'setupParticipants', this function sets up MLS participants. The
168
- -- assumption is that the creator is remote to the local backend, and the rest
169
- -- of participants are local.
170
- setupParticipantsOnServer ::
171
- HasCallStack =>
172
- FilePath ->
173
- Domain ->
174
- SetupOptions ->
175
- [Int ] ->
176
- State. StateT [LastPrekey ] TestM (Participant , [Participant ])
177
- setupParticipantsOnServer tmp originDomain SetupOptions {.. } ns = do
178
- creator <- lift (randomQualifiedId originDomain) >>= setupParticipant tmp DontCreateClients 1
179
- locals <- for ns $ \ n ->
180
- lift randomQualifiedUser >>= setupParticipant tmp createClients n
181
- lift . when makeConnections $
182
- traverse_
183
- ( \ u ->
184
- connectWithRemoteUser
185
- (qUnqualified . pUserId $ u)
186
- (pUserId creator)
187
- )
188
- locals
189
- pure (creator, locals)
180
+ where
181
+ creatorUserOrId :: CreatorOrigin -> TestM (Qualified UserId )
182
+ creatorUserOrId = \ case
183
+ LocalCreator -> randomQualifiedUser
184
+ RemoteCreator d -> randomQualifiedId d
190
185
191
186
withLastPrekeys :: Monad m => State. StateT [LastPrekey ] m a -> m a
192
187
withLastPrekeys m = State. evalStateT m someLastPrekeys
@@ -242,11 +237,12 @@ takeLastPrekey = do
242
237
State. put lpks
243
238
pure lpk
244
239
245
- -- | Setup: Alice creates a group and invites bob. Return welcome and commit message.
240
+ -- | Setup: Alice creates a group and invites Bob that is local or remote to
241
+ -- Alice depending on the passed in creator origin. Return welcome and commit
242
+ -- message.
246
243
aliceInvitesBob :: HasCallStack => Int -> SetupOptions -> TestM MessagingSetup
247
244
aliceInvitesBob numBobClients opts@ SetupOptions {.. } = withSystemTempDirectory " mls" $ \ tmp -> do
248
245
(alice, [bob]) <- withLastPrekeys $ setupParticipants tmp opts [numBobClients]
249
-
250
246
-- create a group
251
247
conversation <- setupGroup tmp createConv alice " group"
252
248
0 commit comments