Skip to content

Commit 728712c

Browse files
authored
Convert API clients to kotlin (commons-app#5567)
* Convert UserClient to kotlin * Added tests for WikiBaseClient * Removed superfluous dao tests in review helper and got the proper ReviewDaoTest running in the unit test suite * Improved tests for ReviewHelper * Convert the ReviewHelper to kotlin * Convert the WikiBaseClient to kotlin * Convert the WikidataClient to kotlin
1 parent c434052 commit 728712c

File tree

15 files changed

+500
-530
lines changed

15 files changed

+500
-530
lines changed

app/src/androidTest/java/fr/free/nrw/commons/ReviewDaoTest.java

-74
This file was deleted.

app/src/main/java/fr/free/nrw/commons/mwapi/UserClient.java

-46
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package fr.free.nrw.commons.mwapi
2+
3+
import fr.free.nrw.commons.utils.DateUtil
4+
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResponse
5+
import fr.free.nrw.commons.wikidata.mwapi.MwQueryResult
6+
import fr.free.nrw.commons.wikidata.mwapi.UserInfo
7+
import io.reactivex.Single
8+
import java.text.ParseException
9+
import java.util.Date
10+
import javax.inject.Inject
11+
12+
class UserClient @Inject constructor(private val userInterface: UserInterface) {
13+
/**
14+
* Checks to see if a user is currently blocked from Commons
15+
*
16+
* @return whether or not the user is blocked from Commons
17+
*/
18+
fun isUserBlockedFromCommons(): Single<Boolean> =
19+
userInterface.getUserBlockInfo()
20+
.map(::processBlockExpiry)
21+
.single(false)
22+
23+
@Throws(ParseException::class)
24+
private fun processBlockExpiry(response: MwQueryResponse): Boolean {
25+
val blockExpiry = response.query()?.userInfo()?.blockexpiry()
26+
return when {
27+
blockExpiry.isNullOrEmpty() -> false
28+
"infinite" == blockExpiry -> true
29+
else -> {
30+
val endDate = DateUtil.iso8601DateParse(blockExpiry)
31+
val current = Date()
32+
endDate.after(current)
33+
}
34+
}
35+
}
36+
}

app/src/main/java/fr/free/nrw/commons/review/ReviewHelper.java

-166
This file was deleted.

0 commit comments

Comments
 (0)