diff --git a/changelog.d/7475.bugfix b/changelog.d/7475.bugfix new file mode 100644 index 0000000000..7d0c3866a0 --- /dev/null +++ b/changelog.d/7475.bugfix @@ -0,0 +1 @@ +[Push Notifications, Threads] - quick reply to threaded notification now sent to thread except main timeline diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationBroadcastReceiver.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationBroadcastReceiver.kt index 455f4778e8..e231686c27 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationBroadcastReceiver.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationBroadcastReceiver.kt @@ -118,6 +118,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { private fun handleSmartReply(intent: Intent, context: Context) { val message = getReplyMessage(intent) val roomId = intent.getStringExtra(KEY_ROOM_ID) + val threadId = intent.getStringExtra(KEY_THREAD_ID) if (message.isNullOrBlank() || roomId.isNullOrBlank()) { // ignore this event @@ -126,13 +127,20 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { } activeSessionHolder.getActiveSession().let { session -> session.getRoom(roomId)?.let { room -> - sendMatrixEvent(message, session, room, context) + sendMatrixEvent(message, threadId, session, room, context) } } } - private fun sendMatrixEvent(message: String, session: Session, room: Room, context: Context?) { - room.sendService().sendTextMessage(message) + private fun sendMatrixEvent(message: String, threadId: String?, session: Session, room: Room, context: Context?) { + if (threadId != null) { + room.relationService().replyInThread( + rootThreadEventId = threadId, + replyInThreadText = message, + ) + } else { + room.sendService().sendTextMessage(message) + } // Create a new event to be displayed in the notification drawer, right now @@ -148,7 +156,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { body = message, imageUriString = null, roomId = room.roomId, - threadId = null, // needs to be changed: https://github.com/vector-im/element-android/issues/7475 + threadId = threadId, roomName = room.roomSummary()?.displayName ?: room.roomId, roomIsDirect = room.roomSummary()?.isDirect == true, outGoingMessage = true, @@ -223,6 +231,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { companion object { const val KEY_ROOM_ID = "roomID" + const val KEY_THREAD_ID = "threadID" const val KEY_TEXT_REPLY = "key_text_reply" } } diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt index 7bf78bdb95..5b3a244137 100755 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationUtils.kt @@ -657,7 +657,7 @@ class NotificationUtils @Inject constructor( // Quick reply if (!roomInfo.hasSmartReplyError) { - buildQuickReplyIntent(roomInfo.roomId, senderDisplayNameForReplyCompat)?.let { replyPendingIntent -> + buildQuickReplyIntent(roomInfo.roomId, threadId, senderDisplayNameForReplyCompat)?.let { replyPendingIntent -> val remoteInput = RemoteInput.Builder(NotificationBroadcastReceiver.KEY_TEXT_REPLY) .setLabel(stringProvider.getString(R.string.action_quick_reply)) .build() @@ -892,13 +892,17 @@ class NotificationUtils @Inject constructor( However, for Android devices running Marshmallow and below (API level 23 and below), it will be more appropriate to use an activity. Since you have to provide your own UI. */ - private fun buildQuickReplyIntent(roomId: String, senderName: String?): PendingIntent? { + private fun buildQuickReplyIntent(roomId: String, threadId: String?, senderName: String?): PendingIntent? { val intent: Intent if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { intent = Intent(context, NotificationBroadcastReceiver::class.java) intent.action = actionIds.smartReply intent.data = createIgnoredUri(roomId) intent.putExtra(NotificationBroadcastReceiver.KEY_ROOM_ID, roomId) + threadId?.let { + intent.putExtra(NotificationBroadcastReceiver.KEY_THREAD_ID, it) + } + return PendingIntent.getBroadcast( context, clock.epochMillis().toInt(),