mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-02 15:53:55 +01:00
change the ReviewHelper for api called
This commit is contained in:
parent
66f917b189
commit
55e59b8ec7
1 changed files with 60 additions and 20 deletions
|
|
@ -23,13 +23,17 @@ class ReviewHelper
|
||||||
@JvmField @Inject
|
@JvmField @Inject
|
||||||
var dao: ReviewDao? = null
|
var dao: ReviewDao? = null
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetches recent changes from MediaWiki API
|
|
||||||
* Calls the API to get the latest 50 changes
|
/**
|
||||||
* When more results are available, the query gets continued beyond this range
|
* Gets multiple random media items for review.
|
||||||
*
|
* - Fetches recent changes and filters them
|
||||||
* @return
|
* - Checks if files are nominated for deletion
|
||||||
*/
|
* - Filters out already reviewed images
|
||||||
|
*
|
||||||
|
* @param count Number of media items to fetch
|
||||||
|
* @return Observable of Media items
|
||||||
|
*/
|
||||||
private fun getRecentChanges() =
|
private fun getRecentChanges() =
|
||||||
reviewInterface
|
reviewInterface
|
||||||
.getRecentChanges()
|
.getRecentChanges()
|
||||||
|
|
@ -38,19 +42,40 @@ class ReviewHelper
|
||||||
.flatMapIterable { changes: List<MwQueryPage>? -> changes }
|
.flatMapIterable { changes: List<MwQueryPage>? -> changes }
|
||||||
.filter { isChangeReviewable(it) }
|
.filter { isChangeReviewable(it) }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a random file change for review. Checks if the image has already been shown to the user
|
* Gets multiple random media items for review.
|
||||||
* - Picks a random file from those changes
|
* - Fetches recent changes and filters them
|
||||||
* - Checks if the file is nominated for deletion
|
* - Checks if files are nominated for deletion
|
||||||
* - Retries upto 5 times for getting a file which is not nominated for deletion
|
* - Filters out already reviewed images
|
||||||
*
|
*
|
||||||
* @return Random file change
|
* @param count Number of media items to fetch
|
||||||
*/
|
* @return Observable of Media items
|
||||||
fun getRandomMedia(): Single<Media> =
|
*/
|
||||||
getRecentChanges()
|
fun getRandomMediaBatch(count: Int): Observable<Media> =
|
||||||
.flatMapSingle(::getRandomMediaFromRecentChange)
|
getRecentChanges()
|
||||||
.filter { !it.filename.isNullOrBlank() && !getReviewStatus(it.pageId) }
|
.flatMapSingle(::getRandomMediaFromRecentChange)
|
||||||
.firstOrError()
|
.filter { media ->
|
||||||
|
!media.filename.isNullOrBlank() &&
|
||||||
|
!getReviewStatus(media.pageId)
|
||||||
|
}
|
||||||
|
.take(count.toLong())
|
||||||
|
.onErrorResumeNext { error: Throwable ->
|
||||||
|
Timber.e(error, "Error getting random media batch")
|
||||||
|
Observable.empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a random file change for review.
|
||||||
|
*
|
||||||
|
* @return Random file change
|
||||||
|
*/
|
||||||
|
fun getRandomMedia(): Single<Media> =
|
||||||
|
getRandomMediaBatch(1)
|
||||||
|
.firstOrError()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a proper Media object if the file is not already nominated for deletion
|
* Returns a proper Media object if the file is not already nominated for deletion
|
||||||
|
|
@ -108,6 +133,20 @@ class ReviewHelper
|
||||||
.getGlobalUsageInfo(filename)
|
.getGlobalUsageInfo(filename)
|
||||||
.map { it.query()?.firstPage()?.checkWhetherFileIsUsedInWikis() }
|
.map { it.query()?.firstPage()?.checkWhetherFileIsUsedInWikis() }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fun checkFileUsageBatch(filenames: List<String>): Observable<Pair<String, Boolean>> =
|
||||||
|
Observable.fromIterable(filenames)
|
||||||
|
.flatMap { filename ->
|
||||||
|
checkFileUsage(filename)
|
||||||
|
.map { isUsed -> Pair(filename, isUsed) }
|
||||||
|
}
|
||||||
|
.onErrorResumeNext { error: Throwable ->
|
||||||
|
Timber.e(error, "Error checking file usage batch")
|
||||||
|
Observable.empty()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the change is reviewable or not.
|
* Checks if the change is reviewable or not.
|
||||||
* - checks the type and revisionId of the change
|
* - checks the type and revisionId of the change
|
||||||
|
|
@ -145,5 +184,6 @@ class ReviewHelper
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val imageExtensions = arrayOf(".jpg", ".jpeg", ".png")
|
private val imageExtensions = arrayOf(".jpg", ".jpeg", ".png")
|
||||||
|
private const val MAX_RETRIES = 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue