Skip to content

Commit 7cd8a6d

Browse files
coolteydbrant
andauthored
Fix: show the correct article extracts for the featured article in (#4933)
zhwiki Co-authored-by: Dmitry Brant <[email protected]>
1 parent b20c944 commit 7cd8a6d

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

app/src/main/java/org/wikipedia/dataclient/page/PageSummary.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ open class PageSummary(
2424
var description: String? = null,
2525
@SerialName("originalimage") private val originalImage: Thumbnail? = null,
2626
@SerialName("wikibase_item") val wikiBaseItem: String? = null,
27-
@SerialName("extract_html") val extractHtml: String? = null,
27+
@SerialName("extract_html") var extractHtml: String? = null,
2828
@SerialName("description_source") val descriptionSource: String = "",
2929
@Serializable(with = LocationSerializer::class) var coordinates: Location? = null,
3030
val type: String = TYPE_STANDARD,

app/src/main/java/org/wikipedia/feed/aggregated/AggregatedFeedContentClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class AggregatedFeedContentClient {
154154
if (hasParentLanguageCode) {
155155
// TODO: Needs to update tfa and most read
156156
feedContentResponse.tfa?.let {
157-
val tfaResponse = L10nUtil.getPagesForLanguageVariant(listOf(it), wikiSite).first()
157+
val tfaResponse = L10nUtil.getPagesForLanguageVariant(listOf(it), wikiSite, shouldUpdateExtracts = true).first()
158158
feedContentResponse = AggregatedFeedContent(
159159
tfa = tfaResponse,
160160
news = feedContentResponse.news,

app/src/main/java/org/wikipedia/util/L10nUtil.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import android.util.SparseArray
77
import android.view.View
88
import androidx.annotation.StringRes
99
import androidx.core.os.ConfigurationCompat
10+
import kotlinx.coroutines.Deferred
1011
import kotlinx.coroutines.Dispatchers
1112
import kotlinx.coroutines.async
13+
import kotlinx.coroutines.awaitAll
1214
import kotlinx.coroutines.withContext
1315
import org.wikipedia.Constants
1416
import org.wikipedia.WikipediaApp
@@ -137,7 +139,7 @@ object L10nUtil {
137139
}
138140
}
139141

140-
suspend fun getPagesForLanguageVariant(list: List<PageSummary>, wikiSite: WikiSite): List<PageSummary> {
142+
suspend fun getPagesForLanguageVariant(list: List<PageSummary>, wikiSite: WikiSite, shouldUpdateExtracts: Boolean = false): List<PageSummary> {
141143
return withContext(Dispatchers.IO) {
142144
val newList = mutableListOf<PageSummary>()
143145
val titles = list.joinToString(separator = "|") { it.apiTitle }
@@ -151,6 +153,20 @@ object L10nUtil {
151153
ServiceFactory.get(wikiSite).getVariantTitlesByTitles(titles)
152154
}
153155

156+
// Third, update the extracts from the page/summary endpoint if needed.
157+
val summaryForExtractsDeferred = mutableListOf<Deferred<PageSummary>>()
158+
if (shouldUpdateExtracts) {
159+
summaryForExtractsDeferred.addAll(list.map { pageSummary ->
160+
async {
161+
ServiceFactory.getRest(wikiSite).getPageSummary(null, pageSummary.apiTitle)
162+
}
163+
})
164+
summaryForExtractsDeferred.awaitAll().forEachIndexed { index, pageSummary ->
165+
list[index].extract = pageSummary.extract
166+
list[index].extractHtml = pageSummary.extractHtml
167+
}
168+
}
169+
154170
list.forEach { pageSummary ->
155171
// Find the correct display title from the varianttitles map, and insert the new page summary to the list.
156172
val displayTitle = mwQueryResponse.await().query?.pages?.find { StringUtil.addUnderscores(it.title) == pageSummary.apiTitle }?.varianttitles?.get(wikiSite.languageCode)

0 commit comments

Comments
 (0)