Skip to content

Commit 752e2ee

Browse files
authored
Merge pull request #5565 from nextcloud/bugfix/noid/improveNotificationHandling
Bugfix/noid/improve notification handling
2 parents 03757d5 + 78383fa commit 752e2ee

File tree

3 files changed

+58
-28
lines changed

3 files changed

+58
-28
lines changed

app/src/main/java/com/nextcloud/talk/jobs/NotificationWorker.kt

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
192192

193193
private fun handleNonCallPushMessage() {
194194
val mainActivityIntent = createMainActivityIntent()
195-
if (pushMessage.notificationId != Long.MIN_VALUE) {
196-
getNcDataAndShowNotification(mainActivityIntent)
197-
} else {
198-
showNotification(mainActivityIntent, null)
199-
}
195+
getNcDataAndShowNotification(mainActivityIntent)
200196
}
201197

202198
private fun handleRemoteTalkSharePushMessage() {
@@ -206,12 +202,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
206202
bundle.putLong(KEY_INTERNAL_USER_ID, signatureVerification.user!!.id!!)
207203
bundle.putBoolean(KEY_REMOTE_TALK_SHARE, true)
208204
mainActivityIntent.putExtras(bundle)
209-
210-
if (pushMessage.notificationId != Long.MIN_VALUE) {
211-
getNcDataAndShowNotification(mainActivityIntent)
212-
} else {
213-
showNotification(mainActivityIntent, null)
214-
}
205+
getNcDataAndShowNotification(mainActivityIntent)
215206
}
216207

