-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from rees46/feat/data-from-push-notification
Feat/data from push notification
- Loading branch information
Showing
26 changed files
with
258 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
personalization-sdk/src/main/kotlin/com/personalization/OnMessageListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
personalization-sdk/src/main/kotlin/com/personalization/di/SdkComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...main/kotlin/com/personalization/features/notification/actions/mapper/ActionUrls.mapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.personalization.features.notification.actions.mapper | ||
|
||
import com.personalization.errors.JsonResponseErrorHandler | ||
import org.json.JSONArray | ||
|
||
fun parseActionUrls(actionUrlsJson: String?): List<String> { | ||
return try { | ||
actionUrlsJson?.let { | ||
val jsonArray = JSONArray(it) | ||
List(jsonArray.length()) { index -> jsonArray.getString(index) } | ||
} ?: emptyList() | ||
} catch (exception: Exception) { | ||
JsonResponseErrorHandler( | ||
tag = "parseNotificationActions", | ||
response = null | ||
).logError(exception = exception) | ||
emptyList() | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ain/kotlin/com/personalization/features/notification/actions/mapper/ActionsName.mapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.personalization.features.notification.actions.mapper | ||
|
||
import com.personalization.errors.JsonResponseErrorHandler | ||
import com.personalization.features.notification.actions.model.NotificationAction | ||
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_ACTION | ||
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_TITLE | ||
import org.json.JSONArray | ||
|
||
fun parseNotificationActions(actionsJson: String?): List<NotificationAction> { | ||
return try { | ||
actionsJson?.let { | ||
val jsonArray = JSONArray(it) | ||
List(jsonArray.length()) { index -> | ||
val jsonObject = jsonArray.getJSONObject(index) | ||
NotificationAction( | ||
action = jsonObject.getString(NOTIFICATION_ACTION), | ||
title = jsonObject.getString(NOTIFICATION_TITLE) | ||
) | ||
} | ||
} ?: emptyList() | ||
} catch (exception: Exception) { | ||
JsonResponseErrorHandler( | ||
tag = "parseNotificationActions", | ||
response = null | ||
).logError(exception = exception) | ||
|
||
emptyList() | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
.../kotlin/com/personalization/features/notification/actions/model/notification.action.kt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.personalization.features.notification.actions.model | ||
|
||
data class NotificationAction( | ||
val action: String, | ||
val title: String | ||
) |
28 changes: 28 additions & 0 deletions
28
...n/kotlin/com/personalization/features/notification/data/mapper/NotificationData.mapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.personalization.features.notification.data.mapper | ||
|
||
import com.google.firebase.messaging.RemoteMessage | ||
import com.personalization.features.notification.actions.mapper.parseActionUrls | ||
import com.personalization.features.notification.actions.mapper.parseNotificationActions | ||
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_ACTIONS | ||
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_ACTION_URLS | ||
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_BODY | ||
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_EVENT | ||
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_ICON | ||
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_IMAGE | ||
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_PARAM_ID | ||
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_TITLE | ||
import com.personalization.features.notification.domain.model.NotificationConstants.TYPE_PARAM | ||
import com.personalization.features.notification.event.mapper.parseNotificationEvent | ||
import com.personalization.sdk.data.models.dto.notification.NotificationData | ||
|
||
fun RemoteMessage.toNotificationData(): NotificationData = NotificationData( | ||
id = this.data[NOTIFICATION_PARAM_ID], | ||
title = this.data[NOTIFICATION_TITLE], | ||
body = this.data[NOTIFICATION_BODY], | ||
icon = this.data[NOTIFICATION_ICON], | ||
type = this.data[TYPE_PARAM], | ||
actions = parseNotificationActions(this.data[NOTIFICATION_ACTIONS]), | ||
actionUrls = parseActionUrls(this.data[NOTIFICATION_ACTION_URLS]), | ||
image = this.data[NOTIFICATION_IMAGE], | ||
event = parseNotificationEvent(this.data[NOTIFICATION_EVENT]) | ||
) |
27 changes: 0 additions & 27 deletions
27
...in/kotlin/com/personalization/features/notification/data/mapper/NotificationDataMapper.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
...rc/main/kotlin/com/personalization/features/notification/domain/model/NotificationData.kt
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
...rc/main/kotlin/com/personalization/features/notification/event/mapper/EventType.mapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.personalization.features.notification.event.mapper | ||
|
||
import com.personalization.errors.JsonResponseErrorHandler | ||
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_PAYLOAD | ||
import com.personalization.features.notification.domain.model.NotificationConstants.NOTIFICATION_URI | ||
import com.personalization.features.notification.domain.model.NotificationConstants.TYPE_PARAM | ||
import com.personalization.features.notification.event.model.NotificationEvent | ||
import org.json.JSONObject | ||
|
||
fun parseNotificationEvent(eventJson: String?): NotificationEvent { | ||
val emptyData = NotificationEvent( | ||
type = "", | ||
uri = "", | ||
payload = emptyMap() | ||
) | ||
return try { | ||
eventJson?.let { | ||
val jsonObject = JSONObject(it) | ||
|
||
NotificationEvent( | ||
type = jsonObject.optString(TYPE_PARAM, ""), | ||
uri = jsonObject.optString(NOTIFICATION_URI, ""), | ||
payload = jsonObject.optJSONObject(NOTIFICATION_PAYLOAD)?.let { payloadObj -> | ||
payloadObj.keys().asSequence().associateWith { key -> payloadObj[key] } | ||
} ?: emptyMap() | ||
) | ||
|
||
} ?: emptyData | ||
|
||
} catch (exception: Exception) { | ||
JsonResponseErrorHandler( | ||
tag = "parseNotificationEvent", | ||
response = null | ||
).logError(exception = exception) | ||
|
||
emptyData | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ain/kotlin/com/personalization/features/notification/event/model/notification.event.kt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.personalization.features.notification.event.model | ||
|
||
data class NotificationEvent( | ||
val type: String?, | ||
val uri: String?, | ||
val payload: Map<String, Any>? = null | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.