From 3c68fafd8e4b0cab7a85565f125384955497dbca Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Mon, 28 Sep 2020 14:34:06 +0200 Subject: [PATCH] Set a global limit for the authors concatenation --- api/src/main/java/com/readrops/api/localfeed/XmlAdapter.kt | 4 +++- .../java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt | 3 ++- .../java/com/readrops/api/localfeed/rss1/RSS1ItemsAdapter.kt | 3 ++- .../java/com/readrops/api/localfeed/rss2/RSS2ItemsAdapter.kt | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/com/readrops/api/localfeed/XmlAdapter.kt b/api/src/main/java/com/readrops/api/localfeed/XmlAdapter.kt index 91807c54..798e476d 100644 --- a/api/src/main/java/com/readrops/api/localfeed/XmlAdapter.kt +++ b/api/src/main/java/com/readrops/api/localfeed/XmlAdapter.kt @@ -11,7 +11,7 @@ import com.readrops.db.entities.Item import java.io.InputStream interface XmlAdapter { - + fun fromXml(inputStream: InputStream): T companion object { @@ -32,6 +32,8 @@ interface XmlAdapter { else -> throw IllegalArgumentException("Unknown RSS type : $type") } } + + const val AUTHORS_MAX = 4 } } diff --git a/api/src/main/java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt b/api/src/main/java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt index 4a942b93..8ff9a80b 100644 --- a/api/src/main/java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt +++ b/api/src/main/java/com/readrops/api/localfeed/json/JSONItemsAdapter.kt @@ -1,5 +1,6 @@ package com.readrops.api.localfeed.json +import com.readrops.api.localfeed.XmlAdapter.Companion.AUTHORS_MAX import com.readrops.api.utils.DateUtils import com.readrops.api.utils.ParseException import com.readrops.api.utils.nextNullableString @@ -99,7 +100,7 @@ class JSONItemsAdapter : JsonAdapter>() { // here, nextNullableString doesn't check if authors values are empty return if (authors.filterNot { author -> author.isNullOrEmpty() }.isNotEmpty()) - authors.filterNot { author -> author.isNullOrEmpty() }.joinToString(limit = 4) else null + authors.filterNot { author -> author.isNullOrEmpty() }.joinToString(limit = AUTHORS_MAX) else null } private fun validateItem(item: Item) { diff --git a/api/src/main/java/com/readrops/api/localfeed/rss1/RSS1ItemsAdapter.kt b/api/src/main/java/com/readrops/api/localfeed/rss1/RSS1ItemsAdapter.kt index d5134784..ddc93353 100644 --- a/api/src/main/java/com/readrops/api/localfeed/rss1/RSS1ItemsAdapter.kt +++ b/api/src/main/java/com/readrops/api/localfeed/rss1/RSS1ItemsAdapter.kt @@ -4,6 +4,7 @@ import com.gitlab.mvysny.konsumexml.Names import com.gitlab.mvysny.konsumexml.allChildrenAutoIgnore import com.gitlab.mvysny.konsumexml.konsumeXml import com.readrops.api.localfeed.XmlAdapter +import com.readrops.api.localfeed.XmlAdapter.Companion.AUTHORS_MAX import com.readrops.api.utils.* import com.readrops.db.entities.Item import java.io.InputStream @@ -36,7 +37,7 @@ class RSS1ItemsAdapter : XmlAdapter> { } item.guid = item.link - if (authors.filterNotNull().isNotEmpty()) item.author = authors.filterNotNull().joinToString(limit = 4) + if (authors.filterNotNull().isNotEmpty()) item.author = authors.filterNotNull().joinToString(limit = AUTHORS_MAX) if (item.link == null) item.link = about validateItem(item) diff --git a/api/src/main/java/com/readrops/api/localfeed/rss2/RSS2ItemsAdapter.kt b/api/src/main/java/com/readrops/api/localfeed/rss2/RSS2ItemsAdapter.kt index 7a5c6890..9ecc01fe 100644 --- a/api/src/main/java/com/readrops/api/localfeed/rss2/RSS2ItemsAdapter.kt +++ b/api/src/main/java/com/readrops/api/localfeed/rss2/RSS2ItemsAdapter.kt @@ -2,6 +2,7 @@ package com.readrops.api.localfeed.rss2 import com.gitlab.mvysny.konsumexml.* import com.readrops.api.localfeed.XmlAdapter +import com.readrops.api.localfeed.XmlAdapter.Companion.AUTHORS_MAX import com.readrops.api.utils.* import com.readrops.db.entities.Item import java.io.InputStream @@ -47,7 +48,7 @@ class RSS2ItemsAdapter : XmlAdapter> { validateItem(item) if (item.guid == null) item.guid = item.link if (item.author == null && creators.filterNotNull().isNotEmpty()) - item.author = creators.filterNotNull().first() + item.author = creators.filterNotNull().joinToString(limit = AUTHORS_MAX) if (enclosures.isNotEmpty()) item.imageLink = enclosures.first() else if (mediaContents.isNotEmpty()) item.imageLink = mediaContents.first()