Revert "Merge branch 'backend-overhaul' into master" (#3125)

* Revert "Merge branch 'backend-overhaul' into master"

This reverts commit 0090f24257, reversing
changes made to 9bccbfe443.

* fixed test handleSubmitTest
This commit is contained in:
Ashish Kumar 2019-08-12 14:32:25 +05:30 committed by Vivek Maskara
parent cbdfb05530
commit 5865d59d22
77 changed files with 3471 additions and 1816 deletions

View file

@ -26,16 +26,16 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.AuthenticatedActivity;
import fr.free.nrw.commons.delete.DeleteHelper;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.theme.NavigationBaseActivity;
import fr.free.nrw.commons.utils.DialogUtil;
import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
public class ReviewActivity extends NavigationBaseActivity {
public class ReviewActivity extends AuthenticatedActivity {
@BindView(R.id.pager_indicator_review)
public CirclePageIndicator pagerIndicator;
@ -94,6 +94,15 @@ public class ReviewActivity extends NavigationBaseActivity {
return media;
}
@Override
protected void onAuthCookieAcquired(String authCookie) {
}
@Override
protected void onAuthFailure() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

View file

@ -4,6 +4,8 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -11,23 +13,17 @@ import androidx.core.app.NotificationCompat;
import org.wikipedia.dataclient.mwapi.MwQueryPage;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.actions.PageEditClient;
import fr.free.nrw.commons.actions.ThanksClient;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.delete.DeleteHelper;
import fr.free.nrw.commons.di.ApplicationlessInjection;
import fr.free.nrw.commons.utils.ViewUtil;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import timber.log.Timber;
@ -36,15 +32,13 @@ import timber.log.Timber;
public class ReviewController {
private static final int NOTIFICATION_SEND_THANK = 0x102;
private static final int NOTIFICATION_CHECK_CATEGORY = 0x101;
protected static ArrayList<String> categories;
@Inject
ThanksClient thanksClient;
private final DeleteHelper deleteHelper;
@Nullable
MwQueryPage.Revision firstRevision; // TODO: maybe we can expand this class to include fileName
@Inject
@Named("commons-page-edit")
PageEditClient pageEditClient;
MediaWikiApi mwApi;
@Inject
SessionManager sessionManager;
private NotificationManager notificationManager;
private NotificationCompat.Builder notificationBuilder;
private Media media;
@ -95,16 +89,40 @@ public class ReviewController {
.getCommonsApplicationComponent()
.inject(this);
ViewUtil.showShortToast(context, context.getString(R.string.check_category_toast, media.getDisplayTitle()));
Toast toast = new Toast(context);
toast.setGravity(Gravity.CENTER, 0, 0);
toast = Toast.makeText(context, context.getString(R.string.check_category_toast, media.getDisplayTitle()), Toast.LENGTH_SHORT);
toast.show();
publishProgress(context, 0);
String summary = context.getString(R.string.check_category_edit_summary);
Observable.defer((Callable<ObservableSource<Boolean>>) () ->
pageEditClient.appendEdit(media.getFilename(), "\n{{subst:chc}}\n", summary))
Observable.fromCallable(() -> {
publishProgress(context, 0);
String editToken;
String authCookie;
String summary = context.getString(R.string.check_category_edit_summary);
authCookie = sessionManager.getAuthCookie();
mwApi.setAuthCookie(authCookie);
try {
editToken = mwApi.getEditToken();
if (editToken == null) {
return false;
}
publishProgress(context, 1);
mwApi.appendEdit(editToken, "\n{{subst:chc}}\n", media.getFilename(), summary);
publishProgress(context, 2);
} catch (Exception e) {
Timber.d(e);
return false;
}
return true;
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((result) -> {
publishProgress(context, 2);
String message;
String title;
@ -118,7 +136,15 @@ public class ReviewController {
reviewCallback.onFailure();
}
showNotification(title, message);
notificationBuilder.setDefaults(NotificationCompat.DEFAULT_ALL)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setSmallIcon(R.drawable.ic_launcher)
.setProgress(0, 0, false)
.setOngoing(false)
.setPriority(NotificationCompat.PRIORITY_HIGH);
notificationManager.notify(NOTIFICATION_CHECK_CATEGORY, notificationBuilder.build());
}, Timber::e);
}
@ -146,20 +172,39 @@ public class ReviewController {
.getInstance(context)
.getCommonsApplicationComponent()
.inject(this);
ViewUtil.showShortToast(context, context.getString(R.string.send_thank_toast, media.getDisplayTitle()));
Toast toast = new Toast(context);
toast.setGravity(Gravity.CENTER, 0, 0);
toast = Toast.makeText(context, context.getString(R.string.send_thank_toast, media.getDisplayTitle()), Toast.LENGTH_SHORT);
toast.show();
publishProgress(context, 0);
if (firstRevision == null) {
return;
}
Observable.fromCallable(() -> {
publishProgress(context, 0);
Observable.defer((Callable<ObservableSource<Boolean>>) () -> thanksClient.thank(firstRevision.getRevisionId()))
String editToken;
String authCookie;
authCookie = sessionManager.getAuthCookie();
mwApi.setAuthCookie(authCookie);
try {
editToken = mwApi.getEditToken();
if (editToken == null) {
return false;
}
publishProgress(context, 1);
assert firstRevision != null;
mwApi.thank(editToken, firstRevision.getRevisionId());
publishProgress(context, 2);
} catch (Exception e) {
Timber.d(e);
return false;
}
return true;
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe((result) -> {
publishProgress(context, 2);
String message;
String title;
String message = "";
String title = "";
if (result) {
title = context.getString(R.string.send_thank_success_title);
message = context.getString(R.string.send_thank_success_message, media.getDisplayTitle());
@ -168,23 +213,19 @@ public class ReviewController {
message = context.getString(R.string.send_thank_failure_message, media.getDisplayTitle());
}
showNotification(title, message);
notificationBuilder.setDefaults(NotificationCompat.DEFAULT_ALL)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setSmallIcon(R.drawable.ic_launcher)
.setProgress(0, 0, false)
.setOngoing(false)
.setPriority(NotificationCompat.PRIORITY_HIGH);
notificationManager.notify(NOTIFICATION_SEND_THANK, notificationBuilder.build());
}, Timber::e);
}
private void showNotification(String title, String message) {
notificationBuilder.setDefaults(NotificationCompat.DEFAULT_ALL)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setSmallIcon(R.drawable.ic_launcher)
.setProgress(0, 0, false)
.setOngoing(false)
.setPriority(NotificationCompat.PRIORITY_HIGH);
notificationManager.notify(NOTIFICATION_SEND_THANK, notificationBuilder.build());
}
public interface ReviewCallback {
void onSuccess();

View file

@ -14,7 +14,6 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.media.MediaClient;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
import io.reactivex.Observable;
@ -25,21 +24,24 @@ public class ReviewHelper {
private static final String[] imageExtensions = new String[]{".jpg", ".jpeg", ".png"};
private final MediaClient mediaClient;
private final OkHttpJsonApiClient okHttpJsonApiClient;
private final MediaWikiApi mediaWikiApi;
private final ReviewInterface reviewInterface;
@Inject
public ReviewHelper(MediaClient mediaClient, ReviewInterface reviewInterface) {
this.mediaClient = mediaClient;
public ReviewHelper(OkHttpJsonApiClient okHttpJsonApiClient,
MediaWikiApi mediaWikiApi,
ReviewInterface reviewInterface) {
this.okHttpJsonApiClient = okHttpJsonApiClient;
this.mediaWikiApi = mediaWikiApi;
this.reviewInterface = reviewInterface;
}
/**
* Fetches recent changes from MediaWiki AP
* Fetches recent changes from MediaWiki API
* Calls the API to get 10 changes in the last 1 hour
* Earlier we were getting changes for the last 30 days but as the API returns just 10 results
* its best to fetch for just last 1 hour.
*
* @return
*/
private Observable<RecentChange> getRecentChanges() {
@ -79,25 +81,23 @@ public class ReviewHelper {
/**
* Returns a proper Media object if the file is not already nominated for deletion
* Else it returns an empty Media object
*
* @param recentChange
* @return
*/
private Single<Media> getRandomMediaFromRecentChange(RecentChange recentChange) {
return Single.just(recentChange)
.flatMap(change -> mediaClient.checkPageExistsUsingTitle("Commons:Deletion_requests/" + change.getTitle()))
.flatMap(change -> mediaWikiApi.pageExists("Commons:Deletion_requests/" + change.getTitle()))
.flatMap(isDeleted -> {
if (isDeleted) {
return Single.just(new Media(""));
}
return mediaClient.getMedia(recentChange.getTitle());
return okHttpJsonApiClient.getMedia(recentChange.getTitle(), false);
});
}
/**
* Gets the first revision of the file from filename
*
* @param filename
* @return
*/
@ -110,7 +110,6 @@ public class ReviewHelper {
* Checks if the change is reviewable or not.
* - checks the type and revisionId of the change
* - checks supported image extensions
*
* @param recentChange
* @return
*/