Fix some Nextcloud news folder insertion/deletion problems

This commit is contained in:
Shinokuni 2019-08-22 22:11:08 +02:00
parent 50de656f35
commit 21b261b0e1
3 changed files with 11 additions and 5 deletions

View File

@ -65,7 +65,7 @@ public abstract class FeedDao implements BaseDao<Feed> {
@Query("Select remoteId From Feed Where account_id = :accountId")
public abstract List<String> getFeedRemoteIdsOfAccount(int accountId);
@Query("Delete from Feed Where id in (:ids)")
@Query("Delete from Feed Where remoteId in (:ids)")
abstract void deleteByIds(List<String> ids);
@Query("Select id From Folder Where remoteId = :remoteId And account_id = :accountId")

View File

@ -32,7 +32,7 @@ public abstract class FolderDao implements BaseDao<Folder> {
@Query("Select remoteId From Folder Where account_id = :accountId")
public abstract List<String> getFolderRemoteIdsOfAccount(int accountId);
@Query("Delete From Folder Where id in (:ids)")
@Query("Delete From Folder Where remoteId in (:ids)")
abstract void deleteByIds(List<String> ids);
/**

View File

@ -205,10 +205,16 @@ public class NextNewsRepository extends ARepository {
NextNewsAPI api = new NextNewsAPI(account.toCredentials());
try {
NextNewsFolders folders = api.createFolder(new NextNewsFolder(Integer.parseInt(folder.getRemoteId()), folder.getName()));
int folderRemoteId = folder.getRemoteId() == null ? 0 : Integer.parseInt(folder.getRemoteId());
NextNewsFolders folders = api.createFolder(new NextNewsFolder(folderRemoteId, folder.getName()));
if (folders != null)
insertFolders(folders.getFolders());
if (folders != null) {
NextNewsFolder nextNewsFolder = folders.getFolders().get(0); // always only one item returned by the server, see doc
folder.setName(nextNewsFolder.getName());
folder.setRemoteId(String.valueOf(nextNewsFolder.getId()));
database.folderDao().insert(folder);
}
else
emitter.onError(new Exception("Unknown error"));
} catch (Exception e) {