217208
private fun handleCallPushMessage() {
@@ -387,7 +378,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
387378
credentials,
388379
ApiUtils.getUrlForNcNotificationWithId(
389380
user!!.baseUrl!!,
390-
(pushMessage.notificationId!!).toString()
381+
pushMessage.notificationId.toString()
391382
)
392383
)
393384
.blockingSubscribe(object : Observer<NotificationOverall> {
@@ -408,7 +399,17 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
408399
}
409400

410401
override fun onError(e: Throwable) {
411-
Log.e(TAG, "Failed to get NC notification", e)
402+
fun setContentsFromPushNotificationSubject() {
403+
if (pushMessage.subject.contains(LINEBREAK)) {
404+
pushMessage.text = pushMessage.subject.substringAfter(LINEBREAK)
405+
pushMessage.subject = pushMessage.subject.substringBefore(LINEBREAK)
406+
}
407+
}
408+
409+
setContentsFromPushNotificationSubject()
410+
showNotification(intent, null)
411+
412+
Log.e(TAG, "Failed to get NC notification. Using decrypted data from push notification itself", e)
412413
if (BuildConfig.DEBUG) {
413414
Handler(Looper.getMainLooper()).post {
414415
Toast.makeText(context, "Failed to get NC notification", Toast.LENGTH_LONG).show()
@@ -505,13 +506,25 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
505506

506507
var contentText: CharSequence? = ""
507508
if (!TextUtils.isEmpty(pushMessage.text)) {
508-
contentText = EmojiCompat.get().process(pushMessage.text!!)
509+
contentText = EmojiCompat.get().process(pushMessage.text)
509510
}
510511

511512
val autoCancelOnClick = TYPE_RECORDING != pushMessage.type
512513

513514
val notificationBuilder =
514-
createNotificationBuilder(category, contentTitle, contentText, baseUrl, pendingIntent, autoCancelOnClick)
515+
createNotificationBuilder(
516+
category,
517+
contentTitle,
518+
contentText,
519+
baseUrl,
520+
pendingIntent,
521+
autoCancelOnClick
522+
)
523+
524+
if (ncNotification != null) {
525+
notificationBuilder.setLargeIcon(getLargeIcon())
526+
}
527+
515528
val activeStatusBarNotification = findNotificationForRoom(
516529
context,
517530
signatureVerification.user!!,
@@ -523,12 +536,13 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
523536
val systemNotificationId: Int =
524537
activeStatusBarNotification?.id ?: calculateCRC32(System.currentTimeMillis().toString()).toInt()
525538

526-
if ((TYPE_CHAT == pushMessage.type || TYPE_REMINDER == pushMessage.type) &&
527-
pushMessage.notificationUser != null
528-
) {
529-
prepareChatNotification(notificationBuilder, activeStatusBarNotification)
530-
addReplyAction(notificationBuilder, systemNotificationId)
531-
addMarkAsReadAction(notificationBuilder, systemNotificationId)
539+
if (TYPE_CHAT == pushMessage.type || TYPE_REMINDER == pushMessage.type) {
540+
notificationBuilder.setOnlyAlertOnce(false)
541+
if (pushMessage.notificationUser != null) {
542+
styleChatNotification(notificationBuilder, activeStatusBarNotification)
543+
addReplyAction(notificationBuilder, systemNotificationId)
544+
addMarkAsReadAction(notificationBuilder, systemNotificationId)
545+
}
532546
}
533547

534548
if (TYPE_RECORDING == pushMessage.type && ncNotification != null) {
@@ -549,7 +563,6 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
549563
val notificationBuilder = NotificationCompat.Builder(context!!, "1")
550564
.setPriority(NotificationCompat.PRIORITY_HIGH)
551565
.setCategory(category)
552-
.setLargeIcon(getLargeIcon())
553566
.setSmallIcon(R.drawable.ic_notification)
554567
.setContentTitle(contentTitle)
555568
.setContentText(contentText)
@@ -600,7 +613,7 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
600613
"one2one" -> {
601614
pushMessage.subject = ""
602615
largeIcon =
603-
ContextCompat.getDrawable(context!!, R.drawable.ic_people_group_black_24px)?.toBitmap()!!
616+
ContextCompat.getDrawable(context!!, R.drawable.ic_baseline_person_black_24)?.toBitmap()!!
604617
}
605618

606619
"group" ->
@@ -630,12 +643,13 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
630643
return crc32.value
631644
}
632645

633-
private fun prepareChatNotification(
646+
private fun styleChatNotification(
634647
notificationBuilder: NotificationCompat.Builder,
635648
activeStatusBarNotification: StatusBarNotification?
636649
) {
637-
val notificationUser = pushMessage.notificationUser
638-
val userType = notificationUser!!.type
650+
val notificationUser = pushMessage.notificationUser ?: return
651+
652+
val userType = notificationUser.type
639653
var style: NotificationCompat.MessagingStyle? = null
640654
if (activeStatusBarNotification != null) {
641655
style = NotificationCompat.MessagingStyle.extractMessagingStyleFromNotification(
@@ -646,7 +660,6 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
646660
.setKey(signatureVerification.user!!.id.toString() + "@" + notificationUser.id)
647661
.setName(EmojiCompat.get().process(notificationUser.name!!))
648662
.setBot("bot" == userType)
649-
notificationBuilder.setOnlyAlertOnce(false)
650663

651664
if ("user" == userType || "guest" == userType) {
652665
val baseUrl = signatureVerification.user!!.baseUrl
@@ -1023,5 +1036,6 @@ class NotificationWorker(context: Context, workerParams: WorkerParameters) : Wor
10231036
private const val TIMER_START = 1
10241037
private const val TIMER_COUNT = 12
10251038
private const val TIMER_DELAY: Long = 5
1039+
private const val LINEBREAK: String = "\n"
10261040
}
10271041
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!--
2+
~ Nextcloud Talk - Android Client
3+
~
4+
~ SPDX-FileCopyrightText: 2021-2025 Google LLC
5+
~ SPDX-License-Identifier: Apache-2.0
6+
-->
7+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
8+
android:width="24dp"
9+
android:height="24dp"
10+
android:tint="#FF000000"
11+
android:viewportWidth="960"
12+
android:viewportHeight="960">
13+
<path
14+
android:fillColor="@android:color/white"
15+
android:pathData="M480,480Q414,480 367,433Q320,386 320,320Q320,254 367,207Q414,160 480,160Q546,160 593,207Q640,254 640,320Q640,386 593,433Q546,480 480,480ZM160,800L160,688Q160,654 177.5,625.5Q195,597 224,582Q286,551 350,535.5Q414,520 480,520Q546,520 610,535.5Q674,551 736,582Q765,597 782.5,625.5Q800,654 800,688L800,800L160,800ZM240,720L720,720L720,688Q720,677 714.5,668Q709,659 700,654Q646,627 591,613.5Q536,600 480,600Q424,600 369,613.5Q314,627 260,654Q251,659 245.5,668Q240,677 240,688L240,720ZM480,400Q513,400 536.5,376.5Q560,353 560,320Q560,287 536.5,263.5Q513,240 480,240Q447,240 423.5,263.5Q400,287 400,320Q400,353 423.5,376.5Q447,400 480,400ZM480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320Q480,320 480,320ZM480,720L480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720L480,720Z" />
16+
</vector>

detekt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
22
# SPDX-License-Identifier: GPL-3.0-or-later
33
build:
4-
maxIssues: 80
4+
maxIssues: 81
55
weights:
66
# complexity: 2
77
# LongParameterList: 1

0 commit comments

Comments
 (0)