Insert starred items at initial synchronisation and don´t forget starred items which are read

This commit is contained in:
Shinokuni 2021-07-02 14:30:01 +02:00
parent 1011eee9df
commit af5138c1cb

View File

@ -130,6 +130,9 @@ public class FreshRSSRepository extends ARepository {
insertItems(syncResult.getItems());
logger.addSplit("items insertion");
insertItems(syncResult.getStarredItems());
logger.addSplit("starred items insertion");
insertItemsIds(syncResult.getUnreadIds(), syncResult.getStarredIds());
logger.addSplit("insert and update items ids");
@ -256,10 +259,20 @@ public class FreshRSSRepository extends ARepository {
private void insertItemsIds(List<String> unreadIds, List<String> starredIds) {
database.itemStateDao().deleteItemsStates(account.getId());
database.itemStateDao().insertItemStates(unreadIds.stream().map(id ->
new ItemState(0, false, starredIds.stream()
.anyMatch(starredId -> starredId.equals(id)), id, account.getId()))
.collect(Collectors.toList()));
database.itemStateDao().insertItemStates(unreadIds.stream().map(id -> {
boolean starred = starredIds.stream().filter(starredId -> starredId.equals(id)).count() == 1;
starredIds.remove(id);
return new ItemState(0, false, starred, id, account.getId());
}
).collect(Collectors.toList()));
// insert starred items ids which are read
if (!starredIds.isEmpty()) {
database.itemStateDao().insertItemStates(starredIds.stream().map(id ->
new ItemState(0, true, true, id, account.getId()))
.collect(Collectors.toList()));
}
}
}