From 75935c824baa57f84e2be89a8134a44e8b6721ea Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 22 Sep 2022 20:35:04 -0400 Subject: [PATCH 0001/1042] Implements MSC3881 (enabled and device_id fields for Pusher API) --- .../sdk/api/session/pushers/HttpPusher.kt | 4 ++++ .../android/sdk/api/session/pushers/Pusher.kt | 5 +++-- .../internal/database/mapper/PushersMapper.kt | 8 ++++++-- .../sdk/internal/database/model/PusherEntity.kt | 13 +++---------- .../internal/session/pushers/AddPusherTask.kt | 2 ++ .../session/pushers/DefaultPushersService.kt | 4 +++- .../sdk/internal/session/pushers/JsonPusher.kt | 16 +++++++++++++++- .../im/vector/app/core/pushers/PushersManager.kt | 2 ++ 8 files changed, 38 insertions(+), 16 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/HttpPusher.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/HttpPusher.kt index 1ae23e2b70..4110bb0a42 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/HttpPusher.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/HttpPusher.kt @@ -58,6 +58,10 @@ data class HttpPusher( */ val url: String, + val enabled: Boolean, + + val deviceId: String, + /** * If true, the homeserver should add another pusher with the given pushkey and App ID in addition * to any others with different user IDs. Otherwise, the homeserver must remove any other pushers diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/Pusher.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/Pusher.kt index b85ab32b21..92ac6c483b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/Pusher.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/Pusher.kt @@ -24,8 +24,9 @@ data class Pusher( val profileTag: String? = null, val lang: String?, val data: PusherData, - - val state: PusherState + val enabled: Boolean, + val deviceId: String?, + val state: PusherState, ) { companion object { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/PushersMapper.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/PushersMapper.kt index 2dba2c228b..c3a37f5b95 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/PushersMapper.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/mapper/PushersMapper.kt @@ -33,7 +33,9 @@ internal object PushersMapper { profileTag = pushEntity.profileTag, lang = pushEntity.lang, data = PusherData(pushEntity.data?.url, pushEntity.data?.format), - state = pushEntity.state + enabled = pushEntity.enabled, + deviceId = pushEntity.deviceId, + state = pushEntity.state, ) } @@ -46,7 +48,9 @@ internal object PushersMapper { deviceDisplayName = pusher.deviceDisplayName, profileTag = pusher.profileTag, lang = pusher.lang, - data = PusherDataEntity(pusher.data?.url, pusher.data?.format) + data = PusherDataEntity(pusher.data?.url, pusher.data?.format), + enabled = pusher.enabled, + deviceId = pusher.deviceId, ) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PusherEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PusherEntity.kt index af8e4f2d37..c08f695168 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PusherEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/model/PusherEntity.kt @@ -18,15 +18,6 @@ package org.matrix.android.sdk.internal.database.model import io.realm.RealmObject import org.matrix.android.sdk.api.session.pushers.PusherState -// TODO -// at java.lang.Thread.run(Thread.java:764) -// Caused by: java.lang.IllegalArgumentException: 'value' is not a valid managed object. -// at io.realm.ProxyState.checkValidObject(ProxyState.java:213) -// at io.realm.im_vector_matrix_android_internal_database_model_PusherEntityRealmProxy -// .realmSet$data(im_vector_matrix_android_internal_database_model_PusherEntityRealmProxy.java:413) -// at org.matrix.android.sdk.internal.database.model.PusherEntity.setData(PusherEntity.kt:16) -// at org.matrix.android.sdk.internal.session.pushers.AddHttpPusherWorker$doWork$$inlined$fold$lambda$2.execute(AddHttpPusherWorker.kt:70) -// at io.realm.Realm.executeTransaction(Realm.java:1493) internal open class PusherEntity( var pushKey: String = "", var kind: String? = null, @@ -35,7 +26,9 @@ internal open class PusherEntity( var deviceDisplayName: String? = null, var profileTag: String? = null, var lang: String? = null, - var data: PusherDataEntity? = null + var data: PusherDataEntity? = null, + var enabled: Boolean = true, + var deviceId: String? = null, ) : RealmObject() { private var stateStr: String = PusherState.UNREGISTERED.name diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPusherTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPusherTask.kt index 7d81e19265..c284f006ca 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPusherTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/AddPusherTask.kt @@ -71,6 +71,8 @@ internal class DefaultAddPusherTask @Inject constructor( echo.profileTag = pusher.profileTag echo.data?.format = pusher.data?.format echo.data?.url = pusher.data?.url + echo.enabled = pusher.enabled + echo.deviceId = pusher.deviceId echo.state = PusherState.REGISTERED } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt index e912d9ccf8..082b5b63eb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/DefaultPushersService.kt @@ -78,7 +78,9 @@ internal class DefaultPushersService @Inject constructor( appDisplayName = appDisplayName, deviceDisplayName = deviceDisplayName, data = JsonPusherData(url, EVENT_ID_ONLY.takeIf { withEventIdOnly }), - append = append + append = append, + enabled = enabled, + deviceId = deviceId, ) override suspend fun addEmailPusher( diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/JsonPusher.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/JsonPusher.kt index 71a1ea8c66..f009549b5a 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/JsonPusher.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/JsonPusher.kt @@ -33,6 +33,8 @@ import java.security.InvalidParameterException * "device_display_name": "Alice's Phone", * "profile_tag": "xyz", * "lang": "en-US", + * "enabled": true, + * "device_id": "abc123", * "data": { * "url": "https://example.com/_matrix/push/v1/notify" * } @@ -112,7 +114,19 @@ internal data class JsonPusher( * The default is false. */ @Json(name = "append") - val append: Boolean? = false + val append: Boolean? = false, + + /** + * Whether the pusher should actively create push notifications + */ + @Json(name = "org.matrix.msc3881.enabled") + val enabled: Boolean = false, + + /** + * The device_id of the session that registered the pusher + */ + @Json(name = "org.matrix.msc3881.device_id") + val deviceId: String? = null, ) { init { // Do some parameter checks. It's ok to throw Exception, to inform developer of the problem diff --git a/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt b/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt index c77f454ab0..8be9b192fe 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt @@ -70,6 +70,8 @@ class PushersManager @Inject constructor( appNameProvider.getAppName(), activeSessionHolder.getActiveSession().sessionParams.deviceId ?: "MOBILE", gateway, + enabled = true, + deviceId = activeSessionHolder.getActiveSession().sessionParams.deviceId ?: "MOBILE", append = false, withEventIdOnly = true ) From 5c27f65d3e8d5558aa00ad565da8f97ef5c29579 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 22 Sep 2022 20:43:37 -0400 Subject: [PATCH 0002/1042] Adds changelog file --- changelog.d/7217.wip | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7217.wip diff --git a/changelog.d/7217.wip b/changelog.d/7217.wip new file mode 100644 index 0000000000..a8cc2a3ef3 --- /dev/null +++ b/changelog.d/7217.wip @@ -0,0 +1 @@ +Implements MSC3881: Parses `enabled` and `device_id` fields from updated Pusher API From 8c7901177eb83dec5a2ca19728a63b918214ecdd Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Thu, 22 Sep 2022 20:44:46 -0400 Subject: [PATCH 0003/1042] Adds comments to new fields in HttpPusher --- .../matrix/android/sdk/api/session/pushers/HttpPusher.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/HttpPusher.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/HttpPusher.kt index 4110bb0a42..c4ec57a766 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/HttpPusher.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/HttpPusher.kt @@ -58,8 +58,14 @@ data class HttpPusher( */ val url: String, + /** + * Whether the pusher should actively create push notifications + */ val enabled: Boolean, + /** + * The device ID of the session that registered the pusher + */ val deviceId: String, /** From 65c89638ab7b6569c584e164a26d8e790f4c0ac3 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Fri, 23 Sep 2022 09:24:20 -0400 Subject: [PATCH 0004/1042] Fixes lint error with comments --- .../matrix/android/sdk/api/session/pushers/HttpPusher.kt | 4 ++-- .../android/sdk/internal/session/pushers/JsonPusher.kt | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/HttpPusher.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/HttpPusher.kt index c4ec57a766..1258c5c02f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/HttpPusher.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/pushers/HttpPusher.kt @@ -59,12 +59,12 @@ data class HttpPusher( val url: String, /** - * Whether the pusher should actively create push notifications + * Whether the pusher should actively create push notifications. */ val enabled: Boolean, /** - * The device ID of the session that registered the pusher + * The device ID of the session that registered the pusher. */ val deviceId: String, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/JsonPusher.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/JsonPusher.kt index f009549b5a..c1cf3eb276 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/JsonPusher.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/pushers/JsonPusher.kt @@ -117,13 +117,13 @@ internal data class JsonPusher( val append: Boolean? = false, /** - * Whether the pusher should actively create push notifications + * Whether the pusher should actively create push notifications. */ @Json(name = "org.matrix.msc3881.enabled") - val enabled: Boolean = false, + val enabled: Boolean = true, /** - * The device_id of the session that registered the pusher + * The device_id of the session that registered the pusher. */ @Json(name = "org.matrix.msc3881.device_id") val deviceId: String? = null, From 52171ef748e2e088db25bd90ba01cdf1ccfb0ef9 Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Fri, 23 Sep 2022 09:36:53 -0400 Subject: [PATCH 0005/1042] Changes deviceDisplayName on pusher to use device model name --- .../java/im/vector/app/core/pushers/PushersManager.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt b/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt index 8be9b192fe..ac932bee72 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt @@ -66,14 +66,14 @@ class PushersManager @Inject constructor( pushKey, stringProvider.getString(R.string.pusher_app_id), profileTag = DEFAULT_PUSHER_FILE_TAG + "_" + abs(activeSessionHolder.getActiveSession().myUserId.hashCode()), - localeProvider.current().language, - appNameProvider.getAppName(), - activeSessionHolder.getActiveSession().sessionParams.deviceId ?: "MOBILE", - gateway, + lang = localeProvider.current().language, + appDisplayName = appNameProvider.getAppName(), + deviceDisplayName = android.os.Build.MODEL, + url = gateway, enabled = true, deviceId = activeSessionHolder.getActiveSession().sessionParams.deviceId ?: "MOBILE", append = false, - withEventIdOnly = true + withEventIdOnly = true, ) suspend fun registerEmailForPush(email: String) { From f724751c8602523ee257462d841f17027df1736d Mon Sep 17 00:00:00 2001 From: ericdecanini Date: Fri, 23 Sep 2022 11:03:56 -0400 Subject: [PATCH 0006/1042] Adds new pusher fields to Notification Targets screen --- .../src/main/res/values/strings.xml | 10 +++--- .../features/settings/push/PushGatewayItem.kt | 4 +++ .../src/main/res/layout/item_pushgateway.xml | 34 +++++++++++++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index dec46159dd..c436044153 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -1697,13 +1697,15 @@ No push rules defined No registered push gateways - app_id: - push_key: - app_display_name: - session_name: + App ID: + Push Key: + App Display Name: + Device Display Name: + Device ID: Url: Format: Profile tag: + Enabled: Voice & Video Help & About diff --git a/vector/src/main/java/im/vector/app/features/settings/push/PushGatewayItem.kt b/vector/src/main/java/im/vector/app/features/settings/push/PushGatewayItem.kt index 5ef6e02330..4fa1e422a1 100644 --- a/vector/src/main/java/im/vector/app/features/settings/push/PushGatewayItem.kt +++ b/vector/src/main/java/im/vector/app/features/settings/push/PushGatewayItem.kt @@ -50,6 +50,8 @@ abstract class PushGatewayItem : VectorEpoxyModel(R.layo holder.format.setTextOrHide(pusher.data.format, hideWhenBlank = true, holder.formatTitle) holder.profileTag.setTextOrHide(pusher.profileTag, hideWhenBlank = true, holder.profileTagTitle) holder.deviceName.text = pusher.deviceDisplayName + holder.deviceId.text = pusher.deviceId ?: "null" + holder.enabled.text = pusher.enabled.toString() holder.removeButton.setOnClickListener { interactions.onRemovePushTapped(pusher) } @@ -59,10 +61,12 @@ abstract class PushGatewayItem : VectorEpoxyModel(R.layo val kind by bind(R.id.pushGatewayKind) val pushKey by bind(R.id.pushGatewayKeyValue) val deviceName by bind(R.id.pushGatewayDeviceNameValue) + val deviceId by bind(R.id.pushGatewayDeviceIdValue) val formatTitle by bind(R.id.pushGatewayFormat) val format by bind(R.id.pushGatewayFormatValue) val profileTagTitle by bind(R.id.pushGatewayProfileTag) val profileTag by bind(R.id.pushGatewayProfileTagValue) + val enabled by bind(R.id.pushGatewayEnabledValue) val urlTitle by bind(R.id.pushGatewayURL) val url by bind(R.id.pushGatewayURLValue) val appName by bind(R.id.pushGatewayAppNameValue) diff --git a/vector/src/main/res/layout/item_pushgateway.xml b/vector/src/main/res/layout/item_pushgateway.xml index afc40e5b7a..67a3a7d390 100644 --- a/vector/src/main/res/layout/item_pushgateway.xml +++ b/vector/src/main/res/layout/item_pushgateway.xml @@ -83,6 +83,23 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp" + tools:text="Pixel 6" /> + + + + + + + +