fix(sync): replace publish date of an article with the current time if it is a future date (#638)
This commit is contained in:
parent
f06d8ce05e
commit
d40743d5ff
@ -98,11 +98,12 @@ abstract class AbstractRssRepository(
|
|||||||
supervisorScope {
|
supervisorScope {
|
||||||
coroutineWorker.setProgress(SyncWorker.setIsSyncing(true))
|
coroutineWorker.setProgress(SyncWorker.setIsSyncing(true))
|
||||||
val preTime = System.currentTimeMillis()
|
val preTime = System.currentTimeMillis()
|
||||||
|
val preDate = Date(preTime)
|
||||||
val accountId = context.currentAccountId
|
val accountId = context.currentAccountId
|
||||||
feedDao.queryAll(accountId)
|
feedDao.queryAll(accountId)
|
||||||
.chunked(16)
|
.chunked(16)
|
||||||
.forEach {
|
.forEach {
|
||||||
it.map { feed -> async { syncFeed(feed) } }
|
it.map { feed -> async { syncFeed(feed, preDate) } }
|
||||||
.awaitAll()
|
.awaitAll()
|
||||||
.forEach {
|
.forEach {
|
||||||
if (it.feed.isNotification) {
|
if (it.feed.isNotification) {
|
||||||
@ -165,9 +166,9 @@ abstract class AbstractRssRepository(
|
|||||||
articleDao.markAsStarredByArticleId(accountId, articleId, isStarred)
|
articleDao.markAsStarredByArticleId(accountId, articleId, isStarred)
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun syncFeed(feed: Feed): FeedWithArticle {
|
private suspend fun syncFeed(feed: Feed, preDate: Date = Date()): FeedWithArticle {
|
||||||
val latest = articleDao.queryLatestByFeedId(context.currentAccountId, feed.id)
|
val latest = articleDao.queryLatestByFeedId(context.currentAccountId, feed.id)
|
||||||
val articles = rssHelper.queryRssXml(feed, latest?.link)
|
val articles = rssHelper.queryRssXml(feed, latest?.link, preDate)
|
||||||
if (feed.icon == null) {
|
if (feed.icon == null) {
|
||||||
val iconLink = rssHelper.queryRssIconLink(feed.url)
|
val iconLink = rssHelper.queryRssIconLink(feed.url)
|
||||||
if (iconLink != null) {
|
if (iconLink != null) {
|
||||||
|
@ -32,6 +32,7 @@ import me.ash.reader.infrastructure.rss.provider.fever.FeverDTO
|
|||||||
import me.ash.reader.ui.ext.currentAccountId
|
import me.ash.reader.ui.ext.currentAccountId
|
||||||
import me.ash.reader.ui.ext.decodeHTML
|
import me.ash.reader.ui.ext.decodeHTML
|
||||||
import me.ash.reader.ui.ext.dollarLast
|
import me.ash.reader.ui.ext.dollarLast
|
||||||
|
import me.ash.reader.ui.ext.isFuture
|
||||||
import me.ash.reader.ui.ext.showToast
|
import me.ash.reader.ui.ext.showToast
|
||||||
import me.ash.reader.ui.ext.spacerDollar
|
import me.ash.reader.ui.ext.spacerDollar
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
@ -137,6 +138,7 @@ class FeverRssService @Inject constructor(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
val preTime = System.currentTimeMillis()
|
val preTime = System.currentTimeMillis()
|
||||||
|
val preDate = Date(preTime)
|
||||||
val accountId = context.currentAccountId
|
val accountId = context.currentAccountId
|
||||||
val account = accountDao.queryById(accountId)!!
|
val account = accountDao.queryById(accountId)!!
|
||||||
val feverAPI = getFeverAPI()
|
val feverAPI = getFeverAPI()
|
||||||
@ -192,7 +194,10 @@ class FeverRssService @Inject constructor(
|
|||||||
*itemsBody.items?.map {
|
*itemsBody.items?.map {
|
||||||
Article(
|
Article(
|
||||||
id = accountId.spacerDollar(it.id!!),
|
id = accountId.spacerDollar(it.id!!),
|
||||||
date = it.created_on_time?.run { Date(this * 1000) } ?: Date(),
|
date = it.created_on_time
|
||||||
|
?.run { Date(this * 1000) }
|
||||||
|
?.takeIf { !it.isFuture(preDate) }
|
||||||
|
?: preDate,
|
||||||
title = it.title.decodeHTML() ?: context.getString(R.string.empty),
|
title = it.title.decodeHTML() ?: context.getString(R.string.empty),
|
||||||
author = it.author,
|
author = it.author,
|
||||||
rawDescription = it.html ?: "",
|
rawDescription = it.html ?: "",
|
||||||
@ -204,7 +209,7 @@ class FeverRssService @Inject constructor(
|
|||||||
accountId = accountId,
|
accountId = accountId,
|
||||||
isUnread = (it.is_read ?: 0) <= 0,
|
isUnread = (it.is_read ?: 0) <= 0,
|
||||||
isStarred = (it.is_saved ?: 0) > 0,
|
isStarred = (it.is_saved ?: 0) > 0,
|
||||||
updateAt = Date(),
|
updateAt = preDate,
|
||||||
).also {
|
).also {
|
||||||
sinceId = it.id.dollarLast()
|
sinceId = it.id.dollarLast()
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,7 @@ import me.ash.reader.infrastructure.rss.provider.greader.GoogleReaderDTO
|
|||||||
import me.ash.reader.ui.ext.currentAccountId
|
import me.ash.reader.ui.ext.currentAccountId
|
||||||
import me.ash.reader.ui.ext.decodeHTML
|
import me.ash.reader.ui.ext.decodeHTML
|
||||||
import me.ash.reader.ui.ext.dollarLast
|
import me.ash.reader.ui.ext.dollarLast
|
||||||
|
import me.ash.reader.ui.ext.isFuture
|
||||||
import me.ash.reader.ui.ext.showToast
|
import me.ash.reader.ui.ext.showToast
|
||||||
import me.ash.reader.ui.ext.spacerDollar
|
import me.ash.reader.ui.ext.spacerDollar
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
@ -405,7 +406,10 @@ class GoogleReaderRssService @Inject constructor(
|
|||||||
val articleId = it.id!!.ofItemStreamIdToId()
|
val articleId = it.id!!.ofItemStreamIdToId()
|
||||||
Article(
|
Article(
|
||||||
id = accountId.spacerDollar(articleId),
|
id = accountId.spacerDollar(articleId),
|
||||||
date = it.published?.run { Date(this * 1000) } ?: preDate,
|
date = it.published
|
||||||
|
?.run { Date(this * 1000) }
|
||||||
|
?.takeIf { !it.isFuture(preDate) }
|
||||||
|
?: preDate,
|
||||||
title = it.title.decodeHTML() ?: context.getString(R.string.empty),
|
title = it.title.decodeHTML() ?: context.getString(R.string.empty),
|
||||||
author = it.author,
|
author = it.author,
|
||||||
rawDescription = it.summary?.content ?: "",
|
rawDescription = it.summary?.content ?: "",
|
||||||
|
@ -18,6 +18,7 @@ import me.ash.reader.infrastructure.di.IODispatcher
|
|||||||
import me.ash.reader.infrastructure.html.Readability
|
import me.ash.reader.infrastructure.html.Readability
|
||||||
import me.ash.reader.ui.ext.currentAccountId
|
import me.ash.reader.ui.ext.currentAccountId
|
||||||
import me.ash.reader.ui.ext.decodeHTML
|
import me.ash.reader.ui.ext.decodeHTML
|
||||||
|
import me.ash.reader.ui.ext.isFuture
|
||||||
import me.ash.reader.ui.ext.spacerDollar
|
import me.ash.reader.ui.ext.spacerDollar
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
@ -67,6 +68,7 @@ class RssHelper @Inject constructor(
|
|||||||
suspend fun queryRssXml(
|
suspend fun queryRssXml(
|
||||||
feed: Feed,
|
feed: Feed,
|
||||||
latestLink: String?,
|
latestLink: String?,
|
||||||
|
preDate: Date = Date(),
|
||||||
): List<Article> =
|
): List<Article> =
|
||||||
try {
|
try {
|
||||||
val accountId = context.currentAccountId
|
val accountId = context.currentAccountId
|
||||||
@ -76,7 +78,7 @@ class RssHelper @Inject constructor(
|
|||||||
.entries
|
.entries
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.takeWhile { latestLink == null || latestLink != it.link }
|
.takeWhile { latestLink == null || latestLink != it.link }
|
||||||
.map { buildArticleFromSyndEntry(feed, accountId, it) }
|
.map { buildArticleFromSyndEntry(feed, accountId, it, preDate) }
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@ -89,6 +91,7 @@ class RssHelper @Inject constructor(
|
|||||||
feed: Feed,
|
feed: Feed,
|
||||||
accountId: Int,
|
accountId: Int,
|
||||||
syndEntry: SyndEntry,
|
syndEntry: SyndEntry,
|
||||||
|
preDate: Date = Date(),
|
||||||
): Article {
|
): Article {
|
||||||
val desc = syndEntry.description?.value
|
val desc = syndEntry.description?.value
|
||||||
val content = syndEntry.contents
|
val content = syndEntry.contents
|
||||||
@ -108,7 +111,7 @@ class RssHelper @Inject constructor(
|
|||||||
id = accountId.spacerDollar(UUID.randomUUID().toString()),
|
id = accountId.spacerDollar(UUID.randomUUID().toString()),
|
||||||
accountId = accountId,
|
accountId = accountId,
|
||||||
feedId = feed.id,
|
feedId = feed.id,
|
||||||
date = syndEntry.publishedDate ?: syndEntry.updatedDate ?: Date(),
|
date = (syndEntry.publishedDate ?: syndEntry.updatedDate).takeIf { !it.isFuture(preDate) } ?: preDate,
|
||||||
title = syndEntry.title.decodeHTML() ?: feed.name,
|
title = syndEntry.title.decodeHTML() ?: feed.name,
|
||||||
author = syndEntry.author,
|
author = syndEntry.author,
|
||||||
rawDescription = (content ?: desc) ?: "",
|
rawDescription = (content ?: desc) ?: "",
|
||||||
@ -116,7 +119,7 @@ class RssHelper @Inject constructor(
|
|||||||
fullContent = content,
|
fullContent = content,
|
||||||
img = findImg((content ?: desc) ?: ""),
|
img = findImg((content ?: desc) ?: ""),
|
||||||
link = syndEntry.link ?: "",
|
link = syndEntry.link ?: "",
|
||||||
updateAt = Date(),
|
updateAt = preDate,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,3 +86,5 @@ private fun String.parseToDate(
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Date.isFuture(staticDate: Date = Date()): Boolean = this.time > staticDate.time
|
||||||
|
Loading…
x
Reference in New Issue
Block a user