Refactor notifications to Kotlin & paging (#4026)
This refactors the NotificationsFragment and related classes to Kotlin & paging. While trying to preserve as much of the original behavior as possible, this adds the following improvements as well: - The "show notifications filter" preference was added again - The "load more" button now has a background ripple effect when clicked - The "legal" report category of Mastodon 4.2 is now supported in report notifications - Unknown notifications now display "unknown notification type" instead of an empty line Other code quality improvements: - All views from xml layouts are now referenced via ViewBindings - the classes responsible for showing system notifications were moved to a new package `systemnotifications` while the classes from this refactoring are in `notifications` - the id of the local Tusky account is now called `tuskyAccountId` in all places I could find closes https://github.com/tuskyapp/Tusky/issues/3429 --------- Co-authored-by: Zongle Wang <wangzongler@gmail.com>
This commit is contained in:
parent
3bbf96b057
commit
b2c0b18c8e
121 changed files with 6992 additions and 4654 deletions
|
|
@ -0,0 +1,66 @@
|
|||
/* Copyright 2024 Tusky Contributors
|
||||
*
|
||||
* This file is a part of Tusky.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky.db
|
||||
|
||||
import androidx.room.withTransaction
|
||||
import com.keylesspalace.tusky.db.entity.HomeTimelineEntity
|
||||
import com.keylesspalace.tusky.db.entity.NotificationEntity
|
||||
import com.keylesspalace.tusky.db.entity.NotificationReportEntity
|
||||
import com.keylesspalace.tusky.db.entity.TimelineAccountEntity
|
||||
import com.keylesspalace.tusky.db.entity.TimelineStatusEntity
|
||||
import javax.inject.Inject
|
||||
|
||||
class DatabaseCleaner @Inject constructor(
|
||||
private val db: AppDatabase
|
||||
) {
|
||||
/**
|
||||
* Cleans the [HomeTimelineEntity], [TimelineStatusEntity], [TimelineAccountEntity], [NotificationEntity] and [NotificationReportEntity] tables from old entries.
|
||||
* Should be regularly run to prevent the database from growing too big.
|
||||
* @param tuskyAccountId id of the account for which to clean tables
|
||||
* @param timelineLimit how many timeline items to keep
|
||||
* @param notificationLimit how many notifications to keep
|
||||
*/
|
||||
suspend fun cleanupOldData(
|
||||
tuskyAccountId: Long,
|
||||
timelineLimit: Int,
|
||||
notificationLimit: Int
|
||||
) {
|
||||
db.withTransaction {
|
||||
// the order here is important - foreign key constraints must not be violated
|
||||
db.notificationsDao().cleanupNotifications(tuskyAccountId, notificationLimit)
|
||||
db.notificationsDao().cleanupReports(tuskyAccountId)
|
||||
db.timelineDao().cleanupHomeTimeline(tuskyAccountId, timelineLimit)
|
||||
db.timelineStatusDao().cleanupStatuses(tuskyAccountId)
|
||||
db.timelineAccountDao().cleanupAccounts(tuskyAccountId)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes everything from the [HomeTimelineEntity], [TimelineStatusEntity], [TimelineAccountEntity], [NotificationEntity] and [NotificationReportEntity] tables for one user.
|
||||
* Intended to be used when a user logs out.
|
||||
* @param tuskyAccountId id of the account for which to clean tables
|
||||
*/
|
||||
suspend fun cleanupEverything(tuskyAccountId: Long) {
|
||||
db.withTransaction {
|
||||
// the order here is important - foreign key constraints must not be violated
|
||||
db.notificationsDao().removeAllNotifications(tuskyAccountId)
|
||||
db.notificationsDao().removeAllReports(tuskyAccountId)
|
||||
db.timelineDao().removeAllHomeTimelineItems(tuskyAccountId)
|
||||
db.timelineStatusDao().removeAllStatuses(tuskyAccountId)
|
||||
db.timelineAccountDao().removeAllAccounts(tuskyAccountId)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue