Skip to content
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
284 commits
Select commit Hold shift + click to select a range
a478868
Breadcrumbs.
fisx May 4, 2023
dfa644d
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx May 8, 2023
66e6969
Better breadcrumbs.
fisx May 8, 2023
cdf3650
Polish docs.
fisx May 8, 2023
ef149e3
afterthought.
fisx May 8, 2023
f9f0e87
Update services/brig/test/integration/API/Federation.hs
fisx May 8, 2023
1044124
More tests.
fisx May 8, 2023
5c22938
Remove a lying comment.
fisx May 8, 2023
02c1432
Refactor: keep the semantics of `_runSettings` intact.
fisx May 8, 2023
7dfb4e8
Remove a lying comment.
fisx May 8, 2023
6f9b9cf
Fixup / WIP
fisx May 8, 2023
beba208
Fixup
fisx May 8, 2023
0008020
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx May 9, 2023
3b8b383
I take it back!
fisx May 9, 2023
d508cb9
more docs.
fisx May 9, 2023
167083a
rm bogus TODO, add a non-bogus one :)
fisx May 10, 2023
8cd69f1
revert changes of status code in integration tests.
fisx May 10, 2023
0ede02d
Various updates, mainly moving some common code into wire-api and
lepsa May 10, 2023
adbf7d9
FS-1115: More common code for federation domain updates
lepsa May 10, 2023
236c2fd
Use tinylog instead of `print`.
fisx May 10, 2023
1a6a103
sanitize-pr
fisx May 10, 2023
950867e
Use retry instead of threadDelay-loop.
fisx May 10, 2023
676862a
FS-1115: Updating design docs on how update intervals are supplied
lepsa May 11, 2023
fc00935
Clarify source comment.
fisx May 11, 2023
d39dd45
FS-1115: Cleaning up un-needed changes to options
lepsa May 11, 2023
6f5ee22
update docs.wire.com
fisx May 11, 2023
db39702
docs.
fisx May 11, 2023
1a90c97
Merge branch 'develop' into FS-1115
fisx May 12, 2023
3846ae3
docs.
fisx May 12, 2023
8b45f0f
Fix: `/i/user/meta-info` (stern) (#3281)
battermann May 10, 2023
708bec2
Handle race conditions in /integration (#3278)
fisx May 11, 2023
e89b052
Update docs.wire.com (#3284)
fisx May 11, 2023
5638e5e
Restore deleted scripts (#3287)
smatting May 11, 2023
417e368
Refactor federation domain configuration.
fisx May 12, 2023
ce50aa2
Merge remote-tracking branch 'refs/remotes/owen/FS-1115' into FS-1115
fisx May 12, 2023
5bed564
Fixup
fisx May 12, 2023
4199dc5
Complete CRUD api for federator remotes (Update is missing) [WIP].
fisx May 12, 2023
728567a
Complete CRUD api for federator remotes (Update is missing): tests.
fisx May 12, 2023
f5c1b3e
docs.
fisx May 12, 2023
a6e9255
Cleanup
fisx May 12, 2023
64b2420
FS-1179: Setting up a location in galley for processing deleted domains
lepsa May 14, 2023
8f348c8
FS-1179: Fixing the polysemy error.
lepsa May 11, 2023
1e086c2
FS-1179: Initial processing for deleting remote domains.
lepsa May 14, 2023
d7f60e3
FS-1179: Fixing an error http reponse code.
lepsa May 16, 2023
6a583bf
wip
lepsa May 18, 2023
1d05c84
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx May 19, 2023
c0df89a
Remove dead code.
fisx May 19, 2023
ea18bcb
nit-pick.
fisx May 19, 2023
4b79d4b
Typo.
fisx May 19, 2023
2f3ec7b
Fine-tune logging.
fisx May 19, 2023
84e78f0
Fix haddocks.
fisx May 19, 2023
6d1f719
Implement put.
fisx May 19, 2023
e85c97d
Clariy updateFrequency everywhere.
fisx May 19, 2023
6327def
nit-pick.
fisx May 19, 2023
5915c82
Fixup
fisx May 19, 2023
f2e998d
Cleanup
fisx May 19, 2023
012f39d
Implement put. (For real this time.)
fisx May 19, 2023
aa52e91
Move integration tests to /integration.
fisx May 19, 2023
9c17a69
FS-1179: Work in progress. Tests are broken due to timing issues
lepsa May 22, 2023
1d38803
FS-1179: Fixing an errant delete
lepsa May 22, 2023
e2015dc
FS-1179: Commiting and switching to FS-1115
lepsa May 22, 2023
3374dd6
...
fisx May 22, 2023
411f03d
wip
lepsa May 22, 2023
96521f5
...
fisx May 22, 2023
e474e0b
FS-1115: Setting up calls to Brig from integration tests.
lepsa May 22, 2023
af21829
...
fisx May 22, 2023
3287003
...
fisx May 22, 2023
166e2ba
...
fisx May 22, 2023
bad86a1
...
fisx May 22, 2023
6390674
...
fisx May 22, 2023
b49a742
...
fisx May 22, 2023
f02819f
Fix
fisx May 22, 2023
15ec903
...
fisx May 22, 2023
dd061ae
WIP: Chasing down cache issues between some bug fixes
lepsa May 23, 2023
a6bab56
...
fisx May 23, 2023
8f553bd
...
fisx May 23, 2023
e44cfe9
...
fisx May 23, 2023
19f2732
...
fisx May 23, 2023
d662c85
Tests are passing!
fisx May 23, 2023
bea0419
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx May 23, 2023
f6ae0c7
process leif's feedback.
fisx May 23, 2023
f0bfa62
...
fisx May 23, 2023
2e959b0
Fixing compile issues after a merge
lepsa May 24, 2023
37b4f09
Updating templates
lepsa May 24, 2023
8f8af7c
Removing a JSON roundtrip, better using aeson.
lepsa May 24, 2023
236f4bb
Moving more of the federation domain update code into wire-api.
lepsa May 24, 2023
fff9883
wip
lepsa May 24, 2023
1a76c9c
Merge remote-tracking branch 'refs/remotes/owen/FS-1115' into FS-1115
fisx May 24, 2023
4efa58e
sanitize-pr
fisx May 24, 2023
0a122f3
Merge branch 'FS-1115' of github.com:lepsa/wire-server into FS-1115
lepsa May 24, 2023
9c68bd8
FS-1115: Updating brig integration config to help tests
lepsa May 24, 2023
c8cac98
s/AllowList/AllowDynamic/g
fisx May 24, 2023
ca572dd
rm trailing whitespace.
fisx May 24, 2023
7c39b34
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx May 24, 2023
d3997dc
docs
fisx May 24, 2023
17ab5da
Updating with PR feedback
lepsa May 25, 2023
fbfac87
Have federation domain tests use MakesValue more
lepsa May 25, 2023
8cdd041
FS-1115: Removing more FedConn type specific code from federation tests
lepsa May 25, 2023
1ffaab2
More code leaning on typeclasses
lepsa May 25, 2023
e8a7f8b
Pre-emptive rework before merging
lepsa May 25, 2023
25ad1af
WIP: One compiler error, but mostly sorted
lepsa May 25, 2023
56f7954
Mark flaky test case.
fisx May 25, 2023
db19f40
Merge remote-tracking branch 'refs/remotes/owen/FS-1115' into FS-1115
fisx May 25, 2023
9c6836d
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx May 25, 2023
01ef6ff
docs.
fisx May 25, 2023
1f0d1ab
Merge remote-tracking branch 'origin/develop' into FS-1115
lepsa May 26, 2023
b630396
Merge remote-tracking branch 'lepsa/FS-1115' into FS-1179
lepsa May 26, 2023
a12cf1b
Formatting
lepsa May 26, 2023
c8fbb4d
Merge remote-tracking branch 'origin/develop' into FS-1115
lepsa May 29, 2023
05b692f
Merge branch 'FS-1115' into FS-1179
lepsa May 29, 2023
e779c86
FS-1179: Setting up the receiving RabbitMQ loop.
lepsa May 29, 2023
ced3efb
wip
lepsa May 29, 2023
82ebc0e
FS-1179: Refactoring the RabbitMQ code
lepsa May 29, 2023
803b0df
Code formatting
lepsa May 29, 2023
f2cf2da
Merge branch 'develop' into FS-1115
fisx May 31, 2023
5c1b3d1
FS-1179: Fixing tests using the wrong domain.
lepsa May 31, 2023
13b448c
Merge remote-tracking branch 'origin/develop' into FS-1179
lepsa Jun 2, 2023
9b44c5e
Merge remote-tracking branch 'refs/remotes/owen/FS-1115' into FS-1115
fisx Jun 2, 2023
689b5e9
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx Jun 4, 2023
0e0487c
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx Jun 4, 2023
28d27d6
docs.
fisx Jun 4, 2023
d334aa6
Changelog.
fisx Jun 4, 2023
171a31e
docs.
fisx Jun 4, 2023
125ba0a
sanitize-pr
fisx Jun 4, 2023
98bf16a
Fixup
fisx Jun 4, 2023
6f77d21
FS-1179: Moving a delete call into Brig, and calling it from Galley.
lepsa Jun 5, 2023
26aa9ef
FS-1179: Fixing tests by telling cassandra to run queries anyway
lepsa Jun 5, 2023
03153e0
Update docs/src/understand/configure-federation.md
fisx Jun 5, 2023
3466906
Update docs/src/developer/developer/federation-design-aspects.md
fisx Jun 5, 2023
5571ca2
FS-1179: Coping code from other tests to setup remote conversations.
lepsa Jun 5, 2023
87455fa
Merge remote-tracking branch 'lepsa/FS-1115' into FS-1179
lepsa Jun 6, 2023
9f0a323
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx Jun 6, 2023
ad83b45
Fix cannon config map
fisx Jun 6, 2023
0990d32
whitespace
fisx Jun 6, 2023
d49da1a
FS-1179: Improving tests in galley, and adding a new test to brig
lepsa Jun 6, 2023
b976f94
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx Jun 6, 2023
81e1278
FS-1179: PR formatting
lepsa Jun 6, 2023
827e155
Merge remote-tracking branch 'lepsa/FS-1115' into FS-1179
lepsa Jun 6, 2023
7e56c4a
Adding a round-trip test for rabbitmq.
lepsa Jun 7, 2023
8e9d364
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx Jun 9, 2023
781cacd
hi ci
fisx Jun 9, 2023
5cd4559
docs.
fisx Jun 9, 2023
61a5c87
docs.
fisx Jun 11, 2023
87b2e52
Merge branch 'FS-1115' of github.com:lepsa/wire-server into FS-1179-g…
lepsa Jun 15, 2023
e6a48e2
Merge remote-tracking branch 'origin/develop' into FS-1179-galley
lepsa Jun 15, 2023
3a35a64
FS-1179: Add an internal endpoint for deleting a federation domain
lepsa Jun 15, 2023
1dc2112
FS-1179: Adding a defederation worker to background worker
lepsa Jun 15, 2023
a9519eb
FS-1179: Some timeout config for the background worker.
lepsa Jun 15, 2023
74caf82
Keeping brig and backend worker in sync
lepsa Jun 15, 2023
6c1ecd7
Merge remote-tracking branch 'origin/develop' into FS-1115
battermann Jun 19, 2023
28d87c9
Merge branch 'develop' into FS-1115
battermann Jun 19, 2023
977fd77
WIP: New tests and various changes to background worker
lepsa Jun 20, 2023
0080e89
hi ci
fisx Jun 20, 2023
ab9c14a
Tweak docs.
fisx Jun 20, 2023
57746ee
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx Jun 20, 2023
046b87b
nit-pick.
fisx Jun 20, 2023
f577998
Mark test case as flaky.
fisx Jun 20, 2023
4f28941
Tweak log levels.
fisx Jun 20, 2023
5908f7a
Tweak log msg.
fisx Jun 20, 2023
8ea7eb6
wip
lepsa Jun 21, 2023
582b654
Update libs/wire-api/src/Wire/API/Routes/Internal/Brig.hs
lepsa Jun 21, 2023
a5e4840
Update docs/src/understand/configure-federation.md
lepsa Jun 21, 2023
bb5455c
Update services/brig/src/Brig/API/Internal.hs
lepsa Jun 21, 2023
ac6a5c2
Update services/brig/src/Brig/API/Internal.hs
lepsa Jun 21, 2023
f44ff72
Update services/brig/src/Brig/API/Internal.hs
lepsa Jun 21, 2023
a753af5
Update services/federator/src/Federator/Run.hs
lepsa Jun 21, 2023
b0f24b5
Update services/galley/src/Galley/App.hs
lepsa Jun 21, 2023
c1588b4
FS-1115: PR notes
lepsa Jun 21, 2023
9494a19
try fix helm charts
battermann Jun 21, 2023
d348831
Merge remote-tracking branch 'lepsa/FS-1115' into FS-1179-galley
lepsa Jun 22, 2023
553ee0d
WIP
lepsa Jun 22, 2023
d1b4f1c
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx Jun 22, 2023
d649710
hi ci
battermann Jun 22, 2023
0008cf8
changed federation strategy in CI from allowDynamic to allowAll
battermann Jun 22, 2023
37baaf6
Merge branch 'develop' into FS-1115
battermann Jun 22, 2023
131b12b
Merge remote-tracking branch 'lepsa/FS-1115' into FS-1179-galley
lepsa Jun 23, 2023
8d8242a
correct error in case of allowDynamic
battermann Jun 23, 2023
0a1b730
default case made explicit
battermann Jun 23, 2023
75ec8e6
Merge remote-tracking branch 'refs/remotes/owen/FS-1115' into FS-1115
fisx Jun 23, 2023
2988c1a
Merge remote-tracking branch 'lepsa/FS-1115' into FS-1179-galley
lepsa Jun 26, 2023
57fb696
FS-1179: Modifications to tests to help stop hangups
lepsa Jun 26, 2023
7b8d78c
Cleaning up comments
lepsa Jun 26, 2023
81ae556
Merge remote-tracking branch 'origin/develop' into FS-1115
fisx Jun 26, 2023
22e7798
Create use domain names in integration tests.
fisx Jun 26, 2023
866f52b
Better errors in /integration.
fisx Jun 26, 2023
372c71c
nit-picks.
fisx Jun 26, 2023
88bf195
Better errors in /integration.
fisx Jun 26, 2023
2ba8dd6
revert commit noise.
fisx Jun 26, 2023
a20a21a
Fix `make list-flaky-tests`.
fisx Jun 26, 2023
354252d
nit-picks, renames, minor refactorings.
fisx Jun 26, 2023
a2432df
s/type/newtype/
fisx Jun 26, 2023
3318c4a
Polish Wire.API.FederationUpdate (names and declaration order).
fisx Jun 26, 2023
47ae909
Fix: Always cancel `syncFedDomainUpdateThread`.
fisx Jun 26, 2023
a830cdb
hi ci
fisx Jun 26, 2023
47b2c24
Merge remote-tracking branch 'lepsa/FS-1115' into FS-1179-galley
lepsa Jun 27, 2023
3931f89
Fixing things post-merge
lepsa Jun 27, 2023
5d8c001
Adding a changelog entry
lepsa Jun 27, 2023
4ed00ce
FS-1179: Brig now deletes the notification queue for deleted domains
lepsa Jun 27, 2023
4e58cbb
FS-1179: Removing and errant import
lepsa Jun 27, 2023
0f83de8
FS-1179: PR sanitisation.
lepsa Jun 27, 2023
f3b57ea
Merge remote-tracking branch 'origin/develop' into FS-1179-galley
lepsa Jun 27, 2023
f1a47fe
Merge remote-tracking branch 'origin/develop' into FS-1179-galley
lepsa Jun 28, 2023
ae58130
FS-1179: Updating a TODO
lepsa Jun 28, 2023
88b1e43
FS-1179: Writing cleanup code so that we don't have dangling threads
lepsa Jun 28, 2023
92b777b
FS-1179: PR formatting
lepsa Jun 28, 2023
6439de9
Merge remote-tracking branch 'origin/develop' into FS-1179-galley
lepsa Jun 29, 2023
0513524
PR formatting
lepsa Jun 29, 2023
28ceb08
More comments and exception handling
lepsa Jun 29, 2023
e397f76
Fixing tests now that they have moved to hspec
lepsa Jun 29, 2023
642af64
Formatting
lepsa Jun 29, 2023
c90889c
Fix background-worker integration tests.
fisx Jun 29, 2023
772aad3
Merge remote-tracking branch 'origin/develop' into FS-1179-galley
lepsa Jun 30, 2023
4b105c5
Merge remote-tracking branch 'lepsa/FS-1179-galley' into FS-1179-galley
lepsa Jun 30, 2023
3123028
Updating the internal notes
lepsa Jun 30, 2023
c352e1b
WPB-240: Initial implementation of notifications sending for defedera…
lepsa Jun 30, 2023
ec51ff2
Merge remote-tracking branch 'origin/develop' into FS-1179-galley
fisx Jul 2, 2023
cbbf535
Removing a redundant language extension
lepsa Jul 3, 2023
42b04b4
Removing a redundant language extension
lepsa Jul 3, 2023
2394deb
Merge remote-tracking branch 'lepsa/FS-1179-galley' into WPB-240
lepsa Jul 3, 2023
9a2df02
Merge branch 'WPB-240' of github.com:lepsa/wire-server into WPB-240
lepsa Jul 4, 2023
020bf6c
WPB-240: Matching event fanout count to the limit in options.
lepsa Jul 4, 2023
8be415a
WPB-240: Comments and code in tests for quickly filling the DB
lepsa Jul 5, 2023
9bd4816
Merge remote-tracking branch 'origin/develop' into FS-1179-galley
lepsa Jul 5, 2023
37cbed9
FS-1179: Reworking after a discussion with Akshay about how to use AMQP.
lepsa Jul 5, 2023
3048b3d
Merge remote-tracking branch 'lepsa/FS-1179-galley' into WPB-240
lepsa Jul 5, 2023
92da980
PR formatting
lepsa Jul 5, 2023
049d526
Merge remote-tracking branch 'lepsa/FS-1179-galley' into WPB-240
lepsa Jul 5, 2023
2af54f5
Hi CI
lepsa Jul 5, 2023
456235a
FS-1179: Adding galley and brig to background-worker's configmap
lepsa Jul 5, 2023
8692dfd
Merge remote-tracking branch 'origin/develop' into FS-1179-galley
lepsa Jul 6, 2023
32b5e05
FS-1179: Removing the confusing "integration" tests for background-wo…
lepsa Jul 10, 2023
b0355f7
PR notes
lepsa Jul 10, 2023
c376e07
Merge remote-tracking branch 'origin/develop' into FS-1179-galley
fisx Jul 11, 2023
c4c28aa
`make sanitize-pr`.
fisx Jul 11, 2023
48cb312
Fixup
fisx Jul 11, 2023
2085ed9
Merge remote-tracking branch 'refs/remotes/owen/FS-1179-galley' into …
fisx Jul 11, 2023
4494d06
Changing the format of federation.delete.
lepsa Jul 12, 2023
17ae61f
Merge remote-tracking branch 'origin/develop' into FS-1179-galley
lepsa Jul 12, 2023
d0cabf2
Sanitizing code
lepsa Jul 12, 2023
a8c8b51
Merge remote-tracking branch 'origin/develop' into FS-1179-galley
fisx Jul 12, 2023
bebc4ad
FS-1179: Removing dead code and bumping schema migrations
lepsa Jul 13, 2023
7a67199
FS-1179: Removing more dead code
lepsa Jul 13, 2023
d5952e7
PR formatting
lepsa Jul 14, 2023
0b33f11
Hi CI
lepsa Jul 14, 2023
692e851
Merge remote-tracking branch 'lepsa/FS-1179-galley' into WPB-240
lepsa Jul 17, 2023
097e6b9
Merge remote-tracking branch 'origin/develop' into WPB-240
lepsa Jul 18, 2023
5a5ed57
WPB-240: Formatting code
lepsa Jul 18, 2023
2f0b500
WPB-240: Changelog entries
lepsa Jul 18, 2023
9e0349a
WPB-240: Removing dead code
lepsa Jul 18, 2023
a41a371
WPB-240: Moving notification code into an effect, as mentioned in PR.
lepsa Jul 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.d/1-api-changes/WPB-240
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Added a new notification event type, "federation.delete".
This event contains a single domain for a remote server that the local server is de-federating from.
This notification is sent twice during de-federation. Once before and once after cleaning up and removing references to the remote server from the local database.
1 change: 1 addition & 0 deletions changelog.d/6-federation/WPB-240
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
De-federating from a remote server sends a pair of notifications to clients, announcing which server will no longer be federated with.
64 changes: 64 additions & 0 deletions libs/wire-api/src/Wire/API/Event/Federation.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module Wire.API.Event.Federation
( Event (..),
EventType (..),
)
where

import Data.Aeson (FromJSON, ToJSON)
import qualified Data.Aeson as A
import qualified Data.Aeson.KeyMap as KeyMap
import Data.Domain
import Data.Json.Util (ToJSONObject (toJSONObject))
import Data.Schema
import qualified Data.Swagger as S
import Imports
import Wire.Arbitrary

data Event = Event
{ _eventType :: EventType,
_eventDomain :: Domain
}
deriving (Eq, Show, Ord, Generic)

instance Arbitrary Event where
arbitrary =
Event
<$> arbitrary
<*> arbitrary

data EventType
= FederationDelete
deriving (Eq, Show, Ord, Generic)
deriving (Arbitrary) via (GenericUniform EventType)
deriving (A.FromJSON, A.ToJSON, S.ToSchema) via Schema EventType

instance ToSchema EventType where
schema =
enum @Text "EventType" $
mconcat
[ element "federation.delete" FederationDelete
]

eventObjectSchema :: ObjectSchema SwaggerDoc Event
eventObjectSchema =
Event
<$> _eventType .= field "type" schema
<*> _eventDomain .= field "domain" schema

instance ToSchema Event where
schema = object "Event" eventObjectSchema

instance ToJSONObject Event where
toJSONObject =
KeyMap.fromList
. fromMaybe []
. schemaOut eventObjectSchema

instance S.ToSchema Event where
declareNamedSchema = schemaToSwagger

instance FromJSON Event where
parseJSON = schemaParseJSON

instance ToJSON Event where
toJSON = schemaToJSON
1 change: 1 addition & 0 deletions libs/wire-api/wire-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ library
Wire.API.Error.Gundeck
Wire.API.Event.Conversation
Wire.API.Event.FeatureConfig
Wire.API.Event.Federation
Wire.API.Event.Team
Wire.API.FederationStatus
Wire.API.FederationUpdate
Expand Down
2 changes: 2 additions & 0 deletions services/galley/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
, conduit
, containers
, cookie
, cql-io
, cryptonite
, currency-codes
, data-default
Expand Down Expand Up @@ -149,6 +150,7 @@ mkDerivation {
cereal
comonad
containers
cql-io
cryptonite
currency-codes
data-default
Expand Down
1 change: 1 addition & 0 deletions services/galley/galley.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ library
, cereal >=0.4
, comonad
, containers >=0.5
, cql-io
, cryptonite
, currency-codes >=2.0
, data-default >=0.5
Expand Down
41 changes: 39 additions & 2 deletions services/galley/src/Galley/API/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Galley.API.Internal
)
where

import Cassandra (ClientState, Consistency (LocalQuorum), Page (..), paramsP)
import Control.Exception
import Control.Exception.Safe (catchAny)
import Control.Lens hiding (Getter, Setter, (.=))
Expand All @@ -39,6 +40,7 @@ import Data.Range
import Data.Singletons
import Data.Text (unpack)
import Data.Time
import Database.CQL.IO (paginate)
import Galley.API.Action
import qualified Galley.API.Clients as Clients
import qualified Galley.API.Create as Create
Expand All @@ -59,12 +61,16 @@ import Galley.API.Teams.Features
import qualified Galley.API.Update as Update
import Galley.API.Util
import Galley.App
import Galley.Cassandra.Conversation.Members
import Galley.Cassandra.Queries
import Galley.Cassandra.Store (embedClient)
import qualified Galley.Data.Conversation as Data
import Galley.Data.Conversation.Types
import Galley.Effects
import Galley.Effects.BackendNotificationQueueAccess
import Galley.Effects.ClientStore
import Galley.Effects.ConversationStore
import Galley.Effects.ExternalAccess
import Galley.Effects.FederatorAccess
import Galley.Effects.GundeckAccess
import Galley.Effects.LegalHoldStore as LegalHoldStore
Expand All @@ -73,7 +79,9 @@ import qualified Galley.Effects.MemberStore as E
import Galley.Effects.ProposalStore
import Galley.Effects.TeamStore
import qualified Galley.Effects.TeamStore as E
import Galley.Env (currentFanoutLimit, _options)
import qualified Galley.Intra.Push as Intra
import Galley.Intra.Push.Internal (pushEventJson)
import Galley.Monad
import Galley.Options
import qualified Galley.Queue as Q
Expand All @@ -85,8 +93,8 @@ import Imports hiding (head)
import qualified Network.AMQP as Q
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Predicate hiding (Error, err, setStatus)
import qualified Network.Wai.Predicate as Predicate
import Network.Wai.Predicate hiding (Error, err, result, setStatus)
import qualified Network.Wai.Predicate as Predicate hiding (result)
import Network.Wai.Routing hiding (App, route, toList)
import Network.Wai.Utilities hiding (Error)
import Network.Wai.Utilities.ZAuth
Expand All @@ -106,6 +114,7 @@ import Wire.API.CustomBackend
import Wire.API.Error
import Wire.API.Error.Galley
import Wire.API.Event.Conversation
import qualified Wire.API.Event.Federation as Federation
import Wire.API.Federation.API
import Wire.API.Federation.API.Galley
import qualified Wire.API.Federation.API.Galley as F
Expand Down Expand Up @@ -534,6 +543,7 @@ internalDeleteFederationDomainH ::
Member MemberStore r,
Member ConversationStore r,
Member (Embed IO) r,
Member (Input ClientState) r,
Member CodeStore r,
Member TeamStore r,
Member BrigAccess r,
Expand All @@ -543,8 +553,35 @@ internalDeleteFederationDomainH ::
Domain ::: JSON ->
Sem r Response
internalDeleteFederationDomainH (domain ::: _) = do
-- We have to send the same event twice.
-- Once before and once after defederation work.
-- https://wearezeta.atlassian.net/wiki/spaces/ENGINEERIN/pages/809238539/Use+case+Stopping+to+federate+with+a+domain
void sendNotifications
deleteFederationDomain domain
void sendNotifications
pure (empty & setStatus status200)
where
sendNotifications = do
maxPage <- inputs $ fromRange . currentFanoutLimit . _options -- This is based on the limits in removeIfLargeFanout
page <- embedClient $ paginate selectAllMembers (paramsP LocalQuorum () maxPage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this should be an effect, instead of accessed directly, but I'm not sure what we want to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a new effect for this.

sendNotificationPage page
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we void here instead of the call sites?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the void in front of this call.

pushEvents results = do
let (bots, mems) = localBotsAndUsers results
recipients = Intra.recipient <$> mems
event = Intra.FederationEvent $ Federation.Event Federation.FederationDelete domain
for_ (Intra.newPush ListComplete Nothing event recipients) $ \p -> do
-- TODO: Transient or not?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO or Futurework?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Futurework, I think.

-- RouteAny is used as it will wake up mobile clients
-- and notify them of the changes to federation state.
push1 $ p & Intra.pushRoute .~ Intra.RouteAny
deliverAsync (bots `zip` repeat (pushEventJson event))
sendNotificationPage page = do
let res = result page
mems = mapMaybe toMember res
pushEvents mems
when (hasMore page) $ do
page' <- embedClient $ nextPage page
sendNotificationPage page'

-- Remove remote members from local conversations
deleteFederationDomainRemoteUserFromLocalConversations ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
module Galley.Cassandra.Conversation.Members
( addMembers,
members,
allMembers,
toMember,
lookupRemoteMembers,
removeMembersFromLocalConv,
toMemberStatus,
Expand Down Expand Up @@ -122,6 +124,11 @@ members conv =
fmap (mapMaybe toMember) . retry x1 $
query Cql.selectMembers (params LocalQuorum (Identity conv))

allMembers :: Client [LocalMember]
allMembers =
fmap (mapMaybe toMember) . retry x1 $
query Cql.selectAllMembers (params LocalQuorum ())

toMemberStatus ::
( -- otr muted
Maybe MutedStatus,
Expand Down Expand Up @@ -386,6 +393,7 @@ interpretMemberStoreToCassandra = interpret $ \case
CreateBotMember sr bid cid -> embedClient $ addBotMember sr bid cid
GetLocalMember cid uid -> embedClient $ member cid uid
GetLocalMembers cid -> embedClient $ members cid
GetAllLocalMembers -> embedClient allMembers
GetRemoteMember cid uid -> embedClient $ lookupRemoteMember cid (tDomain uid) (tUnqualified uid)
GetRemoteMembers rcid -> embedClient $ lookupRemoteMembers rcid
CheckLocalMemberRemoteConv uid rcnv -> fmap (not . null) $ embedClient $ lookupLocalMemberRemoteConv uid rcnv
Expand Down
3 changes: 3 additions & 0 deletions services/galley/src/Galley/Cassandra/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ selectMember = "select user, service, provider, status, otr_muted_status, otr_mu
selectMembers :: PrepQuery R (Identity ConvId) (UserId, Maybe ServiceId, Maybe ProviderId, Maybe MemberStatus, Maybe MutedStatus, Maybe Text, Maybe Bool, Maybe Text, Maybe Bool, Maybe Text, Maybe RoleName)
selectMembers = "select user, service, provider, status, otr_muted_status, otr_muted_ref, otr_archived, otr_archived_ref, hidden, hidden_ref, conversation_role from member where conv = ?"

selectAllMembers :: PrepQuery R () (UserId, Maybe ServiceId, Maybe ProviderId, Maybe MemberStatus, Maybe MutedStatus, Maybe Text, Maybe Bool, Maybe Text, Maybe Bool, Maybe Text, Maybe RoleName)
selectAllMembers = "select user, service, provider, status, otr_muted_status, otr_muted_ref, otr_archived, otr_archived_ref, hidden, hidden_ref, conversation_role from member"

insertMember :: PrepQuery W (ConvId, UserId, Maybe ServiceId, Maybe ProviderId, RoleName) ()
insertMember = "insert into member (conv, user, service, provider, status, conversation_role) values (?, ?, ?, ?, 0, ?)"

Expand Down
3 changes: 2 additions & 1 deletion services/galley/src/Galley/Effects/ExternalAccess.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Galley.Effects.ExternalAccess
)
where

import Data.Aeson
import Data.Id
import Galley.Data.Services
import Imports
Expand All @@ -34,7 +35,7 @@ import Wire.API.Event.Conversation

data ExternalAccess m a where
Deliver :: Foldable f => f (BotMember, Event) -> ExternalAccess m [BotMember]
DeliverAsync :: Foldable f => f (BotMember, Event) -> ExternalAccess m ()
DeliverAsync :: (ToJSON e, Foldable f) => f (BotMember, e) -> ExternalAccess m ()
DeliverAndDeleteAsync :: Foldable f => ConvId -> f (BotMember, Event) -> ExternalAccess m ()

makeSem ''ExternalAccess
2 changes: 2 additions & 0 deletions services/galley/src/Galley/Effects/MemberStore.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Galley.Effects.MemberStore
-- * Read members
getLocalMember,
getLocalMembers,
getAllLocalMembers,
getRemoteMember,
getRemoteMembers,
checkLocalMemberRemoteConv,
Expand Down Expand Up @@ -70,6 +71,7 @@ data MemberStore m a where
CreateBotMember :: ServiceRef -> BotId -> ConvId -> MemberStore m BotMember
GetLocalMember :: ConvId -> UserId -> MemberStore m (Maybe LocalMember)
GetLocalMembers :: ConvId -> MemberStore m [LocalMember]
GetAllLocalMembers :: MemberStore m [LocalMember]
GetRemoteMember :: ConvId -> Remote UserId -> MemberStore m (Maybe RemoteMember)
GetRemoteMembers :: ConvId -> MemberStore m [RemoteMember]
CheckLocalMemberRemoteConv :: UserId -> Remote ConvId -> MemberStore m Bool
Expand Down
9 changes: 5 additions & 4 deletions services/galley/src/Galley/External.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Bilge.Request
import Bilge.Retry (httpHandlers)
import Control.Lens
import Control.Retry
import Data.Aeson (ToJSON)
import Data.ByteString.Conversion.To
import Data.Id
import Data.Misc
Expand Down Expand Up @@ -60,7 +61,7 @@ interpretExternalAccess = interpret $ \case
-- | Like deliver, but ignore orphaned bots and return immediately.
--
-- FUTUREWORK: Check if this can be removed.
deliverAsync :: [(BotMember, Event)] -> App ()
deliverAsync :: ToJSON e => [(BotMember, e)] -> App ()
deliverAsync = void . forkIO . void . deliver

-- | Like deliver, but remove orphaned bots and return immediately.
Expand All @@ -69,10 +70,10 @@ deliverAndDeleteAsync cnv pushes = void . forkIO $ do
gone <- deliver pushes
mapM_ (deleteBot cnv . botMemId) gone

deliver :: [(BotMember, Event)] -> App [BotMember]
deliver :: forall e. ToJSON e => [(BotMember, e)] -> App [BotMember]
deliver pp = mapM (async . exec) pp >>= foldM eval [] . zip (map fst pp)
where
exec :: (BotMember, Event) -> App Bool
exec :: (BotMember, e) -> App Bool
exec (b, e) =
lookupService (botMemService b) >>= \case
Nothing -> pure False
Expand Down Expand Up @@ -118,7 +119,7 @@ deliver pp = mapM (async . exec) pp >>= foldM eval [] . zip (map fst pp)

-- Internal -------------------------------------------------------------------

deliver1 :: Service -> BotMember -> Event -> App ()
deliver1 :: ToJSON e => Service -> BotMember -> e -> App ()
deliver1 s bm e
| s ^. serviceEnabled = do
let t = toByteString' (s ^. serviceToken)
Expand Down
3 changes: 3 additions & 0 deletions services/galley/src/Galley/Intra/Push/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ import Imports hiding (forkIO)
import UnliftIO.Async (mapConcurrently_)
import Wire.API.Event.Conversation (Event (evtFrom))
import qualified Wire.API.Event.FeatureConfig as FeatureConfig
import qualified Wire.API.Event.Federation as Federation
import qualified Wire.API.Event.Team as Teams
import Wire.API.Team.Member

data PushEvent
= ConvEvent Event
| TeamEvent Teams.Event
| FeatureConfigEvent FeatureConfig.Event
| FederationEvent Federation.Event

pushEventJson :: PushEvent -> Object
pushEventJson (ConvEvent e) = toJSONObject e
pushEventJson (TeamEvent e) = toJSONObject e
pushEventJson (FeatureConfigEvent e) = toJSONObject e
pushEventJson (FederationEvent e) = toJSONObject e

data RecipientBy user = Recipient
{ _recipientUserId :: user,
Expand Down
Loading