diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index c24bf1b7bf5..aecdd392da4 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -205,6 +205,7 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_FILE_PATHS import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_BREAKOUT_ROOM import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_MODERATOR +import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_OPENED_VIA_NOTIFICATION import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_RECORDING_STATE import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_START_CALL_AFTER_ROOM_SWITCH @@ -367,6 +368,7 @@ class ChatActivity : var sessionIdAfterRoomJoined: String? = null lateinit var roomToken: String var conversationThreadId: Long? = null + var openedViaNotification: Boolean = false var conversationThreadInfo: ThreadInfo? = null var conversationUser: User? = null lateinit var spreedCapabilities: SpreedCapability @@ -409,12 +411,11 @@ class ChatActivity : private val onBackPressedCallback = object : OnBackPressedCallback(true) { override fun handleOnBackPressed() { - if (isChatThread()) { + if (!openedViaNotification && isChatThread()) { isEnabled = false onBackPressedDispatcher.onBackPressed() } else { val intent = Intent(this@ChatActivity, ConversationsListActivity::class.java) - intent.putExtras(Bundle()) startActivity(intent) } } @@ -595,6 +596,8 @@ class ChatActivity : null } + openedViaNotification = extras?.getBoolean(KEY_OPENED_VIA_NOTIFICATION) ?: false + sharedText = extras?.getString(BundleKeys.KEY_SHARED_TEXT).orEmpty() Log.d(TAG, " roomToken = $roomToken") diff --git a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt index df264362187..4a996cb5c5c 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt +++ b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt @@ -85,6 +85,8 @@ import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ONE_TO_ONE import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SHARE_RECORDING_TO_CHAT_URL import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_SYSTEM_NOTIFICATION_ID +import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_THREAD_ID +import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_OPENED_VIA_NOTIFICATION import com.nextcloud.talk.utils.preferences.AppPreferences import io.reactivex.Observable import io.reactivex.Observer @@ -397,6 +399,10 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor val ncNotification = notificationOverall.ocs!!.notification if (ncNotification != null) { enrichPushMessageByNcNotificationData(ncNotification) + + val threadId = parseThreadId(ncNotification.objectId) + threadId?.let { intent.putExtra(KEY_THREAD_ID, it) } + showNotification(intent, ncNotification) } } @@ -827,6 +833,8 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor } } + private fun parseThreadId(objectId: String?): Long? = objectId?.split("/")?.getOrNull(2)?.toLongOrNull() + private fun sendNotification(notificationId: Int, notification: Notification) { Log.d(TAG, "show notification with id $notificationId") if (ActivityCompat.checkSelfPermission( @@ -982,6 +990,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor val bundle = Bundle() bundle.putString(KEY_ROOM_TOKEN, pushMessage.id) bundle.putLong(KEY_INTERNAL_USER_ID, signatureVerification.user!!.id!!) + bundle.putBoolean(KEY_OPENED_VIA_NOTIFICATION, true) intent.putExtras(bundle) return intent } diff --git a/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt b/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt index 7d6d5280a39..d31b7c6e388 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.kt @@ -84,4 +84,5 @@ object BundleKeys { const val KEY_FOCUS_INPUT: String = "KEY_FOCUS_INPUT" const val KEY_THREAD_ID = "KEY_THREAD_ID" const val KEY_FROM_QR: String = "KEY_FROM_QR" + const val KEY_OPENED_VIA_NOTIFICATION: String = "KEY_OPENED_VIA_NOTIFICATION" }