summaryrefslogtreecommitdiff
path: root/app/src/main/java/org/terst/feedreader/data
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/terst/feedreader/data')
-rw-r--r--app/src/main/java/org/terst/feedreader/data/CachedExtraction.kt41
1 files changed, 41 insertions, 0 deletions
diff --git a/app/src/main/java/org/terst/feedreader/data/CachedExtraction.kt b/app/src/main/java/org/terst/feedreader/data/CachedExtraction.kt
new file mode 100644
index 0000000..313d467
--- /dev/null
+++ b/app/src/main/java/org/terst/feedreader/data/CachedExtraction.kt
@@ -0,0 +1,41 @@
+package org.terst.feedreader.data
+
+import org.terst.feedreader.readability.ConsentNotice
+
+/** What a cached `articles.extractedContent` value turned out to be worth. */
+data class CachedExtraction(
+ /** The content to show, or null if there is nothing usable. */
+ val content: String?,
+ /**
+ * True when a cached consent notice was thrown away. The caller has nothing to
+ * show and should extract again -- the cache is the reason the article looked
+ * broken, so dropping it silently would just leave a blank reader.
+ */
+ val discardedConsentNotice: Boolean
+)
+
+/**
+ * Reads a cached extraction, dropping it if it is the site's cookie/consent notice
+ * rather than the article.
+ *
+ * Needed because the extractor's own guard can only keep a bad extraction from
+ * being written in future. The reported bug ("reader mode just extracts cookie
+ * disclaimer", with `extractedContent cached: true`) was already on disk: every
+ * subsequent open read it straight back out, so no amount of fixing the extractor
+ * would have changed what the user saw. A poisoned row is cleared here rather than
+ * in a schema migration, so it is repaired whenever the article is next opened --
+ * including for anything extracted before this check existed.
+ *
+ * [clearCache] is passed in rather than taking the DAO so this stays a plain
+ * decision that can be tested without a database.
+ */
+suspend fun loadCachedExtraction(
+ cached: String?,
+ clearCache: suspend () -> Unit
+): CachedExtraction {
+ if (!ConsentNotice.looksLikeConsentNotice(cached)) {
+ return CachedExtraction(content = cached, discardedConsentNotice = false)
+ }
+ clearCache()
+ return CachedExtraction(content = null, discardedConsentNotice = true)
+}