From 838768800a641aa6c549b6da9636c01b47acea71 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Thu, 17 Sep 2020 22:11:05 +0200 Subject: [PATCH] Handle the absence of some tags in RSS2 and ATOM feeds --- .../readrops/api/localfeed/LocalRSSDataSource.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/api/src/main/java/com/readrops/api/localfeed/LocalRSSDataSource.kt b/api/src/main/java/com/readrops/api/localfeed/LocalRSSDataSource.kt index 3541ff1d..5b2726c5 100644 --- a/api/src/main/java/com/readrops/api/localfeed/LocalRSSDataSource.kt +++ b/api/src/main/java/com/readrops/api/localfeed/LocalRSSDataSource.kt @@ -102,6 +102,8 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) { adapter.fromJson(Buffer().readFrom(stream))!! } + handleSpecialCases(feed, type, response) + feed.etag = response.header(LibUtils.ETAG_HEADER) feed.lastModified = response.header(LibUtils.LAST_MODIFIED_HEADER) @@ -122,4 +124,15 @@ class LocalRSSDataSource(private val httpClient: OkHttpClient) { adapter.fromJson(Buffer().readFrom(stream))!! } } + + private fun handleSpecialCases(feed: Feed, type: LocalRSSHelper.RSSType, response: Response) { + with(feed) { + if (type == LocalRSSHelper.RSSType.RSS_2) { + if (url == null) url = response.request.url.toString() + } else if (type == LocalRSSHelper.RSSType.ATOM) { + if (url == null) url = response.request.url.toString() + if (siteUrl == null) siteUrl = response.request.url.scheme + "://" + response.request.url.host + } + } + } } \ No newline at end of file