feat: notification filtering

This commit is contained in:
rebelonion 2024-05-09 06:02:17 -05:00
parent be97229618
commit e1a865c973
10 changed files with 151 additions and 10 deletions

View file

@ -64,7 +64,7 @@ class CommentNotificationTask : Task {
val type: CommentNotificationWorker.NotificationType = when (it.type) {
1 -> CommentNotificationWorker.NotificationType.COMMENT_REPLY
2 -> CommentNotificationWorker.NotificationType.COMMENT_WARNING
3 -> CommentNotificationWorker.NotificationType.APP_GLOBAL
3 -> CommentNotificationWorker.NotificationType.DANTOTSU_UPDATE
420 -> CommentNotificationWorker.NotificationType.NO_NOTIFICATION
else -> CommentNotificationWorker.NotificationType.UNKNOWN
}
@ -76,6 +76,7 @@ class CommentNotificationTask : Task {
val commentStore = CommentStore(
title,
message,
CommentNotificationWorker.NotificationType.COMMENT_WARNING,
it.mediaId,
it.commentId
)
@ -101,6 +102,7 @@ class CommentNotificationTask : Task {
val commentStore = CommentStore(
title,
message,
CommentNotificationWorker.NotificationType.COMMENT_REPLY,
it.mediaId,
it.commentId
)
@ -118,13 +120,14 @@ class CommentNotificationTask : Task {
)
}
CommentNotificationWorker.NotificationType.APP_GLOBAL -> {
CommentNotificationWorker.NotificationType.DANTOTSU_UPDATE -> {
val title = "Update from Dantotsu"
val message = it.content ?: "New feature available"
val commentStore = CommentStore(
title,
message,
CommentNotificationWorker.NotificationType.DANTOTSU_UPDATE,
null,
null
)
@ -132,7 +135,7 @@ class CommentNotificationTask : Task {
createNotification(
context,
CommentNotificationWorker.NotificationType.APP_GLOBAL,
CommentNotificationWorker.NotificationType.DANTOTSU_UPDATE,
message,
title,
0,
@ -265,7 +268,7 @@ class CommentNotificationTask : Task {
builder.build()
}
CommentNotificationWorker.NotificationType.APP_GLOBAL -> {
CommentNotificationWorker.NotificationType.DANTOTSU_UPDATE -> {
val intent = Intent(context, MainActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}

View file

@ -27,7 +27,7 @@ class CommentNotificationWorker(appContext: Context, workerParams: WorkerParamet
enum class NotificationType(val id: String) {
COMMENT_REPLY(Notifications.CHANNEL_COMMENTS),
COMMENT_WARNING(Notifications.CHANNEL_COMMENT_WARING),
APP_GLOBAL(Notifications.CHANNEL_APP_GLOBAL),
DANTOTSU_UPDATE(Notifications.CHANNEL_APP_GLOBAL),
NO_NOTIFICATION("no_notification"),
UNKNOWN("unknown")
}

View file

@ -3,11 +3,11 @@ package ani.dantotsu.notifications.comment
import kotlinx.serialization.Serializable
@Suppress("INAPPROPRIATE_CONST_NAME")
@Serializable
data class CommentStore(
val title: String,
val content: String,
val type: CommentNotificationWorker.NotificationType,
val mediaId: Int? = null,
val commentId: Int? = null,
val time: Long = System.currentTimeMillis(),
@ -15,6 +15,6 @@ data class CommentStore(
companion object {
@Suppress("INAPPROPRIATE_CONST_NAME")
private const val serialVersionUID = 1L
private const val serialVersionUID = 2L
}
}