fixing notifications being dismissed early when there's only 1 left and fixes wrong room being opened when tapping notification

This commit is contained in:
Adam Brown 2022-04-26 21:57:56 +01:00
parent f71f7e9099
commit f3f256e0d3
2 changed files with 10 additions and 3 deletions

View File

@ -4,8 +4,11 @@ import android.app.Notification
import android.app.PendingIntent
import android.app.Person
import android.content.Context
import android.content.Intent
import android.os.Build
import androidx.annotation.RequiresApi
import app.dapk.st.core.AppLogTag
import app.dapk.st.core.log
import app.dapk.st.imageloader.IconLoader
import app.dapk.st.matrix.sync.RoomEvent
import app.dapk.st.matrix.sync.RoomOverview
@ -28,7 +31,7 @@ class NotificationFactory(
}
}
val summaryNotification = if (notifications.filterIsInstance<NotificationDelegate.Room>().size > 1) {
val summaryNotification = if (notifications.filterIsInstance<NotificationDelegate.Room>().isNotEmpty()) {
createSummary(notifications)
} else {
null
@ -102,8 +105,9 @@ class NotificationFactory(
val openRoomIntent = PendingIntent.getActivity(
context,
roomOverview.roomId.hashCode(),
MessengerActivity.newInstance(context, roomOverview.roomId),
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
MessengerActivity.newInstance(context, roomOverview.roomId)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK),
PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
)
return NotificationDelegate.Room(

View File

@ -2,7 +2,9 @@ package app.dapk.st.notifications
import android.app.Notification
import android.app.NotificationManager
import app.dapk.st.core.AppLogTag
import app.dapk.st.core.extensions.ifNull
import app.dapk.st.core.log
import app.dapk.st.matrix.common.RoomId
import app.dapk.st.matrix.sync.RoomEvent
import app.dapk.st.matrix.sync.RoomOverview
@ -20,6 +22,7 @@ class NotificationRenderer(
val notifications = notificationFactory.createNotifications(result)
notifications.summaryNotification.ifNull {
log(AppLogTag.NOTIFICATION, "cancelling summary")
notificationManager.cancel(SUMMARY_NOTIFICATION_ID)
}