Commit ebec547d authored by Matthieu's avatar Matthieu
Browse files

Only clear feed from the right user

parent ea2c9bc6
......@@ -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)
}
......
......@@ -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)
}
......
......@@ -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)
}
......
......@@ -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>)
......
......@@ -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""")
......
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment