Skip to content

Commit

Permalink
[1.213.*] Pre-release merge (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
tramline-github[bot] authored Jul 30, 2024
2 parents 89b185b + b8b94b8 commit e761d8c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class RssRepository(
id = feedId
)

postQueries.transaction {
transactionRunner.invoke {
val feedLastCleanUpAtEpochMilli =
feedLastCleanUpAt?.toEpochMilliseconds()
?: Instant.DISTANT_PAST.toEpochMilliseconds()
Expand Down Expand Up @@ -486,7 +486,7 @@ class RssRepository(

suspend fun updateFeedsLastCleanUpAt(feedIds: List<String>) {
withContext(ioDispatcher) {
feedQueries.transaction {
transactionRunner.invoke {
feedIds.forEach { feedId ->
feedQueries.updateLastCleanUpAt(lastCleanUpAt = Clock.System.now(), id = feedId)
}
Expand All @@ -503,7 +503,7 @@ class RssRepository(
postsAfter: Instant = Instant.DISTANT_PAST
) {
withContext(ioDispatcher) {
postQueries.transaction {
transactionRunner.invoke {
feedIds.forEach { feedId ->
postQueries.markPostsAsRead(sourceId = feedId, after = postsAfter)
}
Expand Down Expand Up @@ -868,7 +868,7 @@ class RssRepository(

suspend fun updatedSourcePinnedPosition(sources: List<Source>) {
withContext(ioDispatcher) {
feedQueries.transaction {
transactionRunner.invoke {
sources.forEachIndexed { index, source ->
feedQueries.updatedPinnedPosition(index.toDouble(), source.id)
feedGroupQueries.updatedPinnedPosition(index.toDouble(), source.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,34 +53,34 @@ class FeedFetcher(private val httpClient: HttpClient, private val feedParser: Fe
transformUrl: Boolean,
redirectCount: Int,
): FeedFetchResult {
return if (redirectCount < MAX_REDIRECTS_ALLOWED) {
try {
// We are mainly doing this check to avoid creating duplicates while refreshing feeds
// after the app update
val transformedUrl = transformUrl(url, transformUrl)
val response = httpClient.get(transformedUrl.toString())

when (response.status) {
HttpStatusCode.OK -> {
parseContent(response, transformedUrl.toString(), redirectCount)
}
HttpStatusCode.MultipleChoices,
HttpStatusCode.MovedPermanently,
HttpStatusCode.Found,
HttpStatusCode.SeeOther,
HttpStatusCode.TemporaryRedirect,
HttpStatusCode.PermanentRedirect -> {
handleHttpRedirect(response, transformedUrl.toString(), redirectCount)
}
else -> {
FeedFetchResult.HttpStatusError(statusCode = response.status)
}
if (redirectCount >= MAX_REDIRECTS_ALLOWED) {
return FeedFetchResult.TooManyRedirects
}

return try {
// We are mainly doing this to avoid creating duplicates while refreshing feeds
// after the app update
val transformedUrl = transformUrl(url, transformUrl)
val response = httpClient.get(transformedUrl.toString())

when (response.status) {
HttpStatusCode.OK -> {
parseContent(response, transformedUrl.toString(), redirectCount)
}
HttpStatusCode.MultipleChoices,
HttpStatusCode.MovedPermanently,
HttpStatusCode.Found,
HttpStatusCode.SeeOther,
HttpStatusCode.TemporaryRedirect,
HttpStatusCode.PermanentRedirect -> {
handleHttpRedirect(response, transformedUrl.toString(), redirectCount)
}
else -> {
FeedFetchResult.HttpStatusError(statusCode = response.status)
}
} catch (e: Exception) {
FeedFetchResult.Error(e)
}
} else {
FeedFetchResult.TooManyRedirects
} catch (e: Exception) {
FeedFetchResult.Error(e)
}
}

Expand All @@ -89,23 +89,23 @@ class FeedFetcher(private val httpClient: HttpClient, private val feedParser: Fe
url: String,
redirectCount: Int
): FeedFetchResult {
return if (response.contentType()?.withoutParameters() == ContentType.Text.Html) {
val feedUrl = fetchFeedLinkFromHtmlIfExists(response.bodyAsText(), url)

if (feedUrl != url && !feedUrl.isNullOrBlank()) {
fetch(url = feedUrl, transformUrl = false, redirectCount = redirectCount + 1)
} else {
throw UnsupportedOperationException()
}
} else {
if (response.contentType()?.withoutParameters() != ContentType.Text.Html) {
val content = response.bodyAsChannel()
val responseCharset = response.contentType()?.parameter("charset")
val charset = Charset.forName(responseCharset ?: Charsets.UTF8.name)

val feedPayload = feedParser.parse(feedUrl = url, content = content, charset = charset)

FeedFetchResult.Success(feedPayload)
return FeedFetchResult.Success(feedPayload)
}

val feedUrl = fetchFeedLinkFromHtmlIfExists(response.bodyAsText(), url)

if (feedUrl != url && !feedUrl.isNullOrBlank()) {
return fetch(url = feedUrl, transformUrl = false, redirectCount = redirectCount + 1)
}

throw UnsupportedOperationException()
}

private suspend fun handleHttpRedirect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package dev.sasikanth.rss.reader.core.network.parser

import co.touchlab.kermit.Logger
import dev.sasikanth.rss.reader.core.model.remote.FeedPayload
import dev.sasikanth.rss.reader.di.scopes.AppScope
import dev.sasikanth.rss.reader.exceptions.XmlParsingError
import dev.sasikanth.rss.reader.util.DispatchersProvider
import io.ktor.http.URLBuilder
Expand All @@ -35,7 +34,6 @@ import org.kobjects.ktxml.api.XmlPullParserException
import org.kobjects.ktxml.mini.MiniXmlPullParser

@Inject
@AppScope
class FeedParser(private val dispatchersProvider: DispatchersProvider) {

suspend fun parse(
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ coil = "3.0.0-alpha09"
spotless = "6.25.0"
ktfmt = "0.44"
kotlininject = "0.7.1"
ksp = "2.0.0-1.0.23"
ksp = "2.0.0-1.0.24"
material_color_utilities = "1.0.0-alpha01"
ksoup = "0.1.2"
sqliteAndroid = "3.45.0"
Expand Down

0 comments on commit e761d8c

Please sign in to comment.