Fix clear=true
This commit is contained in:
parent
b20f1322ef
commit
3daa41f89a
4 changed files with 28 additions and 3 deletions
|
|
@ -4,8 +4,13 @@ import android.app.Application
|
|||
import com.google.android.material.color.DynamicColors
|
||||
import io.heckel.ntfy.db.Repository
|
||||
import io.heckel.ntfy.util.Log
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
|
||||
class Application : Application() {
|
||||
val ioScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
|
||||
val repository by lazy {
|
||||
val repository = Repository.getInstance(applicationContext)
|
||||
if (repository.getRecordLogs()) {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import io.heckel.ntfy.ui.MainActivity
|
|||
import io.heckel.ntfy.util.*
|
||||
import java.util.*
|
||||
import androidx.core.net.toUri
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class NotificationService(val context: Context) {
|
||||
private val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
|
|
@ -135,8 +136,8 @@ class NotificationService(val context: Context) {
|
|||
private fun setStyleAndText(builder: NotificationCompat.Builder, subscription: Subscription, notification: Notification) {
|
||||
val contentUri = notification.attachment?.contentUri
|
||||
val isSupportedImage = supportedImage(notification.attachment?.type)
|
||||
val subscriptionIcon = if (subscription.icon != null) subscription.icon.readBitmapFromUriOrNull(context) else null
|
||||
val notificationIcon = if (notification.icon != null) notification.icon.contentUri?.readBitmapFromUriOrNull(context) else null
|
||||
val subscriptionIcon = subscription.icon?.readBitmapFromUriOrNull(context)
|
||||
val notificationIcon = notification.icon?.contentUri?.readBitmapFromUriOrNull(context)
|
||||
val largeIcon = notificationIcon ?: subscriptionIcon
|
||||
if (contentUri != null && isSupportedImage) {
|
||||
try {
|
||||
|
|
@ -299,6 +300,8 @@ class NotificationService(val context: Context) {
|
|||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
putExtra(VIEW_ACTION_EXTRA_URL, url)
|
||||
putExtra(VIEW_ACTION_EXTRA_NOTIFICATION_ID, notification.notificationId)
|
||||
putExtra(VIEW_ACTION_EXTRA_SUBSCRIPTION_ID, notification.subscriptionId)
|
||||
putExtra(VIEW_ACTION_EXTRA_SEQUENCE_ID, notification.sequenceId)
|
||||
}
|
||||
val pendingIntent = PendingIntent.getActivity(context, Random().nextInt(), intent, PendingIntent.FLAG_IMMUTABLE)
|
||||
builder.addAction(NotificationCompat.Action.Builder(0, action.label, pendingIntent).build())
|
||||
|
|
@ -469,6 +472,8 @@ class NotificationService(val context: Context) {
|
|||
Log.d(TAG, "Created $this")
|
||||
val url = intent.getStringExtra(VIEW_ACTION_EXTRA_URL)
|
||||
val notificationId = intent.getIntExtra(VIEW_ACTION_EXTRA_NOTIFICATION_ID, 0)
|
||||
val subscriptionId = intent.getLongExtra(VIEW_ACTION_EXTRA_SUBSCRIPTION_ID, 0)
|
||||
val sequenceId = intent.getStringExtra(VIEW_ACTION_EXTRA_SEQUENCE_ID) ?: ""
|
||||
if (url == null) {
|
||||
finish()
|
||||
return
|
||||
|
|
@ -492,6 +497,16 @@ class NotificationService(val context: Context) {
|
|||
val notifier = NotificationService(this)
|
||||
notifier.cancel(notificationId)
|
||||
|
||||
// Mark notification as read; We can't use lifecycleScope here, because we
|
||||
// call finish() right after, so we do this awkward ioScope thing.
|
||||
if (subscriptionId != 0L && sequenceId.isNotEmpty()) {
|
||||
val app = applicationContext as io.heckel.ntfy.app.Application
|
||||
app.ioScope.launch {
|
||||
val repository = Repository.getInstance(app)
|
||||
repository.markAsReadBySequenceId(subscriptionId, sequenceId)
|
||||
}
|
||||
}
|
||||
|
||||
// Close this activity
|
||||
finish()
|
||||
}
|
||||
|
|
@ -529,5 +544,7 @@ class NotificationService(val context: Context) {
|
|||
|
||||
private const val VIEW_ACTION_EXTRA_URL = "url"
|
||||
private const val VIEW_ACTION_EXTRA_NOTIFICATION_ID = "notificationId"
|
||||
private const val VIEW_ACTION_EXTRA_SUBSCRIPTION_ID = "subscriptionId"
|
||||
private const val VIEW_ACTION_EXTRA_SEQUENCE_ID = "sequenceId"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ class UserActionWorker(private val context: Context, params: WorkerParameters) :
|
|||
broadcaster.sendUserAction(action)
|
||||
if (action.clear == true) {
|
||||
notifier.cancel(notification)
|
||||
repository.markAsReadBySequenceId(subscription.id, notification.sequenceId)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -98,6 +99,7 @@ class UserActionWorker(private val context: Context, params: WorkerParameters) :
|
|||
repository.updateNotification(notification)
|
||||
if (clear) {
|
||||
notifier.cancel(notification)
|
||||
repository.markAsReadBySequenceId(subscription.id, notification.sequenceId)
|
||||
} else {
|
||||
notifier.update(subscription, notification)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ Features:
|
|||
* Show last notification time for UnifiedPush subscriptions (#1230, #1454, thanks to @Tealk and @user4andre for reporting)
|
||||
|
||||
Bug fixes + maintenance:
|
||||
* Fix clear=true on action buttons not marking notification as read (#1029, thanks to @ElFishi for reporting)
|
||||
* Fix crash when URL scheme is missing in default server (#1582, ntfy-android#158, thanks to @hard-zero1 for reporting)
|
||||
* Fix notification timestamp to use original send time instead of receive time (#1112, thanks to @voruti for reporting)
|
||||
* Fix notifications being missed after service restart (#1591, thanks to @Epifeny for reporting)
|
||||
* Fix notifications being missed after service restart (#1591, thanks to @Epifeny for reporting)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue