Skip to content
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

Pydio events #4442

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Allow empty recipient list
  • Loading branch information
pcapriotti committed Feb 5, 2025
commit 50a11d7669542ceec14f80af703e836bbf1d247a
4 changes: 2 additions & 2 deletions libs/wire-api/src/Wire/API/Push/V2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ data Push = Push
-- assumption that no 'ConnId' is used by two 'Recipient's. This is *probably* correct, but
-- not in any contract. (Changing this may require a new version module, since we need to
-- support both the old and the new data type simultaneously during upgrade.)
_pushRecipients :: Range 1 1024 (Set Recipient),
_pushRecipients :: Range 0 1024 (Set Recipient),
-- | Originating user
--
-- 'Nothing' here means that the originating user is on another backend.
Expand Down Expand Up @@ -262,7 +262,7 @@ data Push = Push
deriving (Eq, Show)
deriving (FromJSON, ToJSON, S.ToSchema) via (Schema Push)

newPush :: Maybe UserId -> Range 1 1024 (Set Recipient) -> List1 Object -> Push
newPush :: Maybe UserId -> Range 0 1024 (Set Recipient) -> List1 Object -> Push
newPush from to pload =
Push
{ _pushRecipients = to,
Expand Down
18 changes: 4 additions & 14 deletions libs/wire-subsystems/src/Wire/NotificationSubsystem.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{-# LANGUAGE TemplateHaskell #-}

{-# OPTIONS -Wwarn #-}

module Wire.NotificationSubsystem where

import Control.Concurrent.Async (Async)
import Control.Lens (makeLenses)
import Data.Aeson
import Data.Id
import Data.List.NonEmpty (NonEmpty ((:|)))
import Imports
import Polysemy
import Wire.API.Push.V2 hiding (Push (..), Recipient, newPush)
Expand All @@ -27,7 +24,7 @@ data Push = Push
_pushRoute :: Route,
_pushNativePriority :: Maybe Priority,
pushOrigin :: Maybe UserId,
_pushRecipients :: NonEmpty Recipient,
_pushRecipients :: [Recipient],
pushJson :: Object,
_pushApsData :: Maybe ApsData,
pushIsPydioEvent :: Bool
Expand Down Expand Up @@ -56,8 +53,8 @@ data NotificationSubsystem m a where

makeSem ''NotificationSubsystem

newPush1 :: Maybe UserId -> Object -> NonEmpty Recipient -> Bool -> Push
newPush1 from e rr isPydioEvent =
newPush :: Maybe UserId -> Object -> [Recipient] -> Bool -> Push
newPush from e rr isPydioEvent =
Push
{ _pushConn = Nothing,
_pushTransient = False,
Expand All @@ -70,12 +67,5 @@ newPush1 from e rr isPydioEvent =
pushIsPydioEvent = isPydioEvent
}

newPush :: Maybe UserId -> Object -> [Recipient] -> Bool -> Maybe Push
newPush _ _ [] _ = todo
newPush u e (r : rr) isPydioEvent = Just $ newPush1 u e (r :| rr) isPydioEvent

newPushLocal :: UserId -> Object -> [Recipient] -> Bool -> Maybe Push
newPushLocal :: UserId -> Object -> [Recipient] -> Bool -> Push
newPushLocal uid = newPush (Just uid)

newPushLocal1 :: UserId -> Object -> NonEmpty Recipient -> Bool -> Push
newPushLocal1 uid = newPush1 (Just uid)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Bilge (RequestId)
import Control.Concurrent.Async (Async)
import Control.Lens (set, (.~))
import Data.Aeson
import Data.List.NonEmpty (nonEmpty)
import Data.List1 (List1)
import Data.List1 qualified as List1
import Data.Proxy
Expand Down Expand Up @@ -155,7 +154,7 @@ chunkPushes maxRecipients
splitPush :: Natural -> Push -> (Push, Push)
splitPush n p =
let (r1, r2) = splitAt (fromIntegral n) (toList p._pushRecipients)
in (p {_pushRecipients = fromJust $ nonEmpty r1}, p {_pushRecipients = fromJust $ nonEmpty r2})
in (p {_pushRecipients = r1}, p {_pushRecipients = r2})

pushSlowlyImpl ::
( Member Delay r,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Control.Concurrent.Async (async, wait)
import Control.Exception (throwIO)
import Data.Data (Proxy (Proxy))
import Data.Id
import Data.List.NonEmpty (NonEmpty ((:|)), fromList)
import Data.List1 qualified as List1
import Data.Range (fromRange, toRange)
import Data.Set qualified as Set
Expand Down Expand Up @@ -54,7 +53,7 @@ spec = describe "NotificationSubsystem.Interpreter" do
_pushRoute = V2.RouteDirect,
_pushNativePriority = Nothing,
pushOrigin = Nothing,
_pushRecipients = Recipient user1 (V2.RecipientClientsSome clients1) :| [],
_pushRecipients = [Recipient user1 (V2.RecipientClientsSome clients1)],
pushJson = payload1,
_pushApsData = Nothing,
pushIsPydioEvent = False
Expand All @@ -67,8 +66,9 @@ spec = describe "NotificationSubsystem.Interpreter" do
_pushNativePriority = Just V2.LowPriority,
pushOrigin = Just origin2,
_pushRecipients =
Recipient user21 V2.RecipientClientsAll
:| [Recipient user22 V2.RecipientClientsAll],
[ Recipient user21 V2.RecipientClientsAll,
Recipient user22 V2.RecipientClientsAll
],
pushJson = payload2,
_pushApsData = Just apsData,
pushIsPydioEvent = False
Expand Down Expand Up @@ -107,7 +107,7 @@ spec = describe "NotificationSubsystem.Interpreter" do
origin2 <- generate arbitrary
(user21, user22) <- generate arbitrary
(payload1, payload2) <- generate $ resize 1 arbitrary
lotOfRecipients <- fromList <$> replicateM 31 (generate arbitrary)
lotOfRecipients <- replicateM 31 (generate arbitrary)
apsData <- generate arbitrary
let pushBiggerThanFanoutLimit =
Push
Expand All @@ -129,8 +129,9 @@ spec = describe "NotificationSubsystem.Interpreter" do
_pushNativePriority = Just V2.LowPriority,
pushOrigin = Just origin2,
_pushRecipients =
Recipient user21 V2.RecipientClientsAll
:| [Recipient user22 V2.RecipientClientsAll],
[ Recipient user21 V2.RecipientClientsAll,
Recipient user22 V2.RecipientClientsAll
],
pushJson = payload2,
_pushApsData = Just apsData,
pushIsPydioEvent = False
Expand Down Expand Up @@ -172,7 +173,7 @@ spec = describe "NotificationSubsystem.Interpreter" do
_pushRoute = V2.RouteDirect,
_pushNativePriority = Nothing,
pushOrigin = Nothing,
_pushRecipients = Recipient user1 (V2.RecipientClientsSome clients1) :| [],
_pushRecipients = [Recipient user1 (V2.RecipientClientsSome clients1)],
pushJson = payload1,
_pushApsData = Nothing,
pushIsPydioEvent = False
Expand All @@ -185,8 +186,9 @@ spec = describe "NotificationSubsystem.Interpreter" do
_pushNativePriority = Just V2.LowPriority,
pushOrigin = Just origin2,
_pushRecipients =
Recipient user21 V2.RecipientClientsAll
:| [Recipient user22 V2.RecipientClientsAll],
[ Recipient user21 V2.RecipientClientsAll,
Recipient user22 V2.RecipientClientsAll
],
pushJson = payload2,
_pushApsData = Nothing,
pushIsPydioEvent = False
Expand Down Expand Up @@ -230,7 +232,7 @@ spec = describe "NotificationSubsystem.Interpreter" do
_pushRoute = V2.RouteDirect,
_pushNativePriority = Nothing,
pushOrigin = Nothing,
_pushRecipients = Recipient user1 (V2.RecipientClientsSome clients1) :| [],
_pushRecipients = [Recipient user1 (V2.RecipientClientsSome clients1)],
pushJson = payload1,
_pushApsData = Nothing,
pushIsPydioEvent = False
Expand Down Expand Up @@ -361,7 +363,7 @@ waitUntilPushes pushesRef n = do
normalisePush :: Push -> [Push]
normalisePush p =
map
(\r -> p {_pushRecipients = r :| []})
(\r -> p {_pushRecipients = [r]})
(toList (_pushRecipients p))

sizeOfChunks :: [Push] -> Natural
Expand Down
6 changes: 3 additions & 3 deletions services/brig/src/Brig/IO/Intra.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ onClientEvent ::
Sem r ()
onClientEvent orig conn e = do
let event = ClientEvent e
let rcps = Recipient orig V2.RecipientClientsAll :| []
let rcpt = Recipient orig V2.RecipientClientsAll
pushNotifications
[ newPush1 (Just orig) (toJSONObject event) rcps False
[ newPush (Just orig) (toJSONObject event) [rcpt] False
& pushConn .~ conn
& pushApsData .~ toApsData event
]
Expand Down Expand Up @@ -356,7 +356,7 @@ notify ::
notify event orig route conn recipients = do
rs <- (\u -> Recipient u RecipientClientsAll) <$$> recipients
let push =
newPush1 (Just orig) (toJSONObject event) rs False
newPush (Just orig) (toJSONObject event) (toList rs) False
& pushConn .~ conn
& pushRoute .~ route
& pushApsData .~ toApsData event
Expand Down
13 changes: 6 additions & 7 deletions services/galley/src/Galley/API/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,10 +1099,9 @@ pushTypingIndicatorEvents ::
Sem r ()
pushTypingIndicatorEvents qusr tEvent users mcon qcnv ts = do
let e = Event qcnv Nothing qusr tEvent (EdTyping ts)
for_ (newPushLocal (qUnqualified qusr) (toJSONObject e) (userRecipient <$> users) False) $ \p ->
pushNotifications
[ p
& pushConn .~ mcon
& pushRoute .~ PushV2.RouteDirect
& pushTransient .~ True
]
pushNotifications
[ newPushLocal (qUnqualified qusr) (toJSONObject e) (userRecipient <$> users) False
& pushConn .~ mcon
& pushRoute .~ PushV2.RouteDirect
& pushTransient .~ True
]
25 changes: 11 additions & 14 deletions services/galley/src/Galley/API/Create.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import Control.Error (headMay)
import Control.Lens hiding ((??))
import Data.Id
import Data.Json.Util
import Data.List.NonEmpty qualified as NonEmpty
import Data.Misc (FutureWork (FutureWork))
import Data.Qualified
import Data.Range
Expand Down Expand Up @@ -551,12 +550,11 @@ createConnectConversation lusr conn j = do
now <- input
let e = Event (tUntagged lcnv) Nothing (tUntagged lusr) now (EdConnect j)
notifyCreatedConversation lusr conn c
for_ (newPushLocal (tUnqualified lusr) (toJSONObject e) (localMemberToRecipient <$> Data.convLocalMembers c) (isPydioEvent $ evtType e)) $ \p ->
pushNotifications
[ p
& pushRoute .~ PushV2.RouteDirect
& pushConn .~ conn
]
pushNotifications
[ newPushLocal (tUnqualified lusr) (toJSONObject e) (localMemberToRecipient <$> Data.convLocalMembers c) (isPydioEvent $ evtType e)
& pushRoute .~ PushV2.RouteDirect
& pushConn .~ conn
]
conversationCreated lusr c
update n conv = do
let mems = Data.convLocalMembers conv
Expand Down Expand Up @@ -591,12 +589,11 @@ createConnectConversation lusr conn j = do
Nothing -> pure $ Data.convName conv
t <- input
let e = Event (tUntagged lcnv) Nothing (tUntagged lusr) t (EdConnect j)
for_ (newPushLocal (tUnqualified lusr) (toJSONObject e) (localMemberToRecipient <$> Data.convLocalMembers conv) (isPydioEvent $ evtType e)) $ \p ->
pushNotifications
[ p
& pushRoute .~ PushV2.RouteDirect
& pushConn .~ conn
]
pushNotifications
[ newPushLocal (tUnqualified lusr) (toJSONObject e) (localMemberToRecipient <$> Data.convLocalMembers conv) (isPydioEvent $ evtType e)
& pushRoute .~ PushV2.RouteDirect
& pushConn .~ conn
]
pure $ Data.convSetName n' conv
| otherwise = pure conv

Expand Down Expand Up @@ -691,7 +688,7 @@ notifyCreatedConversation lusr conn c = do
c' <- conversationViewWithCachedOthers remoteOthers localOthers c (qualifyAs lusr (lmId m))
let e = Event (tUntagged lconv) Nothing (tUntagged lusr) t (EdConversation c')
pure $
newPushLocal1 (tUnqualified lusr) (toJSONObject e) (NonEmpty.singleton (localMemberToRecipient m)) (isPydioEvent $ evtType e)
newPushLocal (tUnqualified lusr) (toJSONObject e) [localMemberToRecipient m] (isPydioEvent $ evtType e)
& pushConn .~ conn
& pushRoute .~ route

Expand Down
4 changes: 2 additions & 2 deletions services/galley/src/Galley/API/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ rmUser lusr conn = do
now
(EdMembersLeave EdReasonDeleted (QualifiedUserIdList [qUser]))
for_ (bucketRemote (fmap rmId (Data.convRemoteMembers c))) $ notifyRemoteMembers now qUser (Data.convId c)
pure $
pure . Just $
newPushLocal (tUnqualified lusr) (toJSONObject e) (localMemberToRecipient <$> Data.convLocalMembers c) (isPydioEvent $ evtType e)
<&> set pushConn conn
& set pushConn conn
. set pushRoute PushV2.RouteDirect
| otherwise -> pure Nothing

Expand Down
12 changes: 6 additions & 6 deletions services/galley/src/Galley/API/Push.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ runMessagePush ::
MessagePush ->
Sem r ()
runMessagePush loc mqcnv mp@(MessagePush _ _ _ botMembers event) = do
pushNotifications $ maybeToList $ toPush mp
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 -> Maybe Push
toPush :: MessagePush -> Push
toPush (MessagePush mconn mm rs _ event) =
let usr = qUnqualified (evtFrom event)
in newPush (Just usr) (toJSONObject event) rs False
<&> set pushConn mconn
. set pushNativePriority (mmNativePriority mm)
. set pushRoute (bool RouteDirect RouteAny (mmNativePush mm))
. set pushTransient (mmTransient mm)
& set pushConn mconn
. set pushNativePriority (mmNativePriority mm)
. set pushRoute (bool RouteDirect RouteAny (mmNativePush mm))
. set pushTransient (mmTransient mm)
Loading