Search in sources :

Example 1 with TwoStepVerificationSetupActivity

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);
        }
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) LinearLayout(android.widget.LinearLayout) SparseLongArray(org.telegram.messenger.support.SparseLongArray) Bundle(android.os.Bundle) Uri(android.net.Uri) ImageView(android.widget.ImageView) AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) LocationListener(android.location.LocationListener) Bulletin(org.telegram.ui.Components.Bulletin) ByteBuffer(java.nio.ByteBuffer) AudioInfo(org.telegram.messenger.audioinfo.AudioInfo) JSONObject(org.json.JSONObject) MediaCodecInfo(android.media.MediaCodecInfo) Locale(java.util.Locale) MediaStore(android.provider.MediaStore) UiThread(androidx.annotation.UiThread) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) SparseArray(android.util.SparseArray) CountDownLatch(java.util.concurrent.CountDownLatch) TextView(android.widget.TextView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Location(android.location.Location) LocationManager(android.location.LocationManager) ChatActivity(org.telegram.ui.ChatActivity) Context(android.content.Context) MediaMetadataRetriever(android.media.MediaMetadataRetriever) Theme(org.telegram.ui.ActionBar.Theme) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) RequestDelegate(org.telegram.tgnet.RequestDelegate) TwoStepVerificationActivity(org.telegram.ui.TwoStepVerificationActivity) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) MediaPlayer(android.media.MediaPlayer) SystemClock(android.os.SystemClock) HashMap(java.util.HashMap) AlertsCreator(org.telegram.ui.Components.AlertsCreator) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TLRPC(org.telegram.tgnet.TLRPC) Point(org.telegram.ui.Components.Point) Toast(android.widget.Toast) PaymentFormActivity(org.telegram.ui.PaymentFormActivity) TLObject(org.telegram.tgnet.TLObject) NativeByteBuffer(org.telegram.tgnet.NativeByteBuffer) Build(android.os.Build) SerializedData(org.telegram.tgnet.SerializedData) LongSparseArray(androidx.collection.LongSparseArray) TwoStepVerificationSetupActivity(org.telegram.ui.TwoStepVerificationSetupActivity) FileOutputStream(java.io.FileOutputStream) TextUtils(android.text.TextUtils) InputContentInfoCompat(androidx.core.view.inputmethod.InputContentInfoCompat) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileInputStream(java.io.FileInputStream) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Gravity(android.view.Gravity) TypedValue(android.util.TypedValue) Bitmap(android.graphics.Bitmap) Base64(android.util.Base64) ClipDescription(android.content.ClipDescription) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) FileChannel(java.nio.channels.FileChannel) MimeTypeMap(android.webkit.MimeTypeMap) InputStream(java.io.InputStream) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TLRPC(org.telegram.tgnet.TLRPC) PaymentFormActivity(org.telegram.ui.PaymentFormActivity) TextView(android.widget.TextView) ImageView(android.widget.ImageView) RequestDelegate(org.telegram.tgnet.RequestDelegate) TwoStepVerificationActivity(org.telegram.ui.TwoStepVerificationActivity) JSONObject(org.json.JSONObject) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) TwoStepVerificationSetupActivity(org.telegram.ui.TwoStepVerificationSetupActivity) Point(org.telegram.ui.Components.Point) TLObject(org.telegram.tgnet.TLObject) LinearLayout(android.widget.LinearLayout)

Aggregations

ClipDescription (android.content.ClipDescription)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 BitmapFactory (android.graphics.BitmapFactory)1 PorterDuff (android.graphics.PorterDuff)1 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Location (android.location.Location)1 LocationListener (android.location.LocationListener)1 LocationManager (android.location.LocationManager)1 MediaCodecInfo (android.media.MediaCodecInfo)1 MediaMetadataRetriever (android.media.MediaMetadataRetriever)1 MediaPlayer (android.media.MediaPlayer)1 Uri (android.net.Uri)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 SystemClock (android.os.SystemClock)1 MediaStore (android.provider.MediaStore)1 TextUtils (android.text.TextUtils)1