From c7b26a65b14293e9acda0f70c02949223503e615 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Mon, 11 Nov 2024 21:33:28 +0100 Subject: [PATCH] Add support for adding a new feed in a specific folder for FreshRSS and Nextcloud News --- .../services/freshrss/FreshRSSDataSource.kt | 7 +-- .../api/services/freshrss/FreshRSSService.kt | 44 ++++++++++++++----- .../freshrss/FreshRSSDataSourceTest.kt | 3 +- .../NextcloudNewsDataSourceTest.kt | 4 +- .../app/feeds/newfeed/NewFeedScreenModel.kt | 21 +++++++-- .../app/repositories/FreshRSSRepository.kt | 2 +- .../repositories/NextcloudNewsRepository.kt | 2 +- 7 files changed, 62 insertions(+), 21 deletions(-) diff --git a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSDataSource.kt b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSDataSource.kt index d9333f22..61dc79c8 100644 --- a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSDataSource.kt +++ b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSDataSource.kt @@ -105,12 +105,13 @@ class FreshRSSDataSource(private val service: FreshRSSService) { } } - suspend fun createFeed(token: String, feedUrl: String) { - service.createOrDeleteFeed(token, FEED_PREFIX + feedUrl, "subscribe") + suspend fun createFeed(token: String, feedUrl: String, folderId: String?) { + // no feed here of the folder prefix for the folder id + service.createOrDeleteFeed(token, FEED_PREFIX + feedUrl, "subscribe", folderId) } suspend fun deleteFeed(token: String, feedUrl: String) { - service.createOrDeleteFeed(token, FEED_PREFIX + feedUrl, "unsubscribe") + service.createOrDeleteFeed(token, FEED_PREFIX + feedUrl, "unsubscribe", null) } suspend fun updateFeed(token: String, feedUrl: String, title: String, folderId: String) { diff --git a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSService.kt b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSService.kt index 3dfd0d55..c4de0005 100644 --- a/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSService.kt +++ b/api/src/main/java/com/readrops/api/services/freshrss/FreshRSSService.kt @@ -31,29 +31,49 @@ interface FreshRSSService { suspend fun getFolders(): List @GET("reader/api/0/stream/contents/user/-/state/com.google/reading-list") - suspend fun getItems(@Query("xt") excludeTarget: List?, @Query("n") max: Int, - @Query("ot") lastModified: Long?): List + suspend fun getItems( + @Query("xt") excludeTarget: List?, + @Query("n") max: Int, + @Query("ot") lastModified: Long? + ): List @GET("reader/api/0/stream/contents/user/-/state/com.google/starred") suspend fun getStarredItems(@Query("n") max: Int): List @GET("reader/api/0/stream/items/ids") - suspend fun getItemsIds(@Query("xt") excludeTarget: String?, @Query("s") includeTarget: String?, - @Query("n") max: Int): List + suspend fun getItemsIds( + @Query("xt") excludeTarget: String?, + @Query("s") includeTarget: String?, + @Query("n") max: Int + ): List @FormUrlEncoded @POST("reader/api/0/edit-tag") - suspend fun setItemsState(@Field("T") token: String, @Field("a") addAction: String?, - @Field("r") removeAction: String?, @Field("i") itemIds: List) + suspend fun setItemsState( + @Field("T") token: String, + @Field("a") addAction: String?, + @Field("r") removeAction: String?, + @Field("i") itemIds: List + ) @FormUrlEncoded @POST("reader/api/0/subscription/edit") - suspend fun createOrDeleteFeed(@Field("T") token: String, @Field("s") feedUrl: String, @Field("ac") action: String) + suspend fun createOrDeleteFeed( + @Field("T") token: String, + @Field("s") feedUrl: String, + @Field("ac") action: String, + @Field("a") folderId: String? + ) @FormUrlEncoded @POST("reader/api/0/subscription/edit") - suspend fun updateFeed(@Field("T") token: String, @Field("s") feedUrl: String, @Field("t") title: String, - @Field("a") folderId: String, @Field("ac") action: String) + suspend fun updateFeed( + @Field("T") token: String, + @Field("s") feedUrl: String, + @Field("t") title: String, + @Field("a") folderId: String, + @Field("ac") action: String + ) @FormUrlEncoded @POST("reader/api/0/edit-tag") @@ -61,7 +81,11 @@ interface FreshRSSService { @FormUrlEncoded @POST("reader/api/0/rename-tag") - suspend fun updateFolder(@Field("T") token: String, @Field("s") folderId: String, @Field("dest") newFolderId: String) + suspend fun updateFolder( + @Field("T") token: String, + @Field("s") folderId: String, + @Field("dest") newFolderId: String + ) @FormUrlEncoded @POST("reader/api/0/disable-tag") diff --git a/api/src/test/java/com/readrops/api/services/freshrss/FreshRSSDataSourceTest.kt b/api/src/test/java/com/readrops/api/services/freshrss/FreshRSSDataSourceTest.kt index 3f70016e..ebed4412 100644 --- a/api/src/test/java/com/readrops/api/services/freshrss/FreshRSSDataSourceTest.kt +++ b/api/src/test/java/com/readrops/api/services/freshrss/FreshRSSDataSourceTest.kt @@ -179,11 +179,12 @@ class FreshRSSDataSourceTest : KoinTest { fun createFeedTest() = runTest { mockServer.enqueueOK() - freshRSSDataSource.createFeed("token", "https://feed.url") + freshRSSDataSource.createFeed("token", "https://feed.url", "feed/1") val request = mockServer.takeRequest() with(request.body.readUtf8()) { assertTrue { contains("T=token") } + assertTrue { contains("a=feed%2F1") } assertTrue { contains( "s=${ diff --git a/api/src/test/java/com/readrops/api/services/nextcloudnews/NextcloudNewsDataSourceTest.kt b/api/src/test/java/com/readrops/api/services/nextcloudnews/NextcloudNewsDataSourceTest.kt index 7dd86fce..2f72c292 100644 --- a/api/src/test/java/com/readrops/api/services/nextcloudnews/NextcloudNewsDataSourceTest.kt +++ b/api/src/test/java/com/readrops/api/services/nextcloudnews/NextcloudNewsDataSourceTest.kt @@ -136,13 +136,13 @@ class NextcloudNewsDataSourceTest : KoinTest { val stream = TestUtils.loadResource("services/nextcloudnews/adapters/feeds.json") mockServer.enqueueOKStream(stream) - val feeds = nextcloudNewsDataSource.createFeed("https://news.ycombinator.com/rss", null) + val feeds = nextcloudNewsDataSource.createFeed("https://news.ycombinator.com/rss", 100) val request = mockServer.takeRequest() assertTrue { feeds.isNotEmpty() } with(request.requestUrl!!) { assertEquals("https://news.ycombinator.com/rss", queryParameter("url")) - assertEquals(null, queryParameter("folderId")) + assertEquals("100", queryParameter("folderId")) } } diff --git a/app/src/main/java/com/readrops/app/feeds/newfeed/NewFeedScreenModel.kt b/app/src/main/java/com/readrops/app/feeds/newfeed/NewFeedScreenModel.kt index 21bd7fef..20ce3ecb 100644 --- a/app/src/main/java/com/readrops/app/feeds/newfeed/NewFeedScreenModel.kt +++ b/app/src/main/java/com/readrops/app/feeds/newfeed/NewFeedScreenModel.kt @@ -101,7 +101,13 @@ class NewFeedScreenModel( screenModelScope.launch(dispatcher) { insertFeeds(state.value.parsingResults .filter { it.isSelected } - .map { Feed(url = it.url, folderId = it.folderId) }) + .map { + Feed( + url = it.url, + folderId = it.folderId, + remoteFolderId = it.folder?.remoteId + ) + }) } } else { when { @@ -131,7 +137,15 @@ class NewFeedScreenModel( try { if (dataSource.isUrlRSSResource(url)) { - insertFeeds(listOf(Feed(url = url, folderId = state.value.folderId))) + insertFeeds( + listOf( + Feed( + url = url, + folderId = state.value.folderId, + remoteFolderId = state.value.selectedFolder?.remoteId + ) + ) + ) } else { val rssUrls = HtmlParser.getFeedLink(url, get()) @@ -144,7 +158,8 @@ class NewFeedScreenModel( listOf( Feed( url = rssUrls.first().url, - folderId = state.value.folderId + folderId = state.value.folderId, + remoteFolderId = state.value.selectedFolder?.remoteId ) ) ) diff --git a/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.kt b/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.kt index eb269488..704b3164 100644 --- a/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.kt +++ b/app/src/main/java/com/readrops/app/repositories/FreshRSSRepository.kt @@ -95,7 +95,7 @@ class FreshRSSRepository( onUpdate(newFeed) try { - dataSource.createFeed(account.writeToken!!, newFeed.url!!) + dataSource.createFeed(account.writeToken!!, newFeed.url!!, newFeed.remoteFolderId) } catch (e: Exception) { errors[newFeed] = e } diff --git a/app/src/main/java/com/readrops/app/repositories/NextcloudNewsRepository.kt b/app/src/main/java/com/readrops/app/repositories/NextcloudNewsRepository.kt index f695a23c..2bba4aa7 100644 --- a/app/src/main/java/com/readrops/app/repositories/NextcloudNewsRepository.kt +++ b/app/src/main/java/com/readrops/app/repositories/NextcloudNewsRepository.kt @@ -94,7 +94,7 @@ class NextcloudNewsRepository( onUpdate(newFeed) try { - val feeds = dataSource.createFeed(newFeed.url!!, null) + val feeds = dataSource.createFeed(newFeed.url!!, newFeed.remoteFolderId?.toInt()) insertFeeds(feeds) } catch (e: Exception) { errors[newFeed] = e