Skip to content

Commit

Permalink
Merge pull request #41 from wireapp/feature/gundeck/clear-notifications
Browse files Browse the repository at this point in the history
Delete notifications of deleted users.
  • Loading branch information
romanb authored Aug 2, 2017
2 parents ac27609 + 969f0eb commit 90ce5b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
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

0 comments on commit 90ce5b3

Please sign in to comment.