Skip to content

Commit 613bb56

Browse files
committed
get notifications v3
1 parent 5fa33ab commit 613bb56

File tree

3 files changed

+85
-29
lines changed

3 files changed

+85
-29
lines changed

libs/wire-api/src/Wire/API/Routes/Public/Gundeck.hs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import Wire.API.Push.V2.Token
3131
import Wire.API.Routes.MultiVerb
3232
import Wire.API.Routes.Named
3333
import Wire.API.Routes.Public
34+
import Wire.API.Routes.Version
3435

3536
type GundeckAPI = PushAPI :<|> NotificationAPI
3637

@@ -97,8 +98,9 @@ type NotificationAPI =
9798
(Maybe QueuedNotification)
9899
)
99100
:<|> Named
100-
"get-notifications"
101+
"get-notifications@v2"
101102
( Summary "Fetch notifications"
103+
:> Until 'V3
102104
:> ZUser
103105
:> "notifications"
104106
:> QueryParam' [Optional, Strict, Description "Only return notifications more recent than this"] "since" RawNotificationId
@@ -112,6 +114,23 @@ type NotificationAPI =
112114
]
113115
GetNotificationsResponse
114116
)
117+
:<|> Named
118+
"get-notifications"
119+
( Summary "Fetch notifications"
120+
:> From 'V3
121+
:> ZUser
122+
:> "notifications"
123+
:> QueryParam' [Optional, Strict, Description "Only return notifications more recent than this"] "since" NotificationId
124+
:> QueryParam' [Optional, Strict, Description "Only return notifications targeted at the given client"] "client" ClientId
125+
:> QueryParam' [Optional, Strict, Description "Maximum number of notifications to return"] "size" (Range 100 10000 Int32)
126+
:> MultiVerb
127+
'GET
128+
'[JSON]
129+
'[ ErrorResponse 'E.NotificationNotFound,
130+
Respond 200 "Notification list" QueuedNotificationList
131+
]
132+
(Maybe QueuedNotificationList)
133+
)
115134

116135
swaggerDoc :: Swagger.Swagger
117136
swaggerDoc = toSwagger (Proxy @GundeckAPI)

services/gundeck/src/Gundeck/API/Public.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ servantSitemap = pushAPI :<|> notificationAPI
4848
notificationAPI =
4949
Named @"get-notification-by-id" getById
5050
:<|> Named @"get-last-notification" getLastNotification
51+
:<|> Named @"get-notifications@v2" paginateUntilV2
5152
:<|> Named @"get-notifications" paginate
5253

5354
addToken :: UserId -> ConnId -> Public.PushToken -> Gundeck (Either Public.AddTokenError Public.AddTokenSuccess)
@@ -98,13 +99,13 @@ listTokens = Push.listTokens
9899
--
99100
-- (arianvp): I am not sure why it is convenient for clients to distinct
100101
-- between these two cases.
101-
paginate ::
102+
paginateUntilV2 ::
102103
UserId ->
103104
Maybe Public.RawNotificationId ->
104105
Maybe ClientId ->
105106
Maybe (Range 100 10000 Int32) ->
106107
Gundeck Public.GetNotificationsResponse
107-
paginate uid mbSince mbClient mbSize = do
108+
paginateUntilV2 uid mbSince mbClient mbSize = do
108109
let size = fromMaybe (unsafeRange 1000) mbSize
109110
Notification.PaginateResult gap page <- Notification.paginate uid (join since) mbClient size
110111
pure $
@@ -124,6 +125,17 @@ paginate uid mbSince mbClient mbSize = do
124125
isV1UUID :: UUID -> Maybe UUID
125126
isV1UUID u = if UUID.version u == 1 then Just u else Nothing
126127

128+
paginate ::
129+
UserId ->
130+
Maybe Public.NotificationId ->
131+
Maybe ClientId ->
132+
Maybe (Range 100 10000 Int32) ->
133+
Gundeck (Maybe Public.QueuedNotificationList)
134+
paginate uid mbSince mbClient mbSize = do
135+
let size = fromMaybe (unsafeRange 1000) mbSize
136+
Notification.PaginateResult gap page <- Notification.paginate uid mbSince mbClient size
137+
pure $ if gap then Nothing else Just page
138+
127139
getById :: UserId -> Public.NotificationId -> Maybe ClientId -> Gundeck (Maybe Public.QueuedNotification)
128140
getById = Notification.getById
129141

