Only clear feed from the right user

This commit is contained in:
Matthieu 2021-08-14 19:40:31 +02:00
parent ea2c9bc6db
commit ebec547dd0
7 changed files with 10 additions and 10 deletions

View File

@ -73,7 +73,7 @@ class NotificationsRemoteMediator @Inject constructor(
db.withTransaction {
// clear table in the database
if (loadType == LoadType.REFRESH) {
db.notificationDao().clearFeedContent()
db.notificationDao().clearFeedContent(user.user_id, user.instance_uri)
}
db.notificationDao().insertAll(apiResponse)
}

View File

@ -59,7 +59,7 @@ class HomeFeedRemoteMediator @Inject constructor(
db.withTransaction {
// clear table in the database
if (loadType == LoadType.REFRESH) {
db.homePostDao().clearFeedContent()
db.homePostDao().clearFeedContent(user.user_id, user.instance_uri)
}
db.homePostDao().insertAll(dbObjects)
}

View File

@ -74,7 +74,7 @@ class PublicFeedRemoteMediator @Inject constructor(
db.withTransaction {
// clear table in the database
if (loadType == LoadType.REFRESH) {
db.publicPostDao().clearFeedContent()
db.publicPostDao().clearFeedContent(user.user_id, user.instance_uri)
}
db.publicPostDao().insertAll(dbObjects)
}

View File

@ -9,7 +9,7 @@ interface FeedContentDao<T: FeedContentDatabase>{
fun feedContent(userId: String, instanceUri: String): PagingSource<Int, T>
suspend fun clearFeedContent()
suspend fun clearFeedContent(userId: String, instanceUri: String)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(feedContent: List<T>)

View File

@ -8,8 +8,8 @@ import org.pixeldroid.app.utils.api.objects.Notification
@Dao
interface NotificationDao: FeedContentDao<Notification> {
@Query("DELETE FROM notifications")
override suspend fun clearFeedContent()
@Query("DELETE FROM notifications WHERE user_id=:userId AND instance_uri=:instanceUri")
override suspend fun clearFeedContent(userId: String, instanceUri: String)
@Query("""SELECT * FROM notifications WHERE user_id=:userId AND instance_uri=:instanceUri
ORDER BY CAST(created_at AS FLOAT) DESC""")

View File

@ -12,8 +12,8 @@ interface HomePostDao: FeedContentDao<HomeStatusDatabaseEntity> {
ORDER BY CAST(created_at AS FLOAT)""")
override fun feedContent(userId: String, instanceUri: String): PagingSource<Int, HomeStatusDatabaseEntity>
@Query("DELETE FROM homePosts")
override suspend fun clearFeedContent()
@Query("DELETE FROM homePosts WHERE user_id=:userId AND instance_uri=:instanceUri")
override suspend fun clearFeedContent(userId: String, instanceUri: String)
@Query("DELETE FROM homePosts WHERE user_id=:userId AND instance_uri=:instanceUri AND id=:id")
override suspend fun delete(id: String, userId: String, instanceUri: String)

View File

@ -12,8 +12,8 @@ interface PublicPostDao: FeedContentDao<PublicFeedStatusDatabaseEntity> {
ORDER BY CAST(created_at AS FLOAT)""")
override fun feedContent(userId: String, instanceUri: String): PagingSource<Int, PublicFeedStatusDatabaseEntity>
@Query("DELETE FROM publicPosts")
override suspend fun clearFeedContent()
@Query("DELETE FROM publicPosts WHERE user_id=:userId AND instance_uri=:instanceUri")
override suspend fun clearFeedContent(userId: String, instanceUri: String)
@Query("DELETE FROM publicPosts WHERE user_id=:userId AND instance_uri=:instanceUri AND id=:id")
override suspend fun delete(id: String, userId: String, instanceUri: String)