mirror of https://github.com/readrops/Readrops.git
Integrate ItemStateChange table in Nextcloud News synchronisation
This commit is contained in:
parent
dfe225ed8d
commit
c9caa0be89
|
@ -121,8 +121,9 @@ public abstract class ARepository {
|
||||||
item.isStarred(), item.getRemoteId(), account.getId())));
|
item.isStarred(), item.getRemoteId(), account.getId())));
|
||||||
} else if (account.isLocal()) {
|
} else if (account.isLocal()) {
|
||||||
return database.itemDao().setReadState(item.getId(), item.isRead());
|
return database.itemDao().setReadState(item.getId(), item.isRead());
|
||||||
} else { // TODO nextcloud case, use only ItemStateChange table
|
} else { // nextcloud case
|
||||||
return Completable.complete();
|
return database.itemStateChangesDao().upsertItemReadStateChange(item, account.getId())
|
||||||
|
.andThen(database.itemDao().setReadState(item.getId(), item.isRead()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -142,8 +143,9 @@ public abstract class ARepository {
|
||||||
item.isStarred(), item.getRemoteId(), account.getId())));
|
item.isStarred(), item.getRemoteId(), account.getId())));
|
||||||
} else if (account.isLocal()) {
|
} else if (account.isLocal()) {
|
||||||
return database.itemDao().setStarState(item.getId(), item.isRead());
|
return database.itemDao().setStarState(item.getId(), item.isRead());
|
||||||
} else { // TODO nextcloud case, use only ItemStateChange table
|
} else { // nextcloud case
|
||||||
return Completable.complete();
|
return database.itemStateChangesDao().upsertItemReadStateChange(item, account.getId())
|
||||||
|
.andThen(database.itemDao().setStarState(item.getId(), item.isRead()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import com.readrops.db.entities.Feed;
|
||||||
import com.readrops.db.entities.Folder;
|
import com.readrops.db.entities.Folder;
|
||||||
import com.readrops.db.entities.Item;
|
import com.readrops.db.entities.Item;
|
||||||
import com.readrops.db.entities.account.Account;
|
import com.readrops.db.entities.account.Account;
|
||||||
|
import com.readrops.db.pojo.ItemReadStarState;
|
||||||
|
|
||||||
import org.joda.time.LocalDateTime;
|
import org.joda.time.LocalDateTime;
|
||||||
import org.koin.java.KoinJavaComponent;
|
import org.koin.java.KoinJavaComponent;
|
||||||
|
@ -31,6 +32,7 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import io.reactivex.Completable;
|
import io.reactivex.Completable;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
|
@ -81,26 +83,55 @@ public class NextNewsRepository extends ARepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Observable<Feed> sync(List<Feed> feeds) {
|
public Observable<Feed> sync(List<Feed> feeds) {
|
||||||
|
setCredentials(account);
|
||||||
return Observable.create(emitter -> {
|
return Observable.create(emitter -> {
|
||||||
try {
|
try {
|
||||||
long lastModified = LocalDateTime.now().toDateTime().getMillis();
|
long lastModified = LocalDateTime.now().toDateTime().getMillis();
|
||||||
SyncType syncType;
|
SyncType syncType;
|
||||||
|
|
||||||
if (account.getLastModified() != 0)
|
if (account.getLastModified() != 0) {
|
||||||
syncType = SyncType.CLASSIC_SYNC;
|
syncType = SyncType.CLASSIC_SYNC;
|
||||||
else
|
} else {
|
||||||
syncType = SyncType.INITIAL_SYNC;
|
syncType = SyncType.INITIAL_SYNC;
|
||||||
|
}
|
||||||
|
|
||||||
NextNewsSyncData syncData = new NextNewsSyncData();
|
NextNewsSyncData syncData = new NextNewsSyncData();
|
||||||
|
|
||||||
if (syncType == SyncType.CLASSIC_SYNC) {
|
if (syncType == SyncType.CLASSIC_SYNC) {
|
||||||
syncData.setLastModified(account.getLastModified() / 1000L);
|
syncData.setLastModified(account.getLastModified() / 1000L);
|
||||||
|
|
||||||
syncData.setReadItems(database.itemDao().getReadChanges(account.getId()));
|
List<ItemReadStarState> itemStateChanges = database
|
||||||
syncData.setUnreadItems(database.itemDao().getUnreadChanges(account.getId()));
|
.itemStateChangesDao()
|
||||||
|
.getItemStateChanges(account.getId());
|
||||||
|
|
||||||
|
syncData.setReadItems(itemStateChanges.stream()
|
||||||
|
.filter(it -> it.getReadChange() && it.getRead())
|
||||||
|
.map(ItemReadStarState::getRemoteId)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
|
syncData.setUnreadItems(itemStateChanges.stream()
|
||||||
|
.filter(it -> it.getReadChange() && !it.getRead())
|
||||||
|
.map(ItemReadStarState::getRemoteId)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
|
List<String> starredItemsIds = itemStateChanges.stream()
|
||||||
|
.filter(it -> it.getStarChange() && it.getStarred())
|
||||||
|
.map(ItemReadStarState::getRemoteId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (!starredItemsIds.isEmpty()) {
|
||||||
|
syncData.setStarredItems(database.itemDao().getStarChanges(starredItemsIds, account.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> unstarredItemsIds = itemStateChanges.stream()
|
||||||
|
.filter(it -> it.getStarChange() && !it.getStarred())
|
||||||
|
.map(ItemReadStarState::getRemoteId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (!unstarredItemsIds.isEmpty()) {
|
||||||
|
syncData.setUnstarredItems(database.itemDao().getUnstarChanges(unstarredItemsIds, account.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
syncData.setStarredItems(database.itemDao().getStarChanges(account.getId()));
|
|
||||||
syncData.setUnstarredItems(database.itemDao().getUnstarChanges(account.getId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TimingLogger timings = new TimingLogger(TAG, "nextcloud news " + syncType.name().toLowerCase());
|
TimingLogger timings = new TimingLogger(TAG, "nextcloud news " + syncType.name().toLowerCase());
|
||||||
|
@ -123,13 +154,7 @@ public class NextNewsRepository extends ARepository {
|
||||||
account.setLastModified(lastModified);
|
account.setLastModified(lastModified);
|
||||||
database.accountDao().updateLastModified(account.getId(), lastModified);
|
database.accountDao().updateLastModified(account.getId(), lastModified);
|
||||||
|
|
||||||
if (!syncData.getReadItems().isEmpty() || !syncData.getUnreadItems().isEmpty()) {
|
database.itemStateChangesDao().resetStateChanges(account.getId());
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!syncData.getStarredItems().isEmpty() || !syncData.getUnstarredItems().isEmpty()) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
emitter.onComplete();
|
emitter.onComplete();
|
||||||
} else {
|
} else {
|
||||||
|
@ -145,6 +170,7 @@ public class NextNewsRepository extends ARepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Single<List<FeedInsertionResult>> addFeeds(List<ParsingResult> results) {
|
public Single<List<FeedInsertionResult>> addFeeds(List<ParsingResult> results) {
|
||||||
|
setCredentials(account);
|
||||||
return Single.create(emitter -> {
|
return Single.create(emitter -> {
|
||||||
List<FeedInsertionResult> feedInsertionResults = new ArrayList<>();
|
List<FeedInsertionResult> feedInsertionResults = new ArrayList<>();
|
||||||
|
|
||||||
|
|
|
@ -58,17 +58,11 @@ public interface ItemDao extends BaseDao<Item> {
|
||||||
@RawQuery(observedEntities = {Item.class, ItemState.class})
|
@RawQuery(observedEntities = {Item.class, ItemState.class})
|
||||||
LiveData<ItemWithFeed> getItemById(SupportSQLiteQuery query);
|
LiveData<ItemWithFeed> getItemById(SupportSQLiteQuery query);
|
||||||
|
|
||||||
@Query("Select Item.remoteId From Item Inner Join Feed On Item.feed_id = Feed.id Where read = 1 And account_id = :accountId")
|
@Query("Select Item.guid, Feed.remoteId as feedRemoteId From Item Inner Join Feed On Item.feed_id = Feed.id Where Item.remoteId In (:remoteIds) And account_id = :accountId")
|
||||||
List<String> getReadChanges(int accountId);
|
List<StarItem> getStarChanges(List<String> remoteIds, int accountId);
|
||||||
|
|
||||||
@Query("Select Item.remoteId From Item Inner Join Feed On Item.feed_id = Feed.id Where read = 0 And account_id = :accountId")
|
@Query("Select Item.guid, Feed.remoteId as feedRemoteId From Item Inner Join Feed On Item.feed_id = Feed.id Where Item.remoteId In (:remoteIds) And account_id = :accountId")
|
||||||
List<String> getUnreadChanges(int accountId);
|
List<StarItem> getUnstarChanges(List<String> remoteIds, int accountId);
|
||||||
|
|
||||||
@Query("Select Item.guid, Feed.remoteId as feedRemoteId From Item Inner Join Feed On Item.feed_id = Feed.id Where starred = 1 And account_id = :accountId")
|
|
||||||
List<StarItem> getStarChanges(int accountId);
|
|
||||||
|
|
||||||
@Query("Select Item.guid, Feed.remoteId as feedRemoteId From Item Inner Join Feed On Item.feed_id = Feed.id Where starred = 0 And account_id = :accountId")
|
|
||||||
List<StarItem> getUnstarChanges(int accountId);
|
|
||||||
|
|
||||||
@Query("Update Item set read = :read, starred = :starred Where remoteId = :remoteId")
|
@Query("Update Item set read = :read, starred = :starred Where remoteId = :remoteId")
|
||||||
void setReadAndStarState(String remoteId, boolean read, boolean starred);
|
void setReadAndStarState(String remoteId, boolean read, boolean starred);
|
||||||
|
|
Loading…
Reference in New Issue