Skip to content
Merged
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
2 changes: 1 addition & 1 deletion changelog.d/5-internal/WPB-23789
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Progressively move away from singletons to type class to allow progressive migration to `wire-subsystems` of Galley's actions.
Drop `Galley.Intra.Util`,`Galley.Effects`, and `Galley.API.MLS.Commit`. (#5075, #5081, #5086, #5087, #5098, #5101, #5102, #5103)
Drop `Galley.Intra.Util`,`Galley.Effects`, `Galley.API.MLS.Commit`, and `Galley.API.Push`. (#5075, #5081, #5086, #5087, #5098, #5101, #5102, #5103, #5104)
70 changes: 69 additions & 1 deletion libs/wire-subsystems/src/Wire/NotificationSubsystem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ import Control.Lens (view)
import Data.Aeson
import Data.Default
import Data.Id
import Data.Json.Util
import Data.List.NonEmpty qualified as NonEmpty
import Data.Map qualified as Map
import Data.Qualified
import Imports
import Polysemy
import Polysemy.TinyLog
import System.Logger.Class qualified as Log
import Wire.API.Event.Conversation
import Wire.API.Federation.API.Galley.Notifications (ConversationUpdate)
import Wire.API.Message
import Wire.API.Push.V2 hiding (Push (..), Recipient, newPush)
import Wire.API.Push.V2 qualified as PushV2
import Wire.API.Team.Member
import Wire.API.Team.Member qualified as Mem
import Wire.Arbitrary
import Wire.StoredConversation (LocalMember (..))
import Wire.ExternalAccess
import Wire.StoredConversation (BotMember, LocalMember (..))

data Recipient = Recipient
{ recipientUserId :: UserId,
Expand Down Expand Up @@ -107,3 +115,63 @@ instance Default Push where

newPushLocal :: UserId -> Push
newPushLocal uid = def {origin = Just uid}

-- * Message-related

data MessagePush
= MessagePush (Maybe ConnId) MessageMetadata [Recipient] [BotMember] Event

type BotMap = Map UserId BotMember

class ToRecipient a where
toRecipient :: a -> Recipient

instance ToRecipient (UserId, ClientId) where
toRecipient (u, c) = Recipient u (RecipientClientsSome (NonEmpty.singleton c))

instance ToRecipient Recipient where
toRecipient = id

newMessagePush ::
(ToRecipient r) =>
BotMap ->
Maybe ConnId ->
MessageMetadata ->
[r] ->
Event ->
MessagePush
newMessagePush botMap mconn mm userOrBots event =
let toPair r = case Map.lookup (recipientUserId r) botMap of
Just botMember -> ([], [botMember])
Nothing -> ([r], [])
(recipients, botMembers) = foldMap (toPair . toRecipient) userOrBots
in MessagePush mconn mm recipients botMembers event

runMessagePush ::
forall x r.
( Member ExternalAccess r,
Member TinyLog r,
Member NotificationSubsystem r
) =>
Local x ->
Maybe (Qualified ConvId) ->
MessagePush ->
Sem r ()
runMessagePush loc mqcnv mp@(MessagePush _ _ _ botMembers event) = do
pushNotifications [toPush mp]
for_ mqcnv $ \qcnv ->
if tDomain loc /= qDomain qcnv
then unless (null botMembers) $ do
warn $ Log.msg ("Ignoring messages for local bots in a remote conversation" :: ByteString) . Log.field "conversation" (show qcnv)
else deliverAndDeleteAsync (qUnqualified qcnv) (map (,event) botMembers)

toPush :: MessagePush -> Push
toPush (MessagePush mconn mm rs _ event) =
def
{ origin = Just (qUnqualified (eventFromUserId (evtFrom event))),
conn = mconn,
json = toJSONObject event,
recipients = rs,
route = bool RouteDirect RouteAny (mmNativePush mm),
transient = mmTransient mm
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ toV2Push p =
pload :: NonEmpty Object
pload = NonEmpty.singleton p.json
recipients :: [V2.Recipient]
recipients = map toRecipient $ toList p.recipients
toRecipient :: Recipient -> V2.Recipient
toRecipient r =
recipients = map toV2Recipient $ toList p.recipients
toV2Recipient :: Recipient -> V2.Recipient
toV2Recipient r =
(recipient r.recipientUserId p.route)
{ V2._recipientClients = r.recipientClients
}
Expand Down
1 change: 0 additions & 1 deletion services/galley/galley.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ library
Galley.API.Public.TeamConversation
Galley.API.Public.TeamMember
Galley.API.Public.TeamNotification
Galley.API.Push
Galley.API.Query
Galley.API.Teams
Galley.API.Teams.Export
Expand Down
1 change: 0 additions & 1 deletion services/galley/src/Galley/API/Federation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import Galley.API.MLS.Welcome
import Galley.API.Mapping
import Galley.API.Mapping qualified as Mapping
import Galley.API.Message
import Galley.API.Push
import Galley.App
import Galley.Options
import Galley.Types.Conversations.One2One
Expand Down
1 change: 0 additions & 1 deletion services/galley/src/Galley/API/MLS/Propagate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import Data.Json.Util
import Data.List.NonEmpty (NonEmpty, nonEmpty)
import Data.Map qualified as Map
import Data.Qualified
import Galley.API.Push
import Imports
import Network.AMQP qualified as Q
import Polysemy
Expand Down
1 change: 0 additions & 1 deletion services/galley/src/Galley/API/MLS/Welcome.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import Data.Json.Util
import Data.Map qualified as Map
import Data.Qualified
import Data.Time
import Galley.API.Push
import Imports
import Network.Wai.Utilities.JSONResponse
import Polysemy
Expand Down
3 changes: 1 addition & 2 deletions services/galley/src/Galley/API/Message.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import Data.Set qualified as Set
import Data.Set.Lens
import Data.Time.Clock (UTCTime)
import Galley.API.LegalHold.Conflicts
import Galley.API.Push
import Galley.Options
import Galley.Types.Clients qualified as Clients
import Imports hiding (forkIO)
Expand Down Expand Up @@ -83,7 +82,7 @@ import Wire.ConversationSubsystem qualified as ConvSubsystem
import Wire.ConversationSubsystem.Util
import Wire.ExternalAccess
import Wire.FederationAPIAccess
import Wire.NotificationSubsystem (NotificationSubsystem)
import Wire.NotificationSubsystem (BotMap, NotificationSubsystem, newMessagePush, runMessagePush)
import Wire.Sem.Now (Now)
import Wire.Sem.Now qualified as Now
import Wire.StoredConversation
Expand Down
105 changes: 0 additions & 105 deletions services/galley/src/Galley/API/Push.hs

This file was deleted.