mirror of https://github.com/readrops/Readrops.git
Support read state for FreshRSS API new items
When new items will be fetched, they will be now set as read or unread. This doesn't apply to already existing in local items
This commit is contained in:
parent
4c82c4f913
commit
efe54deb9a
|
@ -64,4 +64,7 @@ public abstract class ItemDao implements BaseDao<Item> {
|
|||
|
||||
@Query("Update Item set read_changed = 0 Where feed_id in (Select id From Feed Where account_id = :accountId)")
|
||||
public abstract void resetReadChanges(int accountId);
|
||||
|
||||
@Query("Update Item set read = :read Where remoteId = :remoteId")
|
||||
public abstract void setReadState(String remoteId, boolean read);
|
||||
}
|
||||
|
|
|
@ -90,9 +90,9 @@ public class FreshRSSRepository extends ARepository<FreshRSSAPI> {
|
|||
emitter.onSuccess(syncData);
|
||||
}).flatMap(syncData1 -> api.sync(syncType, syncData1, account.getWriteToken()))
|
||||
.flatMapObservable(syncResult -> {
|
||||
insertFolders(syncResult.getFolders(), account);
|
||||
insertFeeds(syncResult.getFeeds(), account);
|
||||
insertItems(syncResult.getItems(), account, syncType == SyncType.INITIAL_SYNC);
|
||||
insertFolders(syncResult.getFolders());
|
||||
insertFeeds(syncResult.getFeeds());
|
||||
insertItems(syncResult.getItems(), syncType == SyncType.INITIAL_SYNC);
|
||||
|
||||
account.setLastModified(syncResult.getLastUpdated());
|
||||
database.accountDao().updateLastModified(account.getId(), syncResult.getLastUpdated());
|
||||
|
@ -169,7 +169,7 @@ public class FreshRSSRepository extends ARepository<FreshRSSAPI> {
|
|||
.andThen(super.deleteFolder(folder));
|
||||
}
|
||||
|
||||
private List<Feed> insertFeeds(List<FreshRSSFeed> freshRSSFeeds, Account account) {
|
||||
private void insertFeeds(List<FreshRSSFeed> freshRSSFeeds) {
|
||||
List<Feed> feeds = new ArrayList<>();
|
||||
|
||||
for (FreshRSSFeed freshRSSFeed : freshRSSFeeds) {
|
||||
|
@ -184,10 +184,9 @@ public class FreshRSSRepository extends ARepository<FreshRSSAPI> {
|
|||
setFaviconUtils(insertedFeeds);
|
||||
}
|
||||
|
||||
return insertedFeeds;
|
||||
}
|
||||
|
||||
private void insertFolders(List<FreshRSSFolder> freshRSSFolders, Account account) {
|
||||
private void insertFolders(List<FreshRSSFolder> freshRSSFolders) {
|
||||
List<Folder> folders = new ArrayList<>();
|
||||
|
||||
for (FreshRSSFolder freshRSSFolder : freshRSSFolders) {
|
||||
|
@ -205,14 +204,14 @@ public class FreshRSSRepository extends ARepository<FreshRSSAPI> {
|
|||
database.folderDao().foldersUpsert(folders, account);
|
||||
}
|
||||
|
||||
private void insertItems(List<FreshRSSItem> items, Account account, boolean initialSync) {
|
||||
private void insertItems(List<FreshRSSItem> items, boolean initialSync) {
|
||||
List<Item> newItems = new ArrayList<>();
|
||||
|
||||
for (FreshRSSItem freshRSSItem : items) {
|
||||
int feedId = database.feedDao().getFeedIdByRemoteId(String.valueOf(freshRSSItem.getOrigin().getStreamId()), account.getId());
|
||||
|
||||
if (!initialSync && feedId > 0) {
|
||||
if (database.itemDao().remoteItemExists(freshRSSItem.getId(), feedId))
|
||||
if (!initialSync && feedId > 0 && database.itemDao().remoteItemExists(freshRSSItem.getId(), feedId)) {
|
||||
database.itemDao().setReadState(freshRSSItem.getId(), freshRSSItem.isRead());
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ public final class ItemMatcher {
|
|||
newItem.setLink(item.getAlternate().get(0).getHref());
|
||||
newItem.setFeedId(feedId);
|
||||
newItem.setRemoteId(item.getId());
|
||||
newItem.setRead(item.isRead());
|
||||
|
||||
return newItem;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,9 @@ import okhttp3.RequestBody;
|
|||
|
||||
public class FreshRSSAPI extends API<FreshRSSService> {
|
||||
|
||||
private static final String GOOGLE_READ = "user/-/state/com.google/read";
|
||||
public static final String GOOGLE_READ = "user/-/state/com.google/read";
|
||||
|
||||
private static final String FEED_PREFIX = "feed/";
|
||||
|
||||
public FreshRSSAPI(Credentials credentials) {
|
||||
super(credentials, FreshRSSService.class, FreshRSSService.END_POINT);
|
||||
|
@ -134,7 +136,7 @@ public class FreshRSSAPI extends API<FreshRSSService> {
|
|||
* @param lastModified fetch only items created after this timestamp
|
||||
* @return the items
|
||||
*/
|
||||
public Single<FreshRSSItems> getItems(@NonNull String excludeTarget, @NonNull Integer max, @Nullable Long lastModified) {
|
||||
public Single<FreshRSSItems> getItems(@Nullable String excludeTarget, int max, @Nullable Long lastModified) {
|
||||
return api.getItems(excludeTarget, max, lastModified);
|
||||
}
|
||||
|
||||
|
@ -147,7 +149,7 @@ public class FreshRSSAPI extends API<FreshRSSService> {
|
|||
* @param token token for modifications
|
||||
* @return Completable
|
||||
*/
|
||||
public Completable markItemsReadUnread(@NonNull Boolean read, @NonNull List<String> itemIds, @NonNull String token) {
|
||||
public Completable markItemsReadUnread(boolean read, @NonNull List<String> itemIds, @NonNull String token) {
|
||||
if (read)
|
||||
return api.setItemsReadState(token, GOOGLE_READ, null, itemIds);
|
||||
else
|
||||
|
@ -162,7 +164,7 @@ public class FreshRSSAPI extends API<FreshRSSService> {
|
|||
* @return Completable
|
||||
*/
|
||||
public Completable createFeed(@NonNull String token, @NonNull String feedUrl) {
|
||||
return api.createOrDeleteFeed(token, "feed/" + feedUrl, "subscribe");
|
||||
return api.createOrDeleteFeed(token, FEED_PREFIX + feedUrl, "subscribe");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,7 +175,7 @@ public class FreshRSSAPI extends API<FreshRSSService> {
|
|||
* @return Completable
|
||||
*/
|
||||
public Completable deleteFeed(@NonNull String token, @NonNull String feedUrl) {
|
||||
return api.createOrDeleteFeed(token, "feed/" + feedUrl, "unsubscribe");
|
||||
return api.createOrDeleteFeed(token, FEED_PREFIX + feedUrl, "unsubscribe");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -186,7 +188,7 @@ public class FreshRSSAPI extends API<FreshRSSService> {
|
|||
* @return Completable
|
||||
*/
|
||||
public Completable updateFeed(@NonNull String token, @NonNull String feedUrl, @NonNull String title, @NonNull String folderId) {
|
||||
return api.updateFeed(token, "feed/" + feedUrl, title, folderId, "edit");
|
||||
return api.updateFeed(token, FEED_PREFIX + feedUrl, title, folderId, "edit");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,7 +35,7 @@ public interface FreshRSSService {
|
|||
Single<FreshRSSFeeds> getFeeds();
|
||||
|
||||
@GET("reader/api/0/stream/contents/user/-/state/com.google/reading-list")
|
||||
Single<FreshRSSItems> getItems(@Query("xt") String excludeTarget, @Query("n") Integer max, @Query("ot") Long lastModified);
|
||||
Single<FreshRSSItems> getItems(@Query("xt") String excludeTarget, @Query("n") int max, @Query("ot") Long lastModified);
|
||||
|
||||
@GET("reader/api/0/tag/list?output=json")
|
||||
Single<FreshRSSFolders> getFolders();
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
package com.readrops.readropslibrary.services.freshrss.json;
|
||||
|
||||
import com.readrops.readropslibrary.services.freshrss.FreshRSSAPI;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class FreshRSSItem {
|
||||
|
@ -105,4 +107,8 @@ public class FreshRSSItem {
|
|||
this.title = title;
|
||||
}
|
||||
|
||||
public boolean isRead() {
|
||||
return categories.contains(FreshRSSAPI.GOOGLE_READ);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue