-
Notifications
You must be signed in to change notification settings - Fork 333
FS-1517 Partial success on fetch prekeys #3108
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 2 commits
0d0bb98
491f612
6f547e5
9ac243a
4a50171
17246a6
f015fe7
9ebbefd
a9af020
133cf11
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 @@ | ||
| Updating the V3 version of /users/list-prekeys to return partial successes, listing users that could not be listed. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ module Brig.API.Client | |
| claimLocalPrekey, | ||
| claimPrekeyBundle, | ||
| claimMultiPrekeyBundles, | ||
| claimMultiPrekeyBundlesV3, | ||
| Data.lookupClientIds, | ||
| ) | ||
| where | ||
|
|
@@ -328,6 +329,52 @@ claimMultiPrekeyBundles protectee quc = do | |
| tUntagged . qualifyAs luc | ||
| <$> claimLocalMultiPrekeyBundles protectee (tUnqualified luc) | ||
|
|
||
| -- Similar to claimMultiPrekeyBundles except for the following changes | ||
| -- 1) A new return type that contains both the client map and a list of | ||
| -- users that messages couldn't be sent to. | ||
|
lepsa marked this conversation as resolved.
Outdated
|
||
| -- 2) A semantic change on federation errors when gathering remote clients. | ||
| -- Remote federation errors at this step no-longer cause the entire call | ||
| -- to fail, allowing partial results to be returned. | ||
| claimMultiPrekeyBundlesV3 :: | ||
| forall r. | ||
| Member (Concurrency 'Unsafe) r => | ||
| LegalholdProtectee -> | ||
| QualifiedUserClients -> | ||
| ExceptT ClientError (AppT r) QualifiedUserClientPrekeyMapV3 | ||
| claimMultiPrekeyBundlesV3 protectee quc = do | ||
|
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. If the old handler cannot be repurposed to handle both the old and the new endpoint, can you factor out the common bits? My hunch is they should be quite similar, except for the remote part and the construction of the response.
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. Done and done |
||
| loc <- qualifyLocal () | ||
| let (locals, remotes) = | ||
| partitionQualifiedAndTag | ||
| loc | ||
| ( map | ||
| (fmap UserClients . uncurry (flip Qualified)) | ||
| (Map.assocs (qualifiedUserClients quc)) | ||
| ) | ||
| localPrekeys <- traverse claimLocal locals | ||
| remotePrekeys <- mapExceptT wrapHttpClient $ lift $ traverseConcurrently claimRemote remotes | ||
| let prekeys = | ||
| getQualifiedUserClientPrekeyMap $ | ||
| qualifiedUserClientPrekeyMapFromList $ | ||
| localPrekeys <> rights remotePrekeys | ||
| failed = lefts remotePrekeys >>= toQualifiedUser . fst | ||
| pure $ | ||
| QualifiedUserClientPrekeyMapV3 prekeys $ | ||
| if null failed | ||
| then Nothing | ||
| else pure failed | ||
| where | ||
| toQualifiedUser :: Remote UserClients -> [Qualified UserId] | ||
| toQualifiedUser r = fmap (\u -> Qualified u $ tDomain r) . Map.keys . userClients . qUnqualified $ tUntagged r | ||
| claimRemote :: Remote UserClients -> ExceptT FederationError HttpClientIO (Qualified UserClientPrekeyMap) | ||
| claimRemote ruc = | ||
| tUntagged . qualifyAs ruc | ||
| <$> Federation.claimMultiPrekeyBundle (tDomain ruc) (tUnqualified ruc) | ||
|
|
||
| claimLocal :: Local UserClients -> ExceptT ClientError (AppT r) (Qualified UserClientPrekeyMap) | ||
| claimLocal luc = | ||
| tUntagged . qualifyAs luc | ||
| <$> claimLocalMultiPrekeyBundles protectee (tUnqualified luc) | ||
|
|
||
| claimLocalMultiPrekeyBundles :: | ||
| forall r. | ||
| Member (Concurrency 'Unsafe) r => | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -286,7 +286,8 @@ servantSitemap = | |
| :<|> Named @"get-users-prekey-bundle-unqualified" (callsFed (exposeAnnotations getPrekeyBundleUnqualifiedH)) | ||
| :<|> Named @"get-users-prekey-bundle-qualified" (callsFed (exposeAnnotations getPrekeyBundleH)) | ||
| :<|> Named @"get-multi-user-prekey-bundle-unqualified" getMultiUserPrekeyBundleUnqualifiedH | ||
| :<|> Named @"get-multi-user-prekey-bundle-qualified" (callsFed (exposeAnnotations getMultiUserPrekeyBundleH)) | ||
| :<|> Named @"get-multi-user-prekey-bundle-qualified@v2" (callsFed (exposeAnnotations getMultiUserPrekeyBundleH)) | ||
| :<|> Named @"get-multi-user-prekey-bundle-qualified" (callsFed (exposeAnnotations getMultiUserPrekeyBundleHV3)) | ||
|
|
||
| userClientAPI :: ServerT UserClientAPI (Handler r) | ||
| userClientAPI = | ||
|
|
@@ -477,6 +478,21 @@ getMultiUserPrekeyBundleH zusr qualUserClients = do | |
| throwStd (errorToWai @'E.TooManyClients) | ||
| API.claimMultiPrekeyBundles (ProtectedUser zusr) qualUserClients !>> clientError | ||
|
|
||
| getMultiUserPrekeyBundleHV3 :: | ||
| Member (Concurrency 'Unsafe) r => | ||
| UserId -> | ||
| Public.QualifiedUserClients -> | ||
| (Handler r) Public.QualifiedUserClientPrekeyMapV3 | ||
| getMultiUserPrekeyBundleHV3 zusr qualUserClients = do | ||
| maxSize <- fromIntegral . setMaxConvSize <$> view settings | ||
| let Sum (size :: Int) = | ||
| Map.foldMapWithKey | ||
| (\_ v -> Sum . Map.size $ v) | ||
| (Public.qualifiedUserClients qualUserClients) | ||
| when (size > maxSize) $ | ||
| throwStd (errorToWai @'E.TooManyClients) | ||
|
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. Can you factor out this and then use it in both versions of the handler?
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. Done and done |
||
| API.claimMultiPrekeyBundlesV3 (ProtectedUser zusr) qualUserClients !>> clientError | ||
|
|
||
| addClient :: | ||
| (Member GalleyProvider r) => | ||
| UserId -> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.