{-# LANGUAGE StrictData #-}
module Galley.API.Teams.Notifications
( getTeamNotifications,
pushTeamEvent,
)
where
import Data.Id
import Data.Json.Util (toJSONObject)
import Data.List1 qualified as List1
import Data.Range (Range)
import Galley.Data.TeamNotifications qualified as DataTeamQueue
import Galley.Effects
import Galley.Effects.BrigAccess as Intra
import Galley.Effects.TeamNotificationStore qualified as E
import Imports
import Polysemy
import Wire.API.Error
import Wire.API.Error.Galley
import Wire.API.Event.Team (Event)
import Wire.API.Internal.Notification
import Wire.API.User
getTeamNotifications ::
( Member BrigAccess r,
Member (ErrorS 'TeamNotFound) r,
Member TeamNotificationStore r
) =>
UserId ->
Maybe NotificationId ->
Range 1 10000 Int32 ->
Sem r QueuedNotificationList
getTeamNotifications :: forall (r :: EffectRow).
(Member BrigAccess r, Member (ErrorS 'TeamNotFound) r,
Member TeamNotificationStore r) =>
UserId
-> Maybe NotificationId
-> Range 1 10000 Int32
-> Sem r QueuedNotificationList
getTeamNotifications UserId
zusr Maybe NotificationId
since Range 1 10000 Int32
size = do
TeamId
tid <- (forall {k} (e :: k) (r :: EffectRow) a.
Member (ErrorS e) r =>
Maybe a -> Sem r a
forall (e :: GalleyError) (r :: EffectRow) a.
Member (ErrorS e) r =>
Maybe a -> Sem r a
noteS @'TeamNotFound =<<) (Sem r (Maybe TeamId) -> Sem r TeamId)
-> Sem r (Maybe TeamId) -> Sem r TeamId
forall a b. (a -> b) -> a -> b
$ (User -> Maybe TeamId
userTeam =<<) (Maybe User -> Maybe TeamId)
-> Sem r (Maybe User) -> Sem r (Maybe TeamId)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> UserId -> Sem r (Maybe User)
forall (r :: EffectRow).
Member BrigAccess r =>
UserId -> Sem r (Maybe User)
Intra.getUser UserId
zusr
ResultPage
page <- TeamId
-> Maybe NotificationId -> Range 1 10000 Int32 -> Sem r ResultPage
forall (r :: EffectRow).
Member TeamNotificationStore r =>
TeamId
-> Maybe NotificationId -> Range 1 10000 Int32 -> Sem r ResultPage
E.getTeamNotifications TeamId
tid Maybe NotificationId
since Range 1 10000 Int32
size
QueuedNotificationList -> Sem r QueuedNotificationList
forall a. a -> Sem r a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (QueuedNotificationList -> Sem r QueuedNotificationList)
-> QueuedNotificationList -> Sem r QueuedNotificationList
forall a b. (a -> b) -> a -> b
$
[QueuedNotification]
-> Bool -> Maybe UTCTime -> QueuedNotificationList
queuedNotificationList
(Seq QueuedNotification -> [QueuedNotification]
forall a. Seq a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList (ResultPage -> Seq QueuedNotification
DataTeamQueue.resultSeq ResultPage
page))
(ResultPage -> Bool
DataTeamQueue.resultHasMore ResultPage
page)
Maybe UTCTime
forall a. Maybe a
Nothing
pushTeamEvent :: (Member TeamNotificationStore r) => TeamId -> Event -> Sem r ()
pushTeamEvent :: forall (r :: EffectRow).
Member TeamNotificationStore r =>
TeamId -> Event -> Sem r ()
pushTeamEvent TeamId
tid Event
evt = do
NotificationId
nid <- Sem r NotificationId
forall (r :: EffectRow).
Member TeamNotificationStore r =>
Sem r NotificationId
E.mkNotificationId
TeamId -> NotificationId -> List1 Object -> Sem r ()
forall (r :: EffectRow).
Member TeamNotificationStore r =>
TeamId -> NotificationId -> List1 Object -> Sem r ()
E.createTeamNotification TeamId
tid NotificationId
nid (Object -> List1 Object
forall a. a -> List1 a
List1.singleton (Object -> List1 Object) -> Object -> List1 Object
forall a b. (a -> b) -> a -> b
$ Event -> Object
forall a. ToJSONObject a => a -> Object
toJSONObject Event
evt)