From fde635d61bf860c8f139963f1caaad53b3d5775d Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 20 Feb 2024 13:51:59 +0100 Subject: [PATCH] show test notification + modify doc show test notification from occ notification:test-push --talk username This will directly show the push notification without to fetch any data from nextcloud instance. Additionally some additions to documentation were made Signed-off-by: Marcel Hibbe --- .../nextcloud/talk/jobs/NotificationWorker.kt | 31 ++++++++++++++----- docs/notifications.md | 7 +++-- 2 files changed, 28 insertions(+), 10 deletions(-) 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 6a31a389b..78b8a1308 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt +++ b/app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt @@ -172,13 +172,19 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor for (notificationId in pushMessage.notificationIds!!) { cancelNotification(context, signatureVerification.user!!, notificationId) } - } else if (isSpreedNotification()) { + } else if (isTalkNotification()) { Log.d(TAG, "pushMessage.type: " + pushMessage.type) when (pushMessage.type) { TYPE_CHAT, TYPE_ROOM, TYPE_RECORDING, TYPE_REMINDER -> handleNonCallPushMessage() TYPE_REMOTE_TALK_SHARE -> handleRemoteTalkSharePushMessage() TYPE_CALL -> handleCallPushMessage() - else -> Log.e(TAG, "unknown pushMessage.type") + else -> Log.e(TAG, pushMessage.type + " is not handled") + } + } else if (isAdminTalkNotification()) { + Log.d(TAG, "pushMessage.type: " + pushMessage.type) + when (pushMessage.type) { + TYPE_ADMIN_NOTIFICATIONS -> handleTestPushMessage() + else -> Log.e(TAG, pushMessage.type + " is not handled") } } else { Log.d(TAG, "a pushMessage that is not for spreed was received.") @@ -187,6 +193,12 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor return Result.success() } + private fun handleTestPushMessage() { + val intent = Intent(context, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK + showNotification(intent, null) + } + private fun handleNonCallPushMessage() { val mainActivityIntent = createMainActivityIntent() if (pushMessage.notificationId != Long.MIN_VALUE) { @@ -315,7 +327,9 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor } } - private fun isSpreedNotification() = SPREED_APP == pushMessage.app + private fun isTalkNotification() = SPREED_APP == pushMessage.app + + private fun isAdminTalkNotification() = ADMIN_NOTIFICATION_TALK == pushMessage.app private fun getNcDataAndShowNotification(intent: Intent) { val user = signatureVerification.user @@ -419,11 +433,12 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor ) { var category = "" when (pushMessage.type) { - TYPE_CHAT, TYPE_ROOM, TYPE_RECORDING, TYPE_REMINDER, TYPE_REMOTE_TALK_SHARE -> { + TYPE_CHAT, TYPE_ROOM, TYPE_RECORDING, TYPE_REMINDER, TYPE_ADMIN_NOTIFICATIONS, TYPE_REMOTE_TALK_SHARE -> category = Notification.CATEGORY_MESSAGE - } - TYPE_CALL -> category = Notification.CATEGORY_CALL + TYPE_CALL -> + category = Notification.CATEGORY_CALL + else -> Log.e(TAG, "unknown pushMessage.type") } @@ -479,7 +494,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { when (pushMessage.type) { - TYPE_CHAT, TYPE_ROOM, TYPE_RECORDING, TYPE_REMINDER, TYPE_REMOTE_TALK_SHARE -> { + TYPE_CHAT, TYPE_ROOM, TYPE_RECORDING, TYPE_REMINDER, TYPE_ADMIN_NOTIFICATIONS, TYPE_REMOTE_TALK_SHARE -> { notificationBuilder.setChannelId( NotificationUtils.NotificationChannels.NOTIFICATION_CHANNEL_MESSAGES_V4.name ) @@ -1012,7 +1027,9 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor private const val TYPE_RECORDING = "recording" private const val TYPE_REMOTE_TALK_SHARE = "remote_talk_share" private const val TYPE_REMINDER = "reminder" + private const val TYPE_ADMIN_NOTIFICATIONS = "admin_notifications" private const val SPREED_APP = "spreed" + private const val ADMIN_NOTIFICATION_TALK = "admin_notification_talk" private const val TIMER_START = 1 private const val TIMER_COUNT = 12 private const val TIMER_DELAY: Long = 5 diff --git a/docs/notifications.md b/docs/notifications.md index 436b76d2a..c6836e16a 100644 --- a/docs/notifications.md +++ b/docs/notifications.md @@ -22,6 +22,8 @@ If your problem still occurs after checking all these hints, create an issue at ### 🤖 Check android settings +Please check the "Notifications" section in the app settings which should show warnings if anything needs to be +adjusted. Please take into account that the android settings might be different for each manufacturer. It might be worth it to check what other messaging apps recommend to get their apps running on a certain smartphone and adapt this to the talk app. Also [https://dontkillmyapp.com/](https://dontkillmyapp.com/) might be good starting point. @@ -91,9 +93,8 @@ Data to encrypt is: {"nid":525210,"app":"admin_notification_talk","subject":"Tes Signed encrypted push subject Push notification sent successfully ``` -This means the notifications are set up correctly on server side. Note that there won't be any notification on the -phone as this is just a test-message which won't be handled (As a developer you could set a breakpoint in the -"onMessageReceived"-method of the Firebase cloud messaging handling to check if the notification is received). +This means the notifications are set up correctly on server side. A notification should be displayed on the device. +If there is no notification shown on the device, please focus on the settings of the talk android app. If it prints something like ```