mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 11:39:42 +01:00
Merge pull request #1191 from nextcloud/bugfix/noid/handle-401
Start the reauth webview also when there is no getParentController()
This commit is contained in:
commit
b930f1365b
@ -23,6 +23,7 @@
|
|||||||
package com.nextcloud.talk.controllers;
|
package com.nextcloud.talk.controllers;
|
||||||
|
|
||||||
import android.animation.AnimatorInflater;
|
import android.animation.AnimatorInflater;
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.SearchManager;
|
import android.app.SearchManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -32,6 +33,7 @@ import android.os.Bundle;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
@ -85,6 +87,7 @@ import com.nextcloud.talk.events.BottomSheetLockEvent;
|
|||||||
import com.nextcloud.talk.events.EventStatus;
|
import com.nextcloud.talk.events.EventStatus;
|
||||||
import com.nextcloud.talk.events.MoreMenuClickEvent;
|
import com.nextcloud.talk.events.MoreMenuClickEvent;
|
||||||
import com.nextcloud.talk.interfaces.ConversationMenuInterface;
|
import com.nextcloud.talk.interfaces.ConversationMenuInterface;
|
||||||
|
import com.nextcloud.talk.jobs.AccountRemovalWorker;
|
||||||
import com.nextcloud.talk.jobs.ContactAddressBookWorker;
|
import com.nextcloud.talk.jobs.ContactAddressBookWorker;
|
||||||
import com.nextcloud.talk.jobs.DeleteConversationWorker;
|
import com.nextcloud.talk.jobs.DeleteConversationWorker;
|
||||||
import com.nextcloud.talk.models.database.UserEntity;
|
import com.nextcloud.talk.models.database.UserEntity;
|
||||||
@ -260,7 +263,9 @@ public class ConversationsListController extends BaseController implements Searc
|
|||||||
@Override
|
@Override
|
||||||
protected void onAttach(@NonNull View view) {
|
protected void onAttach(@NonNull View view) {
|
||||||
super.onAttach(view);
|
super.onAttach(view);
|
||||||
|
if (!eventBus.isRegistered(this)) {
|
||||||
eventBus.register(this);
|
eventBus.register(this);
|
||||||
|
}
|
||||||
|
|
||||||
currentUser = userUtils.getCurrentUser();
|
currentUser = userUtils.getCurrentUser();
|
||||||
|
|
||||||
@ -377,7 +382,7 @@ public class ConversationsListController extends BaseController implements Searc
|
|||||||
}
|
}
|
||||||
SmoothScrollLinearLayoutManager layoutManager =
|
SmoothScrollLinearLayoutManager layoutManager =
|
||||||
(SmoothScrollLinearLayoutManager) recyclerView.getLayoutManager();
|
(SmoothScrollLinearLayoutManager) recyclerView.getLayoutManager();
|
||||||
if (layoutManager!=null) {
|
if (layoutManager != null) {
|
||||||
layoutManager.scrollToPositionWithOffset(0, 0);
|
layoutManager.scrollToPositionWithOffset(0, 0);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -400,6 +405,7 @@ public class ConversationsListController extends BaseController implements Searc
|
|||||||
searchItem.expandActionView();
|
searchItem.expandActionView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("LongLogTag")
|
||||||
private void fetchData(boolean fromBottomSheet) {
|
private void fetchData(boolean fromBottomSheet) {
|
||||||
dispose(null);
|
dispose(null);
|
||||||
|
|
||||||
@ -476,13 +482,15 @@ public class ConversationsListController extends BaseController implements Searc
|
|||||||
HttpException exception = (HttpException) throwable;
|
HttpException exception = (HttpException) throwable;
|
||||||
switch (exception.code()) {
|
switch (exception.code()) {
|
||||||
case 401:
|
case 401:
|
||||||
if (getParentController() != null &&
|
if (getParentController() != null && getParentController().getRouter() != null) {
|
||||||
getParentController().getRouter() != null) {
|
Log.d(TAG, "Starting reauth webview via getParentController()");
|
||||||
getParentController().getRouter().pushController((RouterTransaction.with
|
getParentController().getRouter().pushController((RouterTransaction.with
|
||||||
(new WebViewLoginController(currentUser.getBaseUrl(),
|
(new WebViewLoginController(currentUser.getBaseUrl(), true))
|
||||||
true))
|
|
||||||
.pushChangeHandler(new VerticalChangeHandler())
|
.pushChangeHandler(new VerticalChangeHandler())
|
||||||
.popChangeHandler(new VerticalChangeHandler())));
|
.popChangeHandler(new VerticalChangeHandler())));
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Starting reauth webview via ConversationsListController");
|
||||||
|
showUnauthorizedDialog();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -811,6 +819,50 @@ public class ConversationsListController extends BaseController implements Searc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showUnauthorizedDialog() {
|
||||||
|
if (getActivity() != null) {
|
||||||
|
|
||||||
|
new LovelyStandardDialog(getActivity(), LovelyStandardDialog.ButtonLayout.HORIZONTAL)
|
||||||
|
.setTopColorRes(R.color.nc_darkRed)
|
||||||
|
.setIcon(DisplayUtils.getTintedDrawable(context.getResources(),
|
||||||
|
R.drawable.ic_delete_black_24dp, R.color.bg_default))
|
||||||
|
.setPositiveButtonColor(context.getResources().getColor(R.color.nc_darkRed))
|
||||||
|
.setCancelable(false)
|
||||||
|
.setTitle(R.string.nc_dialog_invalid_password)
|
||||||
|
.setMessage(R.string.nc_dialog_reauth_or_delete)
|
||||||
|
.setPositiveButton(R.string.nc_delete, new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
boolean otherUserExists = userUtils.scheduleUserForDeletionWithId(currentUser.getId());
|
||||||
|
|
||||||
|
OneTimeWorkRequest accountRemovalWork = new OneTimeWorkRequest.Builder(AccountRemovalWorker.class).build();
|
||||||
|
WorkManager.getInstance().enqueue(accountRemovalWork);
|
||||||
|
|
||||||
|
if (otherUserExists && getView() != null) {
|
||||||
|
onViewBound(getView());
|
||||||
|
onAttach(getView());
|
||||||
|
} else if (!otherUserExists) {
|
||||||
|
getRouter().setRoot(RouterTransaction.with(
|
||||||
|
new ServerSelectionController())
|
||||||
|
.pushChangeHandler(new VerticalChangeHandler())
|
||||||
|
.popChangeHandler(new VerticalChangeHandler()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton(R.string.nc_settings_reauthorize, new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
getRouter().pushController(RouterTransaction.with(
|
||||||
|
new WebViewLoginController(currentUser.getBaseUrl(), true))
|
||||||
|
.pushChangeHandler(new VerticalChangeHandler())
|
||||||
|
.popChangeHandler(new VerticalChangeHandler()));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setInstanceStateHandler(ID_DELETE_CONVERSATION_DIALOG, saveStateHandler)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void deleteConversation(Data data) {
|
private void deleteConversation(Data data) {
|
||||||
OneTimeWorkRequest deleteConversationWorker =
|
OneTimeWorkRequest deleteConversationWorker =
|
||||||
new OneTimeWorkRequest.Builder(DeleteConversationWorker.class).setInputData(data).build();
|
new OneTimeWorkRequest.Builder(DeleteConversationWorker.class).setInputData(data).build();
|
||||||
|
@ -35,6 +35,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.webkit.*;
|
import android.webkit.*;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.content.res.ResourcesCompat;
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
@ -42,6 +43,7 @@ import androidx.work.OneTimeWorkRequest;
|
|||||||
import androidx.work.WorkManager;
|
import androidx.work.WorkManager;
|
||||||
import autodagger.AutoInjector;
|
import autodagger.AutoInjector;
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
|
|
||||||
import com.bluelinelabs.conductor.RouterTransaction;
|
import com.bluelinelabs.conductor.RouterTransaction;
|
||||||
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
|
import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
|
||||||
import com.nextcloud.talk.R;
|
import com.nextcloud.talk.R;
|
||||||
@ -64,9 +66,11 @@ import io.reactivex.disposables.Disposable;
|
|||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import io.requery.Persistable;
|
import io.requery.Persistable;
|
||||||
import io.requery.reactivex.ReactiveEntityStore;
|
import io.requery.reactivex.ReactiveEntityStore;
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.CookieManager;
|
import java.net.CookieManager;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
@ -406,6 +410,9 @@ public class WebViewLoginController extends BaseController {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (finalMessageType != null) {
|
if (finalMessageType != null) {
|
||||||
|
// FIXME when the user registers a new account that was setup before (aka
|
||||||
|
// ApplicationWideMessageHolder.MessageType.ACCOUNT_UPDATED_NOT_ADDED)
|
||||||
|
// The token is not updated in the database and therefor the account not visible/usable
|
||||||
ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType);
|
ApplicationWideMessageHolder.getInstance().setMessageType(finalMessageType);
|
||||||
}
|
}
|
||||||
getRouter().popToRoot();
|
getRouter().popToRoot();
|
||||||
|
@ -96,7 +96,6 @@ public class AccountRemovalWorker extends Worker {
|
|||||||
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new
|
ncApi = retrofit.newBuilder().client(okHttpClient.newBuilder().cookieJar(new
|
||||||
JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
|
JavaNetCookieJar(new CookieManager())).build()).build().create(NcApi.class);
|
||||||
|
|
||||||
String finalCredentials = credentials;
|
|
||||||
ncApi.unregisterDeviceForNotificationsWithNextcloud(credentials, ApiUtils.getUrlNextcloudPush(userEntity
|
ncApi.unregisterDeviceForNotificationsWithNextcloud(credentials, ApiUtils.getUrlNextcloudPush(userEntity
|
||||||
.getBaseUrl()))
|
.getBaseUrl()))
|
||||||
.blockingSubscribe(new Observer<GenericOverall>() {
|
.blockingSubscribe(new Observer<GenericOverall>() {
|
||||||
@ -114,7 +113,33 @@ public class AccountRemovalWorker extends Worker {
|
|||||||
queryMap.put("userPublicKey", finalPushConfigurationState.getUserPublicKey());
|
queryMap.put("userPublicKey", finalPushConfigurationState.getUserPublicKey());
|
||||||
queryMap.put("deviceIdentifierSignature",
|
queryMap.put("deviceIdentifierSignature",
|
||||||
finalPushConfigurationState.getDeviceIdentifierSignature());
|
finalPushConfigurationState.getDeviceIdentifierSignature());
|
||||||
|
unregisterDeviceForNotificationWithProxy(queryMap, userEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
Log.e(TAG, "error while trying to unregister Device For Notifications", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
deleteUser(userEntity);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.d(TAG, "Something went wrong while removing job at parsing PushConfigurationState");
|
||||||
|
deleteUser(userEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unregisterDeviceForNotificationWithProxy(HashMap<String, String> queryMap, UserEntity userEntity) {
|
||||||
ncApi.unregisterDeviceForNotificationsWithProxy
|
ncApi.unregisterDeviceForNotificationsWithProxy
|
||||||
(ApiUtils.getUrlPushProxy(), queryMap)
|
(ApiUtils.getUrlPushProxy(), queryMap)
|
||||||
.subscribe(new Observer<Void>() {
|
.subscribe(new Observer<Void>() {
|
||||||
@ -125,7 +150,6 @@ public class AccountRemovalWorker extends Worker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(Void aVoid) {
|
public void onNext(Void aVoid) {
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
String groupName = String.format(getApplicationContext().getResources()
|
String groupName = String.format(getApplicationContext().getResources()
|
||||||
.getString(R.string
|
.getString(R.string
|
||||||
@ -141,9 +165,23 @@ public class AccountRemovalWorker extends Worker {
|
|||||||
.toString(crc32.getValue()));
|
.toString(crc32.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WebSocketConnectionHelper.deleteExternalSignalingInstanceForUserEntity(userEntity.getId());
|
WebSocketConnectionHelper.deleteExternalSignalingInstanceForUserEntity(userEntity.getId());
|
||||||
|
deleteAllEntriesForAccountIdentifier(userEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
Log.e(TAG, "error while trying to unregister Device For Notification With Proxy", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete() {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteAllEntriesForAccountIdentifier(UserEntity userEntity) {
|
||||||
arbitraryStorageUtils.deleteAllEntriesForAccountIdentifier(userEntity.getId()).subscribe(new Observer() {
|
arbitraryStorageUtils.deleteAllEntriesForAccountIdentifier(userEntity.getId()).subscribe(new Observer() {
|
||||||
@Override
|
@Override
|
||||||
public void onSubscribe(Disposable d) {
|
public void onSubscribe(Disposable d) {
|
||||||
@ -152,27 +190,12 @@ public class AccountRemovalWorker extends Worker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNext(Object o) {
|
public void onNext(Object o) {
|
||||||
userUtils.deleteUser(userEntity.getId()).subscribe(new CompletableObserver() {
|
deleteUser(userEntity);
|
||||||
@Override
|
|
||||||
public void onSubscribe(Disposable d) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable e) {
|
public void onError(Throwable e) {
|
||||||
|
Log.e(TAG, "error while trying to delete All Entries For Account Identifier", e);
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Throwable e) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -182,30 +205,8 @@ public class AccountRemovalWorker extends Worker {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void deleteUser(UserEntity userEntity) {
|
||||||
public void onError(Throwable e) {
|
String username = userEntity.getUsername();
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Throwable e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
userUtils.deleteUser(userEntity.getId())
|
userUtils.deleteUser(userEntity.getId())
|
||||||
.subscribe(new CompletableObserver() {
|
.subscribe(new CompletableObserver() {
|
||||||
@Override
|
@Override
|
||||||
@ -215,37 +216,13 @@ public class AccountRemovalWorker extends Worker {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onComplete() {
|
||||||
|
Log.d(TAG, "deleted user: " + username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable e) {
|
public void onError(Throwable e) {
|
||||||
|
Log.e(TAG, "error while trying to delete user", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
Log.d(TAG, "Something went wrong while removing job at parsing PushConfigurationState");
|
|
||||||
userUtils.deleteUser(userEntity.getId())
|
|
||||||
.subscribe(new CompletableObserver() {
|
|
||||||
@Override
|
|
||||||
public void onSubscribe(Disposable d) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onComplete() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(Throwable e) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.success();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -409,4 +409,6 @@
|
|||||||
<string name="failed_to_save">Failed to save %1$s</string>
|
<string name="failed_to_save">Failed to save %1$s</string>
|
||||||
<string name="selected_list_item">selected</string>
|
<string name="selected_list_item">selected</string>
|
||||||
<string name="filename_progress">%1$s (%2$d)</string>
|
<string name="filename_progress">%1$s (%2$d)</string>
|
||||||
|
<string name="nc_dialog_invalid_password">Invalid password</string>
|
||||||
|
<string name="nc_dialog_reauth_or_delete">Do you want to reauthorize or delete this account?</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user