Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use RSS items from channel on add #347

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ fun ArticleLayout(
openNextList()

showSnackbar(addFeedSuccessMessage)

refreshFeeds()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ fun ArticleView(
}
)

val clearWebView = {
webViewNavigator.clearView()
}

val extractedContent = extractedContentState.content

fun onToggleExtractContent() {
Expand Down
2 changes: 1 addition & 1 deletion capy/src/main/assets/stylesheet.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion capy/src/main/java/com/jocmp/capy/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import com.jocmp.feedbinclient.Feedbin
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import java.io.File
import java.io.InputStream
import java.net.URI
import java.time.ZonedDateTime
Expand Down
1 change: 1 addition & 0 deletions capy/src/main/java/com/jocmp/capy/Article.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ data class Article(
val feedName: String = "",
val faviconURL: String? = null,
val feedURL: String? = null,
val siteURL: String? = null,
val enableStickyFullContent: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.jocmp.feedbinclient.Subscription
import com.jocmp.feedbinclient.UnreadEntriesRequest
import com.jocmp.feedbinclient.UpdateSubscriptionRequest
import com.jocmp.feedbinclient.pagingInfo
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json
Expand Down Expand Up @@ -162,6 +163,10 @@ internal class FeedbinAccountDelegate(
val feed = feedRecords.findBy(subscription.feed_id.toString())

if (feed != null) {
coroutineScope {
launch(Dispatchers.IO) { refreshFeeds() }
}

AddFeedResult.Success(feed)
} else {
AddFeedResult.Failure(AddFeedError.SaveFailure())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class LocalAccountDelegate(

return if (feed != null) {
upsertFolders(feed, folderTitles)
saveArticles(resultFeed.items, cutoffDate = null, feed = feed)

AddFeedResult.Success(feed)
} else {
Expand Down Expand Up @@ -151,7 +152,7 @@ class LocalAccountDelegate(
val updated = updatedAt.toEpochSecond()

val publishedAt = item.pubDate?.toDateTime?.toEpochSecond() ?: updated
val url = cleanedArticleLink(item.link, feed.siteURL)
val url = cleanedURL(item.link, feed.siteURL)
val withinCutoff = cutoffDate == null || publishedAt > cutoffDate.toEpochSecond()

if (url != null && withinCutoff) {
Expand All @@ -164,7 +165,7 @@ class LocalAccountDelegate(
url = url.toString(),
summary = item.summary,
extracted_content_url = null,
image_url = item.image,
image_url = cleanedURL(item.image, siteURL = feed.siteURL)?.toString(),
published_at = publishedAt,
)

Expand Down Expand Up @@ -236,8 +237,8 @@ internal val RssItem.summary: String?
return Jsoup.parse(it).text()
}

internal fun cleanedArticleLink(articleURL: String?, siteURL: String): URL? {
val url = articleURL.orEmpty()
internal fun cleanedURL(inputURL: String?, siteURL: String): URL? {
val url = inputURL.orEmpty()

if (url.isBlank()) {
return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ArticleRenderer(
).renderedText

val document = Jsoup.parse(html).apply {
article.feedURL?.let { setBaseUri(it) }
article.siteURL?.let { setBaseUri(it) }
}

cleanLinks(document)
Expand All @@ -53,6 +53,7 @@ class ArticleRenderer(
private fun cleanLinks(document: Document) {
document.getElementsByTag("img").forEach { element ->
element.attr("loading", "lazy")
element.attr("src", element.absUrl("src"))
}

document.select("img[data-src]").forEach { element ->
Expand Down
2 changes: 1 addition & 1 deletion capy/src/main/java/com/jocmp/capy/common/OptionalURL.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.jocmp.capy.common
import java.net.MalformedURLException
import java.net.URL

fun optionalURL(string: String?): URL? {
fun optionalURL(string: String?, baseURL: String? = null): URL? {
if (string.isNullOrBlank()) {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal fun articleMapper(
faviconURL: String?,
enableStickyContent: Boolean = false,
feedURL: String?,
siteURL: String?,
updatedAt: Long?,
starred: Boolean?,
read: Boolean?,
Expand All @@ -35,6 +36,7 @@ internal fun articleMapper(
url = URL(url),
imageURL = imageURL,
feedURL = feedURL,
siteURL = siteURL,
summary = summary ?: "",
updatedAt = updatedAt!!.toDateTimeFromSeconds,
publishedAt = publishedAt!!.toDateTimeFromSeconds,
Expand Down Expand Up @@ -70,6 +72,7 @@ internal fun listMapper(
contentHtml = "",
extractedContentURL = extractedContentURL,
feedURL = null,
siteURL = null,
url = url,
feedTitle = feedTitle,
imageURL = imageURL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ internal class ArticleRecords internal constructor(
}
}

internal fun cutoffDate(): ZonedDateTime {
private fun cutoffDate(): ZonedDateTime {
return nowUTC().minusMonths(3)
}
}
Expand Down
3 changes: 0 additions & 3 deletions capy/src/main/res/raw/template.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions capy/src/main/sqldelight/com/jocmp/capy/db/articles.sq
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ SELECT
feeds.favicon_url,
feeds.enable_sticky_full_content,
feeds.feed_url,
feeds.site_url,
article_statuses.updated_at,
article_statuses.starred,
article_statuses.read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ class FeedbinAccountDelegateTest {
feedbin.createSubscription(body = CreateSubscriptionRequest(feed_url = url))
} returns successResponse

coEvery {
feedbin.subscriptions()
} returns Response.success(emptyList())

val result = delegate.addFeed(url = url) as AddFeedResult.Success
val feed = result.feed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ class LocalAccountDelegateTest {
override val name: String,
override val feedURL: URL,
override val siteURL: URL? = null,
override val faviconURL: URL? = null
override val faviconURL: URL? = null,
override val items: List<RssItem> = listOf()
) : Feed {
override fun isValid() = true
}
Expand All @@ -294,42 +295,42 @@ class LocalAccountDelegateTest {
fun cleanedArticleLink_whenPresent() {
val url = "https://example.com/article"

val result = cleanedArticleLink(articleURL = url, siteURL = "")
val result = cleanedURL(inputURL = url, siteURL = "")

assertEquals(expected = url, actual = result.toString())
}

@Test
fun cleanedArticleLink_whenNull() {
val result = cleanedArticleLink(articleURL = null, siteURL = "")
val result = cleanedURL(inputURL = null, siteURL = "")

assertEquals(expected = null, actual = result)
}

@Test
fun cleanedArticleLink_whenBlank() {
val result = cleanedArticleLink(articleURL = "", siteURL = "")
val result = cleanedURL(inputURL = "", siteURL = "")

assertEquals(expected = null, actual = result)
}

@Test
fun cleanedArticleLink_withRelativePathMissingSiteURL() {
val result = cleanedArticleLink(articleURL = "/article", siteURL = "")
val result = cleanedURL(inputURL = "/article", siteURL = "")

assertEquals(expected = null, actual = result)
}

@Test
fun cleanedArticleLink_withRelativePathAndInvalidSiteURL() {
val result = cleanedArticleLink(articleURL = "/article", siteURL = "wrong")
val result = cleanedURL(inputURL = "/article", siteURL = "wrong")

assertEquals(expected = null, actual = result)
}

@Test
fun cleanedArticleLink_withRelativePathAndValidSiteURL() {
val result = cleanedArticleLink(articleURL = "/article", siteURL = "https://example.com")
val result = cleanedURL(inputURL = "/article", siteURL = "https://example.com")

assertEquals(expected = "https://example.com/article", actual = result.toString())
}
Expand Down
2 changes: 2 additions & 0 deletions capy/src/test/java/com/jocmp/capy/fixtures/GenericFeed.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jocmp.capy.fixtures

import com.jocmp.feedfinder.parser.Feed
import com.prof18.rssparser.model.RssItem
import java.net.URL

class GenericFeed(
Expand All @@ -9,6 +10,7 @@ class GenericFeed(
override val siteURL: URL? = null,
private val valid: Boolean = true,
override val faviconURL: URL? = null,
override val items: List<RssItem> = emptyList(),
) : Feed {
override fun isValid() = valid

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ArticleMapperTest {
starred = false,
feedTitle = "",
feedURL = null,
siteURL = null,
faviconURL = null
)

Expand Down
3 changes: 3 additions & 0 deletions feedfinder/src/main/java/com/jocmp/feedfinder/parser/Feed.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jocmp.feedfinder.parser

import com.prof18.rssparser.model.RssItem
import java.net.URL

interface Feed {
Expand All @@ -12,4 +13,6 @@ interface Feed {
val siteURL: URL?

val faviconURL: URL?

val items: List<RssItem>
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.jocmp.feedfinder.parser
import com.jocmp.feedfinder.optionalURL
import com.prof18.rssparser.RssParser
import com.prof18.rssparser.model.RssChannel
import com.prof18.rssparser.model.RssItem
import java.net.URL

internal class XMLFeed(
Expand All @@ -24,6 +25,9 @@ internal class XMLFeed(
override val faviconURL: URL?
get() = channel?.image?.url?.let { optionalURL(it) }

override val items: List<RssItem>
get() = channel?.items.orEmpty()

private fun hasEntries(): Boolean {
return channel != null &&
channel.items.isNotEmpty()
Expand Down
Loading