summaryrefslogtreecommitdiff
path: root/app/src/main/java/org/terst/feedreader/data/CachedExtraction.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/org/terst/feedreader/data/CachedExtraction.kt')
-rw-r--r--app/src/main/java/org/terst/feedreader/data/CachedExtraction.kt38
1 files changed, 31 insertions, 7 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
index 313d467..3a791cc 100644
--- a/app/src/main/java/org/terst/feedreader/data/CachedExtraction.kt
+++ b/app/src/main/java/org/terst/feedreader/data/CachedExtraction.kt
@@ -1,6 +1,7 @@
package org.terst.feedreader.data
import org.terst.feedreader.readability.ConsentNotice
+import org.terst.feedreader.readability.UnrenderedTex
/** What a cached `articles.extractedContent` value turned out to be worth. */
data class CachedExtraction(
@@ -11,12 +12,24 @@ data class CachedExtraction(
* 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
-)
+ val discardedConsentNotice: Boolean,
+ /**
+ * True when a cached extraction holding raw TeX source was thrown away -- it was
+ * extracted before extraction knew how to render maths (see [UnrenderedTex]).
+ */
+ val discardedUnrenderedTex: Boolean = false
+) {
+ /**
+ * True when something was thrown away, whatever it was: there is nothing to show and
+ * the caller has to extract again.
+ */
+ val discarded: Boolean get() = discardedConsentNotice || discardedUnrenderedTex
+}
/**
* Reads a cached extraction, dropping it if it is the site's cookie/consent notice
- * rather than the article.
+ * rather than the article, or if it is an older extraction whose maths never got
+ * rendered.
*
* 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
@@ -33,9 +46,20 @@ suspend fun loadCachedExtraction(
cached: String?,
clearCache: suspend () -> Unit
): CachedExtraction {
- if (!ConsentNotice.looksLikeConsentNotice(cached)) {
- return CachedExtraction(content = cached, discardedConsentNotice = false)
- }
+ val discard = when {
+ ConsentNotice.looksLikeConsentNotice(cached) ->
+ CachedExtraction(content = null, discardedConsentNotice = true)
+ // Same shape of problem, different cause: this one was extracted before extraction
+ // rendered maths, so it holds the TeX source the page shipped.
+ UnrenderedTex.looksLikeUnrenderedTex(cached) ->
+ CachedExtraction(
+ content = null,
+ discardedConsentNotice = false,
+ discardedUnrenderedTex = true
+ )
+ else -> null
+ } ?: return CachedExtraction(content = cached, discardedConsentNotice = false)
+
clearCache()
- return CachedExtraction(content = null, discardedConsentNotice = true)
+ return discard
}