@@ -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}
0 commit comments