use of org.telegram.ui.TwoStepVerificationSetupActivity in project Telegram-FOSS by Telegram-FOSS-Team.
the class SendMessagesHelper method sendCallback.
public void sendCallback(final boolean cache, final MessageObject messageObject, final TLRPC.KeyboardButton button, TLRPC.InputCheckPasswordSRP srp, TwoStepVerificationActivity passwordFragment, final ChatActivity parentFragment) {
if (messageObject == null || button == null || parentFragment == null) {
return;
}
final boolean cacheFinal;
int type;
if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
cacheFinal = false;
type = 3;
} else if (button instanceof TLRPC.TL_keyboardButtonGame) {
cacheFinal = false;
type = 1;
} else {
cacheFinal = cache;
if (button instanceof TLRPC.TL_keyboardButtonBuy) {
type = 2;
} else {
type = 0;
}
}
final String key = messageObject.getDialogId() + "_" + messageObject.getId() + "_" + Utilities.bytesToHex(button.data) + "_" + type;
waitingForCallback.put(key, true);
TLObject[] request = new TLObject[1];
RequestDelegate requestDelegate = (response, error) -> AndroidUtilities.runOnUIThread(() -> {
waitingForCallback.remove(key);
if (cacheFinal && response == null) {
sendCallback(false, messageObject, button, parentFragment);
} else if (response != null) {
if (passwordFragment != null) {
passwordFragment.needHideProgress();
passwordFragment.finishFragment();
}
if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
if (response instanceof TLRPC.TL_urlAuthResultRequest) {
TLRPC.TL_urlAuthResultRequest res = (TLRPC.TL_urlAuthResultRequest) response;
parentFragment.showRequestUrlAlert(res, (TLRPC.TL_messages_requestUrlAuth) request[0], button.url, false);
} else if (response instanceof TLRPC.TL_urlAuthResultAccepted) {
TLRPC.TL_urlAuthResultAccepted res = (TLRPC.TL_urlAuthResultAccepted) response;
AlertsCreator.showOpenUrlAlert(parentFragment, res.url, false, false);
} else if (response instanceof TLRPC.TL_urlAuthResultDefault) {
TLRPC.TL_urlAuthResultDefault res = (TLRPC.TL_urlAuthResultDefault) response;
AlertsCreator.showOpenUrlAlert(parentFragment, button.url, false, true);
}
} else if (button instanceof TLRPC.TL_keyboardButtonBuy) {
if (response instanceof TLRPC.TL_payments_paymentForm) {
final TLRPC.TL_payments_paymentForm form = (TLRPC.TL_payments_paymentForm) response;
getMessagesController().putUsers(form.users, false);
parentFragment.presentFragment(new PaymentFormActivity(form, messageObject, parentFragment));
} else if (response instanceof TLRPC.TL_payments_paymentReceipt) {
parentFragment.presentFragment(new PaymentFormActivity((TLRPC.TL_payments_paymentReceipt) response));
}
} else {
TLRPC.TL_messages_botCallbackAnswer res = (TLRPC.TL_messages_botCallbackAnswer) response;
if (!cacheFinal && res.cache_time != 0 && !button.requires_password) {
getMessagesStorage().saveBotCache(key, res);
}
if (res.message != null) {
long uid = messageObject.getFromChatId();
if (messageObject.messageOwner.via_bot_id != 0) {
uid = messageObject.messageOwner.via_bot_id;
}
String name = null;
if (uid > 0) {
TLRPC.User user = getMessagesController().getUser(uid);
if (user != null) {
name = ContactsController.formatName(user.first_name, user.last_name);
}
} else {
TLRPC.Chat chat = getMessagesController().getChat(-uid);
if (chat != null) {
name = chat.title;
}
}
if (name == null) {
name = "bot";
}
if (res.alert) {
if (parentFragment.getParentActivity() == null) {
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
builder.setTitle(name);
builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
builder.setMessage(res.message);
parentFragment.showDialog(builder.create());
} else {
parentFragment.showAlert(name, res.message);
}
} else if (res.url != null) {
if (parentFragment.getParentActivity() == null) {
return;
}
long uid = messageObject.getFromChatId();
if (messageObject.messageOwner.via_bot_id != 0) {
uid = messageObject.messageOwner.via_bot_id;
}
TLRPC.User user = getMessagesController().getUser(uid);
boolean verified = user != null && user.verified;
if (button instanceof TLRPC.TL_keyboardButtonGame) {
TLRPC.TL_game game = messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame ? messageObject.messageOwner.media.game : null;
if (game == null) {
return;
}
parentFragment.showOpenGameAlert(game, messageObject, res.url, !verified && MessagesController.getNotificationsSettings(currentAccount).getBoolean("askgame_" + uid, true), uid);
} else {
AlertsCreator.showOpenUrlAlert(parentFragment, res.url, false, false);
}
}
}
} else if (error != null) {
if (parentFragment.getParentActivity() == null) {
return;
}
if ("PASSWORD_HASH_INVALID".equals(error.text)) {
if (srp == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
builder.setTitle(LocaleController.getString("BotOwnershipTransfer", R.string.BotOwnershipTransfer));
builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("BotOwnershipTransferReadyAlertText", R.string.BotOwnershipTransferReadyAlertText)));
builder.setPositiveButton(LocaleController.getString("BotOwnershipTransferChangeOwner", R.string.BotOwnershipTransferChangeOwner), (dialogInterface, i) -> {
TwoStepVerificationActivity fragment = new TwoStepVerificationActivity();
fragment.setDelegate(password -> sendCallback(cache, messageObject, button, password, fragment, parentFragment));
parentFragment.presentFragment(fragment);
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
parentFragment.showDialog(builder.create());
}
} else if ("PASSWORD_MISSING".equals(error.text) || error.text.startsWith("PASSWORD_TOO_FRESH_") || error.text.startsWith("SESSION_TOO_FRESH_")) {
if (passwordFragment != null) {
passwordFragment.needHideProgress();
}
AlertDialog.Builder builder = new AlertDialog.Builder(parentFragment.getParentActivity());
builder.setTitle(LocaleController.getString("EditAdminTransferAlertTitle", R.string.EditAdminTransferAlertTitle));
LinearLayout linearLayout = new LinearLayout(parentFragment.getParentActivity());
linearLayout.setPadding(AndroidUtilities.dp(24), AndroidUtilities.dp(2), AndroidUtilities.dp(24), 0);
linearLayout.setOrientation(LinearLayout.VERTICAL);
builder.setView(linearLayout);
TextView messageTextView = new TextView(parentFragment.getParentActivity());
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("BotOwnershipTransferAlertText", R.string.BotOwnershipTransferAlertText)));
linearLayout.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
LinearLayout linearLayout2 = new LinearLayout(parentFragment.getParentActivity());
linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 11, 0, 0));
ImageView dotImageView = new ImageView(parentFragment.getParentActivity());
dotImageView.setImageResource(R.drawable.list_circle);
dotImageView.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(11) : 0, AndroidUtilities.dp(9), LocaleController.isRTL ? 0 : AndroidUtilities.dp(11), 0);
dotImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogTextBlack), PorterDuff.Mode.MULTIPLY));
messageTextView = new TextView(parentFragment.getParentActivity());
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("EditAdminTransferAlertText1", R.string.EditAdminTransferAlertText1)));
if (LocaleController.isRTL) {
linearLayout2.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
linearLayout2.addView(dotImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT));
} else {
linearLayout2.addView(dotImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
linearLayout2.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
linearLayout2 = new LinearLayout(parentFragment.getParentActivity());
linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 11, 0, 0));
dotImageView = new ImageView(parentFragment.getParentActivity());
dotImageView.setImageResource(R.drawable.list_circle);
dotImageView.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(11) : 0, AndroidUtilities.dp(9), LocaleController.isRTL ? 0 : AndroidUtilities.dp(11), 0);
dotImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogTextBlack), PorterDuff.Mode.MULTIPLY));
messageTextView = new TextView(parentFragment.getParentActivity());
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("EditAdminTransferAlertText2", R.string.EditAdminTransferAlertText2)));
if (LocaleController.isRTL) {
linearLayout2.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
linearLayout2.addView(dotImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT));
} else {
linearLayout2.addView(dotImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
linearLayout2.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
if ("PASSWORD_MISSING".equals(error.text)) {
builder.setPositiveButton(LocaleController.getString("EditAdminTransferSetPassword", R.string.EditAdminTransferSetPassword), (dialogInterface, i) -> parentFragment.presentFragment(new TwoStepVerificationSetupActivity(TwoStepVerificationSetupActivity.TYPE_INTRO, null)));
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
} else {
messageTextView = new TextView(parentFragment.getParentActivity());
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
messageTextView.setText(LocaleController.getString("EditAdminTransferAlertText3", R.string.EditAdminTransferAlertText3));
linearLayout.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 11, 0, 0));
builder.setNegativeButton(LocaleController.getString("OK", R.string.OK), null);
}
parentFragment.showDialog(builder.create());
} else if ("SRP_ID_INVALID".equals(error.text)) {
TLRPC.TL_account_getPassword getPasswordReq = new TLRPC.TL_account_getPassword();
ConnectionsManager.getInstance(currentAccount).sendRequest(getPasswordReq, (response2, error2) -> AndroidUtilities.runOnUIThread(() -> {
if (error2 == null) {
TLRPC.TL_account_password currentPassword = (TLRPC.TL_account_password) response2;
passwordFragment.setCurrentPasswordInfo(null, currentPassword);
TwoStepVerificationActivity.initPasswordNewAlgo(currentPassword);
sendCallback(cache, messageObject, button, passwordFragment.getNewSrpPassword(), passwordFragment, parentFragment);
}
}), ConnectionsManager.RequestFlagWithoutLogin);
} else {
if (passwordFragment != null) {
passwordFragment.needHideProgress();
passwordFragment.finishFragment();
}
}
}
});
if (cacheFinal) {
getMessagesStorage().getBotCache(key, requestDelegate);
} else {
if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
TLRPC.TL_messages_requestUrlAuth req = new TLRPC.TL_messages_requestUrlAuth();
req.peer = getMessagesController().getInputPeer(messageObject.getDialogId());
req.msg_id = messageObject.getId();
req.button_id = button.button_id;
req.flags |= 2;
request[0] = req;
getConnectionsManager().sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors);
} else if (button instanceof TLRPC.TL_keyboardButtonBuy) {
if ((messageObject.messageOwner.media.flags & 4) == 0) {
TLRPC.TL_payments_getPaymentForm req = new TLRPC.TL_payments_getPaymentForm();
req.msg_id = messageObject.getId();
req.peer = getMessagesController().getInputPeer(messageObject.messageOwner.peer_id);
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put("bg_color", Theme.getColor(Theme.key_windowBackgroundWhite));
jsonObject.put("text_color", Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
jsonObject.put("hint_color", Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
jsonObject.put("link_color", Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
jsonObject.put("button_color", Theme.getColor(Theme.key_featuredStickers_addButton));
jsonObject.put("button_text_color", Theme.getColor(Theme.key_featuredStickers_buttonText));
req.theme_params = new TLRPC.TL_dataJSON();
req.theme_params.data = jsonObject.toString();
req.flags |= 1;
} catch (Exception e) {
FileLog.e(e);
}
getConnectionsManager().sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors);
} else {
TLRPC.TL_payments_getPaymentReceipt req = new TLRPC.TL_payments_getPaymentReceipt();
req.msg_id = messageObject.messageOwner.media.receipt_msg_id;
req.peer = getMessagesController().getInputPeer(messageObject.messageOwner.peer_id);
getConnectionsManager().sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors);
}
} else {
TLRPC.TL_messages_getBotCallbackAnswer req = new TLRPC.TL_messages_getBotCallbackAnswer();
req.peer = getMessagesController().getInputPeer(messageObject.getDialogId());
req.msg_id = messageObject.getId();
req.game = button instanceof TLRPC.TL_keyboardButtonGame;
if (button.requires_password) {
req.password = req.password = srp != null ? srp : new TLRPC.TL_inputCheckPasswordEmpty();
;
req.flags |= 4;
}
if (button.data != null) {
req.flags |= 1;
req.data = button.data;
}
getConnectionsManager().sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors);
}
}
}
Aggregations