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

Delete notifications of deleted users. #41

Merged
merged 1 commit into from
Aug 2, 2017
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
6 changes: 4 additions & 2 deletions services/gundeck/src/Gundeck/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import Network.HTTP.Types
import Network.Wai (Request, Response)
import Network.Wai.Utilities

import qualified Gundeck.Client.Data as Clients
import qualified Gundeck.Push.Data as Push
import qualified Gundeck.Client.Data as Clients
import qualified Gundeck.Notification.Data as Notifications
import qualified Gundeck.Push.Data as Push

register :: UserId ::: ClientId ::: Request ::: JSON ::: JSON -> Gundeck Response
register (uid ::: cid ::: req ::: _) = do
Expand Down Expand Up @@ -54,4 +55,5 @@ removeUser user = do
deleteTokens toks Nothing
Push.erase user
Clients.erase user
Notifications.deleteAll user
return empty
7 changes: 7 additions & 0 deletions services/gundeck/src/Gundeck/Notification/Data.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Gundeck.Notification.Data
, fetch
, fetchId
, fetchLast
, deleteAll
) where

import Cassandra
Expand Down Expand Up @@ -157,6 +158,12 @@ fetch u c since (fromRange -> size) = do
\WHERE user = ? AND id >= ? \
\ORDER BY id ASC"

deleteAll :: MonadClient m => UserId -> m ()
deleteAll u = write cql (params Quorum (Identity u)) & retry x5
where
cql :: PrepQuery W (Identity UserId) ()
cql = "DELETE FROM notifications WHERE user = ?"

-------------------------------------------------------------------------------
-- Conversions

Expand Down
7 changes: 5 additions & 2 deletions services/gundeck/test/integration/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,15 @@ removeUser s g c = do
clt <- randomClient g user
tok <- randomGcmToken clt
_ <- registerPushToken user tok g
_ <- sendPush g (buildPush user [(user, [])] (textPayload "data"))
deleteUser g user
ntfs <- listNotifications user Nothing g
liftIO $ do
keys <- Cql.runClient s (Clients.select user clt)
tokens <- Cql.runClient s (Push.lookup user Push.Quorum)
assertBool "clients gone" (isNothing keys)
assertBool "tokens gone" (null tokens)
isNothing keys @?= True
null tokens @?= True
ntfs @?= []

replacePresence :: Gundeck -> Cannon -> Http ()
replacePresence gu ca = do
Expand Down