Nextcloud News : get read/unread starred items at initial synchronisation

This commit is contained in:
Shinokuni 2021-07-05 21:00:40 +02:00
parent c9caa0be89
commit 8c9b2b2ab1
3 changed files with 35 additions and 5 deletions

View File

@ -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;
}
}
}

View File

@ -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")

View File

@ -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);