feat: subscriptions in notifications

This commit is contained in:
rebelonion 2024-05-17 10:11:42 -05:00
parent 6c1176a182
commit df2867c7db
9 changed files with 105 additions and 19 deletions

View file

@ -188,7 +188,7 @@ class CommentNotificationTask : Task {
null
) ?: listOf()
val newStore = notificationStore.toMutableList()
if (newStore.size > 10) {
if (newStore.size > 30) {
newStore.remove(newStore.minByOrNull { it.time })
}
if (newStore.any { it.content == notification.content }) {

View file

@ -13,8 +13,6 @@ data class CommentStore(
val time: Long = System.currentTimeMillis(),
) : java.io.Serializable {
companion object {
@Suppress("INAPPROPRIATE_CONST_NAME")
private const val serialVersionUID = 2L
}
}

View file

@ -118,6 +118,15 @@ class SubscriptionNotificationTask : Task {
if (ep != null) ep.number + " " + context.getString(R.string.just_released) to null
else null
} ?: return@map
addSubscriptionToStore(
SubscriptionStore(
media.name,
text.first,
media.id
)
)
PrefManager.setVal(PrefName.UnreadCommentNotifications,
PrefManager.getVal<Int>(PrefName.UnreadCommentNotifications) + 1)
val notification = createNotification(
context.applicationContext,
media,
@ -219,4 +228,17 @@ class SubscriptionNotificationTask : Task {
}
)
}
private fun addSubscriptionToStore(notification: SubscriptionStore) {
val notificationStore = PrefManager.getNullableVal<List<SubscriptionStore>>(
PrefName.SubscriptionNotificationStore,
null
) ?: listOf()
val newStore = notificationStore.toMutableList()
if (newStore.size >= 100) {
newStore.remove(newStore.minByOrNull { it.time })
}
newStore.add(notification)
PrefManager.setVal(PrefName.SubscriptionNotificationStore, newStore)
}
}

View file

@ -0,0 +1,16 @@
package ani.dantotsu.notifications.subscription
import kotlinx.serialization.Serializable
@Serializable
data class SubscriptionStore(
val title: String,
val content: String,
val mediaId: Int,
val type: String = "SUBSCRIPTION",
val time: Long = System.currentTimeMillis(),
) : java.io.Serializable {
companion object {
private const val serialVersionUID = 1L
}
}