services/gundeck/test/integration/API.hs

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ tests s =
9393
test s "Fetch all notifications" testFetchAllNotifs,
9494
test s "Fetch new notifications" testFetchNewNotifs,
9595
test s "No new notifications" testNoNewNotifs,
96-
test s "Missing notifications" testMissingNotifs,
96+
test s "Missing notifications (until API Version 3)" testMissingNotifsV2,
97+
test s "Missing notifications (from API Version 3)" testMissingNotifsV3,
9798
test s "Fetch last notification" testFetchLastNotif,
9899
test s "No last notification" testNoLastNotif,
99-
test s "Bad 'since' parameter" testFetchNotifBadSince,
100+
test s "Bad 'since' parameter (until API Version 3)" testFetchNotifBadSinceV2,
101+
test s "Bad 'since' parameter (from API Version 3)" testFetchNotifBadSinceV3,
100102
test s "Fetch notification by ID" testFetchNotifById,
101103
test s "Filter notifications by client" testFilterNotifByClient,
102104
test s "Paging" testNotificationPaging
@@ -482,7 +484,7 @@ testFetchNewNotifs = do
482484
get
483485
( runGundeckR gu
484486
. zUser ally
485-
. path "notifications"
487+
. paths ["v3", "notifications"]
486488
. query [("since", Just (toByteString' (ns !! 1)))]
487489
)
488490
!!! do
@@ -498,31 +500,40 @@ testNoNewNotifs = do
498500
get
499501
( runGundeckR gu
500502
. zUser ally
501-
. path "notifications"
503+
. paths ["v3", "notifications"]
502504
. query [("since", Just (toByteString' n))]
503505
)
504506
!!! do
505507
const 200 === statusCode
506508
const (Just []) === parseNotificationIds
507509

508-
testMissingNotifs :: TestM ()
509-
testMissingNotifs = do
510-
gu <- view tsGundeck
511-
other <- randomId
512-
sendPush (buildPush other [(other, RecipientClientsAll)] (textPayload "hello"))
513-
(old : _) <- map (view queuedNotificationId) <$> listNotifications other Nothing
514-
ally <- randomId
515-
sendPush (buildPush ally [(ally, RecipientClientsAll)] (textPayload "hello"))
516-
ns <- listNotifications ally Nothing
517-
get
518-
( runGundeckR gu
519-
. zUser ally
520-
. path "notifications"
521-
. query [("since", Just (toByteString' old))]
522-
)
523-
!!! do
524-
const 404 === statusCode
525-
const (Just ns) === parseNotifications
510+
testMissingNotifsV2 :: TestM ()
511+
testMissingNotifsV2 = do
512+
testMissingNotifs "v2" $ \ns -> do
513+
const 404 === statusCode
514+
const (Just ns) === parseNotifications
515+
516+
testMissingNotifsV3 :: TestM ()
517+
testMissingNotifsV3 =
518+
testMissingNotifs "v2" $ const $ const 404 === statusCode
519+
520+
testMissingNotifs :: ByteString -> ([QueuedNotification] -> Assertions ()) -> TestM ()
521+
testMissingNotifs version checks =
522+
do
523+
gu <- view tsGundeck
524+
other <- randomId
525+
sendPush (buildPush other [(other, RecipientClientsAll)] (textPayload "hello"))
526+
(old : _) <- map (view queuedNotificationId) <$> listNotifications other Nothing
527+
ally <- randomId
528+
sendPush (buildPush ally [(ally, RecipientClientsAll)] (textPayload "hello"))
529+
ns <- listNotifications ally Nothing
530+
get
531+
( runGundeckR gu
532+
. zUser ally
533+
. paths [version, "notifications"]
534+
. query [("since", Just (toByteString' old))]
535+
)
536+
!!! checks ns
526537

527538
testFetchLastNotif :: TestM ()
528539
testFetchLastNotif = do
@@ -543,8 +554,22 @@ testNoLastNotif = do
543554
const 404 === statusCode
544555
const (Just "not-found") =~= responseBody
545556

546-
testFetchNotifBadSince :: TestM ()
547-
testFetchNotifBadSince = do
557+
testFetchNotifBadSinceV3 :: TestM ()
558+
testFetchNotifBadSinceV3 = do
559+
gu <- view tsGundeck
560+
ally <- randomId
561+
sendPush (buildPush ally [(ally, RecipientClientsAll)] (textPayload "first"))
562+
get
563+
( runGundeckR gu
564+
. zUser ally
565+
. paths ["v3", "notifications"]
566+
. query [("since", Just "jumberjack")]
567+
)
568+
!!! do
569+
const 400 === statusCode
570+
571+
testFetchNotifBadSinceV2 :: TestM ()
572+
testFetchNotifBadSinceV2 = do
548573
gu <- view tsGundeck
549574
ally <- randomId
550575
sendPush (buildPush ally [(ally, RecipientClientsAll)] (textPayload "first"))
@@ -712,7 +737,7 @@ testNotificationPaging = do
712737
maybe id (queryItem "client" . toByteString') c
713738
. maybe id (queryItem "since" . toByteString') start
714739
. queryItem "size" (toByteString' step)
715-
r <- get (runGundeckR gu . path "/notifications" . zUser u . range) <!! const 200 === statusCode
740+
r <- get (runGundeckR gu . paths ["v3", "notifications"] . zUser u . range) <!! const 200 === statusCode
716741
let rs = decode =<< responseBody r
717742
let (ns, more) = (fmap (view queuedNotifications) &&& fmap (view queuedHasMore)) rs
718743
let count' = count + step
@@ -1093,7 +1118,7 @@ getNotifications u c =
10931118
get $
10941119
runGundeckR gu
10951120
. zUser u
1096-
. path "notifications"
1121+
. paths ["v3", "notifications"]
10971122
. maybe id (queryItem "client" . toByteString') c
10981123

10991124
getLastNotification :: UserId -> Maybe ClientId -> TestM (Response (Maybe BL.ByteString))

0 commit comments

Comments
 (0)