@@ -79,10 +79,11 @@ import Polysemy.Input
79
79
import qualified Polysemy.TinyLog as P
80
80
import qualified System.Logger as Log
81
81
import Wire.API.Conversation hiding (Conversation , Member )
82
- import Wire.API.Conversation.Action hiding ( conversationActionToEvent )
82
+ import Wire.API.Conversation.Action
83
83
import Wire.API.Conversation.Role
84
84
import Wire.API.ErrorDescription
85
85
import Wire.API.Event.Conversation hiding (Conversation )
86
+ import Wire.API.Federation.API (Component (Galley ), fedClient )
86
87
import Wire.API.Federation.API.Galley
87
88
import Wire.API.Federation.Error
88
89
import Wire.API.Team.LegalHold
@@ -104,65 +105,6 @@ data NoChanges = NoChanges
104
105
-- deriving (Arbitrary) via (GenericUniform ConversationAction)
105
106
-- deriving (ToJSON, FromJSON) via (CustomEncoded ConversationAction)
106
107
107
- -- conversationActionToEvent ::
108
- -- UTCTime ->
109
- -- Qualified UserId ->
110
- -- Qualified ConvId ->
111
- -- ConversationAction ->
112
- -- Event
113
- -- conversationActionToEvent now quid qcnv (ConversationActionAddMembers newMembers role) =
114
- -- Event MemberJoin qcnv quid now $
115
- -- EdMembersJoin $ SimpleMembers (map (`SimpleMember` role) (toList newMembers))
116
- -- conversationActionToEvent now quid qcnv (ConversationActionRemoveMembers removedMembers) =
117
- -- Event MemberLeave qcnv quid now $
118
- -- EdMembersLeave (QualifiedUserIdList (toList removedMembers))
119
- -- conversationActionToEvent now quid qcnv (ConversationActionRename rename) =
120
- -- Event ConvRename qcnv quid now (EdConvRename rename)
121
- -- conversationActionToEvent now quid qcnv (ConversationActionMessageTimerUpdate update) =
122
- -- Event ConvMessageTimerUpdate qcnv quid now (EdConvMessageTimerUpdate update)
123
- -- conversationActionToEvent now quid qcnv (ConversationActionReceiptModeUpdate update) =
124
- -- Event ConvReceiptModeUpdate qcnv quid now (EdConvReceiptModeUpdate update)
125
- -- conversationActionToEvent now quid qcnv (ConversationActionMemberUpdate target (OtherMemberUpdate role)) =
126
- -- let update = MemberUpdateData target Nothing Nothing Nothing Nothing Nothing Nothing role
127
- -- in Event MemberStateUpdate qcnv quid now (EdMemberUpdate update)
128
- -- conversationActionToEvent now quid qcnv (ConversationActionAccessUpdate update) =
129
- -- Event ConvAccessUpdate qcnv quid now (EdConvAccessUpdate update)
130
- -- conversationActionToEvent now quid qcnv ConversationActionDelete =
131
- -- Event ConvDelete qcnv quid now EdConvDelete
132
-
133
- conversationActionToEvent ::
134
- forall tag .
135
- Sing tag ->
136
- UTCTime ->
137
- Qualified UserId ->
138
- Qualified ConvId ->
139
- ConversationAction tag ->
140
- Event
141
- conversationActionToEvent tag now quid qcnv action =
142
- case tag of
143
- SConversationJoinTag ->
144
- let ConversationJoin newMembers role = action
145
- in Event MemberJoin qcnv quid now $
146
- EdMembersJoin $ SimpleMembers (map (`SimpleMember ` role) (toList newMembers))
147
- SConversationLeaveTag ->
148
- let ConversationLeave removedMembers = action
149
- in Event MemberLeave qcnv quid now $
150
- EdMembersLeave (QualifiedUserIdList (toList removedMembers))
151
- SConversationMemberUpdateTag ->
152
- let ConversationMemberUpdate target (OtherMemberUpdate role) = action
153
- update = MemberUpdateData target Nothing Nothing Nothing Nothing Nothing Nothing role
154
- in Event MemberStateUpdate qcnv quid now (EdMemberUpdate update)
155
- SConversationDeleteTag ->
156
- Event ConvDelete qcnv quid now EdConvDelete
157
- SConversationRenameTag ->
158
- Event ConvRename qcnv quid now $ EdConvRename action
159
- SConversationMessageTimerUpdateTag ->
160
- Event ConvMessageTimerUpdate qcnv quid now (EdConvMessageTimerUpdate action)
161
- SConversationReceiptModeUpdateTag ->
162
- Event ConvReceiptModeUpdate qcnv quid now (EdConvReceiptModeUpdate action)
163
- SConversationAccessDataTag ->
164
- Event ConvAccessUpdate qcnv quid now (EdConvAccessUpdate action)
165
-
166
108
type family HasConversationActionEffects (tag :: ConversationActionTag ) r :: Constraint where
167
109
HasConversationActionEffects 'ConversationJoinTag r =
168
110
Members
@@ -187,6 +129,8 @@ type family HasConversationActionEffects (tag :: ConversationActionTag) r :: Con
187
129
r
188
130
HasConversationActionEffects 'ConversationLeaveTag r =
189
131
(Members '[MemberStore , Error NoChanges ] r )
132
+ HasConversationActionEffects 'ConversationRemoveMembersTag r =
133
+ (Members '[MemberStore , Error NoChanges ] r )
190
134
HasConversationActionEffects 'ConversationMemberUpdateTag r =
191
135
(Members '[MemberStore , Error ConversationError ] r )
192
136
HasConversationActionEffects 'ConversationDeleteTag r =
@@ -288,6 +232,11 @@ performAction origUser lcnv cnv action =
288
232
when (null presentVictims) noChanges
289
233
E. deleteMembers (convId cnv) (toUserList lcnv presentVictims)
290
234
pure (mempty , action) -- FUTUREWORK: should we return the filtered action here?
235
+ SConversationRemoveMembersTag -> do
236
+ let presentVictims = filter (isConvMember lcnv cnv) (toList (crmTargets action))
237
+ when (null presentVictims) noChanges
238
+ E. deleteMembers (convId cnv) (toUserList lcnv presentVictims)
239
+ pure (mempty , action) -- FUTUREWORK: should we return the filtered action here?
291
240
SConversationMemberUpdateTag -> do
292
241
void $ ensureOtherMember lcnv (cmuTarget action) cnv
293
242
E. setOtherMember lcnv (cmuTarget action) (cmuUpdate action)
@@ -315,31 +264,6 @@ performAction origUser lcnv cnv action =
315
264
(bm, act) <- performConversationAccessData origUser lcnv cnv action
316
265
pure (bm, act)
317
266
318
- -- -- | An update to a conversation, including addition and removal of members.
319
- -- -- Used to send notifications to users and to remote backends.
320
- -- class IsConversationAction a where
321
- -- conversationAction :: a -> ConversationAction
322
- -- ensureAllowed ::
323
- -- (IsConvMember mem) =>
324
- -- Local x ->
325
- -- a ->
326
- -- Conversation ->
327
- -- mem ->
328
- -- Sem r ()
329
- -- ensureAllowed _ _ _ _ = pure ()
330
-
331
- -- conversationActionPermission :: Action
332
-
333
- -- conversationActionTag' :: ConversationActionTag
334
- -- performAction ::
335
- -- ( Members '[ConversationStore, Error NoChanges] r
336
- -- ) =>
337
- -- Qualified UserId ->
338
- -- Local ConvId ->
339
- -- Conversation ->
340
- -- a ->
341
- -- Sem r (BotsAndMembers, a)
342
-
343
267
performConversationJoin ::
344
268
(HasConversationActionEffects 'ConversationJoinTag r ) =>
345
269
Qualified UserId ->
@@ -498,7 +422,7 @@ performConversationAccessData qusr lcnv conv action = do
498
422
void . for_ (nonEmpty (bmQualifiedMembers lcnv toRemove)) $ \ usersToRemove -> do
499
423
let rAction = ConversationLeave usersToRemove
500
424
void . runError @ NoChanges $ performAction @ 'ConversationLeaveTag qusr lcnv conv rAction
501
- notifyConversationAction @ 'ConversationLeaveTag qusr Nothing lcnv bmToNotify rAction
425
+ notifyConversationAction (sing @ 'ConversationLeaveTag) qusr Nothing lcnv bmToNotify rAction
502
426
pure (mempty , action)
503
427
where
504
428
maybeRemoveBots :: Member BrigAccess r => BotsAndMembers -> Sem r BotsAndMembers
@@ -568,7 +492,8 @@ updateLocalConversationWithLocalUser lcnv lusr con action = do
568
492
-- perform action
569
493
(extraTargets, action') <- performAction @ tag (qUntagged lusr) lcnv conv action
570
494
571
- notifyConversationAction @ tag
495
+ notifyConversationAction
496
+ (sing @ tag )
572
497
(qUntagged lusr)
573
498
con
574
499
lcnv
@@ -616,7 +541,8 @@ updateLocalConversationWithRemoteUser _tag lcnv rusr action = do
616
541
remotesOtherDomain = remotes Set. \\ remotesUserDomain
617
542
618
543
void $
619
- notifyConversationAction @ tag
544
+ notifyConversationAction
545
+ (sing @ tag )
620
546
(qUntagged rusr)
621
547
Nothing
622
548
lcnv
@@ -678,20 +604,20 @@ notifyConversationAction ::
678
604
forall tag r .
679
605
(SingI tag ) =>
680
606
Members '[FederatorAccess , ExternalAccess , GundeckAccess , Input UTCTime ] r =>
607
+ Sing tag ->
681
608
Qualified UserId ->
682
609
Maybe ConnId ->
683
610
Local ConvId ->
684
611
BotsAndMembers ->
685
612
ConversationAction (tag :: ConversationActionTag ) ->
686
613
Sem r Event
687
- notifyConversationAction quid con lcnv targets action = do
614
+ notifyConversationAction tag quid con lcnv targets action = do
688
615
now <- input
689
616
let e = conversationActionToEvent (sing @ tag ) now quid (qUntagged lcnv) action
690
617
691
- -- TODO: uncomment this!
692
- -- E.runFederatedConcurrently_ (toList (bmRemotes targets)) $ \ruids ->
693
- -- fedClient @'Galley @"on-conversation-updated" $
694
- -- ConversationUpdate now quid (tUnqualified lcnv) (tUnqualified ruids) action
618
+ E. runFederatedConcurrently_ (toList (bmRemotes targets)) $ \ ruids ->
619
+ fedClient @ 'Galley @ " on-conversation-updated" $
620
+ ConversationUpdate now quid (tUnqualified lcnv) (tUnqualified ruids) (SomeConversationAction tag action)
695
621
696
622
-- notify local participants and bots
697
623
pushConversationEvent con e (qualifyAs lcnv (bmLocals targets)) (bmBots targets) $> e
0 commit comments