-
Notifications
You must be signed in to change notification settings - Fork 333
Deleting clients creates MLS remove proposals #2674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
3a9ec89
26e675e
6be235b
8223edc
7322237
85575f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Deleting clients creates MLS remove proposals |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,16 +22,40 @@ module Galley.API.Clients | |
| ) | ||
| where | ||
|
|
||
| import Data.Hex | ||
| import Data.Id | ||
| import Data.Proxy | ||
| import Data.Qualified | ||
| import Data.Range | ||
| import Data.String.Conversions | ||
| import qualified Data.Text as T | ||
| import Data.Time | ||
| import Galley.API.Error | ||
| import Galley.API.MLS.Removal | ||
| import qualified Galley.API.Query as Query | ||
| import Galley.API.Util | ||
| import Galley.Effects | ||
| import qualified Galley.Effects.BrigAccess as E | ||
| import qualified Galley.Effects.ClientStore as E | ||
| import Galley.Effects.ConversationStore (getConversation) | ||
| import Galley.Effects.FederatorAccess | ||
| import Galley.Effects.ProposalStore (ProposalStore) | ||
| import Galley.Env | ||
| import Galley.Types.Clients (clientIds, fromUserClients) | ||
| import Imports | ||
| import Network.Wai | ||
| import Network.Wai.Predicate hiding (setStatus) | ||
| import Network.Wai.Utilities | ||
| import Polysemy | ||
| import qualified Polysemy.Error as Poly | ||
| import Polysemy.Input | ||
| import qualified Polysemy.TinyLog as P | ||
| import qualified System.Logger as Log | ||
| import Wire.API.Conversation hiding (Member) | ||
| import Wire.API.Federation.API | ||
| import Wire.API.Federation.API.Galley (ClientRemovedRequest (ClientRemovedRequest)) | ||
| import Wire.API.Routes.MultiTablePaging | ||
| import Wire.Sem.Paging.Cassandra (CassandraPaging) | ||
|
|
||
| getClientsH :: | ||
| Members '[BrigAccess, ClientStore] r => | ||
|
|
@@ -61,9 +85,71 @@ addClientH (usr ::: clt) = do | |
| pure empty | ||
|
|
||
| rmClientH :: | ||
| Member ClientStore r => | ||
| forall p1 r. | ||
| ( p1 ~ CassandraPaging, | ||
| Members | ||
| '[ ClientStore, | ||
| ConversationStore, | ||
| ExternalAccess, | ||
| FederatorAccess, | ||
| GundeckAccess, | ||
| Input Env, | ||
| Input (Local ()), | ||
| Input UTCTime, | ||
| ListItems p1 ConvId, | ||
| ListItems p1 (Remote ConvId), | ||
| MemberStore, | ||
| Poly.Error InternalError, | ||
| ProposalStore, | ||
| P.TinyLog | ||
| ] | ||
| r | ||
| ) => | ||
| UserId ::: ClientId -> | ||
| Sem r Response | ||
| rmClientH (usr ::: clt) = do | ||
| E.deleteClient usr clt | ||
| rmClientH (usr ::: cid) = do | ||
| lusr <- qualifyLocal usr | ||
| let nRange1000 = toRange (Proxy @1000) :: Range 1 1000 Int32 | ||
| firstConvIds <- Query.conversationIdsPageFrom lusr (GetPaginatedConversationIds Nothing nRange1000) | ||
| goConvs nRange1000 firstConvIds lusr | ||
|
|
||
| E.deleteClient usr cid | ||
| pure empty | ||
| where | ||
| rpc = fedClient @'Galley @"on-client-removed" | ||
| goConvs :: Range 1 1000 Int32 -> ConvIdsPage -> Local UserId -> Sem r () | ||
| goConvs range page lusr = do | ||
| loc :: Local () <- input | ||
|
smatting marked this conversation as resolved.
Outdated
|
||
| let (localConvs, remoteConvs) = partitionQualified loc (mtpResults page) | ||
| for_ localConvs $ \convId -> do | ||
| mConv <- getConversation convId | ||
| for_ mConv $ \conv -> do | ||
| lconv <- qualifyLocal conv | ||
| removeClient lconv (qUntagged lusr) cid | ||
| traverse_ removeRemoteMLSClients (rangedChunks remoteConvs) | ||
| when (mtpHasMore page) $ do | ||
| let nextState = mtpPagingState page | ||
| nextQuery = GetPaginatedConversationIds (Just nextState) range | ||
| newCids <- Query.conversationIdsPageFrom lusr nextQuery | ||
| goConvs range newCids lusr | ||
|
|
||
| removeRemoteMLSClients :: Range 1 1000 [Remote ConvId] -> Sem r () | ||
| removeRemoteMLSClients cids = do | ||
| for_ (bucketRemote (fromRange cids)) $ \remoteConvs -> do | ||
|
smatting marked this conversation as resolved.
Outdated
|
||
| runFederatedEither remoteConvs (rpc (ClientRemovedRequest usr cid (tUnqualified remoteConvs))) | ||
| >>= logAndIgnoreError "Error in onConversationUpdated call" usr | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't have the message been about "on-client-removed"?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure I follow. I am asking if instead of: logAndIgnoreError "Error in onConversationUpdated call" usrit should have been: logAndIgnoreError "Error in onClientRemoved call" usrinstead. |
||
|
|
||
| logAndIgnoreError message usr' res = do | ||
| case res of | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A suggestion: you can use whenLeft :: Applicative m => Either a b -> (a -> m ()) -> m ()
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah nice, didn't know about this one |
||
| Left federationError -> | ||
| P.err | ||
| ( Log.msg | ||
| ( "Federation error while notifying remote backends of a client deletion (Galley). " | ||
| <> message | ||
| <> " " | ||
| <> show federationError | ||
| ) | ||
| . Log.field "user" (show usr') | ||
| . Log.field "client" (hex . T.unpack . client $ cid) | ||
| ) | ||
| Right _ -> pure () | ||
Uh oh!
There was an error while loading. Please reload this page.