mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Move thanks API into main commons codebase (#5463)
* Move thanks API into main commons codebase * KDoc * KDoc --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
parent
2c086b3d79
commit
ef47b7025e
7 changed files with 61 additions and 54 deletions
|
|
@ -0,0 +1,18 @@
|
|||
package fr.free.nrw.commons.actions
|
||||
|
||||
import org.wikipedia.dataclient.mwapi.MwResponse
|
||||
|
||||
/**
|
||||
* Response of the Thanks API.
|
||||
* Context:
|
||||
* The Commons Android app lets you thank other contributors who have uploaded a great picture.
|
||||
* See https://www.mediawiki.org/wiki/Extension:Thanks
|
||||
*/
|
||||
class MwThankPostResponse : MwResponse() {
|
||||
var result: Result? = null
|
||||
|
||||
inner class Result {
|
||||
var success: Int? = null
|
||||
var recipient: String? = null
|
||||
}
|
||||
}
|
||||
|
|
@ -4,8 +4,6 @@ import fr.free.nrw.commons.CommonsApplication
|
|||
import fr.free.nrw.commons.di.NetworkingModule.NAMED_COMMONS_CSRF
|
||||
import io.reactivex.Observable
|
||||
import org.wikipedia.csrf.CsrfTokenClient
|
||||
import org.wikipedia.dataclient.Service
|
||||
import org.wikipedia.dataclient.mwapi.MwPostResponse
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
import javax.inject.Singleton
|
||||
|
|
@ -17,7 +15,7 @@ import javax.inject.Singleton
|
|||
@Singleton
|
||||
class ThanksClient @Inject constructor(
|
||||
@param:Named(NAMED_COMMONS_CSRF) private val csrfTokenClient: CsrfTokenClient,
|
||||
@param:Named("commons-service") private val service: Service
|
||||
private val service: ThanksInterface
|
||||
) {
|
||||
/**
|
||||
* Thanks a user for a particular revision
|
||||
|
|
@ -26,11 +24,16 @@ class ThanksClient @Inject constructor(
|
|||
*/
|
||||
fun thank(revisionId: Long): Observable<Boolean> {
|
||||
return try {
|
||||
service.thank(revisionId.toString(), null, csrfTokenClient.tokenBlocking, CommonsApplication.getInstance().userAgent)
|
||||
.map { mwThankPostResponse -> mwThankPostResponse.result.success== 1 }
|
||||
service.thank(
|
||||
revisionId.toString(), // Rev
|
||||
null, // Log
|
||||
csrfTokenClient.tokenBlocking, // Token
|
||||
CommonsApplication.getInstance().userAgent // Source
|
||||
).map {
|
||||
mwThankPostResponse -> mwThankPostResponse.result?.success == 1
|
||||
}
|
||||
} catch (throwable: Throwable) {
|
||||
Observable.just(false)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package fr.free.nrw.commons.actions
|
||||
|
||||
import io.reactivex.Observable
|
||||
import org.wikipedia.dataclient.Service
|
||||
import retrofit2.http.Field
|
||||
import retrofit2.http.FormUrlEncoded
|
||||
import retrofit2.http.POST
|
||||
|
||||
/**
|
||||
* Thanks API.
|
||||
* Context:
|
||||
* The Commons Android app lets you thank another contributor who has uploaded a great picture.
|
||||
* See https://www.mediawiki.org/wiki/Extension:Thanks
|
||||
*/
|
||||
interface ThanksInterface {
|
||||
@FormUrlEncoded
|
||||
@POST(Service.MW_API_PREFIX + "action=thank")
|
||||
fun thank(
|
||||
@Field("rev") rev: String?,
|
||||
@Field("log") log: String?,
|
||||
@Field("token") token: String,
|
||||
@Field("source") source: String?
|
||||
): Observable<MwThankPostResponse?>
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@ import fr.free.nrw.commons.BetaConstants;
|
|||
import fr.free.nrw.commons.BuildConfig;
|
||||
import fr.free.nrw.commons.actions.PageEditClient;
|
||||
import fr.free.nrw.commons.actions.PageEditInterface;
|
||||
import fr.free.nrw.commons.actions.ThanksInterface;
|
||||
import fr.free.nrw.commons.category.CategoryInterface;
|
||||
import fr.free.nrw.commons.explore.depictions.DepictsClient;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
|
|
@ -256,6 +257,14 @@ public class NetworkingModule {
|
|||
.get(commonsWikiSite, BuildConfig.COMMONS_URL, CategoryInterface.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public ThanksInterface provideThanksInterface(
|
||||
@Named(NAMED_COMMONS_WIKI_SITE) WikiSite commonsWikiSite) {
|
||||
return ServiceFactory
|
||||
.get(commonsWikiSite, BuildConfig.COMMONS_URL, ThanksInterface.class);
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public UserInterface provideUserInterface(@Named(NAMED_COMMONS_WIKI_SITE) WikiSite commonsWikiSite) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue