From 7243142676fa7957d6535072274f0f167d77a479 Mon Sep 17 00:00:00 2001 From: Dariusz Olszewski Date: Sun, 10 Jul 2022 22:27:30 +0200 Subject: [PATCH] Mark as read - use message ID retrieved from server Minimal set of changes, to be cleaned-up. Signed-off-by: Dariusz Olszewski --- .../java/com/nextcloud/talk/jobs/NotificationWorker.java | 6 +++++- .../talk/models/json/push/DecryptedPushMessage.kt | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java index 6d6c0cc2a..b16aca901 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java +++ b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.java @@ -247,6 +247,8 @@ public class NotificationWorker extends Worker { } } + decryptedPushMessage.setObjectId(notification.getObjectId()); + showNotification(intent); } @@ -427,7 +429,9 @@ public class NotificationWorker extends Worker { actualIntent.putExtra(BundleKeys.INSTANCE.getKEY_SYSTEM_NOTIFICATION_ID(), systemNotificationId); actualIntent.putExtra(BundleKeys.INSTANCE.getKEY_ROOM_TOKEN(), decryptedPushMessage.getId()); if (decryptedPushMessage.getNotificationId() != null) { - actualIntent.putExtra(BundleKeys.KEY_MESSAGE_ID, decryptedPushMessage.getNotificationId().intValue()); + // TODO - improve parsing when server returns unexpected objectId + int messageId = Integer.parseInt(decryptedPushMessage.getObjectId().split("/")[1]); + actualIntent.putExtra(BundleKeys.KEY_MESSAGE_ID, messageId); } int intentFlag; diff --git a/app/src/main/java/com/nextcloud/talk/models/json/push/DecryptedPushMessage.kt b/app/src/main/java/com/nextcloud/talk/models/json/push/DecryptedPushMessage.kt index a992f8bda..001305b51 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/push/DecryptedPushMessage.kt +++ b/app/src/main/java/com/nextcloud/talk/models/json/push/DecryptedPushMessage.kt @@ -62,10 +62,13 @@ data class DecryptedPushMessage( var text: String?, @JsonIgnore - var timestamp: Long + var timestamp: Long, + + @JsonIgnore + var objectId: String? ) : Parcelable { // This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject' - constructor() : this(null, null, "", null, 0, null, false, false, false, null, null, 0) + constructor() : this(null, null, "", null, 0, null, false, false, false, null, null, 0, null) override fun equals(other: Any?): Boolean { if (this === other) return true @@ -88,6 +91,7 @@ data class DecryptedPushMessage( if (notificationUser != other.notificationUser) return false if (text != other.text) return false if (timestamp != other.timestamp) return false + if (objectId != other.objectId) return false return true } @@ -105,6 +109,7 @@ data class DecryptedPushMessage( result = 31 * result + (notificationUser?.hashCode() ?: 0) result = 31 * result + (text?.hashCode() ?: 0) result = 31 * result + (timestamp?.hashCode() ?: 0) + result = 31 * result + (objectId?.hashCode() ?: 0) return result } }