Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions changelog.d/5-internal/WPB-23789
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### ConversationSubsystem Migration

* Move conversation-related operations into a unified Polysemy `ConversationSubsystem` effect across the wire-server codebase.
This consolidation improves code organization and separation of concerns for conversation logic.

* Library updates:
- Introduced dedicated error types for ConversationSubsystem to improve error handling
- Consolidated conversation-related operations that were previously scattered across multiple stores and subsystems
16 changes: 16 additions & 0 deletions libs/wire-api/src/Wire/API/Routes/Internal/Galley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Wire.API.Routes.Internal.Galley where
import Control.Lens ((.~))
import Data.Domain
import Data.Id as Id
import Data.LegalHold (UserLegalHoldStatus)
import Data.OpenApi (OpenApi, info, title)
import Data.Range
import GHC.TypeLits (AppendSymbol)
Expand Down Expand Up @@ -622,6 +623,21 @@ type IMiscAPI =
:> Capture "domain" Domain
:> MultiVerb1 'DELETE '[JSON] (RespondEmpty 200 "OK")
)
:<|> Named
"get-user-lh-status"
( "users"
:> Capture "uid" UserId
:> "lh-status"
:> QueryParam "team_id" TeamId
:> Get '[JSON] UserLegalHoldStatus
)
:<|> Named
"get-users-lh-status"
( "users"
:> "lh-status"
:> ReqBody '[JSON] UserIds
:> Post '[JSON] [(UserId, UserLegalHoldStatus)]
)

type IEJPDAPI =
Named
Expand Down
13 changes: 12 additions & 1 deletion libs/wire-api/src/Wire/API/Team/FeatureFlags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module Wire.API.Team.FeatureFlags
FeatureFlags,
FanoutLimit,
featureDefaults,
defaultFanoutLimit,
currentFanoutLimit,
notTeamMember,
findTeamMember,
isTeamMember,
Expand All @@ -42,7 +44,7 @@ import Data.ByteString.UTF8 qualified as UTF8
import Data.Default
import Data.Id (UserId)
import Data.OpenApi qualified as S
import Data.Range (Range)
import Data.Range (Range, fromRange, toRange, unsafeRange)
import Data.SOP
import Data.Schema
import Data.Set qualified as Set
Expand All @@ -53,6 +55,15 @@ import Wire.API.Team.Permission

type FanoutLimit = Range 1 HardTruncationLimit Int32

defaultFanoutLimit :: FanoutLimit
defaultFanoutLimit = toRange (Proxy @HardTruncationLimit)

currentFanoutLimit :: Word32 -> Maybe FanoutLimit -> FanoutLimit
currentFanoutLimit maxTeamSize maxFanoutSize =
let optFanoutLimit = fromIntegral . fromRange $ fromMaybe defaultFanoutLimit maxFanoutSize
maxSize = fromIntegral maxTeamSize
in unsafeRange (min maxSize optFanoutLimit)

-- | Used to extract the feature config type out of 'FeatureDefaults' or
-- related types.
type family ConfigOf a
Expand Down
6 changes: 6 additions & 0 deletions libs/wire-subsystems/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
, bytestring-conversion
, case-insensitive
, cassandra-util
, comonad
, conduit
, constraints
, containers
Expand Down Expand Up @@ -69,6 +70,7 @@
, imports
, iproute
, iso639
, kan-extensions
, lens
, lens-aeson
, lib
Expand Down Expand Up @@ -164,6 +166,7 @@ mkDerivation {
bytestring-conversion
case-insensitive
cassandra-util
comonad
conduit
constraints
containers
Expand Down Expand Up @@ -204,6 +207,7 @@ mkDerivation {
imports
iproute
iso639
kan-extensions
lens
lens-aeson
lrucaching
Expand Down Expand Up @@ -289,6 +293,7 @@ mkDerivation {
bytestring-conversion
case-insensitive
cassandra-util
comonad
conduit
constraints
containers
Expand Down Expand Up @@ -330,6 +335,7 @@ mkDerivation {
imports
iproute
iso639
kan-extensions
lens
lens-aeson
lrucaching
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import Wire.API.UserGroup
import Wire.BackgroundJobsPublisher
import Wire.BackgroundJobsRunner (BackgroundJobsRunner (..))
import Wire.ConversationStore (ConversationStore, getConversation, upsertMembers)
import Wire.ConversationSubsystem
import Wire.ConversationSubsystem hiding (getConversation)
import Wire.Sem.Random
import Wire.StoredConversation
import Wire.UserGroupStore (UserGroupStore, getUserGroup, getUserGroupChannels)
Expand Down
18 changes: 18 additions & 0 deletions libs/wire-subsystems/src/Wire/BrigAPIAccess.hs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ module Wire.BrigAPIAccess

-- * Account status
setAccountStatus,

-- * Assertions
ensureConnectedToLocals,
)
where

Expand All @@ -92,6 +95,7 @@ import Polysemy
import Polysemy.Error
import Web.Scim.Filter qualified as Scim
import Wire.API.Connection
import Wire.API.Error
import Wire.API.Error.Galley
import Wire.API.MLS.CipherSuite
import Wire.API.Routes.Internal.Brig
Expand Down Expand Up @@ -198,3 +202,17 @@ getConnectionsUnqualifiedBidi uids1 uids2 mrel1 mrel2 = do
res1 <- getConnectionsUnqualified uids1 (Just uids2) mrel1
res2 <- getConnectionsUnqualified uids2 (Just uids1) mrel2
pure (res1, res2)

ensureConnectedToLocals ::
( Member (ErrorS 'NotConnected) r,
Member BrigAPIAccess r
) =>
UserId ->
[UserId] ->
Sem r ()
ensureConnectedToLocals _ [] = pure ()
ensureConnectedToLocals u uids = do
(connsFrom, connsTo) <-
getConnectionsUnqualifiedBidi [u] uids (Just Accepted) (Just Accepted)
unless (length connsFrom == length uids && length connsTo == length uids) $
throwS @'NotConnected
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ addMembers conv (UserList lusers rusers) = do
-- User is remote, so we only add it to the member_remote_user
-- table, but the reverse mapping has to be done on the remote
-- backend; so we assume an additional call to their backend has
-- been (or will be) made separately. See Galley.API.Update.addMembers
-- been (or will be) made separately. See Wire.ConversationSubsystem.Update.addMembers
addPrepQuery Cql.insertRemoteMember (conv, domain, uid, role)

pure (map newMemberWithRole lusers, map newRemoteMemberWithRole rusers)
Expand Down
Loading