Implement Nextcloud News add/update/delete folder actions

This commit is contained in:
Shinokuni 2024-06-20 13:40:24 +02:00
parent 116a1b9722
commit 23fd22afff
2 changed files with 21 additions and 1 deletions

View File

@ -111,6 +111,23 @@ class NextcloudNewsRepository(
super.deleteFeed(feed)
}
override suspend fun addFolder(folder: Folder) {
val folders = dataSource.createFolder(folder.name!!)
.onEach { it.accountId = account.id }
database.newFolderDao().insert(folders)
}
override suspend fun updateFolder(folder: Folder) {
dataSource.renameFolder(folder.name!!, folder.remoteId!!.toInt())
super.updateFolder(folder)
}
override suspend fun deleteFolder(folder: Folder) {
dataSource.deleteFolder(folder.remoteId!!.toInt())
super.deleteFolder(folder)
}
private suspend fun insertFolders(folders: List<Folder>) {
folders.forEach { it.accountId = account.id }
database.newFolderDao().upsertFolders(folders, account)
@ -140,6 +157,7 @@ class NextcloudNewsRepository(
) {
database.newItemDao()
.updateReadAndStarState(item.remoteId!!, item.isRead, item.isStarred)
continue
}
item.feedId = feedId

View File

@ -55,7 +55,9 @@ abstract class BaseRepository(
open suspend fun deleteFeed(feed: Feed) = database.newFeedDao().delete(feed)
open suspend fun addFolder(folder: Folder) = database.newFolderDao().insert(folder)
open suspend fun addFolder(folder: Folder) {
database.newFolderDao().insert(folder)
}
open suspend fun updateFolder(folder: Folder) = database.newFolderDao().update(folder)