Create Revision class

This commit is contained in:
Yusuke Matsubara 2018-05-20 12:51:26 +02:00 committed by maskara
parent 44567627d0
commit 77c28f646f
4 changed files with 22 additions and 10 deletions

View file

@ -607,16 +607,16 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
@Override
@Nullable
public String firstRevisionOfFile(String filename) throws IOException {
String res = api.action("query")
public Revision firstRevisionOfFile(String filename) throws IOException {
ApiResult res = api.action("query")
.param("prop", "revisions")
.param("rvprop", "timestamp|ids")
.param("rvprop", "timestamp|ids|user")
.param("titles", filename)
.param("rvdir", "newer")
.param("rvlimit", "1")
.get()
.getString("/api/query/pages/page/revisions/rev/@revid");
return res;
.get();
return new Revision(res.getString("/api/query/pages/page/revisions/rev/@revid"),
res.getString("/api/query/pages/page/revisions/rev/@user"));
}
@Override

View file

@ -110,7 +110,7 @@ public interface MediaWikiApi {
boolean thank(String editToken, String revision) throws IOException;
String firstRevisionOfFile(String filename) throws IOException;
Revision firstRevisionOfFile(String filename) throws IOException;
interface ProgressListener {
void onProgress(long transferred, long total);

View file

@ -0,0 +1,11 @@
package fr.free.nrw.commons.mwapi;
public class Revision {
public String revisionId;
public String username;
public Revision(String revisionId, String username) {
this.revisionId = revisionId;
this.username = username;
}
}

View file

@ -16,6 +16,7 @@ import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.di.ApplicationlessInjection;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.mwapi.Revision;
import timber.log.Timber;
import static android.support.v4.app.NotificationCompat.DEFAULT_ALL;
@ -45,7 +46,7 @@ public class SendThankTask extends AsyncTask<Void, Integer, Boolean> {
private NotificationCompat.Builder notificationBuilder;
private Context context;
private Media media;
private String revision;
private Revision revision;
public SendThankTask(Context context, Media media){
this.context = context;
@ -79,14 +80,14 @@ public class SendThankTask extends AsyncTask<Void, Integer, Boolean> {
mwApi.setAuthCookie(authCookie);
try {
this.revision = mwApi.firstRevisionOfFile(media.getFilename());
revision = mwApi.firstRevisionOfFile(media.getFilename());
editToken = mwApi.getEditToken();
if (editToken.equals("+\\")) {
return false;
}
publishProgress(1);
mwApi.thank(editToken, revision);
mwApi.thank(editToken, revision.revisionId);
publishProgress(2);
}