19
19
module Galley.API.MLS.Message
20
20
( postMLSMessageFromLocalUser ,
21
21
postMLSMessage ,
22
+ MLSMessageStaticErrors ,
22
23
)
23
24
where
24
25
@@ -63,24 +64,30 @@ import Wire.API.MLS.Message
63
64
import Wire.API.MLS.Proposal
64
65
import Wire.API.MLS.Serialisation
65
66
67
+ type MLSMessageStaticErrors =
68
+ '[ ErrorS 'ConvNotFound,
69
+ ErrorS 'MLSUnsupportedMessage,
70
+ ErrorS 'MLSStaleMessage,
71
+ ErrorS 'MLSProposalNotFound,
72
+ ErrorS 'MissingLegalholdConsent,
73
+ ErrorS 'MLSKeyPackageRefNotFound,
74
+ ErrorS 'MLSClientMismatch,
75
+ ErrorS 'MLSUnsupportedProposal
76
+ ]
77
+
66
78
postMLSMessageFromLocalUser ::
67
79
( HasProposalEffects r ,
68
- Members
69
- '[ Error FederationError ,
70
- ErrorS 'ConvNotFound,
71
- ErrorS 'MLSUnsupportedMessage,
72
- ErrorS 'MLSStaleMessage,
73
- ErrorS 'MLSProposalNotFound,
74
- ErrorS 'MissingLegalholdConsent,
75
- TinyLog
76
- ]
77
- r
80
+ Members MLSMessageStaticErrors r ,
81
+ Member (Error FederationError ) r ,
82
+ Member TinyLog r
78
83
) =>
79
84
Local UserId ->
80
85
ConnId ->
81
86
RawMLS SomeMessage ->
82
87
Sem r [Event ]
83
- postMLSMessageFromLocalUser lusr = postMLSMessage lusr (qUntagged lusr)
88
+ postMLSMessageFromLocalUser lusr conn msg =
89
+ map lcuEvent
90
+ <$> postMLSMessage lusr (qUntagged lusr) (Just conn) msg
84
91
85
92
postMLSMessage ::
86
93
( HasProposalEffects r ,
@@ -97,9 +104,9 @@ postMLSMessage ::
97
104
) =>
98
105
Local x ->
99
106
Qualified UserId ->
100
- ConnId ->
107
+ Maybe ConnId ->
101
108
RawMLS SomeMessage ->
102
- Sem r [Event ]
109
+ Sem r [LocalConversationUpdate ]
103
110
postMLSMessage loc qusr con smsg = case rmValue smsg of
104
111
SomeMessage tag msg -> do
105
112
-- fetch conversation
@@ -128,8 +135,8 @@ postMLSMessage loc qusr con smsg = case rmValue smsg of
128
135
type HasProposalEffects r =
129
136
( Member BrigAccess r ,
130
137
Member ConversationStore r ,
131
- Member (Error MLSProtocolError ) r ,
132
138
Member (Error MLSProposalFailure ) r ,
139
+ Member (Error MLSProtocolError ) r ,
133
140
Member (ErrorS 'MLSKeyPackageRefNotFound) r ,
134
141
Member (ErrorS 'MLSClientMismatch) r ,
135
142
Member (ErrorS 'MLSUnsupportedProposal) r ,
@@ -169,11 +176,11 @@ processCommit ::
169
176
Member (ErrorS 'MissingLegalholdConsent) r
170
177
) =>
171
178
Qualified UserId ->
172
- ConnId ->
179
+ Maybe ConnId ->
173
180
Local Data. Conversation ->
174
181
Epoch ->
175
182
Commit ->
176
- Sem r [Event ]
183
+ Sem r [LocalConversationUpdate ]
177
184
processCommit qusr con lconv epoch commit = do
178
185
-- check epoch number
179
186
curEpoch <-
@@ -183,12 +190,12 @@ processCommit qusr con lconv epoch commit = do
183
190
184
191
-- process and execute proposals
185
192
action <- foldMap applyProposalRef (cProposals commit)
186
- events <- executeProposalAction qusr con lconv action
193
+ updates <- executeProposalAction qusr con lconv action
187
194
188
195
-- increment epoch number
189
196
setConversationEpoch (Data. convId (tUnqualified lconv)) (succ epoch)
190
197
191
- pure events
198
+ pure updates
192
199
193
200
applyProposalRef ::
194
201
( HasProposalEffects r ,
@@ -227,10 +234,10 @@ executeProposalAction ::
227
234
Member TeamStore r
228
235
) =>
229
236
Qualified UserId ->
230
- ConnId ->
237
+ Maybe ConnId ->
231
238
Local Data. Conversation ->
232
239
ProposalAction ->
233
- Sem r [Event ]
240
+ Sem r [LocalConversationUpdate ]
234
241
executeProposalAction qusr con lconv action = do
235
242
-- For the moment, assume a fixed ciphersuite.
236
243
-- FUTUREWORK: store ciphersuite with the conversation
@@ -260,17 +267,17 @@ executeProposalAction qusr con lconv action = do
260
267
-- FUTUREWORK: turn this error into a proper response
261
268
throwS @ 'MLSClientMismatch
262
269
263
- addMembers :: NonEmpty (Qualified UserId ) -> Sem r [Event ]
270
+ addMembers :: NonEmpty (Qualified UserId ) -> Sem r [LocalConversationUpdate ]
264
271
addMembers users =
265
272
-- FUTUREWORK: update key package ref mapping to reflect conversation membership
266
273
handleNoChanges
267
274
. handleMLSProposalFailures @ ProposalErrors
268
- . fmap (pure . lcuEvent) -- TODO: keep track of ConversationUpdate in the remote case
275
+ . fmap (pure )
269
276
. updateLocalConversationUnchecked
270
277
@ 'ConversationJoinTag
271
278
lconv
272
279
qusr
273
- ( Just con)
280
+ con
274
281
$ ConversationJoin users roleNameWireMember
275
282
276
283
handleNoChanges :: Monoid a => Sem (Error NoChanges ': r ) a -> Sem r a
@@ -294,7 +301,7 @@ propagateMessage ::
294
301
Local x ->
295
302
Qualified UserId ->
296
303
Data. Conversation ->
297
- ConnId ->
304
+ Maybe ConnId ->
298
305
ByteString ->
299
306
Sem r ()
300
307
propagateMessage loc qusr conv con raw = do
@@ -308,7 +315,7 @@ propagateMessage loc qusr conv con raw = do
308
315
e = Event qcnv qusr now $ EdMLSMessage raw
309
316
lclients = tUnqualified . clients <$> lmems
310
317
mkPush :: UserId -> ClientId -> MessagePush 'NormalMessage
311
- mkPush u c = newMessagePush lcnv lmMap ( Just con) defMessageMetadata (u, c) e
318
+ mkPush u c = newMessagePush lcnv lmMap con defMessageMetadata (u, c) e
312
319
runMessagePush loc (Just qcnv) $
313
320
foldMap (uncurry mkPush) (cToList =<< lclients)
314
321
where
0 commit comments