|
|
|
@ -207,34 +207,37 @@ public class WebviewConnectActivity extends BaseActivity {
|
|
|
|
|
String scope = requestedAdmin ? Helper.OAUTH_SCOPES_ADMIN : Helper.OAUTH_SCOPES;
|
|
|
|
|
oauthVM.createToken(currentInstanceLogin, "authorization_code", client_idLogin, client_secretLogin, Helper.REDIRECT_CONTENT_WEB, scope, code)
|
|
|
|
|
.observe(WebviewConnectActivity.this, tokenObj -> {
|
|
|
|
|
Account account = new Account();
|
|
|
|
|
account.client_id = client_idLogin;
|
|
|
|
|
account.client_secret = client_secretLogin;
|
|
|
|
|
account.token = tokenObj.token_type + " " + tokenObj.access_token;
|
|
|
|
|
account.api = apiLogin;
|
|
|
|
|
account.software = softwareLogin;
|
|
|
|
|
account.instance = currentInstanceLogin;
|
|
|
|
|
//API call to retrieve account information for the new token
|
|
|
|
|
AccountsVM accountsVM = new ViewModelProvider(WebviewConnectActivity.this).get(AccountsVM.class);
|
|
|
|
|
accountsVM.getConnectedAccount(currentInstanceLogin, account.token).observe(WebviewConnectActivity.this, mastodonAccount -> {
|
|
|
|
|
if (mastodonAccount != null) {
|
|
|
|
|
account.mastodon_account = mastodonAccount;
|
|
|
|
|
account.user_id = mastodonAccount.id;
|
|
|
|
|
//We check if user have really moderator rights
|
|
|
|
|
if (requestedAdmin) {
|
|
|
|
|
AdminVM adminVM = new ViewModelProvider(WebviewConnectActivity.this).get(AdminVM.class);
|
|
|
|
|
adminVM.getAccount(account.instance, account.token, account.user_id).observe(WebviewConnectActivity.this, adminAccount -> {
|
|
|
|
|
account.admin = adminAccount != null;
|
|
|
|
|
if (tokenObj != null) {
|
|
|
|
|
Account account = new Account();
|
|
|
|
|
account.client_id = client_idLogin;
|
|
|
|
|
account.client_secret = client_secretLogin;
|
|
|
|
|
account.token = tokenObj.token_type + " " + tokenObj.access_token;
|
|
|
|
|
account.api = apiLogin;
|
|
|
|
|
account.software = softwareLogin;
|
|
|
|
|
account.instance = currentInstanceLogin;
|
|
|
|
|
//API call to retrieve account information for the new token
|
|
|
|
|
AccountsVM accountsVM = new ViewModelProvider(WebviewConnectActivity.this).get(AccountsVM.class);
|
|
|
|
|
accountsVM.getConnectedAccount(currentInstanceLogin, account.token).observe(WebviewConnectActivity.this, mastodonAccount -> {
|
|
|
|
|
if (mastodonAccount != null) {
|
|
|
|
|
account.mastodon_account = mastodonAccount;
|
|
|
|
|
account.user_id = mastodonAccount.id;
|
|
|
|
|
//We check if user have really moderator rights
|
|
|
|
|
if (requestedAdmin) {
|
|
|
|
|
AdminVM adminVM = new ViewModelProvider(WebviewConnectActivity.this).get(AdminVM.class);
|
|
|
|
|
adminVM.getAccount(account.instance, account.token, account.user_id).observe(WebviewConnectActivity.this, adminAccount -> {
|
|
|
|
|
account.admin = adminAccount != null;
|
|
|
|
|
proceedLogin(WebviewConnectActivity.this, account);
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
proceedLogin(WebviewConnectActivity.this, account);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
proceedLogin(WebviewConnectActivity.this, account);
|
|
|
|
|
Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
Toasty.error(WebviewConnectActivity.this, getString(R.string.toast_token), Toasty.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|