Skip to content

Commit 049dd7c

Browse files
authored
Fixes commons-app#4278 "Media details categories editor: Category not actually added" (commons-app#4328)
* rectified category update * changed class name, added javadoc * javadoc
1 parent c12ecf8 commit 049dd7c

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

data-client/src/main/java/org/wikipedia/csrf/CsrfTokenClient.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import androidx.annotation.Nullable;
77
import androidx.annotation.VisibleForTesting;
88

9+
import java.util.concurrent.Callable;
10+
import java.util.concurrent.Executors;
911
import org.wikipedia.AppAdapter;
1012
import org.wikipedia.dataclient.Service;
1113
import org.wikipedia.dataclient.ServiceFactory;
@@ -142,7 +144,9 @@ public void error(@NonNull Throwable caught) {
142144
AppAdapter.get().getPassword(), "");
143145
}
144146

145-
Response<MwQueryResponse> response = service.getCsrfTokenCall().execute();
147+
// Get CSRFToken response off the main thread.
148+
Response<MwQueryResponse> response = Executors.newSingleThreadExecutor().submit(new CsrfTokenCallExecutor(service)).get();
149+
146150
if (response.body() == null || response.body().query() == null
147151
|| TextUtils.isEmpty(response.body().query().csrfToken())) {
148152
continue;
@@ -210,4 +214,34 @@ public void twoFactorPrompt() {
210214
private interface RetryCallback {
211215
void retry();
212216
}
217+
218+
/**
219+
* Class CsrfTokenCallExecutor which implement callable interface to get CsrfTokenCall.
220+
*/
221+
class CsrfTokenCallExecutor implements Callable<Response<MwQueryResponse>> {
222+
223+
/**
224+
* Service for token call.
225+
*/
226+
private Service service;
227+
228+
/**
229+
* Default Constructor.
230+
* @param service
231+
*/
232+
public CsrfTokenCallExecutor(Service service){
233+
this.service = service;
234+
}
235+
236+
/**
237+
* Computes a result, or throws an exception if unable to do so.
238+
*
239+
* @return computed result
240+
* @throws Exception if unable to compute a result
241+
*/
242+
@Override
243+
public Response<MwQueryResponse> call() throws Exception {
244+
return service.getCsrfTokenCall().execute();
245+
}
246+
}
213247
}

0 commit comments

Comments
 (0)