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 5 commits into
base: develop
Choose a base branch
from
Draft
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
10 changes: 10 additions & 0 deletions libs/wire-api/src/Wire/API/Event/Conversation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Wire.API.Event.Conversation
EventType (..),
EventData (..),
AddCodeResult (..),
isPydioEvent,

-- * Event lenses
_EdMembersJoin,
Expand Down Expand Up @@ -224,6 +225,15 @@ eventDataType (EdMLSWelcome _) = MLSWelcome
eventDataType EdConvDelete = ConvDelete
eventDataType (EdProtocolUpdate _) = ProtocolUpdate

isPydioEvent :: EventType -> Bool
isPydioEvent MemberJoin = True
isPydioEvent MemberLeave = True
isPydioEvent MemberStateUpdate = True
isPydioEvent ConvRename = True
isPydioEvent ConvCreate = True
isPydioEvent ConvDelete = True
isPydioEvent _ = False

--------------------------------------------------------------------------------
-- Event data helpers

Expand Down
12 changes: 8 additions & 4 deletions libs/wire-api/src/Wire/API/Push/V2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Wire.API.Push.V2
pushNativeAps,
pushNativePriority,
pushPayload,
pushIsPydioEvent,
singletonPayload,
Recipient (..),
RecipientClients (..),
Expand Down Expand Up @@ -226,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 @@ -255,12 +256,13 @@ data Push = Push
-- | Native push priority.
_pushNativePriority :: !Priority,
-- | Opaque payload
_pushPayload :: !(List1 Object)
_pushPayload :: !(List1 Object),
_pushIsPydioEvent :: !Bool
}
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 All @@ -272,7 +274,8 @@ newPush from to pload =
_pushNativeEncrypt = True,
_pushNativeAps = Nothing,
_pushNativePriority = HighPriority,
_pushPayload = pload
_pushPayload = pload,
_pushIsPydioEvent = False
}

singletonPayload :: (ToJSONObject a) => a -> List1 Object
Expand All @@ -298,6 +301,7 @@ instance ToSchema Push where
<*> (ifNot (== HighPriority) . _pushNativePriority)
.= maybe_ (fromMaybe HighPriority <$> optField "native_priority" schema)
<*> _pushPayload .= field "payload" schema
<*> _pushIsPydioEvent .= field "is_pydio_event" schema
where
ifNot f a = if f a then Nothing else Just a

Expand Down
6 changes: 4 additions & 2 deletions libs/wire-api/test/golden/Test/Wire/API/Golden/Manual/Push.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ testObject_Push_1 =
_pushNativeEncrypt = True,
_pushNativeAps = Nothing,
_pushNativePriority = HighPriority,
_pushPayload = singleton mempty
_pushPayload = singleton mempty,
_pushIsPydioEvent = False
}

testObject_Push_2 :: Push
Expand All @@ -78,5 +79,6 @@ testObject_Push_2 =
_pushPayload =
list1
(KM.fromList [("foo" :: KM.Key) A..= '3', "bar" A..= True])
[KM.fromList [], KM.fromList ["growl" A..= ("foooood" :: Text)], KM.fromList ["lunchtime" A..= ("imminent" :: Text)]]
[KM.fromList [], KM.fromList ["growl" A..= ("foooood" :: Text)], KM.fromList ["lunchtime" A..= ("imminent" :: Text)]],
_pushIsPydioEvent = False
}
4 changes: 2 additions & 2 deletions libs/wire-subsystems/src/Wire/GundeckAPIAccess.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data GundeckAPIAccess m a where
UserDeleted :: UserId -> GundeckAPIAccess m ()
UnregisterPushClient :: UserId -> ClientId -> GundeckAPIAccess m ()
GetPushTokens :: UserId -> GundeckAPIAccess m [V2.PushToken]
RegisterConsumableNotifcationsClient :: UserId -> ClientId -> GundeckAPIAccess m ()
RegisterConsumableNotificationsClient :: UserId -> ClientId -> GundeckAPIAccess m ()

deriving instance Show (GundeckAPIAccess m a)

Expand Down Expand Up @@ -53,7 +53,7 @@ runGundeckAPIAccess ep = interpret $ \case
. zUser uid
. expect2xx
responseJsonMaybe rsp & maybe (pure []) (pure . V2.pushTokens)
RegisterConsumableNotifcationsClient uid cid -> do
RegisterConsumableNotificationsClient uid cid -> do
void . rpcWithRetries "gundeck" ep $
method POST
. paths ["i", "users", toByteString' uid, "clients", toByteString' cid, "consumable-notifications"]
Expand Down
22 changes: 8 additions & 14 deletions libs/wire-subsystems/src/Wire/NotificationSubsystem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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 @@ -25,9 +24,10 @@ data Push = Push
_pushRoute :: Route,
_pushNativePriority :: Maybe Priority,
pushOrigin :: Maybe UserId,
_pushRecipients :: NonEmpty Recipient,
_pushRecipients :: [Recipient],
pushJson :: Object,
_pushApsData :: Maybe ApsData
_pushApsData :: Maybe ApsData,
pushIsPydioEvent :: Bool
}
deriving stock (Eq, Generic, Show)
deriving (Arbitrary) via GenericUniform Push
Expand All @@ -53,8 +53,8 @@ data NotificationSubsystem m a where

