module Network.PushNotify.Ccs.Types
( CCSManager(..)
, GCMCcsConfig(..)
, fromGCMtoCCS
) where
import Network.PushNotify.Gcm
import Network.PushNotify.Ccs.Constants
import Control.Concurrent
import Control.Concurrent.Chan
import Control.Concurrent.STM.TChan
import Control.Retry
import qualified Data.HashMap.Strict as HM
import Data.Aeson.Types
import Data.Default
import Data.IORef
import Data.Text
data CCSManager = CCSManager
{ mState :: IORef (Maybe ())
, mCcsChannel :: TChan (Chan GCMresult , MVar (Chan ()), GCMmessage)
, mWorkerID :: ThreadId
}
data GCMCcsConfig = GCMCcsConfig
{ aPiKey :: Text
, senderID :: Text
, ccsRetrySettings :: RetrySettings
}
instance Default GCMCcsConfig where
def = GCMCcsConfig{
aPiKey = ""
, senderID = ""
, ccsRetrySettings = RetrySettings {
backoff = True
, baseDelay = 200
, numRetries = limitedRetries 2
}
}
fromGCMtoCCS :: RegId -> Text -> GCMmessage -> Value
fromGCMtoCCS regId identif msg =
let Object hmap = toJSON msg
nmap = HM.delete cREGISTRATION_IDS hmap
nmap' = HM.insert cTo (String regId) nmap
nmap'' = HM.insert cMessageId (String identif) nmap'
in Object nmap''