Handle read/star state for local account

This commit is contained in:
Shinokuni 2021-07-01 22:53:25 +02:00
parent d600633aca
commit 1011eee9df
2 changed files with 22 additions and 6 deletions

View File

@ -115,9 +115,16 @@ public abstract class ARepository {
}
public Completable setItemReadState(Item item) {
return database.itemStateChangesDao().upsertItemReadStateChange(item, account.getId())
.andThen(database.itemStateDao().upsertItemReadState(new ItemState(0, item.isRead(),
item.isStarred(), item.getRemoteId(), account.getId())));
if (account.getConfig().useSeparateState()) {
return database.itemStateChangesDao().upsertItemReadStateChange(item, account.getId())
.andThen(database.itemStateDao().upsertItemReadState(new ItemState(0, item.isRead(),
item.isStarred(), item.getRemoteId(), account.getId())));
} else if (account.isLocal()) {
return database.itemDao().setReadState(item.getId(), item.isRead());
} else { // TODO nextcloud case, use only ItemStateChange table
return Completable.complete();
}
}
public Completable setAllItemsReadState(boolean read) {
@ -129,9 +136,15 @@ public abstract class ARepository {
}
public Completable setItemStarState(Item item) {
return database.itemStateChangesDao().upsertItemStarStateChange(item, account.getId())
.andThen(database.itemStateDao().upsertItemStarState(new ItemState(0, item.isRead(),
item.isStarred(), item.getRemoteId(), account.getId())));
if (account.getConfig().useSeparateState()) {
return database.itemStateChangesDao().upsertItemStarStateChange(item, account.getId())
.andThen(database.itemStateDao().upsertItemStarState(new ItemState(0, item.isRead(),
item.isStarred(), item.getRemoteId(), account.getId())));
} else if (account.isLocal()) {
return database.itemDao().setStarState(item.getId(), item.isRead());
} else { // TODO nextcloud case, use only ItemStateChange table
return Completable.complete();
}
}

View File

@ -40,6 +40,9 @@ public interface ItemDao extends BaseDao<Item> {
@Query("Update Item Set read = :read Where id = :itemId")
Completable setReadState(int itemId, boolean read);
@Query("Update Item set starred = :starred Where id = :itemId")
Completable setStarState(int itemId, boolean starred);
@Query("Update Item set read = :readState Where feed_id In (Select id From Feed Where account_id = :accountId)")
Completable setAllItemsReadState(int readState, int accountId);