Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ createApnsPayload androidData iosModifier =
fcmAps :: FCMaps b
fcmAps =
def{fcmAlert = if androidData.fcmShowNotification == SHOW then Just fcmAlert else Nothing,
fcmData = Just (iosModifier androidData),
fcmData = Just (apnsIOSModifier (iosModifier androidData)),
fcmCategory = Just androidData.fcmNotificationType,
fcmMutableContent = 1,
fcmSound = Just $ fromMaybe "" androidData.fcmNotificationJSON.fcmdSound,
Expand All @@ -120,6 +120,9 @@ createApnsPayload androidData iosModifier =
body :: Maybe FCMNotificationBody
body = androidData.fcmNotificationJSON.fcmdBody

apnsIOSModifier :: FCMData b -> IOSFCMData c
apnsIOSModifier androidData = IOSFCMData {fcmEntityIds = androidData.fcmEntityIds}

createAndroidNotification :: FCMNotificationTitle -> FCMNotificationBody -> FCMNotificationType -> Maybe Text -> FCMAndroidNotification
createAndroidNotification title body notificationType sound =
let notification = case notificationType of
Expand Down
74 changes: 69 additions & 5 deletions lib/mobility-core/src/Kernel/External/Notification/FCM/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,13 @@ instance (FromJSON a) => FromJSON (FCMData a) where
parseNotificationJson str =
maybe (typeMismatch "Json string" (String str)) pure $ decodeFromText str

data IOSFCMData a = IOSFCMData
{ fcmEntityIds :: Text
}
deriving (Eq, Show, Generic, PrettyShow, ToJSON, FromJSON)

$(makeLenses ''IOSFCMData)

-- | Android specific options for messages sent through FCM connection server
data FCMAndroidConfig a = FCMAndroidConfig
{ fcmdCollapseKey :: !(Maybe Text),
Expand Down Expand Up @@ -656,7 +663,7 @@ instance Default FCMAlert where

data FCMaps a = FCMaps
{ fcmAlert :: !(Maybe FCMAlert),
fcmData :: !(Maybe (FCMData a)),
fcmData :: !(Maybe (IOSFCMData a)),
fcmCategory :: !(Maybe FCMNotificationType),
fcmMutableContent :: !Int,
fcmSound :: !(Maybe Text),
Expand Down Expand Up @@ -703,7 +710,17 @@ newtype FCMApnPayload a = FCMApnPayload

$(makeLenses ''FCMApnPayload)

$(deriveJSON (aesonPrefix snakeCase) {omitNothingFields = True} ''FCMApnPayload)
instance (ToJSON a) => ToJSON (FCMApnPayload a) where
toJSON FCMApnPayload {..} =
object $
catMaybes
[ ("aps" .=) <$> fcmAps
]

instance (FromJSON a) => FromJSON (FCMApnPayload a) where
parseJSON = withObject "FCMApnPayload" \o ->
FCMApnPayload
<$> o .:? "aps"

instance Default (FCMApnPayload a) where
def = FCMApnPayload Nothing
Expand Down Expand Up @@ -739,7 +756,21 @@ data FCMApnsConfig a = FCMApnsConfig

$(makeLenses ''FCMApnsConfig)

$(deriveJSON (aesonPrefix snakeCase) {omitNothingFields = True} ''FCMApnsConfig)
instance (ToJSON a) => ToJSON (FCMApnsConfig a) where
toJSON FCMApnsConfig {..} =
object $
catMaybes
[ ("headers" .=) <$> fcmaHeaders,
("payload" .=) <$> fcmaPayload,
("options" .=) <$> fcmaOptions
]

instance (FromJSON a) => FromJSON (FCMApnsConfig a) where
parseJSON = withObject "FCMApnsConfig" \o ->
FCMApnsConfig
<$> o .:? "headers"
<*> o .:? "payload"
<*> o .:? "options"

instance Default (FCMApnsConfig a) where
def = FCMApnsConfig Nothing Nothing Nothing
Expand Down Expand Up @@ -776,7 +807,31 @@ data FCMMessage a b = FCMMessage

$(makeLenses ''FCMMessage)

$(deriveJSON (aesonPrefix snakeCase) {omitNothingFields = True} ''FCMMessage)
instance (ToJSON a, ToJSON b) => ToJSON (FCMMessage a b) where
toJSON FCMMessage {..} =
object $
catMaybes
[ ("token" .=) <$> fcmToken,
("topic" .=) <$> fcmTopic,
("condition" .=) <$> fcmCondition,
("notification" .=) <$> fcmNotification,
("android" .=) <$> fcmAndroid,
("webpush" .=) <$> fcmWebpush,
("apns" .=) <$> fcmApns,
("options" .=) <$> fcmOptions
]

instance (FromJSON a, FromJSON b) => FromJSON (FCMMessage a b) where
parseJSON = withObject "FCMMessage" \o ->
FCMMessage
<$> o .:? "token"
<*> o .:? "topic"
<*> o .:? "condition"
<*> o .:? "notification"
<*> o .:? "android"
<*> o .:? "webpush"
<*> o .:? "apns"
<*> o .:? "options"

instance Default (FCMMessage a b) where
def =
Expand All @@ -791,7 +846,16 @@ newtype FCMRequest a b = FCMRequest

$(makeLenses ''FCMRequest)

$(deriveJSON (aesonPrefix snakeCase) {omitNothingFields = True} ''FCMRequest)
instance (ToJSON a, ToJSON b) => ToJSON (FCMRequest a b) where
toJSON FCMRequest {..} =
object
[ "message" .= fcmeMessage
]

instance (FromJSON a, FromJSON b) => FromJSON (FCMRequest a b) where
parseJSON = withObject "FCMRequest" \o ->
FCMRequest
<$> o .: "message"

-- | Priority levels of a notification
data FCMErrorCode
Expand Down