mirror of https://github.com/readrops/Readrops.git
Nextcloud News : get read/unread starred items at initial synchronisation
This commit is contained in:
parent
c9caa0be89
commit
8c9b2b2ab1
|
@ -30,7 +30,8 @@ public class NextNewsDataSource {
|
|||
|
||||
private static final String TAG = NextNewsDataSource.class.getSimpleName();
|
||||
|
||||
protected static final int MAX_ITEMS = 5000;
|
||||
private static final int MAX_ITEMS = 5000;
|
||||
private static final int MAX_STARRED_ITEMS = 1000;
|
||||
|
||||
private NextNewsService api;
|
||||
|
||||
|
@ -86,7 +87,8 @@ public class NextNewsDataSource {
|
|||
private void initialSync(SyncResult syncResult) throws IOException {
|
||||
getFeedsAndFolders(syncResult);
|
||||
|
||||
Response<List<Item>> itemsResponse = api.getItems(3, false, MAX_ITEMS).execute();
|
||||
// unread items
|
||||
Response<List<Item>> itemsResponse = api.getItems(ItemQueryType.ALL.value, false, MAX_ITEMS).execute();
|
||||
List<Item> itemList = itemsResponse.body();
|
||||
|
||||
if (!itemsResponse.isSuccessful())
|
||||
|
@ -94,13 +96,23 @@ public class NextNewsDataSource {
|
|||
|
||||
if (itemList != null)
|
||||
syncResult.setItems(itemList);
|
||||
|
||||
// starred items
|
||||
Response<List<Item>> starredItemsResponse = api.getItems(ItemQueryType.STARRED.value, true, MAX_STARRED_ITEMS).execute();
|
||||
List<Item> starredItems = starredItemsResponse.body();
|
||||
|
||||
if (!itemsResponse.isSuccessful())
|
||||
syncResult.setError(true);
|
||||
|
||||
if (itemList != null)
|
||||
syncResult.setStarredItems(starredItems);
|
||||
}
|
||||
|
||||
private void classicSync(SyncResult syncResult, NextNewsSyncData data) throws IOException {
|
||||
putModifiedItems(data, syncResult);
|
||||
getFeedsAndFolders(syncResult);
|
||||
|
||||
Response<List<Item>> itemsResponse = api.getNewItems(data.getLastModified(), 3).execute();
|
||||
Response<List<Item>> itemsResponse = api.getNewItems(data.getLastModified(), ItemQueryType.ALL.value).execute();
|
||||
List<Item> itemList = itemsResponse.body();
|
||||
|
||||
if (!itemsResponse.isSuccessful())
|
||||
|
@ -265,4 +277,19 @@ public class NextNewsDataSource {
|
|||
STAR,
|
||||
UNSTAR
|
||||
}
|
||||
|
||||
public enum ItemQueryType {
|
||||
ALL(3),
|
||||
STARRED(2);
|
||||
|
||||
private int value;
|
||||
|
||||
ItemQueryType(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import retrofit2.http.Query;
|
|||
|
||||
public interface NextNewsService {
|
||||
|
||||
String END_POINT = "/index.php/apps/news/api/v1-2/";
|
||||
String END_POINT = "/index.php/apps/news/api/v1-2";
|
||||
|
||||
@GET("/ocs/v1.php/cloud/users/{userId}")
|
||||
@Headers("OCS-APIRequest: true")
|
||||
|
|
|
@ -147,8 +147,11 @@ public class NextNewsRepository extends ARepository {
|
|||
insertFeeds(result.getFeeds(), false);
|
||||
timings.addSplit("insert feeds");
|
||||
|
||||
insertItems(result.getItems(), syncType == SyncType.INITIAL_SYNC);
|
||||
boolean initialSync = syncType == SyncType.INITIAL_SYNC;
|
||||
insertItems(result.getItems(), initialSync);
|
||||
timings.addSplit("insert items");
|
||||
|
||||
insertItems(result.getStarredItems(), initialSync);
|
||||
timings.dumpToLog();
|
||||
|
||||
account.setLastModified(lastModified);
|
||||
|
|
Loading…
Reference in New Issue