makeSem ''NotificationSubsystem

newPush1 :: Maybe UserId -> Object -> NonEmpty Recipient -> Push
newPush1 from e rr =
newPush :: Maybe UserId -> Object -> [Recipient] -> Bool -> Push
newPush from e rr isPydioEvent =
Push
{ _pushConn = Nothing,
_pushTransient = False,
Expand All @@ -63,15 +63,9 @@ newPush1 from e rr =
_pushApsData = Nothing,
pushJson = e,
pushOrigin = from,
_pushRecipients = rr
_pushRecipients = rr,
pushIsPydioEvent = isPydioEvent
}

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

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

newPushLocal1 :: UserId -> Object -> NonEmpty Recipient -> 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 @@ -46,7 +45,7 @@ runNotificationSubsystemGundeck cfg = interpret $ \case
CleanupUser uid -> GundeckAPIAccess.userDeleted uid
UnregisterPushClient uid cid -> GundeckAPIAccess.unregisterPushClient uid cid
GetPushTokens uid -> GundeckAPIAccess.getPushTokens uid
SetupConsumableNotifications uid cid -> GundeckAPIAccess.registerConsumableNotifcationsClient uid cid
SetupConsumableNotifications uid cid -> GundeckAPIAccess.registerConsumableNotificationsClient uid cid

data NotificationSubsystemConfig = NotificationSubsystemConfig
{ fanoutLimit :: Range 1 HardTruncationLimit Int32,
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,9 +53,10 @@ 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
_pushApsData = Nothing,
pushIsPydioEvent = False
}
push2 =
Push
Expand All @@ -66,10 +66,12 @@ 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
_pushApsData = Just apsData,
pushIsPydioEvent = False
}
duplicatePush = push2
duplicatePushWithPush1Recipients = push2 {_pushRecipients = _pushRecipients push1}
Expand Down Expand Up @@ -105,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 @@ -116,7 +118,8 @@ spec = describe "NotificationSubsystem.Interpreter" do
pushOrigin = Nothing,
_pushRecipients = lotOfRecipients,
pushJson = payload1,
_pushApsData = Nothing
_pushApsData = Nothing,
pushIsPydioEvent = False
}
pushSmallerThanFanoutLimit =
Push
Expand All @@ -126,10 +129,12 @@ 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
_pushApsData = Just apsData,
pushIsPydioEvent = False
}
pushes =
[ pushBiggerThanFanoutLimit,
Expand Down Expand Up @@ -168,9 +173,10 @@ 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
_pushApsData = Nothing,
pushIsPydioEvent = False
}
push2 =
Push
Expand All @@ -180,10 +186,12 @@ 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
_pushApsData = Nothing,
pushIsPydioEvent = False
}
pushes = [push1, push2]

Expand Down Expand Up @@ -224,9 +232,10 @@ 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
_pushApsData = Nothing,
pushIsPydioEvent = False
}
(_, attemptedPushes, logs) <- runMiniStackAsync mockConfig $ do
thread <- pushAsyncImpl push1
Expand Down Expand Up @@ -321,7 +330,7 @@ runGundeckAPIAccessFailure pushesRef =
GundeckAPIAccess.UserDeleted {} -> unexpectedCall
GundeckAPIAccess.UnregisterPushClient {} -> unexpectedCall
GundeckAPIAccess.GetPushTokens {} -> unexpectedCall
GundeckAPIAccess.RegisterConsumableNotifcationsClient {} -> unexpectedCall
GundeckAPIAccess.RegisterConsumableNotificationsClient {} -> unexpectedCall

data TestException = TestException
deriving (Show)
Expand All @@ -340,7 +349,7 @@ runGundeckAPIAccessIORef pushesRef =
GundeckAPIAccess.UserDeleted {} -> unexpectedCall
GundeckAPIAccess.UnregisterPushClient {} -> unexpectedCall
GundeckAPIAccess.GetPushTokens {} -> unexpectedCall
GundeckAPIAccess.RegisterConsumableNotifcationsClient {} -> unexpectedCall
GundeckAPIAccess.RegisterConsumableNotificationsClient {} -> unexpectedCall

waitUntilPushes :: IORef [a] -> Int -> IO [a]
waitUntilPushes pushesRef n = do
Expand All @@ -354,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
[ 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
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)) $ \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
]
Loading