APK反编译源代码展示 - 南明离火平台提供

应用版本信息
应用名称:国中资本
版本号:1.0.0
包名称:com.byhhd.oxojy

MD5 校验值:1036132062d4d223cd1a714f5bbea98b

反编译源代码说明

SendMessagesHelper.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。


package im.skmzhmurqt.messenger;

import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.media.MediaCodecInfo;
import android.media.MediaMetadataRetriever;
import android.media.MediaPlayer;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Base64;
import android.util.LongSparseArray;
import android.util.SparseArray;
import android.webkit.MimeTypeMap;
import androidx.core.view.inputmethod.InputContentInfoCompat;
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.util.MimeTypes;
import im.skmzhmurqt.messenger.MediaController;
import im.skmzhmurqt.messenger.NotificationCenter;
import im.skmzhmurqt.messenger.SendMessagesHelper;
import im.skmzhmurqt.messenger.audioinfo.AudioInfo;
import im.skmzhmurqt.messenger.support.SparseLongArray;
import im.skmzhmurqt.tgnet.ConnectionsManager;
import im.skmzhmurqt.tgnet.NativeByteBuffer;
import im.skmzhmurqt.tgnet.QuickAckDelegate;
import im.skmzhmurqt.tgnet.RequestDelegate;
import im.skmzhmurqt.tgnet.SerializedData;
import im.skmzhmurqt.tgnet.TLObject;
import im.skmzhmurqt.tgnet.TLRPC;
import im.skmzhmurqt.tgnet.TLRPCContacts;
import im.skmzhmurqt.ui.ChatActivity;
import im.skmzhmurqt.ui.actionbar.AlertDialog;
import im.skmzhmurqt.ui.actionbar.BaseFragment;
import im.skmzhmurqt.ui.components.AlertsCreator;
import im.skmzhmurqt.ui.components.AnimatedFileDrawable;
import im.skmzhmurqt.ui.components.toast.ToastUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class SendMessagesHelper extends BaseController implements NotificationCenter.NotificationCenterDelegate {
    private static volatile SendMessagesHelper[] Instance;
    private static DispatchQueue mediaSendQueue = new DispatchQueue("mediaSendQueue");
    private static ThreadPoolExecutor mediaSendThreadPool;
    private HashMap<String, ArrayList<DelayedMessage>> delayedMessages;
    private SparseArray<TLRPC.Message> editingMessages;
    private LocationProvider locationProvider;
    private SparseArray<TLRPC.Message> sendingMessages;
    private LongSparseArray<Integer> sendingMessagesIdDialogs;
    private SparseArray<MessageObject> unsentMessages;
    private SparseArray<TLRPC.Message> uploadMessages;
    private LongSparseArray<Integer> uploadingMessagesIdDialogs;
    private LongSparseArray<Long> voteSendTime;
    private HashMap<String, Boolean> waitingForCallback;
    private HashMap<String, MessageObject> waitingForLocation;
    private HashMap<String, byte[]> waitingForVote;

    public static class SendingMediaInfo {
        public boolean canDeleteAfter;
        public String caption;
        public ArrayList<TLRPC.MessageEntity> entities;
        public TLRPC.BotInlineResult inlineResult;
        public boolean isVideo;
        public ArrayList<TLRPC.InputDocument> masks;
        public HashMap<String, String> params;
        public String path;
        public MediaController.SearchImage searchImage;
        public int ttl;
        public Uri uri;
        public VideoEditedInfo videoEditedInfo;
    }

    static {
        int cores;
        if (Build.VERSION.SDK_INT >= 17) {
            cores = Runtime.getRuntime().availableProcessors();
        } else {
            cores = 2;
        }
        mediaSendThreadPool = new ThreadPoolExecutor(cores, cores, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue());
        Instance = new SendMessagesHelper[3];
    }

    public static class MediaSendPrepareWorker {
        public volatile String parentObject;
        public volatile TLRPC.TL_photo photo;
        public CountDownLatch sync;

        private MediaSendPrepareWorker() {
        }
    }

    public static class LocationProvider {
        private LocationProviderDelegate delegate;
        private GpsLocationListener gpsLocationListener;
        private Location lastKnownLocation;
        private LocationManager locationManager;
        private Runnable locationQueryCancelRunnable;
        private GpsLocationListener networkLocationListener;

        public interface LocationProviderDelegate {
            void onLocationAcquired(Location location);

            void onUnableLocationAcquire();
        }

        public class GpsLocationListener implements LocationListener {
            private GpsLocationListener() {
            }

            @Override
            public void onLocationChanged(Location location) {
                if (location == null || LocationProvider.this.locationQueryCancelRunnable == null) {
                    return;
                }
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("found location " + location);
                }
                LocationProvider.this.lastKnownLocation = location;
                if (location.getAccuracy() < 100.0f) {
                    if (LocationProvider.this.delegate != null) {
                        LocationProvider.this.delegate.onLocationAcquired(location);
                    }
                    if (LocationProvider.this.locationQueryCancelRunnable != null) {
                        AndroidUtilities.cancelRunOnUIThread(LocationProvider.this.locationQueryCancelRunnable);
                    }
                    LocationProvider.this.cleanup();
                }
            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
            }

            @Override
            public void onProviderEnabled(String provider) {
            }

            @Override
            public void onProviderDisabled(String provider) {
            }
        }

        public LocationProvider() {
            this.gpsLocationListener = new GpsLocationListener();
            this.networkLocationListener = new GpsLocationListener();
        }

        public LocationProvider(LocationProviderDelegate locationProviderDelegate) {
            this.gpsLocationListener = new GpsLocationListener();
            this.networkLocationListener = new GpsLocationListener();
            this.delegate = locationProviderDelegate;
        }

        public void setDelegate(LocationProviderDelegate locationProviderDelegate) {
            this.delegate = locationProviderDelegate;
        }

        public void cleanup() {
            this.locationManager.removeUpdates(this.gpsLocationListener);
            this.locationManager.removeUpdates(this.networkLocationListener);
            this.lastKnownLocation = null;
            this.locationQueryCancelRunnable = null;
        }

        public void start() {
            if (this.locationManager == null) {
                this.locationManager = (LocationManager) ApplicationLoader.applicationContext.getSystemService("location");
            }
            try {
                this.locationManager.requestLocationUpdates("gps", 1L, 0.0f, this.gpsLocationListener);
            } catch (Exception e) {
                FileLog.e(e);
            }
            try {
                this.locationManager.requestLocationUpdates("network", 1L, 0.0f, this.networkLocationListener);
            } catch (Exception e2) {
                FileLog.e(e2);
            }
            try {
                Location lastKnownLocation = this.locationManager.getLastKnownLocation("gps");
                this.lastKnownLocation = lastKnownLocation;
                if (lastKnownLocation == null) {
                    this.lastKnownLocation = this.locationManager.getLastKnownLocation("network");
                }
            } catch (Exception e3) {
                FileLog.e(e3);
            }
            Runnable runnable = this.locationQueryCancelRunnable;
            if (runnable != null) {
                AndroidUtilities.cancelRunOnUIThread(runnable);
            }
            Runnable runnable2 = new Runnable() {
                @Override
                public void run() {
                    if (LocationProvider.this.locationQueryCancelRunnable == this) {
                        if (LocationProvider.this.delegate != null) {
                            if (LocationProvider.this.lastKnownLocation != null) {
                                LocationProvider.this.delegate.onLocationAcquired(LocationProvider.this.lastKnownLocation);
                            } else {
                                LocationProvider.this.delegate.onUnableLocationAcquire();
                            }
                        }
                        LocationProvider.this.cleanup();
                    }
                }
            };
            this.locationQueryCancelRunnable = runnable2;
            AndroidUtilities.runOnUIThread(runnable2, DefaultRenderersFactory.DEFAULT_ALLOWED_VIDEO_JOINING_TIME_MS);
        }

        public void stop() {
            if (this.locationManager == null) {
                return;
            }
            Runnable runnable = this.locationQueryCancelRunnable;
            if (runnable != null) {
                AndroidUtilities.cancelRunOnUIThread(runnable);
            }
            cleanup();
        }
    }

    public class DelayedMessageSendAfterRequest {
        public DelayedMessage delayedMessage;
        public MessageObject msgObj;
        public ArrayList<MessageObject> msgObjs;
        public String originalPath;
        public ArrayList<String> originalPaths;
        public Object parentObject;
        public ArrayList<Object> parentObjects;
        public TLObject request;
        public boolean scheduled;

        protected DelayedMessageSendAfterRequest() {
        }
    }

    public class DelayedMessage {
        public TLRPC.EncryptedChat encryptedChat;
        public HashMap<Object, Object> extraHashMap;
        public int finalGroupMessage;
        public long groupId;
        public String httpLocation;
        public ArrayList<String> httpLocations;
        public ArrayList<TLRPC.InputMedia> inputMedias;
        public TLRPC.InputMedia inputUploadMedia;
        public TLObject locationParent;
        public ArrayList<TLRPC.PhotoSize> locations;
        public ArrayList<MessageObject> messageObjects;
        public ArrayList<TLRPC.Message> messages;
        public MessageObject obj;
        public String originalPath;
        public ArrayList<String> originalPaths;
        public Object parentObject;
        public ArrayList<Object> parentObjects;
        public long peer;
        public boolean performMediaUpload;
        public TLRPC.PhotoSize photoSize;
        ArrayList<DelayedMessageSendAfterRequest> requests;
        public boolean scheduled;
        public TLObject sendEncryptedRequest;
        public TLObject sendRequest;
        public int type;
        public VideoEditedInfo videoEditedInfo;
        public ArrayList<VideoEditedInfo> videoEditedInfos;

        public DelayedMessage(long peer) {
            this.peer = peer;
        }

        public void initForGroup(long id) {
            this.type = 4;
            this.groupId = id;
            this.messageObjects = new ArrayList<>();
            this.messages = new ArrayList<>();
            this.inputMedias = new ArrayList<>();
            this.originalPaths = new ArrayList<>();
            this.parentObjects = new ArrayList<>();
            this.extraHashMap = new HashMap<>();
            this.locations = new ArrayList<>();
            this.httpLocations = new ArrayList<>();
            this.videoEditedInfos = new ArrayList<>();
        }

        public void addDelayedRequest(TLObject req, MessageObject msgObj, String originalPath, Object parentObject, DelayedMessage delayedMessage, boolean scheduled) {
            DelayedMessageSendAfterRequest request = new DelayedMessageSendAfterRequest();
            request.request = req;
            request.msgObj = msgObj;
            request.originalPath = originalPath;
            request.delayedMessage = delayedMessage;
            request.parentObject = parentObject;
            request.scheduled = scheduled;
            if (this.requests == null) {
                this.requests = new ArrayList<>();
            }
            this.requests.add(request);
        }

        public void addDelayedRequest(TLObject req, ArrayList<MessageObject> msgObjs, ArrayList<String> originalPaths, ArrayList<Object> parentObjects, DelayedMessage delayedMessage, boolean scheduled) {
            DelayedMessageSendAfterRequest request = new DelayedMessageSendAfterRequest();
            request.request = req;
            request.msgObjs = msgObjs;
            request.originalPaths = originalPaths;
            request.delayedMessage = delayedMessage;
            request.parentObjects = parentObjects;
            request.scheduled = scheduled;
            if (this.requests == null) {
                this.requests = new ArrayList<>();
            }
            this.requests.add(request);
        }

        public void sendDelayedRequests() {
            if (this.requests != null) {
                int i = this.type;
                if (i != 4 && i != 0) {
                    return;
                }
                int size = this.requests.size();
                for (int a = 0; a < size; a++) {
                    DelayedMessageSendAfterRequest request = this.requests.get(a);
                    if (request.request instanceof TLRPC.TL_messages_sendEncryptedMultiMedia) {
                        SendMessagesHelper.this.getSecretChatHelper().performSendEncryptedRequest((TLRPC.TL_messages_sendEncryptedMultiMedia) request.request, this);
                    } else if (!(request.request instanceof TLRPC.TL_messages_sendMultiMedia)) {
                        SendMessagesHelper.this.performSendMessageRequest(request.request, request.msgObj, request.originalPath, request.delayedMessage, request.parentObject, request.scheduled);
                    } else {
                        SendMessagesHelper.this.performSendMessageRequestMulti((TLRPC.TL_messages_sendMultiMedia) request.request, request.msgObjs, request.originalPaths, request.parentObjects, request.delayedMessage, request.scheduled);
                    }
                }
                this.requests = null;
            }
        }

        public void markAsError() {
            if (this.type == 4) {
                for (int a = 0; a < this.messageObjects.size(); a++) {
                    MessageObject obj = this.messageObjects.get(a);
                    SendMessagesHelper.this.getMessagesStorage().markMessageAsSendError(obj.messageOwner, obj.scheduled);
                    obj.messageOwner.send_state = 2;
                    SendMessagesHelper.this.getNotificationCenter().postNotificationName(NotificationCenter.messageSendError, Integer.valueOf(obj.getId()));
                    SendMessagesHelper.this.processSentMessage(obj.getId());
                    SendMessagesHelper.this.removeFromUploadingMessages(obj.getId(), this.scheduled);
                }
                SendMessagesHelper.this.delayedMessages.remove("group_" + this.groupId);
            } else {
                SendMessagesHelper.this.getMessagesStorage().markMessageAsSendError(this.obj.messageOwner, this.obj.scheduled);
                this.obj.messageOwner.send_state = 2;
                SendMessagesHelper.this.getNotificationCenter().postNotificationName(NotificationCenter.messageSendError, Integer.valueOf(this.obj.getId()));
                SendMessagesHelper.this.processSentMessage(this.obj.getId());
                SendMessagesHelper.this.removeFromUploadingMessages(this.obj.getId(), this.scheduled);
            }
            sendDelayedRequests();
        }
    }

    public static SendMessagesHelper getInstance(int num) {
        SendMessagesHelper localInstance = Instance[num];
        if (localInstance == null) {
            synchronized (SendMessagesHelper.class) {
                localInstance = Instance[num];
                if (localInstance == null) {
                    SendMessagesHelper[] sendMessagesHelperArr = Instance;
                    SendMessagesHelper sendMessagesHelper = new SendMessagesHelper(num);
                    localInstance = sendMessagesHelper;
                    sendMessagesHelperArr[num] = sendMessagesHelper;
                }
            }
        }
        return localInstance;
    }

    public SendMessagesHelper(int instance) {
        super(instance);
        this.delayedMessages = new HashMap<>();
        this.unsentMessages = new SparseArray<>();
        this.sendingMessages = new SparseArray<>();
        this.editingMessages = new SparseArray<>();
        this.uploadMessages = new SparseArray<>();
        this.sendingMessagesIdDialogs = new LongSparseArray<>();
        this.uploadingMessagesIdDialogs = new LongSparseArray<>();
        this.waitingForLocation = new HashMap<>();
        this.waitingForCallback = new HashMap<>();
        this.waitingForVote = new HashMap<>();
        this.voteSendTime = new LongSparseArray<>();
        this.locationProvider = new LocationProvider(new LocationProvider.LocationProviderDelegate() {
            @Override
            public void onLocationAcquired(Location location) {
                SendMessagesHelper.this.sendLocation(location);
                SendMessagesHelper.this.waitingForLocation.clear();
            }

            @Override
            public void onUnableLocationAcquire() {
                HashMap<String, MessageObject> waitingForLocationCopy = new HashMap<>(SendMessagesHelper.this.waitingForLocation);
                SendMessagesHelper.this.getNotificationCenter().postNotificationName(NotificationCenter.wasUnableToFindCurrentLocation, waitingForLocationCopy);
                SendMessagesHelper.this.waitingForLocation.clear();
            }
        });
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$new$0$SendMessagesHelper();
            }
        });
    }

    public void lambda$new$0$SendMessagesHelper() {
        getNotificationCenter().addObserver(this, NotificationCenter.FileDidUpload);
        getNotificationCenter().addObserver(this, NotificationCenter.FileDidFailUpload);
        getNotificationCenter().addObserver(this, NotificationCenter.filePreparingStarted);
        getNotificationCenter().addObserver(this, NotificationCenter.fileNewChunkAvailable);
        getNotificationCenter().addObserver(this, NotificationCenter.filePreparingFailed);
        getNotificationCenter().addObserver(this, NotificationCenter.httpFileDidFailedLoad);
        getNotificationCenter().addObserver(this, NotificationCenter.httpFileDidLoad);
        getNotificationCenter().addObserver(this, NotificationCenter.fileDidLoad);
        getNotificationCenter().addObserver(this, NotificationCenter.fileDidFailToLoad);
    }

    public void cleanup() {
        this.delayedMessages.clear();
        this.unsentMessages.clear();
        this.sendingMessages.clear();
        this.editingMessages.clear();
        this.sendingMessagesIdDialogs.clear();
        this.uploadMessages.clear();
        this.uploadingMessagesIdDialogs.clear();
        this.waitingForLocation.clear();
        this.waitingForCallback.clear();
        this.waitingForVote.clear();
        this.locationProvider.stop();
    }

    @Override
    public void didReceivedNotification(int id, int account, Object... args) {
        String path;
        ArrayList<DelayedMessage> arr;
        int fileType;
        final MessageObject messageObject;
        ArrayList<DelayedMessage> arr2;
        ArrayList<DelayedMessage> arr3;
        TLRPC.InputMedia media;
        ArrayList<DelayedMessage> arr4;
        String location;
        TLRPC.InputFile file;
        String str;
        TLRPC.InputEncryptedFile encryptedFile;
        int a;
        int a2;
        TLRPC.InputEncryptedFile encryptedFile2;
        String str2 = "_t";
        if (id == NotificationCenter.FileDidUpload) {
            String location2 = (String) args[0];
            TLRPC.InputFile file2 = (TLRPC.InputFile) args[1];
            TLRPC.InputEncryptedFile encryptedFile3 = (TLRPC.InputEncryptedFile) args[2];
            ArrayList<DelayedMessage> arr5 = this.delayedMessages.get(location2);
            if (arr5 != null) {
                int a3 = 0;
                while (true) {
                    int a4 = a3;
                    if (a4 >= arr5.size()) {
                        break;
                    }
                    DelayedMessage message = arr5.get(a4);
                    if (message.sendRequest instanceof TLRPC.TL_messages_sendMedia) {
                        TLRPC.InputMedia media2 = ((TLRPC.TL_messages_sendMedia) message.sendRequest).media;
                        media = media2;
                    } else if (message.sendRequest instanceof TLRPC.TL_messages_editMessage) {
                        TLRPC.InputMedia media3 = ((TLRPC.TL_messages_editMessage) message.sendRequest).media;
                        media = media3;
                    } else if (!(message.sendRequest instanceof TLRPC.TL_messages_sendMultiMedia)) {
                        media = null;
                    } else {
                        TLRPC.InputMedia media4 = (TLRPC.InputMedia) message.extraHashMap.get(location2);
                        media = media4;
                    }
                    if (file2 != null && media != null) {
                        if (message.type == 0) {
                            media.file = file2;
                            a2 = a4;
                            arr4 = arr5;
                            String location3 = location2;
                            encryptedFile2 = encryptedFile3;
                            performSendMessageRequest(message.sendRequest, message.obj, message.originalPath, message, true, null, message.parentObject, message.scheduled);
                            file = file2;
                            location = location3;
                        } else {
                            TLRPC.InputMedia media5 = media;
                            a2 = a4;
                            arr4 = arr5;
                            encryptedFile2 = encryptedFile3;
                            TLRPC.InputFile file3 = file2;
                            String location4 = location2;
                            if (message.type == 1) {
                                if (media5.file == null) {
                                    file = file3;
                                    media5.file = file;
                                    if (media5.thumb == null && message.photoSize != null && message.photoSize.location != null) {
                                        performSendDelayedMessage(message);
                                        location = location4;
                                    } else {
                                        performSendMessageRequest(message.sendRequest, message.obj, message.originalPath, null, message.parentObject, message.scheduled);
                                        location = location4;
                                    }
                                } else {
                                    file = file3;
                                    media5.thumb = file;
                                    media5.flags |= 4;
                                    performSendMessageRequest(message.sendRequest, message.obj, message.originalPath, null, message.parentObject, message.scheduled);
                                    location = location4;
                                }
                            } else {
                                file = file3;
                                if (message.type == 2) {
                                    if (media5.file == null) {
                                        media5.file = file;
                                        if (media5.thumb == null && message.photoSize != null && message.photoSize.location != null) {
                                            performSendDelayedMessage(message);
                                            location = location4;
                                        } else {
                                            performSendMessageRequest(message.sendRequest, message.obj, message.originalPath, null, message.parentObject, message.scheduled);
                                            location = location4;
                                        }
                                    } else {
                                        media5.thumb = file;
                                        media5.flags |= 4;
                                        performSendMessageRequest(message.sendRequest, message.obj, message.originalPath, null, message.parentObject, message.scheduled);
                                        location = location4;
                                    }
                                } else if (message.type == 3) {
                                    media5.file = file;
                                    performSendMessageRequest(message.sendRequest, message.obj, message.originalPath, null, message.parentObject, message.scheduled);
                                    location = location4;
                                } else if (message.type != 4) {
                                    location = location4;
                                } else if (media5 instanceof TLRPC.TL_inputMediaUploadedDocument) {
                                    if (media5.file == null) {
                                        media5.file = file;
                                        HashMap<Object, Object> hashMap = message.extraHashMap;
                                        StringBuilder sb = new StringBuilder();
                                        location = location4;
                                        sb.append(location);
                                        sb.append("_i");
                                        MessageObject messageObject2 = (MessageObject) hashMap.get(sb.toString());
                                        int index = message.messageObjects.indexOf(messageObject2);
                                        message.photoSize = (TLRPC.PhotoSize) message.extraHashMap.get(location + str2);
                                        stopVideoService(message.messageObjects.get(index).messageOwner.attachPath);
                                        if (media5.thumb != null || message.photoSize == null) {
                                            uploadMultiMedia(message, media5, null, location);
                                        } else {
                                            message.performMediaUpload = true;
                                            performSendDelayedMessage(message, index);
                                        }
                                    } else {
                                        location = location4;
                                        media5.thumb = file;
                                        media5.flags |= 4;
                                        uploadMultiMedia(message, media5, null, (String) message.extraHashMap.get(location + "_o"));
                                    }
                                } else {
                                    location = location4;
                                    media5.file = file;
                                    uploadMultiMedia(message, media5, null, location);
                                }
                            }
                        }
                        int a5 = a2;
                        arr4.remove(a5);
                        a = a5 - 1;
                        str = str2;
                        encryptedFile = encryptedFile2;
                    } else {
                        arr4 = arr5;
                        TLRPC.InputEncryptedFile encryptedFile4 = encryptedFile3;
                        location = location2;
                        file = file2;
                        if (encryptedFile4 == null || message.sendEncryptedRequest == null) {
                            str = str2;
                            encryptedFile = encryptedFile4;
                            a = a4;
                        } else {
                            TLRPC.TL_decryptedMessage decryptedMessage = null;
                            if (message.type == 4) {
                                TLRPC.TL_messages_sendEncryptedMultiMedia req = (TLRPC.TL_messages_sendEncryptedMultiMedia) message.sendEncryptedRequest;
                                TLRPC.InputEncryptedFile inputEncryptedFile = (TLRPC.InputEncryptedFile) message.extraHashMap.get(location);
                                int index2 = req.files.indexOf(inputEncryptedFile);
                                if (index2 < 0) {
                                    str = str2;
                                    encryptedFile = encryptedFile4;
                                } else {
                                    encryptedFile = encryptedFile4;
                                    req.files.set(index2, encryptedFile);
                                    str = str2;
                                    if (inputEncryptedFile.id == 1) {
                                        message.photoSize = (TLRPC.PhotoSize) message.extraHashMap.get(location + str);
                                        stopVideoService(message.messageObjects.get(index2).messageOwner.attachPath);
                                    }
                                    TLRPC.TL_decryptedMessage decryptedMessage2 = req.messages.get(index2);
                                    decryptedMessage = decryptedMessage2;
                                }
                            } else {
                                str = str2;
                                encryptedFile = encryptedFile4;
                                decryptedMessage = (TLRPC.TL_decryptedMessage) message.sendEncryptedRequest;
                            }
                            if (decryptedMessage != null) {
                                if ((decryptedMessage.media instanceof TLRPC.TL_decryptedMessageMediaVideo) || (decryptedMessage.media instanceof TLRPC.TL_decryptedMessageMediaPhoto) || (decryptedMessage.media instanceof TLRPC.TL_decryptedMessageMediaDocument)) {
                                    long size = ((Long) args[5]).longValue();
                                    decryptedMessage.media.size = (int) size;
                                }
                                decryptedMessage.media.key = (byte[]) args[3];
                                decryptedMessage.media.iv = (byte[]) args[4];
                                if (message.type == 4) {
                                    uploadMultiMedia(message, null, encryptedFile, location);
                                } else {
                                    getSecretChatHelper().performSendEncryptedRequest(decryptedMessage, message.obj.messageOwner, message.encryptedChat, encryptedFile, message.originalPath, message.obj);
                                }
                            }
                            arr4.remove(a4);
                            a = a4 - 1;
                        }
                    }
                    a3 = a + 1;
                    file2 = file;
                    str2 = str;
                    encryptedFile3 = encryptedFile;
                    arr5 = arr4;
                    location2 = location;
                }
                String location5 = location2;
                if (arr5.isEmpty()) {
                    this.delayedMessages.remove(location5);
                }
            }
            return;
        }
        if (id == NotificationCenter.FileDidFailUpload) {
            String location6 = (String) args[0];
            boolean enc = ((Boolean) args[1]).booleanValue();
            ArrayList<DelayedMessage> arr6 = this.delayedMessages.get(location6);
            if (arr6 != null) {
                int a6 = 0;
                while (a6 < arr6.size()) {
                    DelayedMessage obj = arr6.get(a6);
                    if ((enc && obj.sendEncryptedRequest != null) || (!enc && obj.sendRequest != null)) {
                        obj.markAsError();
                        arr6.remove(a6);
                        a6--;
                    }
                    a6++;
                }
                if (arr6.isEmpty()) {
                    this.delayedMessages.remove(location6);
                    return;
                }
                return;
            }
            return;
        }
        if (id == NotificationCenter.filePreparingStarted) {
            MessageObject messageObject3 = (MessageObject) args[0];
            if (messageObject3.getId() == 0) {
                return;
            }
            ArrayList<DelayedMessage> arr7 = this.delayedMessages.get(messageObject3.messageOwner.attachPath);
            if (arr7 != null) {
                int a7 = 0;
                while (true) {
                    if (a7 >= arr7.size()) {
                        break;
                    }
                    DelayedMessage message2 = arr7.get(a7);
                    if (message2.type == 4) {
                        int index3 = message2.messageObjects.indexOf(messageObject3);
                        message2.photoSize = (TLRPC.PhotoSize) message2.extraHashMap.get(messageObject3.messageOwner.attachPath + "_t");
                        message2.performMediaUpload = true;
                        performSendDelayedMessage(message2, index3);
                        arr7.remove(a7);
                        break;
                    }
                    if (message2.obj != messageObject3) {
                        a7++;
                    } else {
                        message2.videoEditedInfo = null;
                        performSendDelayedMessage(message2);
                        arr7.remove(a7);
                        break;
                    }
                }
                if (arr7.isEmpty()) {
                    this.delayedMessages.remove(messageObject3.messageOwner.attachPath);
                    return;
                }
                return;
            }
            return;
        }
        if (id == NotificationCenter.fileNewChunkAvailable) {
            MessageObject messageObject4 = (MessageObject) args[0];
            if (messageObject4.getId() == 0) {
                return;
            }
            String finalPath = (String) args[1];
            long availableSize = ((Long) args[2]).longValue();
            long finalSize = ((Long) args[3]).longValue();
            boolean isEncrypted = ((int) messageObject4.getDialogId()) == 0;
            getFileLoader().checkUploadNewDataAvailable(finalPath, isEncrypted, availableSize, finalSize);
            if (finalSize != 0) {
                stopVideoService(messageObject4.messageOwner.attachPath);
                ArrayList<DelayedMessage> arr8 = this.delayedMessages.get(messageObject4.messageOwner.attachPath);
                if (arr8 != null) {
                    int a8 = 0;
                    while (a8 < arr8.size()) {
                        DelayedMessage message3 = arr8.get(a8);
                        if (message3.type == 4) {
                            int b = 0;
                            while (true) {
                                if (b >= message3.messageObjects.size()) {
                                    arr3 = arr8;
                                    break;
                                }
                                MessageObject obj2 = message3.messageObjects.get(b);
                                if (obj2 != messageObject4) {
                                    b++;
                                } else {
                                    obj2.videoEditedInfo = null;
                                    obj2.messageOwner.params.remove("ve");
                                    obj2.messageOwner.media.document.size = (int) finalSize;
                                    ArrayList<TLRPC.Message> messages = new ArrayList<>();
                                    messages.add(obj2.messageOwner);
                                    arr3 = arr8;
                                    getMessagesStorage().putMessages(messages, false, true, false, 0, obj2.scheduled);
                                    break;
                                }
                            }
                        } else {
                            arr3 = arr8;
                            if (message3.obj == messageObject4) {
                                message3.obj.videoEditedInfo = null;
                                message3.obj.messageOwner.params.remove("ve");
                                message3.obj.messageOwner.media.document.size = (int) finalSize;
                                ArrayList<TLRPC.Message> messages2 = new ArrayList<>();
                                messages2.add(message3.obj.messageOwner);
                                getMessagesStorage().putMessages(messages2, false, true, false, 0, message3.obj.scheduled);
                                return;
                            }
                        }
                        a8++;
                        arr8 = arr3;
                    }
                    return;
                }
                return;
            }
            return;
        }
        if (id == NotificationCenter.filePreparingFailed) {
            MessageObject messageObject5 = (MessageObject) args[0];
            if (messageObject5.getId() == 0) {
                return;
            }
            String finalPath2 = (String) args[1];
            stopVideoService(messageObject5.messageOwner.attachPath);
            ArrayList<DelayedMessage> arr9 = this.delayedMessages.get(finalPath2);
            if (arr9 != null) {
                int a9 = 0;
                while (a9 < arr9.size()) {
                    DelayedMessage message4 = arr9.get(a9);
                    if (message4.type == 4) {
                        int b2 = 0;
                        while (true) {
                            if (b2 >= message4.messages.size()) {
                                break;
                            }
                            if (message4.messageObjects.get(b2) != messageObject5) {
                                b2++;
                            } else {
                                message4.markAsError();
                                arr9.remove(a9);
                                a9--;
                                break;
                            }
                        }
                    } else if (message4.obj == messageObject5) {
                        message4.markAsError();
                        arr9.remove(a9);
                        a9--;
                    }
                    a9++;
                }
                if (arr9.isEmpty()) {
                    this.delayedMessages.remove(finalPath2);
                    return;
                }
                return;
            }
            return;
        }
        if (id != NotificationCenter.httpFileDidLoad) {
            if (id == NotificationCenter.fileDidLoad) {
                String path2 = (String) args[0];
                ArrayList<DelayedMessage> arr10 = this.delayedMessages.get(path2);
                if (arr10 != null) {
                    for (int a10 = 0; a10 < arr10.size(); a10++) {
                        performSendDelayedMessage(arr10.get(a10));
                    }
                    this.delayedMessages.remove(path2);
                    return;
                }
                return;
            }
            if ((id == NotificationCenter.httpFileDidFailedLoad || id == NotificationCenter.fileDidFailToLoad) && (arr = this.delayedMessages.get((path = (String) args[0]))) != null) {
                for (int a11 = 0; a11 < arr.size(); a11++) {
                    arr.get(a11).markAsError();
                }
                this.delayedMessages.remove(path);
                return;
            }
            return;
        }
        final String path3 = (String) args[0];
        ArrayList<DelayedMessage> arr11 = this.delayedMessages.get(path3);
        if (arr11 != null) {
            int a12 = 0;
            while (a12 < arr11.size()) {
                final DelayedMessage message5 = arr11.get(a12);
                if (message5.type == 0) {
                    fileType = 0;
                    messageObject = message5.obj;
                } else if (message5.type == 2) {
                    fileType = 1;
                    messageObject = message5.obj;
                } else if (message5.type != 4) {
                    fileType = -1;
                    messageObject = null;
                } else {
                    MessageObject messageObject6 = (MessageObject) message5.extraHashMap.get(path3);
                    if (messageObject6.getDocument() != null) {
                        fileType = 1;
                        messageObject = messageObject6;
                    } else {
                        fileType = 0;
                        messageObject = messageObject6;
                    }
                }
                if (fileType == 0) {
                    String md5 = Utilities.MD5(path3) + "." + ImageLoader.getHttpUrlExtension(path3, "file");
                    final File cacheFile = new File(FileLoader.getDirectory(4), md5);
                    final MessageObject messageObject7 = messageObject;
                    arr2 = arr11;
                    Utilities.globalQueue.postRunnable(new Runnable() {
                        @Override
                        public final void run() {
                            SendMessagesHelper.this.lambda$didReceivedNotification$2$SendMessagesHelper(cacheFile, messageObject7, message5, path3);
                        }
                    });
                } else {
                    arr2 = arr11;
                    if (fileType == 1) {
                        String md52 = Utilities.MD5(path3) + ".gif";
                        final File cacheFile2 = new File(FileLoader.getDirectory(4), md52);
                        Utilities.globalQueue.postRunnable(new Runnable() {
                            @Override
                            public final void run() {
                                SendMessagesHelper.this.lambda$didReceivedNotification$4$SendMessagesHelper(message5, cacheFile2, messageObject);
                            }
                        });
                    }
                }
                a12++;
                arr11 = arr2;
            }
            this.delayedMessages.remove(path3);
        }
    }

    public void lambda$didReceivedNotification$2$SendMessagesHelper(final File cacheFile, final MessageObject messageObject, final DelayedMessage message, final String path) {
        final TLRPC.TL_photo photo = generatePhotoSizes(cacheFile.toString(), null, false);
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$null$1$SendMessagesHelper(photo, messageObject, cacheFile, message, path);
            }
        });
    }

    public void lambda$null$1$SendMessagesHelper(TLRPC.TL_photo photo, MessageObject messageObject, File cacheFile, DelayedMessage message, String path) {
        if (photo != null) {
            messageObject.messageOwner.media.photo = photo;
            messageObject.messageOwner.attachPath = cacheFile.toString();
            ArrayList<TLRPC.Message> messages = new ArrayList<>();
            messages.add(messageObject.messageOwner);
            getMessagesStorage().putMessages(messages, false, true, false, 0, messageObject.scheduled);
            getNotificationCenter().postNotificationName(NotificationCenter.updateMessageMedia, messageObject.messageOwner);
            message.photoSize = photo.sizes.get(photo.sizes.size() - 1);
            message.locationParent = photo;
            message.httpLocation = null;
            if (message.type == 4) {
                message.performMediaUpload = true;
                performSendDelayedMessage(message, message.messageObjects.indexOf(messageObject));
                return;
            } else {
                performSendDelayedMessage(message);
                return;
            }
        }
        if (BuildVars.LOGS_ENABLED) {
            FileLog.e("can't load image " + path + " to file " + cacheFile.toString());
        }
        message.markAsError();
    }

    public void lambda$didReceivedNotification$4$SendMessagesHelper(final DelayedMessage message, final File cacheFile, final MessageObject messageObject) {
        final TLRPC.Document document = message.obj.getDocument();
        if (document.thumbs.isEmpty() || (document.thumbs.get(0).location instanceof TLRPC.TL_fileLocationUnavailable)) {
            try {
                Bitmap bitmap = ImageLoader.loadBitmap(cacheFile.getAbsolutePath(), null, 90.0f, 90.0f, true);
                if (bitmap != null) {
                    document.thumbs.clear();
                    document.thumbs.add(ImageLoader.scaleAndSaveImage(bitmap, 90.0f, 90.0f, 55, message.sendEncryptedRequest != null));
                    bitmap.recycle();
                }
            } catch (Exception e) {
                document.thumbs.clear();
                FileLog.e(e);
            }
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$null$3$SendMessagesHelper(message, cacheFile, document, messageObject);
            }
        });
    }

    public void lambda$null$3$SendMessagesHelper(DelayedMessage message, File cacheFile, TLRPC.Document document, MessageObject messageObject) {
        message.httpLocation = null;
        message.obj.messageOwner.attachPath = cacheFile.toString();
        if (!document.thumbs.isEmpty()) {
            message.photoSize = document.thumbs.get(0);
            message.locationParent = document;
        }
        ArrayList<TLRPC.Message> messages = new ArrayList<>();
        messages.add(messageObject.messageOwner);
        getMessagesStorage().putMessages(messages, false, true, false, 0, messageObject.scheduled);
        message.performMediaUpload = true;
        performSendDelayedMessage(message);
        getNotificationCenter().postNotificationName(NotificationCenter.updateMessageMedia, message.obj.messageOwner);
    }

    private void revertEditingMessageObject(MessageObject object) {
        object.cancelEditing = true;
        object.messageOwner.media = object.previousMedia;
        object.messageOwner.message = object.previousCaption;
        object.messageOwner.entities = object.previousCaptionEntities;
        object.messageOwner.attachPath = object.previousAttachPath;
        object.messageOwner.send_state = 0;
        object.previousMedia = null;
        object.previousCaption = null;
        object.previousCaptionEntities = null;
        object.previousAttachPath = null;
        object.videoEditedInfo = null;
        object.type = -1;
        object.setType();
        object.caption = null;
        object.generateCaption();
        ArrayList<TLRPC.Message> arr = new ArrayList<>();
        arr.add(object.messageOwner);
        getMessagesStorage().putMessages(arr, false, true, false, 0, object.scheduled);
        ArrayList<MessageObject> arrayList = new ArrayList<>();
        arrayList.add(object);
        getNotificationCenter().postNotificationName(NotificationCenter.replaceMessagesObjects, Long.valueOf(object.getDialogId()), arrayList);
    }

    public void cancelSendingMessage(MessageObject object) {
        ArrayList<MessageObject> arrayList = new ArrayList<>();
        arrayList.add(object);
        cancelSendingMessage(arrayList);
    }

    public void cancelSendingMessage(ArrayList<MessageObject> objects) {
        boolean scheduled;
        long scheduledDialogId;
        TLRPC.Message sendingMessage;
        Iterator<Map.Entry<String, ArrayList<DelayedMessage>>> it;
        boolean enc;
        int channelId;
        int b;
        MessageObject messageObject;
        ArrayList<String> keysToRemove = new ArrayList<>();
        ArrayList<DelayedMessage> checkReadyToSendGroups = new ArrayList<>();
        ArrayList<Integer> messageIds = new ArrayList<>();
        int c = 0;
        boolean enc2 = false;
        int channelId2 = 0;
        boolean scheduled2 = false;
        long scheduledDialogId2 = 0;
        while (c < objects.size()) {
            MessageObject object = objects.get(c);
            if (!object.scheduled) {
                scheduled = scheduled2;
                scheduledDialogId = scheduledDialogId2;
            } else {
                scheduled = true;
                scheduledDialogId = object.getDialogId();
            }
            messageIds.add(Integer.valueOf(object.getId()));
            channelId2 = object.messageOwner.to_id.channel_id;
            TLRPC.Message sendingMessage2 = removeFromSendingMessages(object.getId(), object.scheduled);
            if (sendingMessage2 != null) {
                getConnectionsManager().cancelRequest(sendingMessage2.reqId, true);
            }
            Iterator<Map.Entry<String, ArrayList<DelayedMessage>>> it2 = this.delayedMessages.entrySet().iterator();
            while (it2.hasNext()) {
                Map.Entry<String, ArrayList<DelayedMessage>> entry = it2.next();
                ArrayList<DelayedMessage> messages = entry.getValue();
                long scheduledDialogId3 = scheduledDialogId;
                int a = 0;
                while (true) {
                    if (a >= messages.size()) {
                        sendingMessage = sendingMessage2;
                        it = it2;
                        enc = enc2;
                        channelId = channelId2;
                        break;
                    }
                    DelayedMessage message = messages.get(a);
                    sendingMessage = sendingMessage2;
                    it = it2;
                    if (message.type == 4) {
                        MessageObject messageObject2 = null;
                        int index = 0;
                        while (true) {
                            MessageObject messageObject3 = messageObject2;
                            if (index >= message.messageObjects.size()) {
                                enc = enc2;
                                b = -1;
                                messageObject = messageObject3;
                                break;
                            }
                            MessageObject messageObject4 = message.messageObjects.get(index);
                            enc = enc2;
                            if (messageObject4.getId() == object.getId()) {
                                removeFromUploadingMessages(object.getId(), object.scheduled);
                                b = index;
                                messageObject = messageObject4;
                                break;
                            } else {
                                index++;
                                messageObject2 = messageObject4;
                                enc2 = enc;
                            }
                        }
                        if (b >= 0) {
                            message.messageObjects.remove(b);
                            message.messages.remove(b);
                            message.originalPaths.remove(b);
                            if (message.sendRequest != null) {
                                channelId = channelId2;
                                ((TLRPC.TL_messages_sendMultiMedia) message.sendRequest).multi_media.remove(b);
                            } else {
                                channelId = channelId2;
                                TLRPC.TL_messages_sendEncryptedMultiMedia request = (TLRPC.TL_messages_sendEncryptedMultiMedia) message.sendEncryptedRequest;
                                request.messages.remove(b);
                                request.files.remove(b);
                            }
                            MediaController.getInstance().cancelVideoConvert(object);
                            String keyToRemove = (String) message.extraHashMap.get(messageObject);
                            if (keyToRemove != null) {
                                keysToRemove.add(keyToRemove);
                            }
                            if (message.messageObjects.isEmpty()) {
                                message.sendDelayedRequests();
                            } else {
                                int i = message.finalGroupMessage;
                                int index2 = object.getId();
                                if (i == index2) {
                                    MessageObject prevMessage = message.messageObjects.get(message.messageObjects.size() - 1);
                                    message.finalGroupMessage = prevMessage.getId();
                                    prevMessage.messageOwner.params.put("final", "1");
                                    TLRPC.TL_messages_messages messagesRes = new TLRPC.TL_messages_messages();
                                    messagesRes.messages.add(prevMessage.messageOwner);
                                    getMessagesStorage().putMessages((TLRPC.messages_Messages) messagesRes, message.peer, -2, 0, false, scheduled);
                                }
                                if (!checkReadyToSendGroups.contains(message)) {
                                    checkReadyToSendGroups.add(message);
                                }
                            }
                        } else {
                            channelId = channelId2;
                        }
                    } else {
                        enc = enc2;
                        channelId = channelId2;
                        if (message.obj.getId() == object.getId()) {
                            removeFromUploadingMessages(object.getId(), object.scheduled);
                            messages.remove(a);
                            message.sendDelayedRequests();
                            MediaController.getInstance().cancelVideoConvert(message.obj);
                            if (messages.size() == 0) {
                                keysToRemove.add(entry.getKey());
                                if (message.sendEncryptedRequest != null) {
                                    enc2 = true;
                                }
                            }
                        } else {
                            a++;
                            sendingMessage2 = sendingMessage;
                            it2 = it;
                            enc2 = enc;
                            channelId2 = channelId;
                        }
                    }
                }
                enc2 = enc;
                scheduledDialogId = scheduledDialogId3;
                sendingMessage2 = sendingMessage;
                it2 = it;
                channelId2 = channelId;
            }
            c++;
            scheduled2 = scheduled;
            scheduledDialogId2 = scheduledDialogId;
        }
        for (int a2 = 0; a2 < keysToRemove.size(); a2++) {
            String key = keysToRemove.get(a2);
            if (key.startsWith("http")) {
                ImageLoader.getInstance().cancelLoadHttpFile(key);
            } else {
                getFileLoader().cancelUploadFile(key, enc2);
            }
            stopVideoService(key);
            this.delayedMessages.remove(key);
        }
        int N = checkReadyToSendGroups.size();
        for (int a3 = 0; a3 < N; a3++) {
            sendReadyToSendGroup(checkReadyToSendGroups.get(a3), false, true);
        }
        int a4 = objects.size();
        if (a4 == 1 && objects.get(0).isEditing() && objects.get(0).previousMedia != null) {
            revertEditingMessageObject(objects.get(0));
        } else {
            getMessagesController().deleteMessages(messageIds, null, null, scheduledDialogId2, channelId2, false, scheduled2);
        }
    }

    public boolean retrySendMessage(MessageObject messageObject, boolean unsent) {
        if (messageObject.getId() >= 0) {
            if (messageObject.isEditing()) {
                editMessageMedia(messageObject, null, null, null, null, null, true, messageObject);
            }
            return false;
        }
        if (messageObject.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction) {
            int enc_id = (int) (messageObject.getDialogId() >> 32);
            TLRPC.EncryptedChat encryptedChat = getMessagesController().getEncryptedChat(Integer.valueOf(enc_id));
            if (encryptedChat == null) {
                getMessagesStorage().markMessageAsSendError(messageObject.messageOwner, messageObject.scheduled);
                messageObject.messageOwner.send_state = 2;
                getNotificationCenter().postNotificationName(NotificationCenter.messageSendError, Integer.valueOf(messageObject.getId()));
                processSentMessage(messageObject.getId());
                return false;
            }
            if (messageObject.messageOwner.random_id == 0) {
                messageObject.messageOwner.random_id = getNextRandomId();
            }
            if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
                getSecretChatHelper().sendTTLMessage(encryptedChat, messageObject.messageOwner);
            } else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionDeleteMessages) {
                getSecretChatHelper().sendMessagesDeleteMessage(encryptedChat, null, messageObject.messageOwner);
            } else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionFlushHistory) {
                getSecretChatHelper().sendClearHistoryMessage(encryptedChat, messageObject.messageOwner);
            } else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionNotifyLayer) {
                getSecretChatHelper().sendNotifyLayerMessage(encryptedChat, messageObject.messageOwner);
            } else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionReadMessages) {
                getSecretChatHelper().sendMessagesReadMessage(encryptedChat, null, messageObject.messageOwner);
            } else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages) {
                getSecretChatHelper().sendScreenshotMessage(encryptedChat, null, messageObject.messageOwner);
            } else if (!(messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionTyping) && !(messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionResend)) {
                if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionCommitKey) {
                    getSecretChatHelper().sendCommitKeyMessage(encryptedChat, messageObject.messageOwner);
                } else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionAbortKey) {
                    getSecretChatHelper().sendAbortKeyMessage(encryptedChat, messageObject.messageOwner, 0L);
                } else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionRequestKey) {
                    getSecretChatHelper().sendRequestKeyMessage(encryptedChat, messageObject.messageOwner);
                } else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionAcceptKey) {
                    getSecretChatHelper().sendAcceptKeyMessage(encryptedChat, messageObject.messageOwner);
                } else if (messageObject.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionNoop) {
                    getSecretChatHelper().sendNoopMessage(encryptedChat, messageObject.messageOwner);
                }
            }
            return true;
        }
        if (messageObject.messageOwner.action instanceof TLRPC.TL_messageActionScreenshotTaken) {
            TLRPC.User user = getMessagesController().getUser(Integer.valueOf((int) messageObject.getDialogId()));
            sendScreenshotMessage(user, messageObject.messageOwner.reply_to_msg_id, messageObject.messageOwner);
        }
        if (unsent) {
            this.unsentMessages.put(messageObject.getId(), messageObject);
        }
        sendMessage(messageObject);
        return true;
    }

    public void processSentMessage(int id) {
        int prevSize = this.unsentMessages.size();
        this.unsentMessages.remove(id);
        if (prevSize != 0 && this.unsentMessages.size() == 0) {
            checkUnsentMessages();
        }
    }

    public void processForwardFromMyName(MessageObject messageObject, long did) {
        TLRPC.WebPage webPage;
        ArrayList<TLRPC.MessageEntity> entities;
        HashMap<String, String> params;
        if (messageObject == null) {
            return;
        }
        if (messageObject.messageOwner.media != null && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame) && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice)) {
            if (((int) did) == 0 && messageObject.messageOwner.to_id != null && ((messageObject.messageOwner.media.photo instanceof TLRPC.TL_photo) || (messageObject.messageOwner.media.document instanceof TLRPC.TL_document))) {
                HashMap<String, String> params2 = new HashMap<>();
                params2.put("parentObject", "sent_" + messageObject.messageOwner.to_id.channel_id + "_" + messageObject.getId());
                params = params2;
            } else {
                params = null;
            }
            if (messageObject.messageOwner.media.photo instanceof TLRPC.TL_photo) {
                sendMessage((TLRPC.TL_photo) messageObject.messageOwner.media.photo, null, did, messageObject.replyMessageObject, messageObject.messageOwner.message, messageObject.messageOwner.entities, null, params, true, 0, messageObject.messageOwner.media.ttl_seconds, messageObject);
                return;
            }
            if (messageObject.messageOwner.media.document instanceof TLRPC.TL_document) {
                sendMessage((TLRPC.TL_document) messageObject.messageOwner.media.document, null, messageObject.messageOwner.attachPath, did, messageObject.replyMessageObject, messageObject.messageOwner.message, messageObject.messageOwner.entities, null, params, true, 0, messageObject.messageOwner.media.ttl_seconds, messageObject);
                return;
            }
            if (!(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) && !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo)) {
                if (messageObject.messageOwner.media.phone_number == null) {
                    if (((int) did) != 0) {
                        ArrayList<MessageObject> arrayList = new ArrayList<>();
                        arrayList.add(messageObject);
                        sendMessage(arrayList, did, true, 0);
                        return;
                    }
                    return;
                }
                TLRPC.User user = new TLRPC.TL_userContact_old2();
                user.phone = messageObject.messageOwner.media.phone_number;
                user.first_name = messageObject.messageOwner.media.first_name;
                user.last_name = messageObject.messageOwner.media.last_name;
                user.id = messageObject.messageOwner.media.user_id;
                sendMessage(user, did, messageObject.replyMessageObject, (TLRPC.ReplyMarkup) null, (HashMap<String, String>) null, true, 0);
                return;
            }
            sendMessage(messageObject.messageOwner.media, did, messageObject.replyMessageObject, (TLRPC.ReplyMarkup) null, (HashMap<String, String>) null, true, 0);
            return;
        }
        if (messageObject.messageOwner.message != null) {
            if (!(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage)) {
                webPage = null;
            } else {
                TLRPC.WebPage webPage2 = messageObject.messageOwner.media.webpage;
                webPage = webPage2;
            }
            if (messageObject.messageOwner.entities != null && !messageObject.messageOwner.entities.isEmpty()) {
                ArrayList<TLRPC.MessageEntity> entities2 = new ArrayList<>();
                for (int a = 0; a < messageObject.messageOwner.entities.size(); a++) {
                    TLRPC.MessageEntity entity = messageObject.messageOwner.entities.get(a);
                    if ((entity instanceof TLRPC.TL_messageEntityBold) || (entity instanceof TLRPC.TL_messageEntityItalic) || (entity instanceof TLRPC.TL_messageEntityPre) || (entity instanceof TLRPC.TL_messageEntityCode) || (entity instanceof TLRPC.TL_messageEntityTextUrl)) {
                        entities2.add(entity);
                    }
                }
                entities = entities2;
            } else {
                entities = null;
            }
            sendMessage(messageObject.messageOwner.message, did, messageObject.replyMessageObject, webPage, true, entities, null, null, true, 0);
            return;
        }
        if (((int) did) != 0) {
            ArrayList<MessageObject> arrayList2 = new ArrayList<>();
            arrayList2.add(messageObject);
            sendMessage(arrayList2, did, true, 0);
        }
    }

    public void sendScreenshotMessage(TLRPC.User user, int messageId, TLRPC.Message resendMessage) {
        TLRPC.Message message;
        if (user != null && messageId != 0) {
            if (user.id == getUserConfig().getClientUserId()) {
                return;
            }
            TLRPC.TL_messages_sendScreenshotNotification req = new TLRPC.TL_messages_sendScreenshotNotification();
            req.peer = new TLRPC.TL_inputPeerUser();
            req.peer.access_hash = user.access_hash;
            req.peer.user_id = user.id;
            if (resendMessage != null) {
                req.reply_to_msg_id = messageId;
                req.random_id = resendMessage.random_id;
                message = resendMessage;
            } else {
                TLRPC.Message message2 = new TLRPC.TL_messageService();
                message2.random_id = getNextRandomId();
                message2.dialog_id = user.id;
                message2.unread = true;
                message2.out = true;
                int newMessageId = getUserConfig().getNewMessageId();
                message2.id = newMessageId;
                message2.local_id = newMessageId;
                message2.from_id = getUserConfig().getClientUserId();
                message2.flags |= 256;
                message2.flags |= 8;
                message2.reply_to_msg_id = messageId;
                message2.to_id = new TLRPC.TL_peerUser();
                message2.to_id.user_id = user.id;
                message2.date = getConnectionsManager().getCurrentTime();
                message2.action = new TLRPC.TL_messageActionScreenshotTaken();
                getUserConfig().saveConfig(false);
                message = message2;
            }
            req.random_id = message.random_id;
            MessageObject newMsgObj = new MessageObject(this.currentAccount, message, false);
            newMsgObj.messageOwner.send_state = 1;
            ArrayList<MessageObject> objArr = new ArrayList<>();
            objArr.add(newMsgObj);
            getMessagesController().updateInterfaceWithMessages(message.dialog_id, objArr, false);
            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
            ArrayList<TLRPC.Message> arr = new ArrayList<>();
            arr.add(message);
            getMessagesStorage().putMessages(arr, false, true, false, 0, false);
            performSendMessageRequest(req, newMsgObj, null, null, null, false);
        }
    }

    public void sendSticker(TLRPC.Document document, long peer, MessageObject replyingMessageObject, Object parentObject, boolean notify, int scheduleDate) {
        TLRPC.Document document2;
        if (document == null) {
            return;
        }
        if (((int) peer) != 0) {
            document2 = document;
        } else {
            int high_id = (int) (peer >> 32);
            TLRPC.EncryptedChat encryptedChat = getMessagesController().getEncryptedChat(Integer.valueOf(high_id));
            if (encryptedChat == null) {
                return;
            }
            TLRPC.TL_document_layer82 newDocument = new TLRPC.TL_document_layer82();
            newDocument.id = document.id;
            newDocument.access_hash = document.access_hash;
            newDocument.date = document.date;
            newDocument.mime_type = document.mime_type;
            newDocument.file_reference = document.file_reference;
            if (newDocument.file_reference == null) {
                newDocument.file_reference = new byte[0];
            }
            newDocument.size = document.size;
            newDocument.dc_id = document.dc_id;
            newDocument.attributes = new ArrayList<>(document.attributes);
            if (newDocument.mime_type == null) {
                newDocument.mime_type = "";
            }
            TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 90);
            if (thumb instanceof TLRPC.TL_photoSize) {
                File file = FileLoader.getPathToAttach(thumb, true);
                if (file.exists()) {
                    try {
                        byte[] arr = new byte[(int) file.length()];
                        RandomAccessFile reader = new RandomAccessFile(file, "r");
                        reader.readFully(arr);
                        TLRPC.PhotoSize newThumb = new TLRPC.TL_photoCachedSize();
                        TLRPC.TL_fileLocation_layer82 fileLocation = new TLRPC.TL_fileLocation_layer82();
                        fileLocation.dc_id = thumb.location.dc_id;
                        fileLocation.volume_id = thumb.location.volume_id;
                        fileLocation.local_id = thumb.location.local_id;
                        fileLocation.secret = thumb.location.secret;
                        newThumb.location = fileLocation;
                        newThumb.size = thumb.size;
                        newThumb.w = thumb.w;
                        newThumb.h = thumb.h;
                        newThumb.type = thumb.type;
                        newThumb.bytes = arr;
                        newDocument.thumbs.add(newThumb);
                        newDocument.flags = 1 | newDocument.flags;
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                }
            }
            if (newDocument.thumbs.isEmpty()) {
                TLRPC.PhotoSize thumb2 = new TLRPC.TL_photoSizeEmpty();
                thumb2.type = "s";
                newDocument.thumbs.add(thumb2);
            }
            document2 = newDocument;
        }
        if (document2 instanceof TLRPC.TL_document) {
            sendMessage((TLRPC.TL_document) document2, null, null, peer, replyingMessageObject, null, null, null, null, notify, scheduleDate, 0, parentObject);
        }
    }

    public int sendMessage(ArrayList<MessageObject> messages, final long peer, boolean notify, final int scheduleDate) {
        boolean isMegagroup;
        boolean isSignature;
        boolean canSendStickers;
        boolean canSendMedia;
        boolean canSendPolls;
        boolean canSendPreview;
        TLRPC.Chat chat;
        int a;
        TLRPC.InputPeer inputPeer;
        int myId;
        MessageObject msgObj;
        ArrayList<MessageObject> objArr;
        ArrayList<Long> randomIds;
        ArrayList<TLRPC.Message> arr;
        TLRPC.Chat chat2;
        int lower_id;
        ArrayList<Integer> ids;
        LongSparseArray<TLRPC.Message> messagesByRandomIds;
        final TLRPC.Peer to_id;
        LongSparseArray<Long> groupsMap;
        int a2;
        ArrayList<MessageObject> arrayList;
        long j;
        SendMessagesHelper sendMessagesHelper;
        TLRPC.Message newMsg;
        TLRPC.Message newMsg2;
        ArrayList<MessageObject> objArr2;
        int myId2;
        LongSparseArray<Long> groupsMap2;
        TLRPC.Message newMsg3;
        ArrayList<Long> randomIds2;
        boolean z;
        MessageObject msgObj2;
        boolean z2;
        SendMessagesHelper sendMessagesHelper2 = this;
        ArrayList<MessageObject> arrayList2 = messages;
        long j2 = peer;
        int i = scheduleDate;
        if (arrayList2 != null && !messages.isEmpty()) {
            int lower_id2 = (int) j2;
            if (lower_id2 == 0) {
                for (int a3 = 0; a3 < messages.size(); a3++) {
                    sendMessagesHelper2.processForwardFromMyName(arrayList2.get(a3), j2);
                }
                return 0;
            }
            TLRPC.Peer to_id2 = getMessagesController().getPeer((int) j2);
            boolean isMegagroup2 = false;
            boolean isSignature2 = false;
            if (lower_id2 > 0) {
                TLRPC.User sendToUser = getMessagesController().getUser(Integer.valueOf(lower_id2));
                if (sendToUser == null) {
                    return 0;
                }
                isMegagroup = false;
                isSignature = false;
                canSendStickers = true;
                canSendMedia = true;
                canSendPolls = true;
                canSendPreview = true;
                chat = null;
            } else {
                TLRPC.Chat chat3 = getMessagesController().getChat(Integer.valueOf(-lower_id2));
                if (ChatObject.isChannel(chat3)) {
                    isMegagroup2 = chat3.megagroup;
                    isSignature2 = chat3.signatures;
                }
                boolean canSendStickers2 = ChatObject.canSendStickers(chat3);
                boolean canSendMedia2 = ChatObject.canSendMedia(chat3);
                boolean canSendPreview2 = ChatObject.canSendEmbed(chat3);
                boolean canSendPolls2 = ChatObject.canSendPolls(chat3);
                isMegagroup = isMegagroup2;
                isSignature = isSignature2;
                canSendStickers = canSendStickers2;
                canSendMedia = canSendMedia2;
                canSendPolls = canSendPolls2;
                canSendPreview = canSendPreview2;
                chat = chat3;
            }
            LongSparseArray<Long> groupsMap3 = new LongSparseArray<>();
            ArrayList<MessageObject> objArr3 = new ArrayList<>();
            ArrayList<TLRPC.Message> arr2 = new ArrayList<>();
            ArrayList<Long> randomIds3 = new ArrayList<>();
            ArrayList<Integer> ids2 = new ArrayList<>();
            LongSparseArray<TLRPC.Message> messagesByRandomIds2 = new LongSparseArray<>();
            TLRPC.InputPeer inputPeer2 = getMessagesController().getInputPeer(lower_id2);
            int lower_id3 = lower_id2;
            int myId3 = getUserConfig().getClientUserId();
            TLRPC.InputPeer inputPeer3 = inputPeer2;
            final boolean toMyself = j2 == ((long) myId3);
            int a4 = 0;
            ArrayList<Integer> ids3 = ids2;
            LongSparseArray<TLRPC.Message> messagesByRandomIds3 = messagesByRandomIds2;
            ArrayList<TLRPC.Message> arr3 = arr2;
            ArrayList<Long> randomIds4 = randomIds3;
            ArrayList<MessageObject> objArr4 = objArr3;
            int sendResult = 0;
            while (a4 < messages.size()) {
                MessageObject msgObj3 = arrayList2.get(a4);
                if (msgObj3.getId() <= 0) {
                    a = a4;
                    inputPeer = inputPeer3;
                    myId = myId3;
                    msgObj = msgObj3;
                    objArr = objArr4;
                    randomIds = randomIds4;
                    arr = arr3;
                    chat2 = chat;
                    lower_id = lower_id3;
                    ids = ids3;
                    messagesByRandomIds = messagesByRandomIds3;
                    to_id = to_id2;
                    groupsMap = groupsMap3;
                } else if (msgObj3.needDrawBluredPreview()) {
                    a = a4;
                    inputPeer = inputPeer3;
                    myId = myId3;
                    msgObj = msgObj3;
                    objArr = objArr4;
                    randomIds = randomIds4;
                    arr = arr3;
                    chat2 = chat;
                    lower_id = lower_id3;
                    ids = ids3;
                    messagesByRandomIds = messagesByRandomIds3;
                    to_id = to_id2;
                    groupsMap = groupsMap3;
                } else {
                    boolean toMyself2 = toMyself;
                    if (!canSendStickers && (msgObj3.isSticker() || msgObj3.isAnimatedSticker() || msgObj3.isGif() || msgObj3.isGame())) {
                        if (sendResult != 0) {
                            a2 = a4;
                            inputPeer = inputPeer3;
                            myId = myId3;
                            objArr = objArr4;
                            randomIds = randomIds4;
                            arr = arr3;
                            chat2 = chat;
                            arrayList = arrayList2;
                            sendMessagesHelper = sendMessagesHelper2;
                            lower_id = lower_id3;
                            toMyself = toMyself2;
                            ids = ids3;
                            messagesByRandomIds = messagesByRandomIds3;
                            to_id = to_id2;
                            groupsMap = groupsMap3;
                            j = j2;
                            randomIds4 = randomIds;
                            arr3 = arr;
                            objArr4 = objArr;
                            i = scheduleDate;
                            sendMessagesHelper2 = sendMessagesHelper;
                            a4 = a2 + 1;
                            j2 = j;
                            arrayList2 = arrayList;
                            to_id2 = to_id;
                            groupsMap3 = groupsMap;
                            lower_id3 = lower_id;
                            chat = chat2;
                            inputPeer3 = inputPeer;
                            myId3 = myId;
                            ids3 = ids;
                            messagesByRandomIds3 = messagesByRandomIds;
                        } else {
                            sendResult = ChatObject.isActionBannedByDefault(chat, 8) ? 4 : 1;
                            a2 = a4;
                            inputPeer = inputPeer3;
                            myId = myId3;
                            chat2 = chat;
                            arrayList = arrayList2;
                            sendMessagesHelper = sendMessagesHelper2;
                            lower_id = lower_id3;
                            toMyself = toMyself2;
                            ids = ids3;
                            messagesByRandomIds = messagesByRandomIds3;
                            to_id = to_id2;
                            groupsMap = groupsMap3;
                            j = j2;
                            i = scheduleDate;
                            sendMessagesHelper2 = sendMessagesHelper;
                            a4 = a2 + 1;
                            j2 = j;
                            arrayList2 = arrayList;
                            to_id2 = to_id;
                            groupsMap3 = groupsMap;
                            lower_id3 = lower_id;
                            chat = chat2;
                            inputPeer3 = inputPeer;
                            myId3 = myId;
                            ids3 = ids;
                            messagesByRandomIds3 = messagesByRandomIds;
                        }
                    } else if (!canSendMedia && ((msgObj3.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) || (msgObj3.messageOwner.media instanceof TLRPC.TL_messageMediaDocument))) {
                        if (sendResult != 0) {
                            a2 = a4;
                            inputPeer = inputPeer3;
                            myId = myId3;
                            objArr = objArr4;
                            randomIds = randomIds4;
                            arr = arr3;
                            chat2 = chat;
                            arrayList = arrayList2;
                            sendMessagesHelper = sendMessagesHelper2;
                            lower_id = lower_id3;
                            toMyself = toMyself2;
                            ids = ids3;
                            messagesByRandomIds = messagesByRandomIds3;
                            to_id = to_id2;
                            groupsMap = groupsMap3;
                            j = j2;
                            randomIds4 = randomIds;
                            arr3 = arr;
                            objArr4 = objArr;
                            i = scheduleDate;
                            sendMessagesHelper2 = sendMessagesHelper;
                            a4 = a2 + 1;
                            j2 = j;
                            arrayList2 = arrayList;
                            to_id2 = to_id;
                            groupsMap3 = groupsMap;
                            lower_id3 = lower_id;
                            chat = chat2;
                            inputPeer3 = inputPeer;
                            myId3 = myId;
                            ids3 = ids;
                            messagesByRandomIds3 = messagesByRandomIds;
                        } else {
                            sendResult = ChatObject.isActionBannedByDefault(chat, 7) ? 5 : 2;
                            a2 = a4;
                            inputPeer = inputPeer3;
                            myId = myId3;
                            chat2 = chat;
                            arrayList = arrayList2;
                            sendMessagesHelper = sendMessagesHelper2;
                            lower_id = lower_id3;
                            toMyself = toMyself2;
                            ids = ids3;
                            messagesByRandomIds = messagesByRandomIds3;
                            to_id = to_id2;
                            groupsMap = groupsMap3;
                            j = j2;
                            i = scheduleDate;
                            sendMessagesHelper2 = sendMessagesHelper;
                            a4 = a2 + 1;
                            j2 = j;
                            arrayList2 = arrayList;
                            to_id2 = to_id;
                            groupsMap3 = groupsMap;
                            lower_id3 = lower_id;
                            chat = chat2;
                            inputPeer3 = inputPeer;
                            myId3 = myId;
                            ids3 = ids;
                            messagesByRandomIds3 = messagesByRandomIds;
                        }
                    } else if (!canSendPolls && (msgObj3.messageOwner.media instanceof TLRPC.TL_messageMediaPoll)) {
                        if (sendResult != 0) {
                            a2 = a4;
                            inputPeer = inputPeer3;
                            myId = myId3;
                            objArr = objArr4;
                            randomIds = randomIds4;
                            arr = arr3;
                            chat2 = chat;
                            arrayList = arrayList2;
                            sendMessagesHelper = sendMessagesHelper2;
                            lower_id = lower_id3;
                            toMyself = toMyself2;
                            ids = ids3;
                            messagesByRandomIds = messagesByRandomIds3;
                            to_id = to_id2;
                            groupsMap = groupsMap3;
                            j = j2;
                            randomIds4 = randomIds;
                            arr3 = arr;
                            objArr4 = objArr;
                            i = scheduleDate;
                            sendMessagesHelper2 = sendMessagesHelper;
                            a4 = a2 + 1;
                            j2 = j;
                            arrayList2 = arrayList;
                            to_id2 = to_id;
                            groupsMap3 = groupsMap;
                            lower_id3 = lower_id;
                            chat = chat2;
                            inputPeer3 = inputPeer;
                            myId3 = myId;
                            ids3 = ids;
                            messagesByRandomIds3 = messagesByRandomIds;
                        } else {
                            sendResult = ChatObject.isActionBannedByDefault(chat, 10) ? 6 : 3;
                            a2 = a4;
                            inputPeer = inputPeer3;
                            myId = myId3;
                            chat2 = chat;
                            arrayList = arrayList2;
                            sendMessagesHelper = sendMessagesHelper2;
                            lower_id = lower_id3;
                            toMyself = toMyself2;
                            ids = ids3;
                            messagesByRandomIds = messagesByRandomIds3;
                            to_id = to_id2;
                            groupsMap = groupsMap3;
                            j = j2;
                            i = scheduleDate;
                            sendMessagesHelper2 = sendMessagesHelper;
                            a4 = a2 + 1;
                            j2 = j;
                            arrayList2 = arrayList;
                            to_id2 = to_id;
                            groupsMap3 = groupsMap;
                            lower_id3 = lower_id;
                            chat = chat2;
                            inputPeer3 = inputPeer;
                            myId3 = myId;
                            ids3 = ids;
                            messagesByRandomIds3 = messagesByRandomIds;
                        }
                    } else {
                        TLRPC.Message newMsg4 = new TLRPC.TL_message();
                        final ArrayList<TLRPC.Message> arr4 = arr3;
                        chat2 = chat;
                        boolean forwardFromSaved = msgObj3.getDialogId() == ((long) myId3) && msgObj3.messageOwner.from_id == getUserConfig().getClientUserId();
                        if (msgObj3.isForwarded()) {
                            newMsg = newMsg4;
                            newMsg.fwd_from = new TLRPC.TL_messageFwdHeader();
                            newMsg2 = null;
                            newMsg.fwd_from.flags = msgObj3.messageOwner.fwd_from.flags;
                            newMsg.fwd_from.from_id = msgObj3.messageOwner.fwd_from.from_id;
                            newMsg.fwd_from.date = msgObj3.messageOwner.fwd_from.date;
                            newMsg.fwd_from.channel_id = msgObj3.messageOwner.fwd_from.channel_id;
                            newMsg.fwd_from.channel_post = msgObj3.messageOwner.fwd_from.channel_post;
                            newMsg.fwd_from.post_author = msgObj3.messageOwner.fwd_from.post_author;
                            newMsg.fwd_from.from_name = msgObj3.messageOwner.fwd_from.from_name;
                            newMsg.flags = 4;
                            objArr2 = objArr4;
                        } else {
                            newMsg = newMsg4;
                            newMsg2 = null;
                            if (forwardFromSaved) {
                                objArr2 = objArr4;
                            } else {
                                newMsg.fwd_from = new TLRPC.TL_messageFwdHeader();
                                newMsg.fwd_from.channel_post = msgObj3.getId();
                                newMsg.fwd_from.flags |= 4;
                                if (msgObj3.isFromUser()) {
                                    newMsg.fwd_from.from_id = msgObj3.messageOwner.from_id;
                                    newMsg.fwd_from.flags |= 1;
                                } else {
                                    newMsg.fwd_from.channel_id = msgObj3.messageOwner.to_id.channel_id;
                                    newMsg.fwd_from.flags |= 2;
                                    if (msgObj3.messageOwner.post && msgObj3.messageOwner.from_id > 0) {
                                        newMsg.fwd_from.from_id = msgObj3.messageOwner.from_id;
                                        newMsg.fwd_from.flags |= 1;
                                    }
                                }
                                if (msgObj3.messageOwner.post_author != null) {
                                    newMsg.fwd_from.post_author = msgObj3.messageOwner.post_author;
                                    newMsg.fwd_from.flags |= 8;
                                    objArr2 = objArr4;
                                } else if (msgObj3.isOutOwner() || msgObj3.messageOwner.from_id <= 0 || !msgObj3.messageOwner.post) {
                                    objArr2 = objArr4;
                                } else {
                                    TLRPC.User signUser = getMessagesController().getUser(Integer.valueOf(msgObj3.messageOwner.from_id));
                                    if (signUser == null) {
                                        objArr2 = objArr4;
                                    } else {
                                        objArr2 = objArr4;
                                        newMsg.fwd_from.post_author = ContactsController.formatName(signUser.first_name, signUser.last_name);
                                        newMsg.fwd_from.flags |= 8;
                                    }
                                }
                                newMsg.date = msgObj3.messageOwner.date;
                                newMsg.flags = 4;
                            }
                        }
                        if (j2 == myId3 && newMsg.fwd_from != null) {
                            newMsg.fwd_from.flags |= 16;
                            newMsg.fwd_from.saved_from_msg_id = msgObj3.getId();
                            newMsg.fwd_from.saved_from_peer = msgObj3.messageOwner.to_id;
                        }
                        if (!canSendPreview && (msgObj3.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage)) {
                            newMsg.media = new TLRPC.TL_messageMediaEmpty();
                        } else {
                            newMsg.media = msgObj3.messageOwner.media;
                        }
                        if (newMsg.media != null) {
                            newMsg.flags |= 512;
                        }
                        if (isMegagroup) {
                            newMsg.flags |= Integer.MIN_VALUE;
                        }
                        if (msgObj3.messageOwner.via_bot_id != 0) {
                            newMsg.via_bot_id = msgObj3.messageOwner.via_bot_id;
                            newMsg.flags |= 2048;
                        }
                        newMsg.message = msgObj3.messageOwner.message;
                        newMsg.fwd_msg_id = msgObj3.getId();
                        newMsg.attachPath = msgObj3.messageOwner.attachPath;
                        newMsg.entities = msgObj3.messageOwner.entities;
                        if (!(msgObj3.messageOwner.reply_markup instanceof TLRPC.TL_replyInlineMarkup)) {
                            myId2 = myId3;
                        } else {
                            newMsg.flags |= 64;
                            newMsg.reply_markup = new TLRPC.TL_replyInlineMarkup();
                            int b = 0;
                            int N = msgObj3.messageOwner.reply_markup.rows.size();
                            while (b < N) {
                                TLRPC.TL_keyboardButtonRow oldRow = msgObj3.messageOwner.reply_markup.rows.get(b);
                                TLRPC.TL_keyboardButtonRow newRow = null;
                                int myId4 = myId3;
                                int N2 = oldRow.buttons.size();
                                int c = N;
                                int N3 = 0;
                                while (N3 < N2) {
                                    int N22 = N2;
                                    TLRPC.KeyboardButton button = oldRow.buttons.get(N3);
                                    TLRPC.TL_keyboardButtonRow oldRow2 = oldRow;
                                    if ((button instanceof TLRPC.TL_keyboardButtonUrlAuth) || (button instanceof TLRPC.TL_keyboardButtonUrl) || (button instanceof TLRPC.TL_keyboardButtonSwitchInline)) {
                                        if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
                                            TLRPC.TL_keyboardButtonUrlAuth auth = new TLRPC.TL_keyboardButtonUrlAuth();
                                            auth.flags = button.flags;
                                            if (button.fwd_text != null) {
                                                String str = button.fwd_text;
                                                auth.fwd_text = str;
                                                auth.text = str;
                                            } else {
                                                auth.text = button.text;
                                            }
                                            auth.url = button.url;
                                            auth.button_id = button.button_id;
                                            button = auth;
                                        }
                                        if (newRow == null) {
                                            newRow = new TLRPC.TL_keyboardButtonRow();
                                            newMsg.reply_markup.rows.add(newRow);
                                        }
                                        newRow.buttons.add(button);
                                    }
                                    N3++;
                                    N2 = N22;
                                    oldRow = oldRow2;
                                }
                                b++;
                                N = c;
                                myId3 = myId4;
                            }
                            myId2 = myId3;
                        }
                        if (!newMsg.entities.isEmpty()) {
                            newMsg.flags |= 128;
                        }
                        if (newMsg.attachPath == null) {
                            newMsg.attachPath = "";
                        }
                        int newMessageId = getUserConfig().getNewMessageId();
                        newMsg.id = newMessageId;
                        newMsg.local_id = newMessageId;
                        newMsg.out = true;
                        long lastGroupedId = msgObj3.messageOwner.grouped_id;
                        if (lastGroupedId != 0) {
                            Long gId = groupsMap3.get(msgObj3.messageOwner.grouped_id);
                            if (gId == null) {
                                gId = Long.valueOf(Utilities.random.nextLong());
                                groupsMap3.put(msgObj3.messageOwner.grouped_id, gId);
                            }
                            newMsg.grouped_id = gId.longValue();
                            newMsg.flags |= 131072;
                        }
                        if (a4 == messages.size() - 1) {
                            groupsMap2 = groupsMap3;
                        } else {
                            MessageObject next = arrayList2.get(a4 + 1);
                            groupsMap2 = groupsMap3;
                            if (next.messageOwner.grouped_id != msgObj3.messageOwner.grouped_id) {
                                newMsg2 = 1;
                            }
                        }
                        if (to_id2.channel_id != 0 && !isMegagroup) {
                            newMsg.from_id = isSignature ? getUserConfig().getClientUserId() : -to_id2.channel_id;
                            newMsg.post = true;
                        } else {
                            newMsg.from_id = getUserConfig().getClientUserId();
                            newMsg.flags |= 256;
                        }
                        if (newMsg.random_id == 0) {
                            newMsg.random_id = getNextRandomId();
                        }
                        randomIds4.add(Long.valueOf(newMsg.random_id));
                        final LongSparseArray<TLRPC.Message> messagesByRandomIds4 = messagesByRandomIds3;
                        messagesByRandomIds4.put(newMsg.random_id, newMsg);
                        ArrayList<Integer> ids4 = ids3;
                        ids4.add(Integer.valueOf(newMsg.fwd_msg_id));
                        newMsg.date = i != 0 ? i : getConnectionsManager().getCurrentTime();
                        if ((inputPeer3 instanceof TLRPC.TL_inputPeerChannel) && !isMegagroup) {
                            if (i == 0) {
                                newMsg.views = 1;
                                newMsg.flags |= 1024;
                            }
                        } else {
                            if ((msgObj3.messageOwner.flags & 1024) != 0 && i == 0) {
                                newMsg.views = msgObj3.messageOwner.views;
                                newMsg.flags |= 1024;
                            }
                            newMsg.unread = true;
                        }
                        newMsg.dialog_id = peer;
                        newMsg.to_id = to_id2;
                        if (MessageObject.isVoiceMessage(newMsg) || MessageObject.isRoundVideoMessage(newMsg)) {
                            if ((inputPeer3 instanceof TLRPC.TL_inputPeerChannel) && msgObj3.getChannelId() != 0) {
                                newMsg.media_unread = msgObj3.isContentUnread();
                            } else {
                                newMsg.media_unread = true;
                            }
                        }
                        if (msgObj3.messageOwner.to_id instanceof TLRPC.TL_peerChannel) {
                            newMsg.ttl = -msgObj3.messageOwner.to_id.channel_id;
                        }
                        to_id = to_id2;
                        groupsMap = groupsMap2;
                        MessageObject newMsgObj = new MessageObject(this.currentAccount, newMsg, true);
                        newMsgObj.scheduled = i != 0;
                        newMsgObj.messageOwner.send_state = 1;
                        final ArrayList<MessageObject> objArr5 = objArr2;
                        objArr5.add(newMsgObj);
                        arr4.add(newMsg);
                        putToSendingMessages(newMsg, i != 0);
                        if (!BuildVars.LOGS_ENABLED) {
                            newMsg3 = newMsg;
                            randomIds2 = randomIds4;
                        } else {
                            newMsg3 = newMsg;
                            StringBuilder sb = new StringBuilder();
                            sb.append("forward message user_id = ");
                            sb.append(inputPeer3.user_id);
                            sb.append(" chat_id = ");
                            sb.append(inputPeer3.chat_id);
                            sb.append(" channel_id = ");
                            sb.append(inputPeer3.channel_id);
                            sb.append(" access_hash = ");
                            randomIds2 = randomIds4;
                            sb.append(inputPeer3.access_hash);
                            FileLog.d(sb.toString());
                        }
                        if ((newMsg2 == null || arr4.size() <= 0) && arr4.size() != 100 && a4 != messages.size() - 1 && (a4 == messages.size() - 1 || arrayList2.get(a4 + 1).getDialogId() == msgObj3.getDialogId())) {
                            a2 = a4;
                            inputPeer = inputPeer3;
                            objArr = objArr5;
                            arr = arr4;
                            ids = ids4;
                            j = peer;
                            arrayList = arrayList2;
                            randomIds = randomIds2;
                            toMyself = toMyself2;
                            myId = myId2;
                            sendMessagesHelper = this;
                            messagesByRandomIds = messagesByRandomIds4;
                            lower_id = lower_id3;
                        } else {
                            getMessagesStorage().putMessages(new ArrayList<>(arr4), false, true, false, 0, i != 0);
                            getMessagesController().updateInterfaceWithMessages(peer, objArr5, i != 0);
                            int a5 = a4;
                            getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
                            getUserConfig().saveConfig(false);
                            final TLRPC.TL_messages_forwardMessages req = new TLRPC.TL_messages_forwardMessages();
                            req.to_peer = inputPeer3;
                            req.grouped = lastGroupedId != 0;
                            if (notify) {
                                if (!MessagesController.getNotificationsSettings(this.currentAccount).getBoolean("silent_" + peer, false)) {
                                    z = false;
                                    req.silent = z;
                                    if (i != 0) {
                                        req.schedule_date = i;
                                        req.flags |= 1024;
                                    }
                                    if (!(msgObj3.messageOwner.to_id instanceof TLRPC.TL_peerChannel)) {
                                        TLRPC.Chat channel = getMessagesController().getChat(Integer.valueOf(msgObj3.messageOwner.to_id.channel_id));
                                        req.from_peer = new TLRPC.TL_inputPeerChannel();
                                        req.from_peer.channel_id = msgObj3.messageOwner.to_id.channel_id;
                                        if (channel == null) {
                                            msgObj2 = msgObj3;
                                        } else {
                                            msgObj2 = msgObj3;
                                            req.from_peer.access_hash = channel.access_hash;
                                        }
                                    } else {
                                        msgObj2 = msgObj3;
                                        req.from_peer = new TLRPC.TL_inputPeerEmpty();
                                    }
                                    ArrayList<Long> randomIds5 = randomIds2;
                                    req.random_id = randomIds5;
                                    req.id = ids4;
                                    if (messages.size() == 1 && arrayList2.get(0).messageOwner.with_my_score) {
                                        z2 = true;
                                        req.with_my_score = z2;
                                        randomIds = randomIds5;
                                        arr = arr4;
                                        objArr = objArr5;
                                        final boolean isMegagroupFinal = isMegagroup;
                                        inputPeer = inputPeer3;
                                        ids = ids4;
                                        myId = myId2;
                                        lower_id = lower_id3;
                                        toMyself = toMyself2;
                                        messagesByRandomIds = messagesByRandomIds4;
                                        getConnectionsManager().sendRequest(req, new RequestDelegate() {
                                            @Override
                                            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                                                SendMessagesHelper.this.lambda$sendMessage$9$SendMessagesHelper(peer, scheduleDate, isMegagroupFinal, toMyself, messagesByRandomIds4, arr4, objArr5, to_id, req, tLObject, tL_error);
                                            }
                                        }, 68);
                                        if (a5 != messages.size() - 1) {
                                            sendMessagesHelper = this;
                                            arrayList = messages;
                                            j = peer;
                                            a2 = a5;
                                        } else {
                                            ArrayList<MessageObject> objArr6 = new ArrayList<>();
                                            ArrayList<TLRPC.Message> arr5 = new ArrayList<>();
                                            ArrayList<Long> randomIds6 = new ArrayList<>();
                                            ArrayList<Integer> ids5 = new ArrayList<>();
                                            arrayList = messages;
                                            objArr4 = objArr6;
                                            arr3 = arr5;
                                            randomIds4 = randomIds6;
                                            ids = ids5;
                                            messagesByRandomIds = new LongSparseArray<>();
                                            a2 = a5;
                                            sendMessagesHelper = this;
                                            j = peer;
                                            i = scheduleDate;
                                            sendMessagesHelper2 = sendMessagesHelper;
                                            a4 = a2 + 1;
                                            j2 = j;
                                            arrayList2 = arrayList;
                                            to_id2 = to_id;
                                            groupsMap3 = groupsMap;
                                            lower_id3 = lower_id;
                                            chat = chat2;
                                            inputPeer3 = inputPeer;
                                            myId3 = myId;
                                            ids3 = ids;
                                            messagesByRandomIds3 = messagesByRandomIds;
                                        }
                                    }
                                    z2 = false;
                                    req.with_my_score = z2;
                                    randomIds = randomIds5;
                                    arr = arr4;
                                    objArr = objArr5;
                                    final boolean isMegagroupFinal2 = isMegagroup;
                                    inputPeer = inputPeer3;
                                    ids = ids4;
                                    myId = myId2;
                                    lower_id = lower_id3;
                                    toMyself = toMyself2;
                                    messagesByRandomIds = messagesByRandomIds4;
                                    getConnectionsManager().sendRequest(req, new RequestDelegate() {
                                        @Override
                                        public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                                            SendMessagesHelper.this.lambda$sendMessage$9$SendMessagesHelper(peer, scheduleDate, isMegagroupFinal2, toMyself, messagesByRandomIds4, arr4, objArr5, to_id, req, tLObject, tL_error);
                                        }
                                    }, 68);
                                    if (a5 != messages.size() - 1) {
                                    }
                                }
                            }
                            z = true;
                            req.silent = z;
                            if (i != 0) {
                            }
                            if (!(msgObj3.messageOwner.to_id instanceof TLRPC.TL_peerChannel)) {
                            }
                            ArrayList<Long> randomIds52 = randomIds2;
                            req.random_id = randomIds52;
                            req.id = ids4;
                            if (messages.size() == 1) {
                                z2 = true;
                                req.with_my_score = z2;
                                randomIds = randomIds52;
                                arr = arr4;
                                objArr = objArr5;
                                final boolean isMegagroupFinal22 = isMegagroup;
                                inputPeer = inputPeer3;
                                ids = ids4;
                                myId = myId2;
                                lower_id = lower_id3;
                                toMyself = toMyself2;
                                messagesByRandomIds = messagesByRandomIds4;
                                getConnectionsManager().sendRequest(req, new RequestDelegate() {
                                    @Override
                                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                                        SendMessagesHelper.this.lambda$sendMessage$9$SendMessagesHelper(peer, scheduleDate, isMegagroupFinal22, toMyself, messagesByRandomIds4, arr4, objArr5, to_id, req, tLObject, tL_error);
                                    }
                                }, 68);
                                if (a5 != messages.size() - 1) {
                                }
                            }
                            z2 = false;
                            req.with_my_score = z2;
                            randomIds = randomIds52;
                            arr = arr4;
                            objArr = objArr5;
                            final boolean isMegagroupFinal222 = isMegagroup;
                            inputPeer = inputPeer3;
                            ids = ids4;
                            myId = myId2;
                            lower_id = lower_id3;
                            toMyself = toMyself2;
                            messagesByRandomIds = messagesByRandomIds4;
                            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                                @Override
                                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                                    SendMessagesHelper.this.lambda$sendMessage$9$SendMessagesHelper(peer, scheduleDate, isMegagroupFinal222, toMyself, messagesByRandomIds4, arr4, objArr5, to_id, req, tLObject, tL_error);
                                }
                            }, 68);
                            if (a5 != messages.size() - 1) {
                            }
                        }
                        randomIds4 = randomIds;
                        arr3 = arr;
                        objArr4 = objArr;
                        i = scheduleDate;
                        sendMessagesHelper2 = sendMessagesHelper;
                        a4 = a2 + 1;
                        j2 = j;
                        arrayList2 = arrayList;
                        to_id2 = to_id;
                        groupsMap3 = groupsMap;
                        lower_id3 = lower_id;
                        chat = chat2;
                        inputPeer3 = inputPeer;
                        myId3 = myId;
                        ids3 = ids;
                        messagesByRandomIds3 = messagesByRandomIds;
                    }
                }
                MessageObject msgObj4 = msgObj;
                if (msgObj4.type != 0 || TextUtils.isEmpty(msgObj4.messageText)) {
                    arrayList = messages;
                    j = peer;
                    a2 = a;
                    sendMessagesHelper = this;
                } else {
                    TLRPC.WebPage webPage = msgObj4.messageOwner.media != null ? msgObj4.messageOwner.media.webpage : null;
                    String charSequence = msgObj4.messageText.toString();
                    boolean z3 = webPage != null;
                    ArrayList<TLRPC.MessageEntity> arrayList3 = msgObj4.messageOwner.entities;
                    j = peer;
                    arrayList = messages;
                    a2 = a;
                    sendMessagesHelper = this;
                    sendMessage(charSequence, peer, null, webPage, z3, arrayList3, null, null, notify, scheduleDate);
                }
                randomIds4 = randomIds;
                arr3 = arr;
                objArr4 = objArr;
                i = scheduleDate;
                sendMessagesHelper2 = sendMessagesHelper;
                a4 = a2 + 1;
                j2 = j;
                arrayList2 = arrayList;
                to_id2 = to_id;
                groupsMap3 = groupsMap;
                lower_id3 = lower_id;
                chat = chat2;
                inputPeer3 = inputPeer;
                myId3 = myId;
                ids3 = ids;
                messagesByRandomIds3 = messagesByRandomIds;
            }
            return sendResult;
        }
        return 0;
    }

    public void lambda$sendMessage$9$SendMessagesHelper(final long peer, final int scheduleDate, boolean isMegagroupFinal, boolean toMyself, LongSparseArray messagesByRandomIdsFinal, ArrayList newMsgObjArr, ArrayList newMsgArr, final TLRPC.Peer to_id, final TLRPC.TL_messages_forwardMessages req, TLObject response, final TLRPC.TL_error error) {
        final SendMessagesHelper sendMessagesHelper;
        Integer value;
        TLRPC.Message message;
        int sentCount;
        SparseLongArray newMessagesByIds;
        TLRPC.Updates updates;
        int i;
        int i2 = scheduleDate;
        ArrayList arrayList = newMsgObjArr;
        ArrayList arrayList2 = newMsgArr;
        if (error == null) {
            SparseLongArray newMessagesByIds2 = new SparseLongArray();
            TLRPC.Updates updates2 = (TLRPC.Updates) response;
            int a1 = 0;
            while (a1 < updates2.updates.size()) {
                TLRPC.Update update = updates2.updates.get(a1);
                if (update instanceof TLRPC.TL_updateMessageID) {
                    TLRPC.TL_updateMessageID updateMessageID = (TLRPC.TL_updateMessageID) update;
                    newMessagesByIds2.put(updateMessageID.id, updateMessageID.random_id);
                    updates2.updates.remove(a1);
                    a1--;
                }
                a1++;
            }
            Integer value2 = getMessagesController().dialogs_read_outbox_max.get(Long.valueOf(peer));
            if (i2 != 0) {
                value = 0;
            } else if (value2 == null) {
                Integer value3 = Integer.valueOf(getMessagesStorage().getDialogReadMax(true, peer));
                getMessagesController().dialogs_read_outbox_max.put(Long.valueOf(peer), value3);
                value = value3;
            } else {
                value = value2;
            }
            int a12 = 0;
            int sentCount2 = 0;
            while (a12 < updates2.updates.size()) {
                TLRPC.Update update2 = updates2.updates.get(a12);
                if ((update2 instanceof TLRPC.TL_updateNewMessage) || (update2 instanceof TLRPC.TL_updateNewChannelMessage) || (update2 instanceof TLRPC.TL_updateNewScheduledMessage)) {
                    updates2.updates.remove(a12);
                    int a13 = a12 - 1;
                    if (update2 instanceof TLRPC.TL_updateNewMessage) {
                        TLRPC.TL_updateNewMessage updateNewMessage = (TLRPC.TL_updateNewMessage) update2;
                        TLRPC.Message message2 = updateNewMessage.message;
                        getMessagesController().processNewDifferenceParams(-1, updateNewMessage.pts, -1, updateNewMessage.pts_count);
                        message = message2;
                    } else if (update2 instanceof TLRPC.TL_updateNewScheduledMessage) {
                        message = ((TLRPC.TL_updateNewScheduledMessage) update2).message;
                    } else {
                        TLRPC.TL_updateNewChannelMessage updateNewChannelMessage = (TLRPC.TL_updateNewChannelMessage) update2;
                        TLRPC.Message message3 = updateNewChannelMessage.message;
                        getMessagesController().processNewChannelDifferenceParams(updateNewChannelMessage.pts, updateNewChannelMessage.pts_count, message3.to_id.channel_id);
                        if (isMegagroupFinal) {
                            message3.flags |= Integer.MIN_VALUE;
                        }
                        message = message3;
                    }
                    ImageLoader.saveMessageThumbs(message);
                    if (i2 == 0) {
                        message.unread = value.intValue() < message.id;
                    }
                    if (toMyself) {
                        message.out = true;
                        message.unread = false;
                        message.media_unread = false;
                    }
                    long random_id = newMessagesByIds2.get(message.id);
                    if (random_id != 0) {
                        final TLRPC.Message newMsgObj1 = (TLRPC.Message) messagesByRandomIdsFinal.get(random_id);
                        if (newMsgObj1 == null) {
                            sentCount = sentCount2;
                            newMessagesByIds = newMessagesByIds2;
                            updates = updates2;
                            i = 1;
                        } else {
                            int index = arrayList.indexOf(newMsgObj1);
                            if (index == -1) {
                                sentCount = sentCount2;
                                newMessagesByIds = newMessagesByIds2;
                                updates = updates2;
                                i = 1;
                            } else {
                                MessageObject msgObj1 = (MessageObject) arrayList2.get(index);
                                arrayList.remove(index);
                                arrayList2.remove(index);
                                final int oldId = newMsgObj1.id;
                                final ArrayList<TLRPC.Message> sentMessages = new ArrayList<>();
                                sentMessages.add(message);
                                int sentCount3 = message.id;
                                updateMediaPaths(msgObj1, message, sentCount3, null, true);
                                final int existFlags = msgObj1.getMediaExistanceFlags();
                                newMsgObj1.id = message.id;
                                newMessagesByIds = newMessagesByIds2;
                                updates = updates2;
                                i = 1;
                                final TLRPC.Message message4 = message;
                                getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                                    @Override
                                    public final void run() {
                                        SendMessagesHelper.this.lambda$null$6$SendMessagesHelper(newMsgObj1, oldId, to_id, scheduleDate, sentMessages, peer, message4, existFlags);
                                    }
                                });
                                a12 = a13;
                                sentCount2++;
                            }
                        }
                    } else {
                        sentCount = sentCount2;
                        newMessagesByIds = newMessagesByIds2;
                        updates = updates2;
                        i = 1;
                    }
                    sentCount2 = sentCount;
                    a12 = a13;
                } else {
                    newMessagesByIds = newMessagesByIds2;
                    updates = updates2;
                    i = 1;
                }
                a12 += i;
                arrayList = newMsgObjArr;
                arrayList2 = newMsgArr;
                updates2 = updates;
                newMessagesByIds2 = newMessagesByIds;
                i2 = scheduleDate;
            }
            int sentCount4 = sentCount2;
            TLRPC.Updates updates3 = updates2;
            if (!updates3.updates.isEmpty()) {
                getMessagesController().processUpdates(updates3, false);
            }
            getStatsController().incrementSentItemsCount(ApplicationLoader.getCurrentNetworkType(), 1, sentCount4);
            sendMessagesHelper = this;
        } else {
            sendMessagesHelper = this;
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    SendMessagesHelper.this.lambda$null$7$SendMessagesHelper(error, req);
                }
            });
        }
        for (int a14 = 0; a14 < newMsgObjArr.size(); a14++) {
            final TLRPC.Message newMsgObj12 = (TLRPC.Message) newMsgObjArr.get(a14);
            getMessagesStorage().markMessageAsSendError(newMsgObj12, scheduleDate != 0);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    SendMessagesHelper.this.lambda$null$8$SendMessagesHelper(newMsgObj12, scheduleDate);
                }
            });
        }
    }

    public void lambda$null$6$SendMessagesHelper(final TLRPC.Message newMsgObj1, final int oldId, TLRPC.Peer to_id, final int scheduleDate, ArrayList sentMessages, final long peer, final TLRPC.Message message, final int existFlags) {
        getMessagesStorage().updateMessageStateAndId(newMsgObj1.random_id, Integer.valueOf(oldId), newMsgObj1.id, 0, false, to_id.channel_id, scheduleDate != 0 ? 1 : 0);
        getMessagesStorage().putMessages((ArrayList<TLRPC.Message>) sentMessages, true, true, false, 0, scheduleDate != 0);
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$null$5$SendMessagesHelper(newMsgObj1, peer, oldId, message, existFlags, scheduleDate);
            }
        });
    }

    public void lambda$null$5$SendMessagesHelper(TLRPC.Message newMsgObj1, long peer, int oldId, TLRPC.Message message, int existFlags, int scheduleDate) {
        newMsgObj1.send_state = 0;
        getMediaDataController().increasePeerRaiting(peer);
        NotificationCenter notificationCenter = getNotificationCenter();
        int i = NotificationCenter.messageReceivedByServer;
        Object[] objArr = new Object[7];
        objArr[0] = Integer.valueOf(oldId);
        objArr[1] = Integer.valueOf(message.id);
        objArr[2] = message;
        objArr[3] = Long.valueOf(peer);
        objArr[4] = 0L;
        objArr[5] = Integer.valueOf(existFlags);
        objArr[6] = Boolean.valueOf(scheduleDate != 0);
        notificationCenter.postNotificationName(i, objArr);
        processSentMessage(oldId);
        removeFromSendingMessages(oldId, scheduleDate != 0);
    }

    public void lambda$null$7$SendMessagesHelper(TLRPC.TL_error error, TLRPC.TL_messages_forwardMessages req) {
        AlertsCreator.processError(this.currentAccount, error, null, req, new Object[0]);
    }

    public void lambda$null$8$SendMessagesHelper(TLRPC.Message newMsgObj1, int scheduleDate) {
        newMsgObj1.send_state = 2;
        getNotificationCenter().postNotificationName(NotificationCenter.messageSendError, Integer.valueOf(newMsgObj1.id));
        processSentMessage(newMsgObj1.id);
        removeFromSendingMessages(newMsgObj1.id, scheduleDate != 0);
    }

    private void writePreviousMessageData(TLRPC.Message message, SerializedData data) {
        message.media.serializeToStream(data);
        data.writeString(message.message != null ? message.message : "");
        data.writeString(message.attachPath != null ? message.attachPath : "");
        int count = message.entities.size();
        data.writeInt32(count);
        for (int a = 0; a < count; a++) {
            message.entities.get(a).serializeToStream(data);
        }
    }

    private void editMessageMedia(MessageObject messageObject, TLRPC.TL_photo tL_photo, VideoEditedInfo videoEditedInfo, TLRPC.TL_document tL_document, String str, HashMap<String, String> hashMap, boolean z, Object obj) {
        VideoEditedInfo videoEditedInfo2;
        HashMap<String, String> hashMap2;
        Object obj2;
        DelayedMessage delayedMessage;
        int i;
        VideoEditedInfo videoEditedInfo3;
        TLRPC.TL_document tL_document2;
        HashMap<String, String> hashMap3;
        TLRPC.TL_photo tL_photo2;
        String str2;
        int i2;
        ?? r18;
        TLRPC.TL_document tL_document3;
        VideoEditedInfo videoEditedInfo4;
        HashMap<String, String> hashMap4;
        ?? r8;
        ?? r1;
        ?? r22;
        boolean z2;
        int i3;
        TLRPC.InputMedia inputMedia;
        boolean z3;
        boolean z4;
        DelayedMessage delayedMessage2;
        TLRPC.TL_photo tL_photo3;
        TLRPC.TL_document tL_document4;
        TLRPC.InputMedia inputMedia2;
        String str3;
        ?? tL_inputMediaUploadedDocument;
        TLRPC.TL_document tL_document5;
        VideoEditedInfo videoEditedInfo5;
        boolean z5;
        TLRPC.InputMedia inputMedia3;
        boolean z6;
        TLRPC.InputMedia inputMedia4;
        int i4;
        VideoEditedInfo videoEditedInfo6;
        TLRPC.TL_photo tL_photo4 = tL_photo;
        TLRPC.TL_document tL_document6 = tL_document;
        if (messageObject == null) {
            return;
        }
        TLRPC.Message message = messageObject.messageOwner;
        messageObject.cancelEditing = false;
        try {
            long dialogId = messageObject.getDialogId();
            Object obj3 = "http";
            try {
                if (z) {
                    if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                        tL_photo4 = (TLRPC.TL_photo) messageObject.messageOwner.media.photo;
                        i4 = 2;
                        videoEditedInfo6 = videoEditedInfo;
                    } else {
                        tL_document6 = (TLRPC.TL_document) messageObject.messageOwner.media.document;
                        try {
                            if (!MessageObject.isVideoDocument(tL_document6) && videoEditedInfo == null) {
                                i4 = 7;
                                videoEditedInfo6 = messageObject.videoEditedInfo;
                            }
                            i4 = 3;
                            videoEditedInfo6 = messageObject.videoEditedInfo;
                        } catch (Exception e) {
                            e = e;
                            videoEditedInfo2 = videoEditedInfo;
                            hashMap2 = hashMap;
                            obj2 = tL_document6;
                            FileLog.e(e);
                            revertEditingMessageObject(messageObject);
                        }
                    }
                    try {
                        hashMap3 = message.params;
                    } catch (Exception e2) {
                        e = e2;
                        hashMap2 = hashMap;
                        obj2 = tL_document6;
                        videoEditedInfo2 = videoEditedInfo6;
                    }
                    try {
                        messageObject.editingMessage = message.message;
                        messageObject.editingMessageEntities = message.entities;
                        tL_photo2 = tL_photo4;
                        delayedMessage = null;
                        tL_document2 = tL_document6;
                        int i5 = i4;
                        str2 = message.attachPath;
                        i2 = i5;
                        videoEditedInfo3 = videoEditedInfo6;
                    } catch (Exception e3) {
                        e = e3;
                        obj2 = tL_document6;
                        hashMap2 = hashMap3;
                        videoEditedInfo2 = videoEditedInfo6;
                        FileLog.e(e);
                        revertEditingMessageObject(messageObject);
                    }
                } else {
                    messageObject.previousMedia = message.media;
                    messageObject.previousCaption = message.message;
                    messageObject.previousCaptionEntities = message.entities;
                    messageObject.previousAttachPath = message.attachPath;
                    SerializedData serializedData = new SerializedData(true);
                    writePreviousMessageData(message, serializedData);
                    SerializedData serializedData2 = new SerializedData(serializedData.length());
                    writePreviousMessageData(message, serializedData2);
                    HashMap<String, String> hashMap5 = hashMap == null ? new HashMap<>() : hashMap;
                    try {
                        delayedMessage = null;
                        hashMap5.put("prevMedia", Base64.encodeToString(serializedData2.toByteArray(), 0));
                        serializedData2.cleanup();
                        try {
                            if (tL_photo4 != null) {
                                message.media = new TLRPC.TL_messageMediaPhoto();
                                message.media.flags |= 3;
                                message.media.photo = tL_photo4;
                                i = 2;
                                if (str == null || str.length() <= 0 || !str.startsWith("http")) {
                                    r18 = 1;
                                    message.attachPath = FileLoader.getPathToAttach(tL_photo4.sizes.get(tL_photo4.sizes.size() - 1).location, true).toString();
                                } else {
                                    message.attachPath = str;
                                }
                            } else if (tL_document6 != null) {
                                message.media = new TLRPC.TL_messageMediaDocument();
                                message.media.flags |= 3;
                                message.media.document = tL_document6;
                                if (!MessageObject.isVideoDocument(tL_document) && videoEditedInfo == null) {
                                    i = 7;
                                    if (videoEditedInfo != null) {
                                        hashMap5.put("ve", videoEditedInfo.getString());
                                    }
                                    message.attachPath = str;
                                }
                                i = 3;
                                if (videoEditedInfo != null) {
                                }
                                message.attachPath = str;
                            } else {
                                i = -1;
                            }
                            message.params = hashMap5;
                            message.send_state = 3;
                            videoEditedInfo3 = videoEditedInfo;
                            tL_document2 = tL_document6;
                            hashMap3 = hashMap5;
                            tL_photo2 = tL_photo4;
                            int i6 = i;
                            str2 = str;
                            i2 = i6;
                        } catch (Exception e4) {
                            e = e4;
                            videoEditedInfo2 = videoEditedInfo;
                            obj2 = tL_document6;
                            hashMap2 = hashMap5;
                            FileLog.e(e);
                            revertEditingMessageObject(messageObject);
                        }
                    } catch (Exception e5) {
                        e = e5;
                        videoEditedInfo2 = videoEditedInfo;
                        obj2 = tL_document6;
                        hashMap2 = hashMap5;
                    }
                }
                try {
                    if (message.attachPath == null) {
                        try {
                            message.attachPath = "";
                        } catch (Exception e6) {
                            e = e6;
                            hashMap2 = hashMap3;
                            obj2 = tL_document2;
                            videoEditedInfo2 = videoEditedInfo3;
                            FileLog.e(e);
                            revertEditingMessageObject(messageObject);
                        }
                    }
                    message.local_id = 0;
                    if ((messageObject.type == 3 || videoEditedInfo3 != null || messageObject.type == 2) && !TextUtils.isEmpty(message.attachPath)) {
                        messageObject.attachPathExists = true;
                    }
                    videoEditedInfo3 = videoEditedInfo3;
                    videoEditedInfo3 = videoEditedInfo3;
                    if (messageObject.videoEditedInfo != null && videoEditedInfo3 == null) {
                        videoEditedInfo3 = messageObject.videoEditedInfo;
                    }
                    if (z) {
                        tL_document3 = tL_document2;
                        videoEditedInfo4 = videoEditedInfo3;
                        r8 = videoEditedInfo3;
                    } else {
                        try {
                            if (messageObject.editingMessage != null) {
                                message.message = messageObject.editingMessage.toString();
                                if (messageObject.editingMessageEntities != null) {
                                    message.entities = messageObject.editingMessageEntities;
                                } else {
                                    ArrayList<TLRPC.MessageEntity> entities = getMediaDataController().getEntities(new CharSequence[]{messageObject.editingMessage});
                                    if (entities != null && !entities.isEmpty()) {
                                        message.entities = entities;
                                    }
                                }
                                messageObject.caption = null;
                                messageObject.generateCaption();
                            }
                            ArrayList<TLRPC.Message> arrayList = new ArrayList<>();
                            arrayList.add(message);
                            getMessagesStorage().putMessages(arrayList, false, true, false, 0, messageObject.scheduled);
                            messageObject.type = -1;
                            messageObject.setType();
                            messageObject.createMessageSendInfo();
                            ArrayList arrayList2 = new ArrayList();
                            arrayList2.add(messageObject);
                            try {
                                tL_document3 = tL_document2;
                                videoEditedInfo4 = videoEditedInfo3;
                            } catch (Exception e7) {
                                e = e7;
                                hashMap2 = hashMap3;
                                obj2 = tL_document2;
                                videoEditedInfo2 = videoEditedInfo3;
                                FileLog.e(e);
                                revertEditingMessageObject(messageObject);
                            }
                            try {
                                hashMap4 = null;
                                r8 = 1;
                                getNotificationCenter().postNotificationName(NotificationCenter.replaceMessagesObjects, Long.valueOf(dialogId), arrayList2);
                            } catch (Exception e8) {
                                e = e8;
                                hashMap2 = hashMap3;
                                obj2 = tL_document3;
                                videoEditedInfo2 = videoEditedInfo4;
                                FileLog.e(e);
                                revertEditingMessageObject(messageObject);
                            }
                        } catch (Exception e9) {
                            e = e9;
                            hashMap2 = hashMap3;
                            obj2 = tL_document2;
                            videoEditedInfo2 = videoEditedInfo3;
                        }
                    }
                    String str4 = (hashMap3 == null || !hashMap3.containsKey("originalPath")) ? null : hashMap3.get("originalPath");
                    if ((i2 < 1 || i2 > 3) && (i2 < 5 || i2 > 8)) {
                        hashMap4 = hashMap3;
                        r18 = str2;
                        r1 = tL_photo2;
                        r22 = tL_document3;
                        videoEditedInfo2 = videoEditedInfo4;
                    } else {
                        r22 = 0;
                        if (i2 == 2) {
                            try {
                                TLRPC.TL_inputMediaUploadedPhoto tL_inputMediaUploadedPhoto = new TLRPC.TL_inputMediaUploadedPhoto();
                                if (hashMap3 != null) {
                                    String str5 = hashMap3.get("masks");
                                    if (str5 != null) {
                                        z2 = false;
                                        SerializedData serializedData3 = new SerializedData(Utilities.hexToBytes(str5));
                                        int i7 = 0;
                                        for (int readInt32 = serializedData3.readInt32(false); i7 < readInt32; readInt32 = readInt32) {
                                            hashMap2 = hashMap3;
                                            try {
                                                tL_inputMediaUploadedPhoto.stickers.add(TLRPC.InputDocument.TLdeserialize(serializedData3, serializedData3.readInt32(false), false));
                                                i7++;
                                                hashMap3 = hashMap2;
                                                str5 = str5;
                                            } catch (Exception e10) {
                                                e = e10;
                                                obj2 = tL_document3;
                                                videoEditedInfo2 = videoEditedInfo4;
                                                FileLog.e(e);
                                                revertEditingMessageObject(messageObject);
                                            }
                                        }
                                        hashMap2 = hashMap3;
                                        tL_inputMediaUploadedPhoto.flags |= 1;
                                        serializedData3.cleanup();
                                    } else {
                                        z2 = false;
                                        hashMap2 = hashMap3;
                                    }
                                } else {
                                    z2 = false;
                                    hashMap2 = hashMap3;
                                }
                                if (tL_photo2.access_hash == 0) {
                                    i3 = i2;
                                    inputMedia = tL_inputMediaUploadedPhoto;
                                    z3 = true;
                                } else {
                                    ?? tL_inputMediaPhoto = new TLRPC.TL_inputMediaPhoto();
                                    tL_inputMediaPhoto.id = new TLRPC.TL_inputPhoto();
                                    i3 = i2;
                                    tL_inputMediaPhoto.id.id = tL_photo2.id;
                                    tL_inputMediaPhoto.id.access_hash = tL_photo2.access_hash;
                                    tL_inputMediaPhoto.id.file_reference = tL_photo2.file_reference;
                                    if (tL_inputMediaPhoto.id.file_reference == null) {
                                        tL_inputMediaPhoto.id.file_reference = new byte[0];
                                    }
                                    inputMedia = tL_inputMediaPhoto;
                                    z3 = z2;
                                }
                                DelayedMessage delayedMessage3 = new DelayedMessage(dialogId);
                                delayedMessage3.type = 0;
                                delayedMessage3.obj = messageObject;
                                delayedMessage3.originalPath = str4;
                                delayedMessage3.parentObject = obj;
                                delayedMessage3.inputUploadMedia = tL_inputMediaUploadedPhoto;
                                delayedMessage3.performMediaUpload = z3;
                                if (str2 == null || str2.length() <= 0 || !str2.startsWith("http")) {
                                    delayedMessage3.photoSize = tL_photo2.sizes.get(tL_photo2.sizes.size() - 1);
                                    delayedMessage3.locationParent = tL_photo2;
                                } else {
                                    delayedMessage3.httpLocation = str2;
                                }
                                z4 = z3;
                                delayedMessage2 = delayedMessage3;
                                tL_photo3 = tL_photo2;
                                tL_document4 = tL_document3;
                                videoEditedInfo2 = videoEditedInfo4;
                                inputMedia2 = inputMedia;
                                str3 = str2;
                            } catch (Exception e11) {
                                e = e11;
                                hashMap2 = hashMap3;
                                obj2 = tL_document3;
                                videoEditedInfo2 = videoEditedInfo4;
                            }
                        } else {
                            z4 = false;
                            i3 = i2;
                            hashMap2 = hashMap3;
                            try {
                                if (i3 == 3) {
                                    try {
                                        tL_inputMediaUploadedDocument = new TLRPC.TL_inputMediaUploadedDocument();
                                        tL_document5 = tL_document3;
                                        try {
                                            tL_inputMediaUploadedDocument.mime_type = tL_document5.mime_type;
                                            tL_inputMediaUploadedDocument.attributes = tL_document5.attributes;
                                            if (messageObject.isGif()) {
                                                videoEditedInfo5 = videoEditedInfo4;
                                            } else {
                                                if (videoEditedInfo4 != null) {
                                                    videoEditedInfo5 = videoEditedInfo4;
                                                    try {
                                                        if (!videoEditedInfo5.muted) {
                                                        }
                                                    } catch (Exception e12) {
                                                        e = e12;
                                                        videoEditedInfo2 = videoEditedInfo5;
                                                        obj2 = tL_document5;
                                                        FileLog.e(e);
                                                        revertEditingMessageObject(messageObject);
                                                    }
                                                } else {
                                                    videoEditedInfo5 = videoEditedInfo4;
                                                }
                                                tL_inputMediaUploadedDocument.nosound_video = true;
                                                if (BuildVars.DEBUG_VERSION) {
                                                    FileLog.d("nosound_video = true");
                                                }
                                            }
                                        } catch (Exception e13) {
                                            e = e13;
                                            videoEditedInfo2 = videoEditedInfo4;
                                            obj2 = tL_document5;
                                        }
                                    } catch (Exception e14) {
                                        e = e14;
                                        obj2 = tL_document3;
                                        videoEditedInfo2 = videoEditedInfo4;
                                    }
                                    try {
                                        if (tL_document5.access_hash == 0) {
                                            inputMedia3 = tL_inputMediaUploadedDocument;
                                            z5 = true;
                                            str3 = str2;
                                        } else {
                                            ?? tL_inputMediaDocument = new TLRPC.TL_inputMediaDocument();
                                            tL_inputMediaDocument.id = new TLRPC.TL_inputDocument();
                                            str3 = str2;
                                            tL_inputMediaDocument.id.id = tL_document5.id;
                                            tL_inputMediaDocument.id.access_hash = tL_document5.access_hash;
                                            tL_inputMediaDocument.id.file_reference = tL_document5.file_reference;
                                            if (tL_inputMediaDocument.id.file_reference == null) {
                                                tL_inputMediaDocument.id.file_reference = new byte[0];
                                            }
                                            z5 = false;
                                            inputMedia3 = tL_inputMediaDocument;
                                        }
                                        DelayedMessage delayedMessage4 = new DelayedMessage(dialogId);
                                        delayedMessage4.type = 1;
                                        delayedMessage4.obj = messageObject;
                                        delayedMessage4.originalPath = str4;
                                        delayedMessage4.parentObject = obj;
                                        delayedMessage4.inputUploadMedia = tL_inputMediaUploadedDocument;
                                        delayedMessage4.performMediaUpload = z5;
                                        if (!tL_document5.thumbs.isEmpty()) {
                                            delayedMessage4.photoSize = tL_document5.thumbs.get(0);
                                            delayedMessage4.locationParent = tL_document5;
                                        }
                                        delayedMessage4.videoEditedInfo = videoEditedInfo5;
                                        z4 = z5;
                                        videoEditedInfo2 = videoEditedInfo5;
                                        tL_photo3 = tL_photo2;
                                        inputMedia2 = inputMedia3;
                                        delayedMessage2 = delayedMessage4;
                                        tL_document4 = tL_document5;
                                    } catch (Exception e15) {
                                        e = e15;
                                        videoEditedInfo2 = videoEditedInfo5;
                                        obj2 = tL_document5;
                                        FileLog.e(e);
                                        revertEditingMessageObject(messageObject);
                                    }
                                } else {
                                    VideoEditedInfo videoEditedInfo7 = videoEditedInfo4;
                                    str3 = str2;
                                    tL_document4 = tL_document3;
                                    if (i3 == 7) {
                                        try {
                                            TLRPC.InputMedia tL_inputMediaUploadedDocument2 = new TLRPC.TL_inputMediaUploadedDocument();
                                            tL_inputMediaUploadedDocument2.mime_type = tL_document4.mime_type;
                                            tL_inputMediaUploadedDocument2.attributes = tL_document4.attributes;
                                            if (tL_document4.access_hash == 0) {
                                                inputMedia4 = tL_inputMediaUploadedDocument2;
                                                z6 = tL_inputMediaUploadedDocument2 instanceof TLRPC.TL_inputMediaUploadedDocument;
                                                videoEditedInfo2 = videoEditedInfo7;
                                                tL_photo3 = tL_photo2;
                                            } else {
                                                TLRPC.TL_inputMediaDocument tL_inputMediaDocument2 = new TLRPC.TL_inputMediaDocument();
                                                tL_inputMediaDocument2.id = new TLRPC.TL_inputDocument();
                                                videoEditedInfo2 = videoEditedInfo7;
                                                tL_photo3 = tL_photo2;
                                                try {
                                                    tL_inputMediaDocument2.id.id = tL_document4.id;
                                                    tL_inputMediaDocument2.id.access_hash = tL_document4.access_hash;
                                                    tL_inputMediaDocument2.id.file_reference = tL_document4.file_reference;
                                                    if (tL_inputMediaDocument2.id.file_reference == null) {
                                                        tL_inputMediaDocument2.id.file_reference = new byte[0];
                                                    }
                                                    z6 = false;
                                                    inputMedia4 = tL_inputMediaDocument2;
                                                } catch (Exception e16) {
                                                    e = e16;
                                                    obj2 = tL_document4;
                                                    FileLog.e(e);
                                                    revertEditingMessageObject(messageObject);
                                                }
                                            }
                                            if (0 == 0) {
                                                DelayedMessage delayedMessage5 = new DelayedMessage(dialogId);
                                                delayedMessage5.originalPath = str4;
                                                delayedMessage5.type = 2;
                                                delayedMessage5.obj = messageObject;
                                                if (!tL_document4.thumbs.isEmpty()) {
                                                    delayedMessage5.photoSize = tL_document4.thumbs.get(0);
                                                    delayedMessage5.locationParent = tL_document4;
                                                }
                                                delayedMessage5.parentObject = obj;
                                                delayedMessage5.inputUploadMedia = tL_inputMediaUploadedDocument2;
                                                delayedMessage5.performMediaUpload = z6;
                                                inputMedia2 = inputMedia4;
                                                z4 = z6;
                                                delayedMessage2 = delayedMessage5;
                                                tL_document4 = tL_document4;
                                            } else {
                                                inputMedia2 = inputMedia4;
                                                z4 = z6;
                                                delayedMessage2 = delayedMessage;
                                                tL_document4 = tL_document4;
                                            }
                                        } catch (Exception e17) {
                                            e = e17;
                                            videoEditedInfo2 = videoEditedInfo7;
                                            obj2 = tL_document4;
                                            FileLog.e(e);
                                            revertEditingMessageObject(messageObject);
                                        }
                                    } else {
                                        videoEditedInfo2 = videoEditedInfo7;
                                        tL_photo3 = tL_photo2;
                                        delayedMessage2 = delayedMessage;
                                        inputMedia2 = null;
                                        tL_document4 = tL_document4;
                                    }
                                }
                            } catch (Exception e18) {
                                e = e18;
                                videoEditedInfo2 = r8;
                                obj2 = obj3;
                            }
                        }
                        try {
                            TLRPC.TL_messages_editMessage tL_messages_editMessage = new TLRPC.TL_messages_editMessage();
                            tL_messages_editMessage.id = messageObject.getId();
                            tL_messages_editMessage.peer = getMessagesController().getInputPeer((int) dialogId);
                            tL_messages_editMessage.flags |= 16384;
                            tL_messages_editMessage.media = inputMedia2;
                            if (messageObject.scheduled) {
                                tL_messages_editMessage.schedule_date = messageObject.messageOwner.date;
                                tL_messages_editMessage.flags |= 32768;
                            }
                            if (messageObject.editingMessage != null) {
                                tL_messages_editMessage.message = messageObject.editingMessage.toString();
                                tL_messages_editMessage.flags |= 2048;
                                if (messageObject.editingMessageEntities != null) {
                                    tL_messages_editMessage.entities = messageObject.editingMessageEntities;
                                    tL_messages_editMessage.flags |= 8;
                                } else {
                                    ArrayList<TLRPC.MessageEntity> entities2 = getMediaDataController().getEntities(new CharSequence[]{messageObject.editingMessage});
                                    if (entities2 != null && !entities2.isEmpty()) {
                                        tL_messages_editMessage.entities = entities2;
                                        tL_messages_editMessage.flags |= 8;
                                    }
                                }
                                messageObject.editingMessage = null;
                                messageObject.editingMessageEntities = null;
                            }
                            if (delayedMessage2 != null) {
                                delayedMessage2.sendRequest = tL_messages_editMessage;
                            }
                            r1 = 2;
                            try {
                                if (i3 == 1) {
                                    try {
                                        hashMap4 = hashMap2;
                                        r18 = str3;
                                        r22 = tL_document4;
                                        performSendMessageRequest(tL_messages_editMessage, messageObject, null, delayedMessage2, obj, messageObject.scheduled);
                                        r1 = tL_photo3;
                                    } catch (Exception e19) {
                                        e = e19;
                                        obj2 = tL_document4;
                                        FileLog.e(e);
                                        revertEditingMessageObject(messageObject);
                                    }
                                } else {
                                    r18 = str3;
                                    int i8 = i3;
                                    r22 = tL_document4;
                                    hashMap4 = hashMap2;
                                    try {
                                        if (i8 != 2) {
                                            DelayedMessage delayedMessage6 = delayedMessage2;
                                            r1 = tL_photo3;
                                            if (i8 == 3) {
                                                if (z4) {
                                                    performSendDelayedMessage(delayedMessage6);
                                                    r1 = r1;
                                                } else {
                                                    performSendMessageRequest(tL_messages_editMessage, messageObject, str4, delayedMessage6, obj, messageObject.scheduled);
                                                    r1 = r1;
                                                }
                                            } else if (i8 == 6) {
                                                performSendMessageRequest(tL_messages_editMessage, messageObject, str4, delayedMessage6, obj, messageObject.scheduled);
                                                r1 = r1;
                                            } else if (i8 == 7) {
                                                if (z4) {
                                                    performSendDelayedMessage(delayedMessage6);
                                                    r1 = r1;
                                                } else {
                                                    performSendMessageRequest(tL_messages_editMessage, messageObject, str4, delayedMessage6, obj, messageObject.scheduled);
                                                    r1 = r1;
                                                }
                                            } else if (i8 == 8) {
                                                if (z4) {
                                                    performSendDelayedMessage(delayedMessage6);
                                                    r1 = r1;
                                                } else {
                                                    performSendMessageRequest(tL_messages_editMessage, messageObject, str4, delayedMessage6, obj, messageObject.scheduled);
                                                    r1 = r1;
                                                }
                                            }
                                        } else if (z4) {
                                            performSendDelayedMessage(delayedMessage2);
                                            r1 = tL_photo3;
                                            r18 = r18;
                                            r22 = r22;
                                        } else {
                                            try {
                                                r1 = tL_photo3;
                                                performSendMessageRequest(tL_messages_editMessage, messageObject, str4, null, true, delayedMessage2, obj, messageObject.scheduled);
                                            } catch (Exception e20) {
                                                e = e20;
                                                hashMap2 = hashMap4;
                                                obj2 = r22;
                                                FileLog.e(e);
                                                revertEditingMessageObject(messageObject);
                                            }
                                        }
                                    } catch (Exception e21) {
                                        e = e21;
                                        hashMap2 = hashMap4;
                                        obj2 = r22;
                                    }
                                }
                            } catch (Exception e22) {
                                e = e22;
                                hashMap2 = hashMap4;
                                obj2 = r22;
                            }
                        } catch (Exception e23) {
                            e = e23;
                            obj2 = tL_document4;
                        }
                    }
                } catch (Exception e24) {
                    e = e24;
                    videoEditedInfo2 = videoEditedInfo3;
                    hashMap2 = hashMap3;
                    obj2 = tL_document2;
                }
            } catch (Exception e25) {
                e = e25;
                videoEditedInfo2 = videoEditedInfo;
                hashMap2 = hashMap;
                obj2 = tL_document6;
            }
        } catch (Exception e26) {
            e = e26;
            videoEditedInfo2 = videoEditedInfo;
            hashMap2 = hashMap;
            obj2 = tL_document6;
        }
    }

    public int editMessage(MessageObject messageObject, String message, boolean searchLinks, final BaseFragment fragment, ArrayList<TLRPC.MessageEntity> entities, int scheduleDate, final Runnable callback) {
        if (fragment == null || fragment.getParentActivity() == null) {
            return 0;
        }
        final TLRPC.TL_messages_editMessage req = new TLRPC.TL_messages_editMessage();
        req.peer = getMessagesController().getInputPeer((int) messageObject.getDialogId());
        if (message != null) {
            req.message = message;
            req.flags |= 2048;
            req.no_webpage = !searchLinks;
        }
        req.id = messageObject.getId();
        if (entities != null) {
            req.entities = entities;
            req.flags |= 8;
        }
        if (scheduleDate != 0) {
            req.schedule_date = scheduleDate;
            req.flags |= 32768;
        }
        return getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                SendMessagesHelper.this.lambda$editMessage$11$SendMessagesHelper(fragment, req, callback, tLObject, tL_error);
            }
        });
    }

    public void lambda$editMessage$11$SendMessagesHelper(final BaseFragment fragment, final TLRPC.TL_messages_editMessage req, Runnable callback, TLObject response, final TLRPC.TL_error error) {
        if (error == null) {
            getMessagesController().processUpdates((TLRPC.Updates) response, false);
        } else {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    SendMessagesHelper.this.lambda$null$10$SendMessagesHelper(error, fragment, req);
                }
            });
        }
        if (callback != null) {
            AndroidUtilities.runOnUIThread(callback);
        }
    }

    public void lambda$null$10$SendMessagesHelper(TLRPC.TL_error error, BaseFragment fragment, TLRPC.TL_messages_editMessage req) {
        AlertsCreator.processError(this.currentAccount, error, fragment, req, new Object[0]);
    }

    public void sendLocation(Location location) {
        TLRPC.TL_messageMediaGeo mediaGeo = new TLRPC.TL_messageMediaGeo();
        mediaGeo.geo = new TLRPC.TL_geoPoint();
        mediaGeo.geo.lat = AndroidUtilities.fixLocationCoord(location.getLatitude());
        mediaGeo.geo._long = AndroidUtilities.fixLocationCoord(location.getLongitude());
        for (Map.Entry<String, MessageObject> entry : this.waitingForLocation.entrySet()) {
            MessageObject messageObject = entry.getValue();
            sendMessage((TLRPC.MessageMedia) mediaGeo, messageObject.getDialogId(), messageObject, (TLRPC.ReplyMarkup) null, (HashMap<String, String>) null, true, 0);
        }
    }

    public void sendCurrentLocation(MessageObject messageObject, TLRPC.KeyboardButton button) {
        if (messageObject == null || button == null) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        sb.append(messageObject.getDialogId());
        sb.append("_");
        sb.append(messageObject.getId());
        sb.append("_");
        sb.append(Utilities.bytesToHex(button.data));
        sb.append("_");
        sb.append(button instanceof TLRPC.TL_keyboardButtonGame ? "1" : "0");
        String key = sb.toString();
        this.waitingForLocation.put(key, messageObject);
        this.locationProvider.start();
    }

    public boolean isSendingCurrentLocation(MessageObject messageObject, TLRPC.KeyboardButton button) {
        if (messageObject == null || button == null) {
            return false;
        }
        StringBuilder sb = new StringBuilder();
        sb.append(messageObject.getDialogId());
        sb.append("_");
        sb.append(messageObject.getId());
        sb.append("_");
        sb.append(Utilities.bytesToHex(button.data));
        sb.append("_");
        sb.append(button instanceof TLRPC.TL_keyboardButtonGame ? "1" : "0");
        String key = sb.toString();
        return this.waitingForLocation.containsKey(key);
    }

    public void sendNotificationCallback(final long dialogId, final int msgId, final byte[] data) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$sendNotificationCallback$14$SendMessagesHelper(dialogId, msgId, data);
            }
        });
    }

    public void lambda$sendNotificationCallback$14$SendMessagesHelper(long dialogId, int msgId, byte[] data) {
        TLRPC.Chat chat;
        TLRPC.User user;
        int lowerId = (int) dialogId;
        final String key = dialogId + "_" + msgId + "_" + Utilities.bytesToHex(data) + "_0";
        this.waitingForCallback.put(key, true);
        if (lowerId > 0) {
            if (getMessagesController().getUser(Integer.valueOf(lowerId)) == null && (user = getMessagesStorage().getUserSync(lowerId)) != null) {
                getMessagesController().putUser(user, true);
            }
        } else if (getMessagesController().getChat(Integer.valueOf(-lowerId)) == null && (chat = getMessagesStorage().getChatSync(-lowerId)) != null) {
            getMessagesController().putChat(chat, true);
        }
        TLRPC.TL_messages_getBotCallbackAnswer req = new TLRPC.TL_messages_getBotCallbackAnswer();
        req.peer = getMessagesController().getInputPeer(lowerId);
        req.msg_id = msgId;
        req.game = false;
        if (data != null) {
            req.flags |= 1;
            req.data = data;
        }
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                SendMessagesHelper.this.lambda$null$13$SendMessagesHelper(key, tLObject, tL_error);
            }
        }, 2);
        getMessagesController().markDialogAsRead(dialogId, msgId, msgId, 0, false, 0, true, 0);
    }

    public void lambda$null$12$SendMessagesHelper(String key) {
        this.waitingForCallback.remove(key);
    }

    public void lambda$null$13$SendMessagesHelper(final String key, TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$null$12$SendMessagesHelper(key);
            }
        });
    }

    public byte[] isSendingVote(MessageObject messageObject) {
        if (messageObject == null) {
            return null;
        }
        String key = "poll_" + messageObject.getPollId();
        return this.waitingForVote.get(key);
    }

    public int sendVote(final MessageObject messageObject, TLRPC.TL_pollAnswer answer, final Runnable finishRunnable) {
        if (messageObject == null) {
            return 0;
        }
        final String key = "poll_" + messageObject.getPollId();
        if (this.waitingForCallback.containsKey(key)) {
            return 0;
        }
        this.waitingForVote.put(key, answer != null ? answer.option : new byte[0]);
        TLRPC.TL_messages_sendVote req = new TLRPC.TL_messages_sendVote();
        req.msg_id = messageObject.getId();
        req.peer = getMessagesController().getInputPeer((int) messageObject.getDialogId());
        if (answer != null) {
            req.options.add(answer.option);
        }
        return getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                SendMessagesHelper.this.lambda$sendVote$15$SendMessagesHelper(messageObject, key, finishRunnable, tLObject, tL_error);
            }
        });
    }

    public void lambda$sendVote$15$SendMessagesHelper(MessageObject messageObject, final String key, final Runnable finishRunnable, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            this.voteSendTime.put(messageObject.getPollId(), 0L);
            getMessagesController().processUpdates((TLRPC.Updates) response, false);
            this.voteSendTime.put(messageObject.getPollId(), Long.valueOf(SystemClock.uptimeMillis()));
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public void run() {
                SendMessagesHelper.this.waitingForVote.remove(key);
                Runnable runnable = finishRunnable;
                if (runnable != null) {
                    runnable.run();
                }
            }
        });
    }

    public long getVoteSendTime(long pollId) {
        return this.voteSendTime.get(pollId, 0L).longValue();
    }

    public void sendReaction(MessageObject messageObject, CharSequence reaction, ChatActivity parentFragment) {
        if (messageObject == null || parentFragment == null) {
            return;
        }
        TLRPC.TL_messages_sendReaction req = new TLRPC.TL_messages_sendReaction();
        req.peer = getMessagesController().getInputPeer((int) messageObject.getDialogId());
        req.msg_id = messageObject.getId();
        if (reaction != null) {
            req.reaction = reaction.toString();
            req.flags |= 1;
        }
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                SendMessagesHelper.this.lambda$sendReaction$16$SendMessagesHelper(tLObject, tL_error);
            }
        });
    }

    public void lambda$sendReaction$16$SendMessagesHelper(TLObject response, TLRPC.TL_error error) {
        if (response != null) {
            getMessagesController().processUpdates((TLRPC.Updates) response, false);
        }
    }

    public void sendCallback(boolean cache, final MessageObject messageObject, final TLRPC.KeyboardButton button, final ChatActivity parentFragment) {
        boolean cacheFinal;
        int type;
        if (messageObject == null || button == null) {
            return;
        }
        if (parentFragment == null) {
            return;
        }
        if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
            cacheFinal = false;
            type = 3;
        } else {
            boolean cacheFinal2 = button instanceof TLRPC.TL_keyboardButtonGame;
            if (cacheFinal2) {
                cacheFinal = false;
                type = 1;
            } else if (button instanceof TLRPC.TL_keyboardButtonBuy) {
                cacheFinal = cache;
                type = 2;
            } else {
                cacheFinal = cache;
                type = 0;
            }
        }
        final String key = messageObject.getDialogId() + "_" + messageObject.getId() + "_" + Utilities.bytesToHex(button.data) + "_" + type;
        this.waitingForCallback.put(key, true);
        final TLObject[] request = new TLObject[1];
        final boolean z = cacheFinal;
        RequestDelegate requestDelegate = new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                SendMessagesHelper.this.lambda$sendCallback$18$SendMessagesHelper(key, z, messageObject, button, parentFragment, request, tLObject, tL_error);
            }
        };
        if (cacheFinal) {
            getMessagesStorage().getBotCache(key, requestDelegate);
            return;
        }
        if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
            TLRPC.TL_messages_requestUrlAuth req = new TLRPC.TL_messages_requestUrlAuth();
            req.peer = getMessagesController().getInputPeer((int) messageObject.getDialogId());
            req.msg_id = messageObject.getId();
            req.button_id = button.button_id;
            request[0] = req;
            getConnectionsManager().sendRequest(req, requestDelegate, 2);
            return;
        }
        if (button instanceof TLRPC.TL_keyboardButtonBuy) {
            if ((messageObject.messageOwner.media.flags & 4) == 0) {
                TLRPC.TL_payments_getPaymentForm req2 = new TLRPC.TL_payments_getPaymentForm();
                req2.msg_id = messageObject.getId();
                getConnectionsManager().sendRequest(req2, requestDelegate, 2);
                return;
            } else {
                TLRPC.TL_payments_getPaymentReceipt req3 = new TLRPC.TL_payments_getPaymentReceipt();
                req3.msg_id = messageObject.messageOwner.media.receipt_msg_id;
                getConnectionsManager().sendRequest(req3, requestDelegate, 2);
                return;
            }
        }
        TLRPC.TL_messages_getBotCallbackAnswer req4 = new TLRPC.TL_messages_getBotCallbackAnswer();
        req4.peer = getMessagesController().getInputPeer((int) messageObject.getDialogId());
        req4.msg_id = messageObject.getId();
        req4.game = button instanceof TLRPC.TL_keyboardButtonGame;
        if (button.data != null) {
            req4.flags |= 1;
            req4.data = button.data;
        }
        getConnectionsManager().sendRequest(req4, requestDelegate, 2);
    }

    public void lambda$sendCallback$18$SendMessagesHelper(final String key, final boolean cacheFinal, final MessageObject messageObject, final TLRPC.KeyboardButton button, final ChatActivity parentFragment, final TLObject[] request, final TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$null$17$SendMessagesHelper(key, cacheFinal, response, messageObject, button, parentFragment, request);
            }
        });
    }

    public void lambda$null$17$SendMessagesHelper(String key, boolean cacheFinal, TLObject response, MessageObject messageObject, TLRPC.KeyboardButton button, ChatActivity parentFragment, TLObject[] request) {
        int uid;
        boolean z;
        this.waitingForCallback.remove(key);
        if (cacheFinal && response == null) {
            sendCallback(false, messageObject, button, parentFragment);
            return;
        }
        if (response != null) {
            if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
                if (response instanceof TLRPC.TL_urlAuthResultRequest) {
                    parentFragment.showRequestUrlAlert((TLRPC.TL_urlAuthResultRequest) response, (TLRPC.TL_messages_requestUrlAuth) request[0], button.url);
                    return;
                }
                if (response instanceof TLRPC.TL_urlAuthResultAccepted) {
                    parentFragment.showOpenUrlAlert(((TLRPC.TL_urlAuthResultAccepted) response).url, false);
                    return;
                } else {
                    if (response instanceof TLRPC.TL_urlAuthResultDefault) {
                        parentFragment.showOpenUrlAlert(button.url, true);
                        return;
                    }
                    return;
                }
            }
            if (button instanceof TLRPC.TL_keyboardButtonBuy) {
                if (response instanceof TLRPC.TL_payments_paymentForm) {
                    TLRPC.TL_payments_paymentForm form = (TLRPC.TL_payments_paymentForm) response;
                    getMessagesController().putUsers(form.users, false);
                    return;
                } else {
                    boolean z2 = response instanceof TLRPC.TL_payments_paymentReceipt;
                    return;
                }
            }
            TLRPC.TL_messages_botCallbackAnswer res = (TLRPC.TL_messages_botCallbackAnswer) response;
            if (!cacheFinal && res.cache_time != 0) {
                getMessagesStorage().saveBotCache(key, res);
            }
            if (res.message != null) {
                int uid2 = messageObject.messageOwner.from_id;
                if (messageObject.messageOwner.via_bot_id != 0) {
                    uid2 = messageObject.messageOwner.via_bot_id;
                }
                String name = null;
                if (uid2 > 0) {
                    TLRPC.User user = getMessagesController().getUser(Integer.valueOf(uid2));
                    if (user != null) {
                        name = ContactsController.formatName(user.first_name, user.last_name);
                    }
                } else {
                    TLRPC.Chat chat = getMessagesController().getChat(Integer.valueOf(-uid2));
                    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());
                    return;
                }
                parentFragment.showAlert(name, res.message);
                return;
            }
            if (res.url == null || parentFragment.getParentActivity() == null) {
                return;
            }
            int uid3 = messageObject.messageOwner.from_id;
            if (messageObject.messageOwner.via_bot_id == 0) {
                uid = uid3;
            } else {
                int uid4 = messageObject.messageOwner.via_bot_id;
                uid = uid4;
            }
            TLRPC.User user2 = getMessagesController().getUser(Integer.valueOf(uid));
            boolean verified = user2 != null && user2.verified;
            if (!(button instanceof TLRPC.TL_keyboardButtonGame)) {
                parentFragment.showOpenUrlAlert(res.url, false);
                return;
            }
            TLRPC.TL_game game = messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame ? messageObject.messageOwner.media.game : null;
            if (game == null) {
                return;
            }
            String str = res.url;
            if (!verified) {
                if (MessagesController.getNotificationsSettings(this.currentAccount).getBoolean("askgame_" + uid, true)) {
                    z = true;
                    parentFragment.showOpenGameAlert(game, messageObject, str, z, uid);
                }
            }
            z = false;
            parentFragment.showOpenGameAlert(game, messageObject, str, z, uid);
        }
    }

    public boolean isSendingCallback(MessageObject messageObject, TLRPC.KeyboardButton button) {
        int type;
        if (messageObject == null || button == null) {
            return false;
        }
        if (button instanceof TLRPC.TL_keyboardButtonUrlAuth) {
            type = 3;
        } else if (button instanceof TLRPC.TL_keyboardButtonGame) {
            type = 1;
        } else if (button instanceof TLRPC.TL_keyboardButtonBuy) {
            type = 2;
        } else {
            type = 0;
        }
        String key = messageObject.getDialogId() + "_" + messageObject.getId() + "_" + Utilities.bytesToHex(button.data) + "_" + type;
        return this.waitingForCallback.containsKey(key);
    }

    public void sendEditMessageMedia(TLRPC.InputPeer peer, int id, TLRPC.InputMedia media) {
        if (peer == null) {
            return;
        }
        TLRPCContacts.TL_EditMessageMedia request = new TLRPCContacts.TL_EditMessageMedia();
        request.peer = peer;
        request.id = id;
        request.media = media;
        getConnectionsManager().sendRequest(request, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                SendMessagesHelper.this.lambda$sendEditMessageMedia$19$SendMessagesHelper(tLObject, tL_error);
            }
        });
    }

    public void lambda$sendEditMessageMedia$19$SendMessagesHelper(TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            getMessagesController().processUpdates((TLRPC.Updates) response, false);
        }
    }

    public void sendGame(TLRPC.InputPeer peer, TLRPC.TL_inputMediaGame game, long random_id, long taskId) {
        final long newTaskId;
        if (peer == null || game == null) {
            return;
        }
        TLRPC.TL_messages_sendMedia request = new TLRPC.TL_messages_sendMedia();
        request.peer = peer;
        if (request.peer instanceof TLRPC.TL_inputPeerChannel) {
            request.silent = MessagesController.getNotificationsSettings(this.currentAccount).getBoolean("silent_" + (-peer.channel_id), false);
        } else if (request.peer instanceof TLRPC.TL_inputPeerChat) {
            request.silent = MessagesController.getNotificationsSettings(this.currentAccount).getBoolean("silent_" + (-peer.chat_id), false);
        } else {
            request.silent = MessagesController.getNotificationsSettings(this.currentAccount).getBoolean("silent_" + peer.user_id, false);
        }
        request.random_id = random_id != 0 ? random_id : getNextRandomId();
        request.message = "";
        request.media = game;
        if (taskId == 0) {
            NativeByteBuffer data = null;
            try {
                data = new NativeByteBuffer(peer.getObjectSize() + game.getObjectSize() + 4 + 8);
                data.writeInt32(3);
                data.writeInt64(random_id);
                peer.serializeToStream(data);
                game.serializeToStream(data);
            } catch (Exception e) {
                FileLog.e(e);
            }
            newTaskId = getMessagesStorage().createPendingTask(data);
        } else {
            newTaskId = taskId;
        }
        getConnectionsManager().sendRequest(request, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                SendMessagesHelper.this.lambda$sendGame$20$SendMessagesHelper(newTaskId, tLObject, tL_error);
            }
        });
    }

    public void lambda$sendGame$20$SendMessagesHelper(long newTaskId, TLObject response, TLRPC.TL_error error) {
        if (error == null) {
            getMessagesController().processUpdates((TLRPC.Updates) response, false);
        }
        if (newTaskId != 0) {
            getMessagesStorage().removePendingTask(newTaskId);
        }
    }

    public void sendMessage(MessageObject retryMessageObject) {
        sendMessage(null, null, null, null, null, null, null, null, null, retryMessageObject.getDialogId(), retryMessageObject.messageOwner.attachPath, null, null, true, retryMessageObject, null, retryMessageObject.messageOwner.reply_markup, retryMessageObject.messageOwner.params, !retryMessageObject.messageOwner.silent, retryMessageObject.scheduled ? retryMessageObject.messageOwner.date : 0, 0, null);
    }

    public void sendMessage(TLRPC.User user, long peer, MessageObject reply_to_msg, TLRPC.ReplyMarkup replyMarkup, HashMap<String, String> params, boolean notify, int scheduleDate) {
        sendMessage(null, null, null, null, null, user, null, null, null, peer, null, reply_to_msg, null, true, null, null, replyMarkup, params, notify, scheduleDate, 0, null);
    }

    public void sendMessage(TLRPC.TL_document document, VideoEditedInfo videoEditedInfo, String path, long peer, MessageObject reply_to_msg, String caption, ArrayList<TLRPC.MessageEntity> entities, TLRPC.ReplyMarkup replyMarkup, HashMap<String, String> params, boolean notify, int scheduleDate, int ttl, Object parentObject) {
        sendMessage(null, caption, null, null, videoEditedInfo, null, document, null, null, peer, path, reply_to_msg, null, true, null, entities, replyMarkup, params, notify, scheduleDate, ttl, parentObject);
    }

    public void sendMessage(String message, long peer, MessageObject reply_to_msg, TLRPC.WebPage webPage, boolean searchLinks, ArrayList<TLRPC.MessageEntity> entities, TLRPC.ReplyMarkup replyMarkup, HashMap<String, String> params, boolean notify, int scheduleDate) {
        sendMessage(message, null, null, null, null, null, null, null, null, peer, null, reply_to_msg, webPage, searchLinks, null, entities, replyMarkup, params, notify, scheduleDate, 0, null);
    }

    public void sendMessage(TLRPC.MessageMedia location, long peer, MessageObject reply_to_msg, TLRPC.ReplyMarkup replyMarkup, HashMap<String, String> params, boolean notify, int scheduleDate) {
        sendMessage(null, null, location, null, null, null, null, null, null, peer, null, reply_to_msg, null, true, null, null, replyMarkup, params, notify, scheduleDate, 0, null);
    }

    public void sendMessage(TLRPC.TL_messageMediaPoll poll, long peer, MessageObject reply_to_msg, TLRPC.ReplyMarkup replyMarkup, HashMap<String, String> params, boolean notify, int scheduleDate) {
        sendMessage(null, null, null, null, null, null, null, null, poll, peer, null, reply_to_msg, null, true, null, null, replyMarkup, params, notify, scheduleDate, 0, null);
    }

    public void sendMessage(TLRPC.TL_game game, long peer, TLRPC.ReplyMarkup replyMarkup, HashMap<String, String> params, boolean notify, int scheduleDate) {
        sendMessage(null, null, null, null, null, null, null, game, null, peer, null, null, null, true, null, null, replyMarkup, params, notify, scheduleDate, 0, null);
    }

    public void sendMessage(TLRPC.TL_photo photo, String path, long peer, MessageObject reply_to_msg, String caption, ArrayList<TLRPC.MessageEntity> entities, TLRPC.ReplyMarkup replyMarkup, HashMap<String, String> params, boolean notify, int scheduleDate, int ttl, Object parentObject) {
        sendMessage(null, caption, null, photo, null, null, null, null, null, peer, path, reply_to_msg, null, true, null, entities, replyMarkup, params, notify, scheduleDate, ttl, parentObject);
    }

    public void sendRedpaketTransfer(TLRPC.User user, long peer, String message, String caption) {
        TLRPC.EncryptedChat encryptedChat;
        if ((user != null && user.phone == null) || peer == 0) {
            return;
        }
        int lower_id = (int) peer;
        int high_id = (int) (peer >> 32);
        TLRPC.InputPeer sendToPeer = lower_id != 0 ? getMessagesController().getInputPeer(lower_id) : null;
        if (lower_id == 0) {
            TLRPC.EncryptedChat encryptedChat2 = getMessagesController().getEncryptedChat(Integer.valueOf(high_id));
            if (encryptedChat2 != null) {
                encryptedChat = encryptedChat2;
            } else {
                return;
            }
        } else if (!(sendToPeer instanceof TLRPC.TL_inputPeerChannel)) {
            encryptedChat = null;
        } else {
            TLRPC.Chat chat = getMessagesController().getChat(Integer.valueOf(sendToPeer.channel_id));
            boolean z = (chat == null || chat.megagroup) ? false : true;
            encryptedChat = null;
        }
        if (message != null) {
            try {
                if (encryptedChat != null) {
                    new TLRPC.TL_message_secret();
                } else {
                    new TLRPC.TL_message();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private void sendMessage(java.lang.String r56, java.lang.String r57, im.skmzhmurqt.tgnet.TLRPC.MessageMedia r58, im.skmzhmurqt.tgnet.TLRPC.TL_photo r59, im.skmzhmurqt.messenger.VideoEditedInfo r60, im.skmzhmurqt.tgnet.TLRPC.User r61, im.skmzhmurqt.tgnet.TLRPC.TL_document r62, im.skmzhmurqt.tgnet.TLRPC.TL_game r63, im.skmzhmurqt.tgnet.TLRPC.TL_messageMediaPoll r64, long r65, java.lang.String r67, im.skmzhmurqt.messenger.MessageObject r68, im.skmzhmurqt.tgnet.TLRPC.WebPage r69, boolean r70, im.skmzhmurqt.messenger.MessageObject r71, java.util.ArrayList<im.skmzhmurqt.tgnet.TLRPC.MessageEntity> r72, im.skmzhmurqt.tgnet.TLRPC.ReplyMarkup r73, java.util.HashMap<java.lang.String, java.lang.String> r74, boolean r75, int r76, int r77, java.lang.Object r78) {
        throw new UnsupportedOperationException("Method not decompiled: im.skmzhmurqt.messenger.SendMessagesHelper.sendMessage(java.lang.String, java.lang.String, im.skmzhmurqt.tgnet.TLRPC$MessageMedia, im.skmzhmurqt.tgnet.TLRPC$TL_photo, im.skmzhmurqt.messenger.VideoEditedInfo, im.skmzhmurqt.tgnet.TLRPC$User, im.skmzhmurqt.tgnet.TLRPC$TL_document, im.skmzhmurqt.tgnet.TLRPC$TL_game, im.skmzhmurqt.tgnet.TLRPC$TL_messageMediaPoll, long, java.lang.String, im.skmzhmurqt.messenger.MessageObject, im.skmzhmurqt.tgnet.TLRPC$WebPage, boolean, im.skmzhmurqt.messenger.MessageObject, java.util.ArrayList, im.skmzhmurqt.tgnet.TLRPC$ReplyMarkup, java.util.HashMap, boolean, int, int, java.lang.Object):void");
    }

    public void performSendDelayedMessage(DelayedMessage message) {
        performSendDelayedMessage(message, -1);
    }

    private TLRPC.PhotoSize getThumbForSecretChat(ArrayList<TLRPC.PhotoSize> arrayList) {
        if (arrayList == null || arrayList.isEmpty()) {
            return null;
        }
        int N = arrayList.size();
        for (int a = 0; a < N; a++) {
            TLRPC.PhotoSize size = arrayList.get(a);
            if (size != null && !(size instanceof TLRPC.TL_photoStrippedSize) && !(size instanceof TLRPC.TL_photoSizeEmpty) && size.location != null) {
                TLRPC.TL_photoSize photoSize = new TLRPC.TL_photoSize();
                photoSize.type = size.type;
                photoSize.w = size.w;
                photoSize.h = size.h;
                photoSize.size = size.size;
                photoSize.bytes = size.bytes;
                if (photoSize.bytes == null) {
                    photoSize.bytes = new byte[0];
                }
                photoSize.location = new TLRPC.TL_fileLocation_layer82();
                photoSize.location.dc_id = size.location.dc_id;
                photoSize.location.volume_id = size.location.volume_id;
                photoSize.location.local_id = size.location.local_id;
                photoSize.location.secret = size.location.secret;
                return photoSize;
            }
        }
        return null;
    }

    public void performSendDelayedMessage(DelayedMessage message, int index) {
        int index2;
        TLObject inputMedia;
        MessageObject messageObject;
        TLRPC.InputMedia media;
        TLRPC.InputMedia media2;
        TLRPC.InputMedia media3;
        if (message.type == 0) {
            if (message.httpLocation != null) {
                putToDelayedMessages(message.httpLocation, message);
                ImageLoader.getInstance().loadHttpFile(message.httpLocation, "file", this.currentAccount);
            } else if (message.sendRequest != null) {
                String location = FileLoader.getPathToAttach(message.photoSize).toString();
                putToDelayedMessages(location, message);
                getFileLoader().uploadFile(location, false, true, 16777216);
                putToUploadingMessages(message.obj);
            } else {
                String location2 = FileLoader.getPathToAttach(message.photoSize).toString();
                if (message.sendEncryptedRequest != null && message.photoSize.location.dc_id != 0) {
                    File file = new File(location2);
                    if (!file.exists()) {
                        location2 = FileLoader.getPathToAttach(message.photoSize, true).toString();
                        file = new File(location2);
                    }
                    if (!file.exists()) {
                        putToDelayedMessages(FileLoader.getAttachFileName(message.photoSize), message);
                        getFileLoader().loadFile(ImageLocation.getForObject(message.photoSize, message.locationParent), message.parentObject, "jpg", 2, 0);
                        return;
                    }
                }
                putToDelayedMessages(location2, message);
                getFileLoader().uploadFile(location2, true, true, 16777216);
                putToUploadingMessages(message.obj);
            }
        } else if (message.type == 1) {
            if (message.videoEditedInfo != null && message.videoEditedInfo.needConvert()) {
                String location3 = message.obj.messageOwner.attachPath;
                TLRPC.Document document = message.obj.getDocument();
                if (location3 == null) {
                    location3 = FileLoader.getDirectory(4) + "/" + document.id + ".mp4";
                }
                putToDelayedMessages(location3, message);
                MediaController.getInstance().scheduleVideoConvert(message.obj);
                putToUploadingMessages(message.obj);
            } else {
                if (message.videoEditedInfo != null) {
                    if (message.videoEditedInfo.file != null) {
                        if (message.sendRequest instanceof TLRPC.TL_messages_sendMedia) {
                            media3 = ((TLRPC.TL_messages_sendMedia) message.sendRequest).media;
                        } else {
                            media3 = ((TLRPC.TL_messages_editMessage) message.sendRequest).media;
                        }
                        media3.file = message.videoEditedInfo.file;
                        message.videoEditedInfo.file = null;
                    } else if (message.videoEditedInfo.encryptedFile != null) {
                        TLRPC.TL_decryptedMessage decryptedMessage = (TLRPC.TL_decryptedMessage) message.sendEncryptedRequest;
                        decryptedMessage.media.size = (int) message.videoEditedInfo.estimatedSize;
                        decryptedMessage.media.key = message.videoEditedInfo.key;
                        decryptedMessage.media.iv = message.videoEditedInfo.iv;
                        getSecretChatHelper().performSendEncryptedRequest(decryptedMessage, message.obj.messageOwner, message.encryptedChat, message.videoEditedInfo.encryptedFile, message.originalPath, message.obj);
                        message.videoEditedInfo.encryptedFile = null;
                        return;
                    }
                }
                if (message.sendRequest != null) {
                    if (message.sendRequest instanceof TLRPC.TL_messages_sendMedia) {
                        media2 = ((TLRPC.TL_messages_sendMedia) message.sendRequest).media;
                    } else {
                        media2 = ((TLRPC.TL_messages_editMessage) message.sendRequest).media;
                    }
                    if (media2.file == null) {
                        String location4 = message.obj.messageOwner.attachPath;
                        TLRPC.Document document2 = message.obj.getDocument();
                        if (location4 == null) {
                            location4 = FileLoader.getDirectory(4) + "/" + document2.id + ".mp4";
                        }
                        putToDelayedMessages(location4, message);
                        if (message.obj.videoEditedInfo != null && message.obj.videoEditedInfo.needConvert()) {
                            getFileLoader().uploadFile(location4, false, false, document2.size, ConnectionsManager.FileTypeVideo, true);
                        } else {
                            getFileLoader().uploadFile(location4, false, false, ConnectionsManager.FileTypeVideo);
                        }
                        putToUploadingMessages(message.obj);
                    } else {
                        String location5 = FileLoader.getDirectory(4) + "/" + message.photoSize.location.volume_id + "_" + message.photoSize.location.local_id + ".jpg";
                        putToDelayedMessages(location5, message);
                        getFileLoader().uploadFile(location5, false, true, 16777216);
                        putToUploadingMessages(message.obj);
                    }
                } else {
                    String location6 = message.obj.messageOwner.attachPath;
                    TLRPC.Document document3 = message.obj.getDocument();
                    if (location6 == null) {
                        location6 = FileLoader.getDirectory(4) + "/" + document3.id + ".mp4";
                    }
                    if (message.sendEncryptedRequest != null && document3.dc_id != 0) {
                        File file2 = new File(location6);
                        if (!file2.exists()) {
                            putToDelayedMessages(FileLoader.getAttachFileName(document3), message);
                            getFileLoader().loadFile(document3, message.parentObject, 2, 0);
                            return;
                        }
                    }
                    putToDelayedMessages(location6, message);
                    if (message.obj.videoEditedInfo != null && message.obj.videoEditedInfo.needConvert()) {
                        getFileLoader().uploadFile(location6, true, false, document3.size, ConnectionsManager.FileTypeVideo, true);
                    } else {
                        getFileLoader().uploadFile(location6, true, false, ConnectionsManager.FileTypeVideo);
                    }
                    putToUploadingMessages(message.obj);
                }
            }
        } else if (message.type == 2) {
            if (message.httpLocation != null) {
                putToDelayedMessages(message.httpLocation, message);
                ImageLoader.getInstance().loadHttpFile(message.httpLocation, "gif", this.currentAccount);
            } else if (message.sendRequest != null) {
                if (message.sendRequest instanceof TLRPC.TL_messages_sendMedia) {
                    media = ((TLRPC.TL_messages_sendMedia) message.sendRequest).media;
                } else {
                    media = ((TLRPC.TL_messages_editMessage) message.sendRequest).media;
                }
                if (media.file == null) {
                    String location7 = message.obj.messageOwner.attachPath;
                    putToDelayedMessages(location7, message);
                    getFileLoader().uploadFile(location7, message.sendRequest == null, false, ConnectionsManager.FileTypeFile);
                    putToUploadingMessages(message.obj);
                } else if (media.thumb == null && message.photoSize != null) {
                    String location8 = FileLoader.getDirectory(4) + "/" + message.photoSize.location.volume_id + "_" + message.photoSize.location.local_id + ".jpg";
                    putToDelayedMessages(location8, message);
                    getFileLoader().uploadFile(location8, false, true, 16777216);
                    putToUploadingMessages(message.obj);
                }
            } else {
                String location9 = message.obj.messageOwner.attachPath;
                TLRPC.Document document4 = message.obj.getDocument();
                if (message.sendEncryptedRequest != null && document4.dc_id != 0) {
                    File file3 = new File(location9);
                    if (!file3.exists()) {
                        putToDelayedMessages(FileLoader.getAttachFileName(document4), message);
                        getFileLoader().loadFile(document4, message.parentObject, 2, 0);
                        return;
                    }
                }
                putToDelayedMessages(location9, message);
                getFileLoader().uploadFile(location9, true, false, ConnectionsManager.FileTypeFile);
                putToUploadingMessages(message.obj);
            }
        } else if (message.type == 3) {
            String location10 = message.obj.messageOwner.attachPath;
            putToDelayedMessages(location10, message);
            getFileLoader().uploadFile(location10, message.sendRequest == null, true, ConnectionsManager.FileTypeAudio);
            putToUploadingMessages(message.obj);
        } else if (message.type == 4) {
            boolean add = index < 0;
            if (message.performMediaUpload) {
                if (index >= 0) {
                    index2 = index;
                } else {
                    index2 = message.messageObjects.size() - 1;
                }
                MessageObject messageObject2 = message.messageObjects.get(index2);
                if (messageObject2.getDocument() != null) {
                    if (message.videoEditedInfo != null) {
                        String location11 = messageObject2.messageOwner.attachPath;
                        TLRPC.Document document5 = messageObject2.getDocument();
                        if (location11 == null) {
                            location11 = FileLoader.getDirectory(4) + "/" + document5.id + ".mp4";
                        }
                        putToDelayedMessages(location11, message);
                        message.extraHashMap.put(messageObject2, location11);
                        message.extraHashMap.put(location11 + "_i", messageObject2);
                        if (message.photoSize != null) {
                            message.extraHashMap.put(location11 + "_t", message.photoSize);
                        }
                        MediaController.getInstance().scheduleVideoConvert(messageObject2);
                        message.obj = messageObject2;
                        putToUploadingMessages(messageObject2);
                    } else {
                        TLRPC.Document document6 = messageObject2.getDocument();
                        String documentLocation = messageObject2.messageOwner.attachPath;
                        if (documentLocation != null) {
                            messageObject = messageObject2;
                        } else {
                            StringBuilder sb = new StringBuilder();
                            sb.append(FileLoader.getDirectory(4));
                            sb.append("/");
                            messageObject = messageObject2;
                            sb.append(document6.id);
                            sb.append(".mp4");
                            documentLocation = sb.toString();
                        }
                        if (message.sendRequest != null) {
                            TLRPC.TL_messages_sendMultiMedia request = (TLRPC.TL_messages_sendMultiMedia) message.sendRequest;
                            TLRPC.InputMedia media4 = request.multi_media.get(index2).media;
                            if (media4.file == null) {
                                putToDelayedMessages(documentLocation, message);
                                MessageObject messageObject3 = messageObject;
                                message.extraHashMap.put(messageObject3, documentLocation);
                                message.extraHashMap.put(documentLocation, media4);
                                message.extraHashMap.put(documentLocation + "_i", messageObject3);
                                if (message.photoSize != null) {
                                    message.extraHashMap.put(documentLocation + "_t", message.photoSize);
                                }
                                if (messageObject3.videoEditedInfo != null && messageObject3.videoEditedInfo.needConvert()) {
                                    getFileLoader().uploadFile(documentLocation, false, false, document6.size, ConnectionsManager.FileTypeVideo, true);
                                } else {
                                    getFileLoader().uploadFile(documentLocation, false, false, ConnectionsManager.FileTypeVideo);
                                }
                                putToUploadingMessages(messageObject3);
                            } else {
                                MessageObject messageObject4 = messageObject;
                                String location12 = FileLoader.getDirectory(4) + "/" + message.photoSize.location.volume_id + "_" + message.photoSize.location.local_id + ".jpg";
                                putToDelayedMessages(location12, message);
                                message.extraHashMap.put(location12 + "_o", documentLocation);
                                message.extraHashMap.put(messageObject4, location12);
                                message.extraHashMap.put(location12, media4);
                                getFileLoader().uploadFile(location12, false, true, 16777216);
                                putToUploadingMessages(messageObject4);
                            }
                        } else {
                            MessageObject messageObject5 = messageObject;
                            TLRPC.TL_messages_sendEncryptedMultiMedia request2 = (TLRPC.TL_messages_sendEncryptedMultiMedia) message.sendEncryptedRequest;
                            putToDelayedMessages(documentLocation, message);
                            message.extraHashMap.put(messageObject5, documentLocation);
                            message.extraHashMap.put(documentLocation, request2.files.get(index2));
                            message.extraHashMap.put(documentLocation + "_i", messageObject5);
                            if (message.photoSize != null) {
                                message.extraHashMap.put(documentLocation + "_t", message.photoSize);
                            }
                            if (messageObject5.videoEditedInfo != null && messageObject5.videoEditedInfo.needConvert()) {
                                getFileLoader().uploadFile(documentLocation, true, false, document6.size, ConnectionsManager.FileTypeVideo, true);
                            } else {
                                getFileLoader().uploadFile(documentLocation, true, false, ConnectionsManager.FileTypeVideo);
                            }
                            putToUploadingMessages(messageObject5);
                        }
                    }
                    message.videoEditedInfo = null;
                    message.photoSize = null;
                } else if (message.httpLocation != null) {
                    putToDelayedMessages(message.httpLocation, message);
                    message.extraHashMap.put(messageObject2, message.httpLocation);
                    message.extraHashMap.put(message.httpLocation, messageObject2);
                    ImageLoader.getInstance().loadHttpFile(message.httpLocation, "file", this.currentAccount);
                    message.httpLocation = null;
                } else {
                    if (message.sendRequest != null) {
                        TLRPC.TL_messages_sendMultiMedia request3 = (TLRPC.TL_messages_sendMultiMedia) message.sendRequest;
                        inputMedia = request3.multi_media.get(index2).media;
                    } else {
                        TLObject inputMedia2 = message.sendEncryptedRequest;
                        TLRPC.TL_messages_sendEncryptedMultiMedia request4 = (TLRPC.TL_messages_sendEncryptedMultiMedia) inputMedia2;
                        inputMedia = request4.files.get(index2);
                    }
                    String location13 = FileLoader.getPathToAttach(message.photoSize).toString();
                    putToDelayedMessages(location13, message);
                    message.extraHashMap.put(location13, inputMedia);
                    message.extraHashMap.put(messageObject2, location13);
                    getFileLoader().uploadFile(location13, message.sendEncryptedRequest != null, true, 16777216);
                    putToUploadingMessages(messageObject2);
                    message.photoSize = null;
                }
                message.performMediaUpload = false;
            } else if (!message.messageObjects.isEmpty()) {
                putToSendingMessages(message.messageObjects.get(message.messageObjects.size() - 1).messageOwner, message.finalGroupMessage != 0);
            }
            sendReadyToSendGroup(message, add, true);
        }
    }

    private void uploadMultiMedia(final DelayedMessage message, final TLRPC.InputMedia inputMedia, TLRPC.InputEncryptedFile inputEncryptedFile, String key) {
        Float valueOf = Float.valueOf(1.0f);
        if (inputMedia != null) {
            TLRPC.TL_messages_sendMultiMedia multiMedia = (TLRPC.TL_messages_sendMultiMedia) message.sendRequest;
            int a = 0;
            while (true) {
                if (a >= multiMedia.multi_media.size()) {
                    break;
                }
                if (multiMedia.multi_media.get(a).media != inputMedia) {
                    a++;
                } else {
                    putToSendingMessages(message.messages.get(a), message.scheduled);
                    getNotificationCenter().postNotificationName(NotificationCenter.FileUploadProgressChanged, key, valueOf, false);
                    break;
                }
            }
            TLRPC.TL_messages_uploadMedia req = new TLRPC.TL_messages_uploadMedia();
            req.media = inputMedia;
            req.peer = ((TLRPC.TL_messages_sendMultiMedia) message.sendRequest).peer;
            getConnectionsManager().sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    SendMessagesHelper.this.lambda$uploadMultiMedia$22$SendMessagesHelper(inputMedia, message, tLObject, tL_error);
                }
            });
            return;
        }
        if (inputEncryptedFile != null) {
            TLRPC.TL_messages_sendEncryptedMultiMedia multiMedia2 = (TLRPC.TL_messages_sendEncryptedMultiMedia) message.sendEncryptedRequest;
            int a2 = 0;
            while (true) {
                if (a2 >= multiMedia2.files.size()) {
                    break;
                }
                if (multiMedia2.files.get(a2) != inputEncryptedFile) {
                    a2++;
                } else {
                    putToSendingMessages(message.messages.get(a2), message.scheduled);
                    getNotificationCenter().postNotificationName(NotificationCenter.FileUploadProgressChanged, key, valueOf, false);
                    break;
                }
            }
            sendReadyToSendGroup(message, false, true);
        }
    }

    public void lambda$uploadMultiMedia$22$SendMessagesHelper(final TLRPC.InputMedia inputMedia, final DelayedMessage message, final TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$null$21$SendMessagesHelper(response, inputMedia, message);
            }
        });
    }

    public void lambda$null$21$SendMessagesHelper(TLObject response, TLRPC.InputMedia inputMedia, DelayedMessage message) {
        TLRPC.InputMedia newInputMedia = null;
        if (response != null) {
            TLRPC.MessageMedia messageMedia = (TLRPC.MessageMedia) response;
            if ((inputMedia instanceof TLRPC.TL_inputMediaUploadedPhoto) && (messageMedia instanceof TLRPC.TL_messageMediaPhoto)) {
                TLRPC.TL_inputMediaPhoto inputMediaPhoto = new TLRPC.TL_inputMediaPhoto();
                inputMediaPhoto.id = new TLRPC.TL_inputPhoto();
                inputMediaPhoto.id.id = messageMedia.photo.id;
                inputMediaPhoto.id.access_hash = messageMedia.photo.access_hash;
                inputMediaPhoto.id.file_reference = messageMedia.photo.file_reference;
                newInputMedia = inputMediaPhoto;
            } else if ((inputMedia instanceof TLRPC.TL_inputMediaUploadedDocument) && (messageMedia instanceof TLRPC.TL_messageMediaDocument)) {
                TLRPC.TL_inputMediaDocument inputMediaDocument = new TLRPC.TL_inputMediaDocument();
                inputMediaDocument.id = new TLRPC.TL_inputDocument();
                inputMediaDocument.id.id = messageMedia.document.id;
                inputMediaDocument.id.access_hash = messageMedia.document.access_hash;
                inputMediaDocument.id.file_reference = messageMedia.document.file_reference;
                newInputMedia = inputMediaDocument;
            }
        }
        if (newInputMedia != null) {
            if (inputMedia.ttl_seconds != 0) {
                newInputMedia.ttl_seconds = inputMedia.ttl_seconds;
                newInputMedia.flags |= 1;
            }
            TLRPC.TL_messages_sendMultiMedia req1 = (TLRPC.TL_messages_sendMultiMedia) message.sendRequest;
            int a = 0;
            while (true) {
                if (a >= req1.multi_media.size()) {
                    break;
                }
                if (req1.multi_media.get(a).media != inputMedia) {
                    a++;
                } else {
                    req1.multi_media.get(a).media = newInputMedia;
                    break;
                }
            }
            sendReadyToSendGroup(message, false, true);
            return;
        }
        message.markAsError();
    }

    private void sendReadyToSendGroup(DelayedMessage message, boolean add, boolean check) {
        DelayedMessage maxDelayedMessage;
        if (message.messageObjects.isEmpty()) {
            message.markAsError();
            return;
        }
        String key = "group_" + message.groupId;
        if (message.finalGroupMessage != message.messageObjects.get(message.messageObjects.size() - 1).getId()) {
            if (add) {
                putToDelayedMessages(key, message);
                return;
            }
            return;
        }
        if (add) {
            this.delayedMessages.remove(key);
            getMessagesStorage().putMessages(message.messages, false, true, false, 0, message.scheduled);
            getMessagesController().updateInterfaceWithMessages(message.peer, message.messageObjects, message.scheduled);
            if (!message.scheduled) {
                getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload, new Object[0]);
            }
        }
        if (message.sendRequest instanceof TLRPC.TL_messages_sendMultiMedia) {
            TLRPC.TL_messages_sendMultiMedia request = (TLRPC.TL_messages_sendMultiMedia) message.sendRequest;
            for (int a = 0; a < request.multi_media.size(); a++) {
                TLRPC.InputMedia inputMedia = request.multi_media.get(a).media;
                if ((inputMedia instanceof TLRPC.TL_inputMediaUploadedPhoto) || (inputMedia instanceof TLRPC.TL_inputMediaUploadedDocument)) {
                    return;
                }
            }
            if (check && (maxDelayedMessage = findMaxDelayedMessageForMessageId(message.finalGroupMessage, message.peer)) != null) {
                maxDelayedMessage.addDelayedRequest(message.sendRequest, message.messageObjects, message.originalPaths, message.parentObjects, message, message.scheduled);
                if (message.requests != null) {
                    maxDelayedMessage.requests.addAll(message.requests);
                    return;
                }
                return;
            }
        } else {
            TLRPC.TL_messages_sendEncryptedMultiMedia request2 = (TLRPC.TL_messages_sendEncryptedMultiMedia) message.sendEncryptedRequest;
            for (int a2 = 0; a2 < request2.files.size(); a2++) {
                if (request2.files.get(a2) instanceof TLRPC.TL_inputEncryptedFile) {
                    return;
                }
            }
        }
        if (message.sendRequest instanceof TLRPC.TL_messages_sendMultiMedia) {
            performSendMessageRequestMulti((TLRPC.TL_messages_sendMultiMedia) message.sendRequest, message.messageObjects, message.originalPaths, message.parentObjects, message, message.scheduled);
        } else {
            getSecretChatHelper().performSendEncryptedRequest((TLRPC.TL_messages_sendEncryptedMultiMedia) message.sendEncryptedRequest, message);
        }
        message.sendDelayedRequests();
    }

    public void lambda$null$23$SendMessagesHelper(String path) {
        NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopEncodingService, path, Integer.valueOf(this.currentAccount));
    }

    public void lambda$stopVideoService$24$SendMessagesHelper(final String path) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$null$23$SendMessagesHelper(path);
            }
        });
    }

    public void stopVideoService(final String path) {
        getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$stopVideoService$24$SendMessagesHelper(path);
            }
        });
    }

    public void putToSendingMessages(final TLRPC.Message message, final boolean scheduled) {
        if (Thread.currentThread() != ApplicationLoader.applicationHandler.getLooper().getThread()) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    SendMessagesHelper.this.lambda$putToSendingMessages$25$SendMessagesHelper(message, scheduled);
                }
            });
        } else {
            putToSendingMessages(message, scheduled, true);
        }
    }

    public void lambda$putToSendingMessages$25$SendMessagesHelper(TLRPC.Message message, boolean scheduled) {
        putToSendingMessages(message, scheduled, true);
    }

    protected void putToSendingMessages(TLRPC.Message message, boolean scheduled, boolean notify) {
        if (message == null) {
            return;
        }
        if (message.id > 0) {
            this.editingMessages.put(message.id, message);
            return;
        }
        boolean contains = this.sendingMessages.indexOfKey(message.id) >= 0;
        removeFromUploadingMessages(message.id, scheduled);
        this.sendingMessages.put(message.id, message);
        if (!scheduled && !contains) {
            long did = MessageObject.getDialogId(message);
            LongSparseArray<Integer> longSparseArray = this.sendingMessagesIdDialogs;
            longSparseArray.put(did, Integer.valueOf(longSparseArray.get(did, 0).intValue() + 1));
            if (notify) {
                getNotificationCenter().postNotificationName(NotificationCenter.sendingMessagesChanged, new Object[0]);
            }
        }
    }

    public TLRPC.Message removeFromSendingMessages(int mid, boolean scheduled) {
        TLRPC.Message message;
        long did;
        Integer currentCount;
        if (mid > 0) {
            message = this.editingMessages.get(mid);
            if (message != null) {
                this.editingMessages.remove(mid);
            }
        } else {
            message = this.sendingMessages.get(mid);
            if (message != null) {
                this.sendingMessages.remove(mid);
                if (!scheduled && (currentCount = this.sendingMessagesIdDialogs.get((did = MessageObject.getDialogId(message)))) != null) {
                    int count = currentCount.intValue() - 1;
                    if (count <= 0) {
                        this.sendingMessagesIdDialogs.remove(did);
                    } else {
                        this.sendingMessagesIdDialogs.put(did, Integer.valueOf(count));
                    }
                    getNotificationCenter().postNotificationName(NotificationCenter.sendingMessagesChanged, new Object[0]);
                }
            }
        }
        return message;
    }

    public int getSendingMessageId(long did) {
        for (int a = 0; a < this.sendingMessages.size(); a++) {
            TLRPC.Message message = this.sendingMessages.valueAt(a);
            if (message.dialog_id == did) {
                return message.id;
            }
        }
        for (int a2 = 0; a2 < this.uploadMessages.size(); a2++) {
            TLRPC.Message message2 = this.uploadMessages.valueAt(a2);
            if (message2.dialog_id == did) {
                return message2.id;
            }
        }
        return 0;
    }

    protected void putToUploadingMessages(MessageObject obj) {
        if (obj == null || obj.getId() > 0 || obj.scheduled) {
            return;
        }
        TLRPC.Message message = obj.messageOwner;
        boolean contains = this.uploadMessages.indexOfKey(message.id) >= 0;
        this.uploadMessages.put(message.id, message);
        if (!contains) {
            long did = MessageObject.getDialogId(message);
            LongSparseArray<Integer> longSparseArray = this.uploadingMessagesIdDialogs;
            longSparseArray.put(did, Integer.valueOf(longSparseArray.get(did, 0).intValue() + 1));
            getNotificationCenter().postNotificationName(NotificationCenter.sendingMessagesChanged, new Object[0]);
        }
    }

    protected void removeFromUploadingMessages(int mid, boolean scheduled) {
        TLRPC.Message message;
        if (mid <= 0 && !scheduled && (message = this.uploadMessages.get(mid)) != null) {
            this.uploadMessages.remove(mid);
            long did = MessageObject.getDialogId(message);
            Integer currentCount = this.uploadingMessagesIdDialogs.get(did);
            if (currentCount != null) {
                int count = currentCount.intValue() - 1;
                if (count <= 0) {
                    this.uploadingMessagesIdDialogs.remove(did);
                } else {
                    this.uploadingMessagesIdDialogs.put(did, Integer.valueOf(count));
                }
                getNotificationCenter().postNotificationName(NotificationCenter.sendingMessagesChanged, new Object[0]);
            }
        }
    }

    public boolean isSendingMessage(int mid) {
        return this.sendingMessages.indexOfKey(mid) >= 0 || this.editingMessages.indexOfKey(mid) >= 0;
    }

    public boolean isSendingMessageIdDialog(long did) {
        return this.sendingMessagesIdDialogs.get(did, 0).intValue() > 0;
    }

    public boolean isUploadingMessageIdDialog(long did) {
        return this.uploadingMessagesIdDialogs.get(did, 0).intValue() > 0;
    }

    public void performSendMessageRequestMulti(final TLRPC.TL_messages_sendMultiMedia req, final ArrayList<MessageObject> msgObjs, final ArrayList<String> originalPaths, final ArrayList<Object> parentObjects, final DelayedMessage delayedMessage, final boolean scheduled) {
        int size = msgObjs.size();
        for (int a = 0; a < size; a++) {
            putToSendingMessages(msgObjs.get(a).messageOwner, scheduled);
        }
        getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                SendMessagesHelper.this.lambda$performSendMessageRequestMulti$32$SendMessagesHelper(parentObjects, req, msgObjs, originalPaths, delayedMessage, scheduled, tLObject, tL_error);
            }
        }, (QuickAckDelegate) null, 68);
    }

    public void lambda$performSendMessageRequestMulti$32$SendMessagesHelper(final ArrayList parentObjects, final TLRPC.TL_messages_sendMultiMedia req, final ArrayList msgObjs, final ArrayList originalPaths, final DelayedMessage delayedMessage, final boolean scheduled, final TLObject response, final TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$null$31$SendMessagesHelper(error, parentObjects, req, msgObjs, originalPaths, delayedMessage, scheduled, response);
            }
        });
    }

    public void lambda$null$31$SendMessagesHelper(TLRPC.TL_error error, ArrayList parentObjects, final TLRPC.TL_messages_sendMultiMedia req, final ArrayList msgObjs, ArrayList originalPaths, final DelayedMessage delayedMessage, final boolean scheduled, TLObject response) {
        char c;
        TLRPC.Updates updates;
        int i;
        ArrayList arrayList = originalPaths;
        if (error != null && FileRefController.isFileRefError(error.text)) {
            if (parentObjects != null) {
                ArrayList<Object> arrayList2 = new ArrayList<>(parentObjects);
                getFileRefController().requestReference(arrayList2, req, msgObjs, arrayList, arrayList2, delayedMessage, Boolean.valueOf(scheduled));
                return;
            } else if (delayedMessage != null) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        int size = req.multi_media.size();
                        for (int a = 0; a < size; a++) {
                            if (delayedMessage.parentObjects.get(a) != null) {
                                SendMessagesHelper.this.removeFromSendingMessages(((MessageObject) msgObjs.get(a)).getId(), scheduled);
                                TLRPC.TL_inputSingleMedia request = req.multi_media.get(a);
                                if (request.media instanceof TLRPC.TL_inputMediaPhoto) {
                                    request.media = delayedMessage.inputMedias.get(a);
                                } else if (request.media instanceof TLRPC.TL_inputMediaDocument) {
                                    request.media = delayedMessage.inputMedias.get(a);
                                }
                                DelayedMessage delayedMessage2 = delayedMessage;
                                delayedMessage2.videoEditedInfo = delayedMessage2.videoEditedInfos.get(a);
                                DelayedMessage delayedMessage3 = delayedMessage;
                                delayedMessage3.httpLocation = delayedMessage3.httpLocations.get(a);
                                DelayedMessage delayedMessage4 = delayedMessage;
                                delayedMessage4.photoSize = delayedMessage4.locations.get(a);
                                delayedMessage.performMediaUpload = true;
                                SendMessagesHelper.this.performSendDelayedMessage(delayedMessage, a);
                            }
                        }
                    }
                });
                return;
            }
        }
        boolean isSentError = false;
        if (error == null) {
            SparseArray<TLRPC.Message> newMessages = new SparseArray<>();
            LongSparseArray<Integer> newIds = new LongSparseArray<>();
            TLRPC.Updates updates2 = (TLRPC.Updates) response;
            ArrayList<TLRPC.Update> updatesArr = ((TLRPC.Updates) response).updates;
            int a = 0;
            while (a < updatesArr.size()) {
                TLRPC.Update update = updatesArr.get(a);
                if (update instanceof TLRPC.TL_updateMessageID) {
                    TLRPC.TL_updateMessageID updateMessageID = (TLRPC.TL_updateMessageID) update;
                    newIds.put(updateMessageID.random_id, Integer.valueOf(updateMessageID.id));
                    updatesArr.remove(a);
                    a--;
                } else if (update instanceof TLRPC.TL_updateNewMessage) {
                    final TLRPC.TL_updateNewMessage newMessage = (TLRPC.TL_updateNewMessage) update;
                    newMessages.put(newMessage.message.id, newMessage.message);
                    Utilities.stageQueue.postRunnable(new Runnable() {
                        @Override
                        public final void run() {
                            SendMessagesHelper.this.lambda$null$26$SendMessagesHelper(newMessage);
                        }
                    });
                    updatesArr.remove(a);
                    a--;
                } else if (update instanceof TLRPC.TL_updateNewChannelMessage) {
                    final TLRPC.TL_updateNewChannelMessage newMessage2 = (TLRPC.TL_updateNewChannelMessage) update;
                    newMessages.put(newMessage2.message.id, newMessage2.message);
                    Utilities.stageQueue.postRunnable(new Runnable() {
                        @Override
                        public final void run() {
                            SendMessagesHelper.this.lambda$null$27$SendMessagesHelper(newMessage2);
                        }
                    });
                    updatesArr.remove(a);
                    a--;
                } else if (update instanceof TLRPC.TL_updateNewScheduledMessage) {
                    TLRPC.TL_updateNewScheduledMessage newMessage3 = (TLRPC.TL_updateNewScheduledMessage) update;
                    newMessages.put(newMessage3.message.id, newMessage3.message);
                    updatesArr.remove(a);
                    a--;
                }
                a++;
            }
            int i2 = 0;
            while (true) {
                if (i2 >= msgObjs.size()) {
                    updates = updates2;
                    c = 0;
                    break;
                }
                MessageObject msgObj = (MessageObject) msgObjs.get(i2);
                String originalPath = (String) arrayList.get(i2);
                final TLRPC.Message newMsgObj = msgObj.messageOwner;
                final int oldId = newMsgObj.id;
                final ArrayList<TLRPC.Message> sentMessages = new ArrayList<>();
                String str = newMsgObj.attachPath;
                ArrayList<TLRPC.Update> updatesArr2 = updatesArr;
                Integer id = newIds.get(newMsgObj.random_id);
                if (id != null) {
                    TLRPC.Message message = newMessages.get(id.intValue());
                    if (message == null) {
                        updates = updates2;
                        c = 0;
                        isSentError = true;
                        break;
                    }
                    sentMessages.add(message);
                    LongSparseArray<Integer> newIds2 = newIds;
                    TLRPC.Updates updates3 = updates2;
                    SparseArray<TLRPC.Message> newMessages2 = newMessages;
                    updateMediaPaths(msgObj, message, message.id, originalPath, false);
                    final int existFlags = msgObj.getMediaExistanceFlags();
                    newMsgObj.id = message.id;
                    if ((newMsgObj.flags & Integer.MIN_VALUE) != 0) {
                        message.flags |= Integer.MIN_VALUE;
                    }
                    final long grouped_id = message.grouped_id;
                    if (!scheduled) {
                        Integer value = getMessagesController().dialogs_read_outbox_max.get(Long.valueOf(message.dialog_id));
                        if (value == null) {
                            value = Integer.valueOf(getMessagesStorage().getDialogReadMax(message.out, message.dialog_id));
                            getMessagesController().dialogs_read_outbox_max.put(Long.valueOf(message.dialog_id), value);
                        }
                        message.unread = value.intValue() < message.id;
                    }
                    if (0 == 0) {
                        getStatsController().incrementSentItemsCount(ApplicationLoader.getCurrentNetworkType(), 1, 1);
                        newMsgObj.send_state = 0;
                        getNotificationCenter().postNotificationName(NotificationCenter.messageReceivedByServer, Integer.valueOf(oldId), Integer.valueOf(newMsgObj.id), newMsgObj, Long.valueOf(newMsgObj.dialog_id), Long.valueOf(grouped_id), Integer.valueOf(existFlags), Boolean.valueOf(scheduled));
                        i = i2;
                        getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                            @Override
                            public final void run() {
                                SendMessagesHelper.this.lambda$null$29$SendMessagesHelper(newMsgObj, oldId, scheduled, sentMessages, grouped_id, existFlags);
                            }
                        });
                    } else {
                        i = i2;
                    }
                    i2 = i + 1;
                    arrayList = originalPaths;
                    newIds = newIds2;
                    updatesArr = updatesArr2;
                    updates2 = updates3;
                    newMessages = newMessages2;
                } else {
                    updates = updates2;
                    c = 0;
                    isSentError = true;
                    break;
                }
            }
            final TLRPC.Updates updates4 = updates;
            Utilities.stageQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    SendMessagesHelper.this.lambda$null$30$SendMessagesHelper(updates4);
                }
            });
        } else {
            c = 0;
            AlertsCreator.processError(this.currentAccount, error, null, req, new Object[0]);
            isSentError = true;
        }
        if (isSentError) {
            for (int i3 = 0; i3 < msgObjs.size(); i3++) {
                TLRPC.Message newMsgObj2 = ((MessageObject) msgObjs.get(i3)).messageOwner;
                getMessagesStorage().markMessageAsSendError(newMsgObj2, scheduled);
                newMsgObj2.send_state = 2;
                NotificationCenter notificationCenter = getNotificationCenter();
                int i4 = NotificationCenter.messageSendError;
                Object[] objArr = new Object[1];
                objArr[c] = Integer.valueOf(newMsgObj2.id);
                notificationCenter.postNotificationName(i4, objArr);
                processSentMessage(newMsgObj2.id);
                removeFromSendingMessages(newMsgObj2.id, scheduled);
            }
        }
    }

    public void lambda$null$26$SendMessagesHelper(TLRPC.TL_updateNewMessage newMessage) {
        getMessagesController().processNewDifferenceParams(-1, newMessage.pts, -1, newMessage.pts_count);
    }

    public void lambda$null$27$SendMessagesHelper(TLRPC.TL_updateNewChannelMessage newMessage) {
        getMessagesController().processNewChannelDifferenceParams(newMessage.pts, newMessage.pts_count, newMessage.message.to_id.channel_id);
    }

    public void lambda$null$29$SendMessagesHelper(final TLRPC.Message message, final int i, final boolean z, ArrayList arrayList, final long j, final int i2) {
        getMessagesStorage().updateMessageStateAndId(message.random_id, Integer.valueOf(i), message.id, 0, false, message.to_id.channel_id, z ? 1 : 0);
        getMessagesStorage().putMessages((ArrayList<TLRPC.Message>) arrayList, true, true, false, 0, z);
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$null$28$SendMessagesHelper(message, i, j, i2, z);
            }
        });
    }

    public void lambda$null$28$SendMessagesHelper(TLRPC.Message newMsgObj, int oldId, long grouped_id, int existFlags, boolean scheduled) {
        getMediaDataController().increasePeerRaiting(newMsgObj.dialog_id);
        getNotificationCenter().postNotificationName(NotificationCenter.messageReceivedByServer, Integer.valueOf(oldId), Integer.valueOf(newMsgObj.id), newMsgObj, Long.valueOf(newMsgObj.dialog_id), Long.valueOf(grouped_id), Integer.valueOf(existFlags), Boolean.valueOf(scheduled));
        processSentMessage(oldId);
        removeFromSendingMessages(oldId, scheduled);
    }

    public void lambda$null$30$SendMessagesHelper(TLRPC.Updates updates) {
        getMessagesController().processUpdates(updates, false);
    }

    public void performSendMessageRequest(TLObject req, MessageObject msgObj, String originalPath, DelayedMessage delayedMessage, Object parentObject, boolean scheduled) {
        performSendMessageRequest(req, msgObj, originalPath, null, false, delayedMessage, parentObject, scheduled);
    }

    private DelayedMessage findMaxDelayedMessageForMessageId(int messageId, long dialogId) {
        DelayedMessage maxDelayedMessage = null;
        int maxDalyedMessageId = Integer.MIN_VALUE;
        for (Map.Entry<String, ArrayList<DelayedMessage>> entry : this.delayedMessages.entrySet()) {
            ArrayList<DelayedMessage> messages = entry.getValue();
            int size = messages.size();
            for (int a = 0; a < size; a++) {
                DelayedMessage delayedMessage = messages.get(a);
                if ((delayedMessage.type == 4 || delayedMessage.type == 0) && delayedMessage.peer == dialogId) {
                    int mid = 0;
                    if (delayedMessage.obj != null) {
                        mid = delayedMessage.obj.getId();
                    } else if (delayedMessage.messageObjects != null && !delayedMessage.messageObjects.isEmpty()) {
                        mid = delayedMessage.messageObjects.get(delayedMessage.messageObjects.size() - 1).getId();
                    }
                    if (mid != 0 && mid > messageId && maxDelayedMessage == null && maxDalyedMessageId < mid) {
                        maxDelayedMessage = delayedMessage;
                        maxDalyedMessageId = mid;
                    }
                }
            }
        }
        return maxDelayedMessage;
    }

    public void performSendMessageRequest(final TLObject req, final MessageObject msgObj, final String originalPath, final DelayedMessage parentMessage, final boolean check, final DelayedMessage delayedMessage, final Object parentObject, final boolean scheduled) {
        DelayedMessage maxDelayedMessage;
        if (!(req instanceof TLRPC.TL_messages_editMessage) && check && (maxDelayedMessage = findMaxDelayedMessageForMessageId(msgObj.getId(), msgObj.getDialogId())) != null) {
            maxDelayedMessage.addDelayedRequest(req, msgObj, originalPath, parentObject, delayedMessage, parentMessage != null ? parentMessage.scheduled : false);
            if (parentMessage != null && parentMessage.requests != null) {
                maxDelayedMessage.requests.addAll(parentMessage.requests);
                return;
            }
            return;
        }
        final TLRPC.Message newMsgObj = msgObj.messageOwner;
        putToSendingMessages(newMsgObj, scheduled);
        newMsgObj.reqId = getConnectionsManager().sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                SendMessagesHelper.this.lambda$performSendMessageRequest$44$SendMessagesHelper(req, parentObject, msgObj, originalPath, parentMessage, check, delayedMessage, scheduled, newMsgObj, tLObject, tL_error);
            }
        }, new QuickAckDelegate() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$performSendMessageRequest$46$SendMessagesHelper(newMsgObj);
            }
        }, (req instanceof TLRPC.TL_messages_sendMessage ? 128 : 0) | 68);
        if (parentMessage != null) {
            parentMessage.sendDelayedRequests();
        }
    }

    public void lambda$performSendMessageRequest$44$SendMessagesHelper(final TLObject req, Object parentObject, final MessageObject msgObj, final String originalPath, DelayedMessage parentMessage, boolean check, final DelayedMessage delayedMessage, final boolean scheduled, final TLRPC.Message newMsgObj, final TLObject response, final TLRPC.TL_error error) {
        if (error != null && (((req instanceof TLRPC.TL_messages_sendMedia) || (req instanceof TLRPC.TL_messages_editMessage)) && FileRefController.isFileRefError(error.text))) {
            if (parentObject != null) {
                getFileRefController().requestReference(parentObject, req, msgObj, originalPath, parentMessage, Boolean.valueOf(check), delayedMessage, Boolean.valueOf(scheduled));
                return;
            } else if (delayedMessage != null) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        SendMessagesHelper.this.removeFromSendingMessages(newMsgObj.id, scheduled);
                        TLObject tLObject = req;
                        if (tLObject instanceof TLRPC.TL_messages_sendMedia) {
                            TLRPC.TL_messages_sendMedia request = (TLRPC.TL_messages_sendMedia) tLObject;
                            if (request.media instanceof TLRPC.TL_inputMediaPhoto) {
                                request.media = delayedMessage.inputUploadMedia;
                            } else if (request.media instanceof TLRPC.TL_inputMediaDocument) {
                                request.media = delayedMessage.inputUploadMedia;
                            }
                        } else if (tLObject instanceof TLRPC.TL_messages_editMessage) {
                            TLRPC.TL_messages_editMessage request2 = (TLRPC.TL_messages_editMessage) tLObject;
                            if (request2.media instanceof TLRPC.TL_inputMediaPhoto) {
                                request2.media = delayedMessage.inputUploadMedia;
                            } else if (request2.media instanceof TLRPC.TL_inputMediaDocument) {
                                request2.media = delayedMessage.inputUploadMedia;
                            }
                        }
                        delayedMessage.performMediaUpload = true;
                        SendMessagesHelper.this.performSendDelayedMessage(delayedMessage);
                    }
                });
                return;
            }
        }
        if (req instanceof TLRPC.TL_messages_editMessage) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    SendMessagesHelper.this.lambda$null$35$SendMessagesHelper(error, newMsgObj, response, msgObj, originalPath, scheduled, req);
                }
            });
        } else {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    SendMessagesHelper.this.lambda$null$43$SendMessagesHelper(error, newMsgObj, response, msgObj, scheduled, originalPath, req);
                }
            });
        }
    }

    public void lambda$null$35$SendMessagesHelper(TLRPC.TL_error error, final TLRPC.Message newMsgObj, TLObject response, MessageObject msgObj, String originalPath, final boolean scheduled, TLObject req) {
        TLRPC.Message message;
        if (error == null) {
            String attachPath = newMsgObj.attachPath;
            final TLRPC.Updates updates = (TLRPC.Updates) response;
            ArrayList<TLRPC.Update> updatesArr = ((TLRPC.Updates) response).updates;
            int a = 0;
            while (true) {
                if (a >= updatesArr.size()) {
                    message = null;
                    break;
                }
                TLRPC.Update update = updatesArr.get(a);
                if (update instanceof TLRPC.TL_updateEditMessage) {
                    TLRPC.TL_updateEditMessage newMessage = (TLRPC.TL_updateEditMessage) update;
                    TLRPC.Message message2 = newMessage.message;
                    message = message2;
                    break;
                } else if (update instanceof TLRPC.TL_updateEditChannelMessage) {
                    TLRPC.TL_updateEditChannelMessage newMessage2 = (TLRPC.TL_updateEditChannelMessage) update;
                    TLRPC.Message message3 = newMessage2.message;
                    message = message3;
                    break;
                } else if (!(update instanceof TLRPC.TL_updateNewScheduledMessage)) {
                    a++;
                } else {
                    TLRPC.TL_updateNewScheduledMessage newMessage3 = (TLRPC.TL_updateNewScheduledMessage) update;
                    TLRPC.Message message4 = newMessage3.message;
                    message = message4;
                    break;
                }
            }
            if (message != null) {
                ImageLoader.saveMessageThumbs(message);
                updateMediaPaths(msgObj, message, message.id, originalPath, false);
            }
            Utilities.stageQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    SendMessagesHelper.this.lambda$null$34$SendMessagesHelper(updates, newMsgObj, scheduled);
                }
            });
            if (MessageObject.isVideoMessage(newMsgObj) || MessageObject.isRoundVideoMessage(newMsgObj) || MessageObject.isNewGifMessage(newMsgObj)) {
                stopVideoService(attachPath);
            }
            return;
        }
        AlertsCreator.processError(this.currentAccount, error, null, req, new Object[0]);
        if (MessageObject.isVideoMessage(newMsgObj) || MessageObject.isRoundVideoMessage(newMsgObj) || MessageObject.isNewGifMessage(newMsgObj)) {
            stopVideoService(newMsgObj.attachPath);
        }
        removeFromSendingMessages(newMsgObj.id, scheduled);
        revertEditingMessageObject(msgObj);
    }

    public void lambda$null$34$SendMessagesHelper(TLRPC.Updates updates, final TLRPC.Message newMsgObj, final boolean scheduled) {
        getMessagesController().processUpdates(updates, false);
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$null$33$SendMessagesHelper(newMsgObj, scheduled);
            }
        });
    }

    public void lambda$null$33$SendMessagesHelper(TLRPC.Message newMsgObj, boolean scheduled) {
        processSentMessage(newMsgObj.id);
        removeFromSendingMessages(newMsgObj.id, scheduled);
    }

    public void lambda$null$43$SendMessagesHelper(TLRPC.TL_error error, final TLRPC.Message newMsgObj, TLObject response, MessageObject msgObj, final boolean scheduled, String originalPath, TLObject req) {
        boolean isSentError;
        String attachPath;
        ArrayList<TLRPC.Message> sentMessages;
        int existFlags;
        TLRPC.Message message;
        int existFlags2;
        TLRPC.Message message2;
        TLRPC.Message message3;
        boolean isSentError2 = false;
        if (error == null) {
            final int oldId = newMsgObj.id;
            ArrayList<TLRPC.Message> sentMessages2 = new ArrayList<>();
            String attachPath2 = newMsgObj.attachPath;
            if (response instanceof TLRPC.TL_updateShortSentMessage) {
                final TLRPC.TL_updateShortSentMessage res = (TLRPC.TL_updateShortSentMessage) response;
                attachPath = attachPath2;
                sentMessages = sentMessages2;
                updateMediaPaths(msgObj, null, res.id, null, false);
                int existFlags3 = msgObj.getMediaExistanceFlags();
                int i = res.id;
                newMsgObj.id = i;
                newMsgObj.local_id = i;
                newMsgObj.date = res.date;
                newMsgObj.entities = res.entities;
                newMsgObj.out = res.out;
                if (res.media != null) {
                    newMsgObj.media = res.media;
                    newMsgObj.flags |= 512;
                    ImageLoader.saveMessageThumbs(newMsgObj);
                }
                if ((res.media instanceof TLRPC.TL_messageMediaGame) && !TextUtils.isEmpty(res.message)) {
                    newMsgObj.message = res.message;
                }
                if (!newMsgObj.entities.isEmpty()) {
                    newMsgObj.flags |= 128;
                }
                Utilities.stageQueue.postRunnable(new Runnable() {
                    @Override
                    public final void run() {
                        SendMessagesHelper.this.lambda$null$36$SendMessagesHelper(res);
                    }
                });
                sentMessages.add(newMsgObj);
                existFlags = existFlags3;
                isSentError = false;
            } else {
                attachPath = attachPath2;
                sentMessages = sentMessages2;
                if (response instanceof TLRPC.Updates) {
                    final TLRPC.Updates updates = (TLRPC.Updates) response;
                    ArrayList<TLRPC.Update> updatesArr = ((TLRPC.Updates) response).updates;
                    int a = 0;
                    while (true) {
                        if (a >= updatesArr.size()) {
                            message = null;
                            break;
                        }
                        TLRPC.Update update = updatesArr.get(a);
                        if (update instanceof TLRPC.TL_updateNewMessage) {
                            final TLRPC.TL_updateNewMessage newMessage = (TLRPC.TL_updateNewMessage) update;
                            TLRPC.Message message4 = newMessage.message;
                            sentMessages.add(message4);
                            Utilities.stageQueue.postRunnable(new Runnable() {
                                @Override
                                public final void run() {
                                    SendMessagesHelper.this.lambda$null$37$SendMessagesHelper(newMessage);
                                }
                            });
                            updatesArr.remove(a);
                            message = message4;
                            break;
                        }
                        if (update instanceof TLRPC.TL_updateNewChannelMessage) {
                            final TLRPC.TL_updateNewChannelMessage newMessage2 = (TLRPC.TL_updateNewChannelMessage) update;
                            TLRPC.Message message5 = newMessage2.message;
                            sentMessages.add(message5);
                            if ((newMsgObj.flags & Integer.MIN_VALUE) == 0) {
                                message2 = message5;
                            } else {
                                message2 = message5;
                                newMessage2.message.flags |= Integer.MIN_VALUE;
                            }
                            Utilities.stageQueue.postRunnable(new Runnable() {
                                @Override
                                public final void run() {
                                    SendMessagesHelper.this.lambda$null$38$SendMessagesHelper(newMessage2);
                                }
                            });
                            updatesArr.remove(a);
                            message = message2;
                        } else if (!(update instanceof TLRPC.TL_updateNewScheduledMessage)) {
                            a++;
                        } else {
                            TLRPC.TL_updateNewScheduledMessage newMessage3 = (TLRPC.TL_updateNewScheduledMessage) update;
                            TLRPC.Message message6 = newMessage3.message;
                            sentMessages.add(message6);
                            if ((newMsgObj.flags & Integer.MIN_VALUE) == 0) {
                                message3 = message6;
                            } else {
                                message3 = message6;
                                newMessage3.message.flags |= Integer.MIN_VALUE;
                            }
                            updatesArr.remove(a);
                            message = message3;
                        }
                    }
                    if (message != null) {
                        ImageLoader.saveMessageThumbs(message);
                        if (!scheduled) {
                            Integer value = getMessagesController().dialogs_read_outbox_max.get(Long.valueOf(message.dialog_id));
                            if (value == null) {
                                value = Integer.valueOf(getMessagesStorage().getDialogReadMax(message.out, message.dialog_id));
                                getMessagesController().dialogs_read_outbox_max.put(Long.valueOf(message.dialog_id), value);
                            }
                            message.unread = value.intValue() < message.id;
                        }
                        updateMediaPaths(msgObj, message, message.id, originalPath, false);
                        existFlags2 = msgObj.getMediaExistanceFlags();
                        newMsgObj.id = message.id;
                        if (newMsgObj.message != null && message.message != null) {
                            newMsgObj.message = message.message;
                            final TLRPC.Message finalMessage = message;
                            AndroidUtilities.runOnUIThread(new Runnable() {
                                @Override
                                public final void run() {
                                    SendMessagesHelper.this.lambda$null$39$SendMessagesHelper(finalMessage);
                                }
                            });
                        }
                    } else {
                        isSentError2 = true;
                        existFlags2 = 0;
                    }
                    Utilities.stageQueue.postRunnable(new Runnable() {
                        @Override
                        public final void run() {
                            SendMessagesHelper.this.lambda$null$40$SendMessagesHelper(updates);
                        }
                    });
                    existFlags = existFlags2;
                    isSentError = isSentError2;
                } else {
                    existFlags = 0;
                    isSentError = false;
                }
            }
            if (MessageObject.isLiveLocationMessage(newMsgObj)) {
                getLocationController().addSharingLocation(newMsgObj.dialog_id, newMsgObj.id, newMsgObj.media.period, newMsgObj);
            }
            if (!isSentError) {
                getStatsController().incrementSentItemsCount(ApplicationLoader.getCurrentNetworkType(), 1, 1);
                newMsgObj.send_state = 0;
                getNotificationCenter().postNotificationName(NotificationCenter.messageReceivedByServer, Integer.valueOf(oldId), Integer.valueOf(newMsgObj.id), newMsgObj, Long.valueOf(newMsgObj.dialog_id), 0L, Integer.valueOf(existFlags), Boolean.valueOf(scheduled));
                final ArrayList<TLRPC.Message> arrayList = sentMessages;
                final int i2 = existFlags;
                final String str = attachPath;
                getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
                    @Override
                    public final void run() {
                        SendMessagesHelper.this.lambda$null$42$SendMessagesHelper(newMsgObj, oldId, scheduled, arrayList, i2, str);
                    }
                });
            }
        } else {
            AlertsCreator.processError(this.currentAccount, error, null, req, new Object[0]);
            isSentError = true;
        }
        if (isSentError) {
            getMessagesStorage().markMessageAsSendError(newMsgObj, scheduled);
            newMsgObj.send_state = 2;
            getNotificationCenter().postNotificationName(NotificationCenter.messageSendError, Integer.valueOf(newMsgObj.id));
            processSentMessage(newMsgObj.id);
            if (MessageObject.isVideoMessage(newMsgObj) || MessageObject.isRoundVideoMessage(newMsgObj) || MessageObject.isNewGifMessage(newMsgObj)) {
                stopVideoService(newMsgObj.attachPath);
            }
            removeFromSendingMessages(newMsgObj.id, scheduled);
        }
    }

    public void lambda$null$36$SendMessagesHelper(TLRPC.TL_updateShortSentMessage res) {
        getMessagesController().processNewDifferenceParams(-1, res.pts, res.date, res.pts_count);
    }

    public void lambda$null$37$SendMessagesHelper(TLRPC.TL_updateNewMessage newMessage) {
        getMessagesController().processNewDifferenceParams(-1, newMessage.pts, -1, newMessage.pts_count);
    }

    public void lambda$null$38$SendMessagesHelper(TLRPC.TL_updateNewChannelMessage newMessage) {
        getMessagesController().processNewChannelDifferenceParams(newMessage.pts, newMessage.pts_count, newMessage.message.to_id.channel_id);
    }

    public void lambda$null$39$SendMessagesHelper(TLRPC.Message finalMessage) {
        getNotificationCenter().postNotificationName(NotificationCenter.updateChatNewmsgMentionText, finalMessage);
    }

    public void lambda$null$40$SendMessagesHelper(TLRPC.Updates updates) {
        getMessagesController().processUpdates(updates, false);
    }

    public void lambda$null$42$SendMessagesHelper(final TLRPC.Message message, final int i, final boolean z, ArrayList arrayList, final int i2, String str) {
        getMessagesStorage().updateMessageStateAndId(message.random_id, Integer.valueOf(i), message.id, 0, false, message.to_id.channel_id, z ? 1 : 0);
        getMessagesStorage().putMessages((ArrayList<TLRPC.Message>) arrayList, true, true, false, 0, z);
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$null$41$SendMessagesHelper(message, i, i2, z);
            }
        });
        if (MessageObject.isVideoMessage(message) || MessageObject.isRoundVideoMessage(message) || MessageObject.isNewGifMessage(message)) {
            stopVideoService(str);
        }
    }

    public void lambda$null$41$SendMessagesHelper(TLRPC.Message newMsgObj, int oldId, int existFlags, boolean scheduled) {
        getMediaDataController().increasePeerRaiting(newMsgObj.dialog_id);
        getNotificationCenter().postNotificationName(NotificationCenter.messageReceivedByServer, Integer.valueOf(oldId), Integer.valueOf(newMsgObj.id), newMsgObj, Long.valueOf(newMsgObj.dialog_id), 0L, Integer.valueOf(existFlags), Boolean.valueOf(scheduled));
        processSentMessage(oldId);
        removeFromSendingMessages(oldId, scheduled);
    }

    public void lambda$performSendMessageRequest$46$SendMessagesHelper(final TLRPC.Message newMsgObj) {
        final int msg_id = newMsgObj.id;
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$null$45$SendMessagesHelper(newMsgObj, msg_id);
            }
        });
    }

    public void lambda$null$45$SendMessagesHelper(TLRPC.Message newMsgObj, int msg_id) {
        newMsgObj.send_state = 0;
        getNotificationCenter().postNotificationName(NotificationCenter.messageReceivedByAck, Integer.valueOf(msg_id));
    }

    private void updateMediaPaths(MessageObject newMsgObj, TLRPC.Message sentMessage, int newMsgId, String originalPath, boolean post) {
        String str;
        byte[] oldWaveform;
        File cacheFile2;
        TLRPC.Message newMsg = newMsgObj.messageOwner;
        if (newMsg.media != null) {
            TLRPC.PhotoSize strippedOld = null;
            TLRPC.PhotoSize strippedNew = null;
            TLObject photoObject = null;
            if (newMsg.media.photo != null) {
                strippedOld = FileLoader.getClosestPhotoSizeWithSize(newMsg.media.photo.sizes, 40);
                if (sentMessage != null && sentMessage.media != null && sentMessage.media.photo != null) {
                    strippedNew = FileLoader.getClosestPhotoSizeWithSize(sentMessage.media.photo.sizes, 40);
                } else {
                    strippedNew = strippedOld;
                }
                photoObject = newMsg.media.photo;
            } else if (newMsg.media.document != null) {
                strippedOld = FileLoader.getClosestPhotoSizeWithSize(newMsg.media.document.thumbs, 40);
                if (sentMessage != null && sentMessage.media != null && sentMessage.media.document != null) {
                    strippedNew = FileLoader.getClosestPhotoSizeWithSize(sentMessage.media.document.thumbs, 40);
                } else {
                    strippedNew = strippedOld;
                }
                photoObject = newMsg.media.document;
            } else if (newMsg.media.webpage != null) {
                if (newMsg.media.webpage.photo != null) {
                    strippedOld = FileLoader.getClosestPhotoSizeWithSize(newMsg.media.webpage.photo.sizes, 40);
                    if (sentMessage != null && sentMessage.media != null && sentMessage.media.webpage != null && sentMessage.media.webpage.photo != null) {
                        strippedNew = FileLoader.getClosestPhotoSizeWithSize(sentMessage.media.webpage.photo.sizes, 40);
                    } else {
                        strippedNew = strippedOld;
                    }
                    photoObject = newMsg.media.webpage.photo;
                } else if (newMsg.media.webpage.document != null) {
                    strippedOld = FileLoader.getClosestPhotoSizeWithSize(newMsg.media.webpage.document.thumbs, 40);
                    if (sentMessage != null && sentMessage.media != null && sentMessage.media.webpage != null && sentMessage.media.webpage.document != null) {
                        strippedNew = FileLoader.getClosestPhotoSizeWithSize(sentMessage.media.webpage.document.thumbs, 40);
                    } else {
                        strippedNew = strippedOld;
                    }
                    photoObject = newMsg.media.webpage.document;
                }
            }
            if ((strippedNew instanceof TLRPC.TL_photoStrippedSize) && (strippedOld instanceof TLRPC.TL_photoStrippedSize)) {
                String oldKey = "stripped" + FileRefController.getKeyForParentObject(newMsgObj);
                String newKey = sentMessage != null ? "stripped" + FileRefController.getKeyForParentObject(sentMessage) : "strippedmessage" + newMsgId + "_" + newMsgObj.getChannelId();
                ImageLoader.getInstance().replaceImageInCache(oldKey, newKey, ImageLocation.getForObject(strippedNew, photoObject), post);
            }
        }
        if (sentMessage == null) {
            return;
        }
        long j = -2147483648L;
        if ((sentMessage.media instanceof TLRPC.TL_messageMediaPhoto) && sentMessage.media.photo != null && (newMsg.media instanceof TLRPC.TL_messageMediaPhoto) && newMsg.media.photo != null) {
            if (sentMessage.media.ttl_seconds == 0 && !newMsgObj.scheduled) {
                getMessagesStorage().putSentFile(originalPath, sentMessage.media.photo, 0, "sent_" + sentMessage.to_id.channel_id + "_" + sentMessage.id);
            }
            if (newMsg.media.photo.sizes.size() == 1 && (newMsg.media.photo.sizes.get(0).location instanceof TLRPC.TL_fileLocationUnavailable)) {
                newMsg.media.photo.sizes = sentMessage.media.photo.sizes;
            } else {
                int a = 0;
                while (a < sentMessage.media.photo.sizes.size()) {
                    TLRPC.PhotoSize size = sentMessage.media.photo.sizes.get(a);
                    if (size != null && size.location != null && !(size instanceof TLRPC.TL_photoSizeEmpty) && size.type != null) {
                        int b = 0;
                        while (b < newMsg.media.photo.sizes.size()) {
                            TLRPC.PhotoSize size2 = newMsg.media.photo.sizes.get(b);
                            if (size2 == null || size2.location == null || size2.type == null || ((size2.location.volume_id != j || !size.type.equals(size2.type)) && (size.w != size2.w || size.h != size2.h))) {
                                b++;
                                j = -2147483648L;
                            } else {
                                String fileName = size2.location.volume_id + "_" + size2.location.local_id;
                                String fileName2 = size.location.volume_id + "_" + size.location.local_id;
                                if (!fileName.equals(fileName2)) {
                                    File cacheFile = new File(FileLoader.getDirectory(4), fileName + ".jpg");
                                    if (sentMessage.media.ttl_seconds == 0 && (sentMessage.media.photo.sizes.size() == 1 || size.w > 90 || size.h > 90)) {
                                        cacheFile2 = FileLoader.getPathToAttach(size);
                                    } else {
                                        cacheFile2 = new File(FileLoader.getDirectory(4), fileName2 + ".jpg");
                                    }
                                    cacheFile.renameTo(cacheFile2);
                                    ImageLoader.getInstance().replaceImageInCache(fileName, fileName2, ImageLocation.getForPhoto(size, sentMessage.media.photo), post);
                                    size2.location = size.location;
                                    size2.size = size.size;
                                }
                            }
                        }
                    }
                    a++;
                    j = -2147483648L;
                }
            }
            sentMessage.message = newMsg.message;
            sentMessage.attachPath = newMsg.attachPath;
            newMsg.media.photo.id = sentMessage.media.photo.id;
            newMsg.media.photo.access_hash = sentMessage.media.photo.access_hash;
            return;
        }
        if ((sentMessage.media instanceof TLRPC.TL_messageMediaDocument) && sentMessage.media.document != null && (newMsg.media instanceof TLRPC.TL_messageMediaDocument) && newMsg.media.document != null) {
            if (sentMessage.media.ttl_seconds != 0) {
                str = originalPath;
            } else {
                boolean isVideo = MessageObject.isVideoMessage(sentMessage);
                if (!isVideo && !MessageObject.isGifMessage(sentMessage)) {
                    str = originalPath;
                } else if (MessageObject.isGifDocument(sentMessage.media.document) != MessageObject.isGifDocument(newMsg.media.document)) {
                    str = originalPath;
                } else {
                    if (newMsgObj.scheduled) {
                        str = originalPath;
                    } else {
                        str = originalPath;
                        getMessagesStorage().putSentFile(str, sentMessage.media.document, 2, "sent_" + sentMessage.to_id.channel_id + "_" + sentMessage.id);
                    }
                    if (isVideo) {
                        sentMessage.attachPath = newMsg.attachPath;
                    }
                }
                if (!MessageObject.isVoiceMessage(sentMessage) && !MessageObject.isRoundVideoMessage(sentMessage) && !newMsgObj.scheduled) {
                    getMessagesStorage().putSentFile(str, sentMessage.media.document, 1, "sent_" + sentMessage.to_id.channel_id + "_" + sentMessage.id);
                }
            }
            TLRPC.PhotoSize size22 = FileLoader.getClosestPhotoSizeWithSize(newMsg.media.document.thumbs, 320);
            TLRPC.PhotoSize size3 = FileLoader.getClosestPhotoSizeWithSize(sentMessage.media.document.thumbs, 320);
            if (size22 != null && size22.location != null && size22.location.volume_id == -2147483648L && size3 != null && size3.location != null && !(size3 instanceof TLRPC.TL_photoSizeEmpty) && !(size22 instanceof TLRPC.TL_photoSizeEmpty)) {
                String fileName3 = size22.location.volume_id + "_" + size22.location.local_id;
                String fileName22 = size3.location.volume_id + "_" + size3.location.local_id;
                if (!fileName3.equals(fileName22)) {
                    new File(FileLoader.getDirectory(4), fileName3 + ".jpg").renameTo(new File(FileLoader.getDirectory(4), fileName22 + ".jpg"));
                    ImageLoader.getInstance().replaceImageInCache(fileName3, fileName22, ImageLocation.getForDocument(size3, sentMessage.media.document), post);
                    size22.location = size3.location;
                    size22.size = size3.size;
                }
            } else if (size22 != null && MessageObject.isStickerMessage(sentMessage) && size22.location != null) {
                size3.location = size22.location;
            } else if (size22 == null || ((size22 != null && (size22.location instanceof TLRPC.TL_fileLocationUnavailable)) || (size22 instanceof TLRPC.TL_photoSizeEmpty))) {
                newMsg.media.document.thumbs = sentMessage.media.document.thumbs;
            }
            newMsg.media.document.dc_id = sentMessage.media.document.dc_id;
            newMsg.media.document.id = sentMessage.media.document.id;
            newMsg.media.document.access_hash = sentMessage.media.document.access_hash;
            int a2 = 0;
            while (true) {
                if (a2 >= newMsg.media.document.attributes.size()) {
                    oldWaveform = null;
                    break;
                }
                TLRPC.DocumentAttribute attribute = newMsg.media.document.attributes.get(a2);
                if (!(attribute instanceof TLRPC.TL_documentAttributeAudio)) {
                    a2++;
                } else {
                    byte[] oldWaveform2 = attribute.waveform;
                    oldWaveform = oldWaveform2;
                    break;
                }
            }
            newMsg.media.document.attributes = sentMessage.media.document.attributes;
            if (oldWaveform != null) {
                for (int a3 = 0; a3 < newMsg.media.document.attributes.size(); a3++) {
                    TLRPC.DocumentAttribute attribute2 = newMsg.media.document.attributes.get(a3);
                    if (attribute2 instanceof TLRPC.TL_documentAttributeAudio) {
                        attribute2.waveform = oldWaveform;
                        attribute2.flags |= 4;
                    }
                }
            }
            newMsg.media.document.size = sentMessage.media.document.size;
            newMsg.media.document.mime_type = sentMessage.media.document.mime_type;
            if ((sentMessage.flags & 4) == 0 && MessageObject.isOut(sentMessage)) {
                if (MessageObject.isNewGifDocument(sentMessage.media.document)) {
                    getMediaDataController().addRecentGif(sentMessage.media.document, sentMessage.date);
                } else if (MessageObject.isStickerDocument(sentMessage.media.document) || MessageObject.isAnimatedStickerDocument(sentMessage.media.document)) {
                    getMediaDataController().addRecentSticker(0, sentMessage, sentMessage.media.document, sentMessage.date, false);
                }
            }
            if (newMsg.attachPath != null && newMsg.attachPath.startsWith(FileLoader.getDirectory(4).getAbsolutePath())) {
                File cacheFile3 = new File(newMsg.attachPath);
                File cacheFile22 = FileLoader.getPathToAttach(sentMessage.media.document, sentMessage.media.ttl_seconds != 0);
                if (!cacheFile3.renameTo(cacheFile22)) {
                    if (cacheFile3.exists()) {
                        sentMessage.attachPath = newMsg.attachPath;
                    } else {
                        newMsgObj.attachPathExists = false;
                    }
                    newMsgObj.mediaExists = cacheFile22.exists();
                    sentMessage.message = newMsg.message;
                    return;
                }
                if (MessageObject.isVideoMessage(sentMessage)) {
                    newMsgObj.attachPathExists = true;
                    return;
                }
                newMsgObj.mediaExists = newMsgObj.attachPathExists;
                newMsgObj.attachPathExists = false;
                newMsg.attachPath = "";
                if (str != null && str.startsWith("http")) {
                    getMessagesStorage().addRecentLocalFile(str, cacheFile22.toString(), newMsg.media.document);
                    return;
                }
                return;
            }
            sentMessage.attachPath = newMsg.attachPath;
            sentMessage.message = newMsg.message;
            return;
        }
        if ((sentMessage.media instanceof TLRPC.TL_messageMediaContact) && (newMsg.media instanceof TLRPC.TL_messageMediaContact)) {
            newMsg.media = sentMessage.media;
            return;
        }
        if (sentMessage.media instanceof TLRPC.TL_messageMediaWebPage) {
            newMsg.media = sentMessage.media;
            return;
        }
        if (sentMessage.media instanceof TLRPC.TL_messageMediaGeo) {
            sentMessage.media.geo.lat = newMsg.media.geo.lat;
            sentMessage.media.geo._long = newMsg.media.geo._long;
            return;
        }
        if (sentMessage.media instanceof TLRPC.TL_messageMediaGame) {
            newMsg.media = sentMessage.media;
            if ((newMsg.media instanceof TLRPC.TL_messageMediaGame) && !TextUtils.isEmpty(sentMessage.message)) {
                newMsg.entities = sentMessage.entities;
                newMsg.message = sentMessage.message;
                return;
            }
            return;
        }
        if (sentMessage.media instanceof TLRPC.TL_messageMediaPoll) {
            newMsg.media = sentMessage.media;
        }
    }

    private void putToDelayedMessages(String location, DelayedMessage message) {
        ArrayList<DelayedMessage> arrayList = this.delayedMessages.get(location);
        if (arrayList == null) {
            arrayList = new ArrayList<>();
            this.delayedMessages.put(location, arrayList);
        }
        arrayList.add(message);
    }

    public ArrayList<DelayedMessage> getDelayedMessages(String location) {
        return this.delayedMessages.get(location);
    }

    public long getNextRandomId() {
        long val = 0;
        while (val == 0) {
            val = Utilities.random.nextLong();
        }
        return val;
    }

    public void checkUnsentMessages() {
        getMessagesStorage().getUnsentMessages(1000);
    }

    public void processUnsentMessages(final ArrayList<TLRPC.Message> messages, final ArrayList<TLRPC.Message> scheduledMessages, final ArrayList<TLRPC.User> users, final ArrayList<TLRPC.Chat> chats, final ArrayList<TLRPC.EncryptedChat> encryptedChats) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.this.lambda$processUnsentMessages$47$SendMessagesHelper(users, chats, encryptedChats, messages, scheduledMessages);
            }
        });
    }

    public void lambda$processUnsentMessages$47$SendMessagesHelper(ArrayList users, ArrayList chats, ArrayList encryptedChats, ArrayList messages, ArrayList scheduledMessages) {
        getMessagesController().putUsers(users, true);
        getMessagesController().putChats(chats, true);
        getMessagesController().putEncryptedChats(encryptedChats, true);
        for (int a = 0; a < messages.size(); a++) {
            retrySendMessage(new MessageObject(this.currentAccount, (TLRPC.Message) messages.get(a), false), true);
        }
        if (scheduledMessages != null) {
            for (int a2 = 0; a2 < scheduledMessages.size(); a2++) {
                MessageObject messageObject = new MessageObject(this.currentAccount, (TLRPC.Message) scheduledMessages.get(a2), false);
                messageObject.scheduled = true;
                retrySendMessage(messageObject, true);
            }
        }
    }

    public TLRPC.TL_photo generatePhotoSizes(String path, Uri imageUri, boolean blnOriginalImg) {
        return generatePhotoSizes(null, path, imageUri, blnOriginalImg);
    }

    public TLRPC.TL_photo generatePhotoSizes(TLRPC.TL_photo photo, String path, Uri imageUri, boolean blnOriginalImg) {
        Bitmap bitmap;
        boolean isPng;
        TLRPC.PhotoSize size;
        TLRPC.TL_photo photo2;
        Bitmap bitmap2 = ImageLoader.loadBitmap(path, imageUri, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), true);
        if (bitmap2 == null) {
            bitmap = ImageLoader.loadBitmap(path, imageUri, 800.0f, 800.0f, true);
        } else {
            bitmap = bitmap2;
        }
        if (path != null) {
            boolean isPng2 = path.endsWith(".png");
            isPng = isPng2;
        } else {
            isPng = false;
        }
        ArrayList<TLRPC.PhotoSize> sizes = new ArrayList<>();
        TLRPC.PhotoSize size2 = ImageLoader.scaleAndSaveImage(bitmap, 90.0f, 90.0f, 55, true, isPng);
        if (size2 != null) {
            sizes.add(size2);
        }
        if (blnOriginalImg) {
            try {
                size = ImageLoader.SaveImageWithOriginalInternal(null, path, false);
            } catch (Throwable e) {
                FileLog.e(e);
                ImageLoader.getInstance().clearMemory();
                System.gc();
                try {
                    size = ImageLoader.SaveImageWithOriginalInternal(null, path, false);
                } catch (Throwable e2) {
                    FileLog.e(e2);
                    size = null;
                }
            }
        } else {
            size = ImageLoader.scaleAndSaveImage(bitmap, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 80, false, 101, 101, isPng);
        }
        if (size != null) {
            sizes.add(size);
        }
        if (bitmap != null) {
            bitmap.recycle();
        }
        if (sizes.isEmpty()) {
            return null;
        }
        getUserConfig().saveConfig(false);
        if (photo != null) {
            photo2 = photo;
        } else {
            photo2 = new TLRPC.TL_photo();
        }
        photo2.date = getConnectionsManager().getCurrentTime();
        photo2.sizes = sizes;
        photo2.file_reference = new byte[0];
        return photo2;
    }

    private static boolean prepareSendingDocumentInternal(final AccountInstance accountInstance, String path, String originalPath, Uri uri, String mime, final long dialog_id, final MessageObject reply_to_msg, CharSequence caption, final ArrayList<TLRPC.MessageEntity> entities, final MessageObject editingMessageObject, boolean forceDocument, final boolean notify, final int scheduleDate) {
        String extension;
        String extension2;
        String ext;
        long j;
        String permormer;
        String title;
        boolean isVoice;
        int duration;
        TLRPC.TL_documentAttributeAudio attributeAudio;
        String name;
        Object obj;
        boolean sendNew;
        TLRPC.TL_document document;
        String originalPath2;
        int duration2;
        String str;
        String title2;
        Object[] sentData;
        String originalPath3;
        boolean isEncrypted;
        MimeTypeMap myMime;
        String name2;
        Object obj2;
        long j2;
        String parentObject;
        String parentObject2;
        String name3;
        String str2;
        MimeTypeMap myMime2;
        boolean isEncrypted2;
        String originalPath4;
        char c;
        String str3;
        Object[] sentData2;
        Throwable th;
        String originalPath5 = originalPath;
        if ((path == null || path.length() == 0) && uri == null) {
            return false;
        }
        if (uri != null && AndroidUtilities.isInternalUri(uri)) {
            return false;
        }
        if (path != null && AndroidUtilities.isInternalUri(Uri.fromFile(new File(path)))) {
            return false;
        }
        MimeTypeMap myMime3 = MimeTypeMap.getSingleton();
        if (uri != null) {
            boolean hasExt = false;
            String extension3 = mime != null ? myMime3.getExtensionFromMimeType(mime) : null;
            if (extension3 == null) {
                extension3 = "txt";
            } else {
                hasExt = true;
            }
            String path2 = MediaController.copyFileToCache(uri, extension3);
            if (path2 == null) {
                return false;
            }
            if (hasExt) {
                extension = extension3;
                extension2 = path2;
            } else {
                extension = null;
                extension2 = path2;
            }
        } else {
            extension = null;
            extension2 = path;
        }
        File f = new File(extension2);
        if (f.exists() && f.length() != 0) {
            boolean isEncrypted3 = ((int) dialog_id) == 0;
            boolean allowSticker = !isEncrypted3;
            String name4 = f.getName();
            if (extension != null) {
                String ext2 = extension;
                ext = ext2;
            } else {
                int idx = extension2.lastIndexOf(46);
                if (idx != -1) {
                    String ext3 = extension2.substring(idx + 1);
                    ext = ext3;
                } else {
                    ext = "";
                }
            }
            String extL = ext.toLowerCase();
            String permormer2 = null;
            String title3 = null;
            boolean isVoice2 = false;
            int duration3 = 0;
            if (extL.equals("mp3") || extL.equals("m4a")) {
                AudioInfo audioInfo = AudioInfo.getAudioInfo(f);
                if (audioInfo != null) {
                    j = 0;
                    if (audioInfo.getDuration() != 0) {
                        permormer2 = audioInfo.getArtist();
                        title3 = audioInfo.getTitle();
                    }
                } else {
                    j = 0;
                }
                permormer = permormer2;
                title = title3;
                isVoice = false;
                duration = 0;
            } else if (extL.equals("opus") || extL.equals("ogg") || extL.equals("flac")) {
                MediaMetadataRetriever mediaMetadataRetriever = null;
                try {
                    try {
                        mediaMetadataRetriever = new MediaMetadataRetriever();
                        try {
                            try {
                                mediaMetadataRetriever.setDataSource(f.getAbsolutePath());
                                String d = mediaMetadataRetriever.extractMetadata(9);
                                if (d != null) {
                                    int duration4 = (int) Math.ceil(((float) Long.parseLong(d)) / 1000.0f);
                                    try {
                                        title3 = mediaMetadataRetriever.extractMetadata(7);
                                        duration3 = duration4;
                                        permormer2 = mediaMetadataRetriever.extractMetadata(2);
                                    } catch (Exception e) {
                                        e = e;
                                        duration3 = duration4;
                                        mediaMetadataRetriever = mediaMetadataRetriever;
                                        FileLog.e(e);
                                        if (mediaMetadataRetriever != null) {
                                            try {
                                                mediaMetadataRetriever.release();
                                            } catch (Exception e2) {
                                                FileLog.e(e2);
                                            }
                                        }
                                        permormer = permormer2;
                                        title = title3;
                                        isVoice = isVoice2;
                                        duration = duration3;
                                        j = 0;
                                        if (duration == 0) {
                                        }
                                        if (originalPath5 != null) {
                                        }
                                        document = null;
                                        String parentObject3 = null;
                                        if (sendNew) {
                                        }
                                        originalPath2 = originalPath5;
                                        duration2 = duration;
                                        str = "";
                                        title2 = "opus";
                                        sentData = "m4a";
                                        originalPath3 = "ogg";
                                        isEncrypted = isEncrypted3;
                                        myMime = myMime3;
                                        name2 = name;
                                        obj2 = obj;
                                        j2 = j;
                                        parentObject = "mp3";
                                        parentObject2 = null;
                                        if (document != null) {
                                        }
                                        if (caption == null) {
                                        }
                                        final HashMap<String, String> params = new HashMap<>();
                                        if (originalPath2 == null) {
                                        }
                                        if (forceDocument) {
                                        }
                                        final TLRPC.TL_document documentFinal = document;
                                        final String pathFinal = extension2;
                                        final String parentFinal = parentObject2;
                                        AndroidUtilities.runOnUIThread(new Runnable() {
                                            @Override
                                            public final void run() {
                                                SendMessagesHelper.lambda$prepareSendingDocumentInternal$48(MessageObject.this, accountInstance, documentFinal, pathFinal, params, parentFinal, dialog_id, reply_to_msg, captionFinal, entities, notify, scheduleDate);
                                            }
                                        });
                                        return true;
                                    } catch (Throwable th2) {
                                        mediaMetadataRetriever = mediaMetadataRetriever;
                                        th = th2;
                                        if (mediaMetadataRetriever == null) {
                                            throw th;
                                        }
                                        try {
                                            mediaMetadataRetriever.release();
                                            throw th;
                                        } catch (Exception e3) {
                                            FileLog.e(e3);
                                            throw th;
                                        }
                                    }
                                }
                                if (editingMessageObject == null && extL.equals("ogg")) {
                                    if (MediaController.isOpusFile(f.getAbsolutePath()) == 1) {
                                        isVoice2 = true;
                                    }
                                }
                                try {
                                    mediaMetadataRetriever.release();
                                } catch (Exception e4) {
                                    FileLog.e(e4);
                                }
                            } catch (Exception e5) {
                                e = e5;
                                mediaMetadataRetriever = mediaMetadataRetriever;
                            } catch (Throwable th3) {
                                th = th3;
                                mediaMetadataRetriever = mediaMetadataRetriever;
                            }
                        } catch (Exception e6) {
                            e = e6;
                        } catch (Throwable th4) {
                            th = th4;
                        }
                    } catch (Exception e7) {
                        e = e7;
                    }
                    permormer = permormer2;
                    title = title3;
                    isVoice = isVoice2;
                    duration = duration3;
                    j = 0;
                } catch (Throwable th5) {
                    th = th5;
                }
            } else {
                permormer = null;
                title = null;
                isVoice = false;
                duration = 0;
                j = 0;
            }
            if (duration == 0) {
                TLRPC.TL_documentAttributeAudio attributeAudio2 = new TLRPC.TL_documentAttributeAudio();
                attributeAudio2.duration = duration;
                attributeAudio2.title = title;
                attributeAudio2.performer = permormer;
                if (attributeAudio2.title == null) {
                    attributeAudio2.title = "";
                }
                attributeAudio2.flags |= 1;
                if (attributeAudio2.performer == null) {
                    attributeAudio2.performer = "";
                }
                attributeAudio2.flags |= 2;
                if (isVoice) {
                    attributeAudio2.voice = true;
                }
                attributeAudio = attributeAudio2;
            } else {
                attributeAudio = null;
            }
            if (originalPath5 != null) {
                name = name4;
                obj = "flac";
                sendNew = false;
            } else if (originalPath5.endsWith("attheme")) {
                sendNew = true;
                name = name4;
                obj = "flac";
            } else if (attributeAudio != null) {
                StringBuilder sb = new StringBuilder();
                sb.append(originalPath5);
                sb.append(MimeTypes.BASE_TYPE_AUDIO);
                name = name4;
                obj = "flac";
                sb.append(f.length());
                originalPath5 = sb.toString();
                sendNew = false;
            } else {
                name = name4;
                obj = "flac";
                originalPath5 = originalPath5 + "" + f.length();
                sendNew = false;
            }
            document = null;
            String parentObject32 = null;
            if (!sendNew || isEncrypted3) {
                originalPath2 = originalPath5;
                duration2 = duration;
                str = "";
                title2 = "opus";
                sentData = "m4a";
                originalPath3 = "ogg";
                isEncrypted = isEncrypted3;
                myMime = myMime3;
                name2 = name;
                obj2 = obj;
                j2 = j;
                parentObject = "mp3";
                parentObject2 = null;
            } else {
                Object[] sentData3 = accountInstance.getMessagesStorage().getSentFile(originalPath5, !isEncrypted3 ? 1 : 4);
                if (sentData3 != null) {
                    document = (TLRPC.TL_document) sentData3[0];
                    parentObject32 = (String) sentData3[1];
                }
                if (document != null || extension2.equals(originalPath5) || isEncrypted3) {
                    duration2 = duration;
                    str3 = "";
                    sentData2 = sentData3;
                    document = document;
                } else {
                    MessagesStorage messagesStorage = accountInstance.getMessagesStorage();
                    TLRPC.TL_document document2 = document;
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append(extension2);
                    duration2 = duration;
                    str3 = "";
                    sb2.append(f.length());
                    Object[] sentData4 = messagesStorage.getSentFile(sb2.toString(), !isEncrypted3 ? 1 : 4);
                    if (sentData4 != null) {
                        document = (TLRPC.TL_document) sentData4[0];
                        parentObject32 = (String) sentData4[1];
                        sentData2 = sentData4;
                    } else {
                        sentData2 = sentData4;
                        document = document2;
                    }
                }
                name2 = name;
                str = str3;
                obj2 = obj;
                String parentObject4 = parentObject32;
                title2 = "opus";
                parentObject = "mp3";
                originalPath2 = originalPath5;
                sentData = "m4a";
                originalPath3 = "ogg";
                isEncrypted = isEncrypted3;
                myMime = myMime3;
                j2 = j;
                ensureMediaThumbExists(isEncrypted3, document, extension2, null, 0L);
                parentObject2 = parentObject4;
            }
            if (document != null) {
                TLRPC.TL_document document3 = new TLRPC.TL_document();
                document3.id = j2;
                document3.date = accountInstance.getConnectionsManager().getCurrentTime();
                TLRPC.TL_documentAttributeFilename fileName = new TLRPC.TL_documentAttributeFilename();
                name3 = name2;
                fileName.file_name = name3;
                document3.file_reference = new byte[0];
                document3.attributes.add(fileName);
                document3.size = (int) f.length();
                document3.dc_id = 0;
                if (attributeAudio != null) {
                    document3.attributes.add(attributeAudio);
                }
                if (ext.length() != 0) {
                    switch (extL.hashCode()) {
                        case 106458:
                            if (extL.equals(sentData)) {
                                c = 3;
                                break;
                            }
                            c = 65535;
                            break;
                        case 108272:
                            if (extL.equals(parentObject)) {
                                c = 2;
                                break;
                            }
                            c = 65535;
                            break;
                        case 109967:
                            if (extL.equals(originalPath3)) {
                                c = 4;
                                break;
                            }
                            c = 65535;
                            break;
                        case 3145576:
                            if (extL.equals(obj2)) {
                                c = 5;
                                break;
                            }
                            c = 65535;
                            break;
                        case 3418175:
                            if (extL.equals(title2)) {
                                c = 1;
                                break;
                            }
                            c = 65535;
                            break;
                        case 3645340:
                            if (extL.equals("webp")) {
                                c = 0;
                                break;
                            }
                            c = 65535;
                            break;
                        default:
                            c = 65535;
                            break;
                    }
                    if (c == 0) {
                        myMime2 = myMime;
                        document3.mime_type = "image/webp";
                    } else if (c == 1) {
                        myMime2 = myMime;
                        document3.mime_type = MimeTypes.AUDIO_OPUS;
                    } else if (c == 2) {
                        myMime2 = myMime;
                        document3.mime_type = MimeTypes.AUDIO_MPEG;
                    } else if (c == 3) {
                        myMime2 = myMime;
                        document3.mime_type = "audio/m4a";
                    } else if (c == 4) {
                        myMime2 = myMime;
                        document3.mime_type = "audio/ogg";
                    } else if (c != 5) {
                        myMime2 = myMime;
                        String mimeType = myMime2.getMimeTypeFromExtension(extL);
                        if (mimeType != null) {
                            document3.mime_type = mimeType;
                        } else {
                            document3.mime_type = "application/octet-stream";
                        }
                    } else {
                        myMime2 = myMime;
                        document3.mime_type = MimeTypes.AUDIO_FLAC;
                    }
                } else {
                    myMime2 = myMime;
                    document3.mime_type = "application/octet-stream";
                }
                if (!document3.mime_type.equals("image/gif")) {
                    isEncrypted2 = isEncrypted;
                } else if (editingMessageObject == null || editingMessageObject.getGroupIdForUse() == 0) {
                    try {
                        Bitmap bitmap = ImageLoader.loadBitmap(f.getAbsolutePath(), null, 90.0f, 90.0f, true);
                        if (bitmap != null) {
                            fileName.file_name = "animation.gif";
                            document3.attributes.add(new TLRPC.TL_documentAttributeAnimated());
                            isEncrypted2 = isEncrypted;
                            try {
                                TLRPC.PhotoSize thumb = ImageLoader.scaleAndSaveImage(bitmap, 90.0f, 90.0f, 55, isEncrypted2);
                                if (thumb != null) {
                                    document3.thumbs.add(thumb);
                                    document3.flags |= 1;
                                }
                                bitmap.recycle();
                            } catch (Exception e8) {
                                e = e8;
                                FileLog.e(e);
                                if (!document3.mime_type.equals("image/webp")) {
                                }
                                str2 = str;
                                if (!document3.mime_type.startsWith("image/")) {
                                }
                                document = document3;
                                if (caption == null) {
                                }
                                final HashMap params2 = new HashMap<>();
                                if (originalPath2 == null) {
                                }
                                if (forceDocument) {
                                }
                                final TLRPC.TL_document documentFinal2 = document;
                                final String pathFinal2 = extension2;
                                final String parentFinal2 = parentObject2;
                                AndroidUtilities.runOnUIThread(new Runnable() {
                                    @Override
                                    public final void run() {
                                        SendMessagesHelper.lambda$prepareSendingDocumentInternal$48(MessageObject.this, accountInstance, documentFinal2, pathFinal2, params2, parentFinal2, dialog_id, reply_to_msg, captionFinal, entities, notify, scheduleDate);
                                    }
                                });
                                return true;
                            }
                        } else {
                            isEncrypted2 = isEncrypted;
                        }
                    } catch (Exception e9) {
                        e = e9;
                        isEncrypted2 = isEncrypted;
                    }
                } else {
                    isEncrypted2 = isEncrypted;
                }
                if (!document3.mime_type.equals("image/webp") && allowSticker && editingMessageObject == null) {
                    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
                    try {
                        bmOptions.inJustDecodeBounds = true;
                        RandomAccessFile file = new RandomAccessFile(extension2, "r");
                        ByteBuffer buffer = file.getChannel().map(FileChannel.MapMode.READ_ONLY, 0L, extension2.length());
                        Utilities.loadWebpImage(null, buffer, buffer.limit(), bmOptions, true);
                        file.close();
                    } catch (Exception e10) {
                        FileLog.e(e10);
                    }
                    if (bmOptions.outWidth == 0 || bmOptions.outHeight == 0 || bmOptions.outWidth > 800 || bmOptions.outHeight > 800) {
                        str2 = str;
                    } else {
                        TLRPC.TL_documentAttributeSticker attributeSticker = new TLRPC.TL_documentAttributeSticker();
                        str2 = str;
                        attributeSticker.alt = str2;
                        attributeSticker.stickerset = new TLRPC.TL_inputStickerSetEmpty();
                        document3.attributes.add(attributeSticker);
                        TLRPC.TL_documentAttributeImageSize attributeImageSize = new TLRPC.TL_documentAttributeImageSize();
                        attributeImageSize.w = bmOptions.outWidth;
                        attributeImageSize.h = bmOptions.outHeight;
                        document3.attributes.add(attributeImageSize);
                    }
                } else {
                    str2 = str;
                }
                if (!document3.mime_type.startsWith("image/") && !document3.mime_type.equals("image/gif") && !document3.mime_type.equals("image/webp")) {
                    if (editingMessageObject == null || editingMessageObject.getGroupIdForUse() == 0) {
                        try {
                        } catch (Exception e11) {
                            e = e11;
                        }
                        try {
                            Bitmap bitmap2 = ImageLoader.loadBitmap(f.getAbsolutePath(), null, 90.0f, 90.0f, true);
                            if (bitmap2 != null) {
                                TLRPC.PhotoSize thumb2 = ImageLoader.scaleAndSaveImage(bitmap2, 90.0f, 90.0f, 55, isEncrypted2, document3.mime_type.equals("image/png"));
                                if (thumb2 != null) {
                                    document3.thumbs.add(thumb2);
                                    document3.flags |= 1;
                                }
                                bitmap2.recycle();
                            }
                        } catch (Exception e12) {
                            e = e12;
                            FileLog.e(e);
                            document = document3;
                            if (caption == null) {
                            }
                            final HashMap params22 = new HashMap<>();
                            if (originalPath2 == null) {
                            }
                            if (forceDocument) {
                            }
                            final TLRPC.TL_document documentFinal22 = document;
                            final String pathFinal22 = extension2;
                            final String parentFinal22 = parentObject2;
                            AndroidUtilities.runOnUIThread(new Runnable() {
                                @Override
                                public final void run() {
                                    SendMessagesHelper.lambda$prepareSendingDocumentInternal$48(MessageObject.this, accountInstance, documentFinal22, pathFinal22, params22, parentFinal22, dialog_id, reply_to_msg, captionFinal, entities, notify, scheduleDate);
                                }
                            });
                            return true;
                        }
                    }
                }
                document = document3;
            } else {
                name3 = name2;
                str2 = str;
                myMime2 = myMime;
                isEncrypted2 = isEncrypted;
            }
            final String captionFinal = caption == null ? caption.toString() : str2;
            final HashMap params222 = new HashMap<>();
            if (originalPath2 == null) {
                originalPath4 = originalPath2;
                params222.put("originalPath", originalPath4);
            } else {
                originalPath4 = originalPath2;
            }
            if (forceDocument) {
                params222.put("forceDocument", "1");
            }
            final TLRPC.TL_document documentFinal222 = document;
            final String pathFinal222 = extension2;
            final String parentFinal222 = parentObject2;
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    SendMessagesHelper.lambda$prepareSendingDocumentInternal$48(MessageObject.this, accountInstance, documentFinal222, pathFinal222, params222, parentFinal222, dialog_id, reply_to_msg, captionFinal, entities, notify, scheduleDate);
                }
            });
            return true;
        }
        return false;
    }

    public static void lambda$prepareSendingDocumentInternal$48(MessageObject editingMessageObject, AccountInstance accountInstance, TLRPC.TL_document documentFinal, String pathFinal, HashMap params, String parentFinal, long dialog_id, MessageObject reply_to_msg, String captionFinal, ArrayList entities, boolean notify, int scheduleDate) {
        if (editingMessageObject != null) {
            accountInstance.getSendMessagesHelper().editMessageMedia(editingMessageObject, null, null, documentFinal, pathFinal, params, false, parentFinal);
        } else {
            accountInstance.getSendMessagesHelper().sendMessage(documentFinal, null, pathFinal, dialog_id, reply_to_msg, captionFinal, entities, null, params, notify, scheduleDate, 0, parentFinal);
        }
    }

    public static void prepareSendingDocument(AccountInstance accountInstance, String path, String originalPath, Uri uri, String caption, String mine, long dialog_id, MessageObject reply_to_msg, InputContentInfoCompat inputContent, MessageObject editingMessageObject, boolean notify, int scheduleDate) {
        ArrayList<Uri> uris;
        if ((path == null || originalPath == null) && uri == null) {
            return;
        }
        ArrayList<String> paths = new ArrayList<>();
        ArrayList<String> originalPaths = new ArrayList<>();
        if (uri == null) {
            uris = null;
        } else {
            ArrayList<Uri> uris2 = new ArrayList<>();
            uris2.add(uri);
            uris = uris2;
        }
        if (path != null) {
            paths.add(path);
            originalPaths.add(originalPath);
        }
        prepareSendingDocuments(accountInstance, paths, originalPaths, uris, caption, mine, dialog_id, reply_to_msg, inputContent, editingMessageObject, notify, scheduleDate);
    }

    public static void prepareSendingAudioDocuments(final AccountInstance accountInstance, final ArrayList<MessageObject> messageObjects, final long dialog_id, final MessageObject reply_to_msg, final MessageObject editingMessageObject, final boolean notify, final int scheduleDate) {
        new Thread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.lambda$prepareSendingAudioDocuments$50(messageObjects, dialog_id, accountInstance, editingMessageObject, reply_to_msg, notify, scheduleDate);
            }
        }).start();
    }

    public static void lambda$prepareSendingAudioDocuments$50(ArrayList messageObjects, final long dialog_id, final AccountInstance accountInstance, final MessageObject editingMessageObject, final MessageObject reply_to_msg, final boolean notify, final int scheduleDate) {
        String parentObject;
        TLRPC.TL_document document;
        int size = messageObjects.size();
        for (int a = 0; a < size; a++) {
            final MessageObject messageObject = (MessageObject) messageObjects.get(a);
            String originalPath = messageObject.messageOwner.attachPath;
            File f = new File(originalPath);
            boolean isEncrypted = ((int) dialog_id) == 0;
            String originalPath2 = originalPath == null ? originalPath : originalPath + MimeTypes.BASE_TYPE_AUDIO + f.length();
            TLRPC.TL_document document2 = null;
            if (!isEncrypted) {
                Object[] sentData = accountInstance.getMessagesStorage().getSentFile(originalPath2, !isEncrypted ? 1 : 4);
                if (sentData != null) {
                    document2 = (TLRPC.TL_document) sentData[0];
                    String parentObject2 = (String) sentData[1];
                    ensureMediaThumbExists(isEncrypted, document2, originalPath2, null, 0L);
                    parentObject = parentObject2;
                    if (document2 == null) {
                        document = document2;
                    } else {
                        TLRPC.TL_document document3 = (TLRPC.TL_document) messageObject.messageOwner.media.document;
                        document = document3;
                    }
                    if (isEncrypted) {
                        int high_id = (int) (dialog_id >> 32);
                        TLRPC.EncryptedChat encryptedChat = accountInstance.getMessagesController().getEncryptedChat(Integer.valueOf(high_id));
                        if (encryptedChat == null) {
                            return;
                        }
                    }
                    final HashMap<String, String> params = new HashMap<>();
                    if (originalPath2 == null) {
                        params.put("originalPath", originalPath2);
                    }
                    final TLRPC.TL_document documentFinal = document;
                    final String parentFinal = parentObject;
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public final void run() {
                            SendMessagesHelper.lambda$null$49(MessageObject.this, accountInstance, documentFinal, messageObject, params, parentFinal, dialog_id, reply_to_msg, notify, scheduleDate);
                        }
                    });
                }
            }
            parentObject = null;
            if (document2 == null) {
            }
            if (isEncrypted) {
            }
            final HashMap params2 = new HashMap<>();
            if (originalPath2 == null) {
            }
            final TLRPC.TL_document documentFinal2 = document;
            final String parentFinal2 = parentObject;
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    SendMessagesHelper.lambda$null$49(MessageObject.this, accountInstance, documentFinal2, messageObject, params2, parentFinal2, dialog_id, reply_to_msg, notify, scheduleDate);
                }
            });
        }
    }

    public static void lambda$null$49(MessageObject editingMessageObject, AccountInstance accountInstance, TLRPC.TL_document documentFinal, MessageObject messageObject, HashMap params, String parentFinal, long dialog_id, MessageObject reply_to_msg, boolean notify, int scheduleDate) {
        if (editingMessageObject != null) {
            accountInstance.getSendMessagesHelper().editMessageMedia(editingMessageObject, null, null, documentFinal, messageObject.messageOwner.attachPath, params, false, parentFinal);
        } else {
            accountInstance.getSendMessagesHelper().sendMessage(documentFinal, null, messageObject.messageOwner.attachPath, dialog_id, reply_to_msg, null, null, null, params, notify, scheduleDate, 0, parentFinal);
        }
    }

    public static void prepareSendingDocuments(final AccountInstance accountInstance, final ArrayList<String> paths, final ArrayList<String> originalPaths, final ArrayList<Uri> uris, final String caption, final String mime, final long dialog_id, final MessageObject reply_to_msg, final InputContentInfoCompat inputContent, final MessageObject editingMessageObject, final boolean notify, final int scheduleDate) {
        if (paths == null && originalPaths == null && uris == null) {
            return;
        }
        if (paths != null && originalPaths != null && paths.size() != originalPaths.size()) {
            return;
        }
        new Thread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.lambda$prepareSendingDocuments$51(paths, accountInstance, originalPaths, mime, dialog_id, reply_to_msg, caption, editingMessageObject, notify, scheduleDate, uris, inputContent);
            }
        }).start();
    }

    public static void lambda$prepareSendingDocuments$51(ArrayList paths, AccountInstance accountInstance, ArrayList originalPaths, String mime, long dialog_id, MessageObject reply_to_msg, String caption, MessageObject editingMessageObject, boolean notify, int scheduleDate, ArrayList uris, InputContentInfoCompat inputContent) {
        boolean error = false;
        if (paths != null) {
            for (int a = 0; a < paths.size(); a++) {
                if (!prepareSendingDocumentInternal(accountInstance, (String) paths.get(a), (String) originalPaths.get(a), null, mime, dialog_id, reply_to_msg, caption, null, editingMessageObject, false, notify, scheduleDate)) {
                    error = true;
                }
            }
        }
        if (uris != null) {
            for (int a2 = 0; a2 < uris.size(); a2++) {
                if (!prepareSendingDocumentInternal(accountInstance, null, null, (Uri) uris.get(a2), mime, dialog_id, reply_to_msg, caption, null, editingMessageObject, false, notify, scheduleDate)) {
                    error = true;
                }
            }
        }
        if (inputContent != null) {
            inputContent.releasePermission();
        }
        if (error) {
            ToastUtils.show(R.string.UnsupportedAttachment);
        }
    }

    public static void prepareSendingPhoto(AccountInstance accountInstance, String imageFilePath, Uri imageUri, long dialog_id, MessageObject reply_to_msg, CharSequence caption, ArrayList<TLRPC.MessageEntity> entities, ArrayList<TLRPC.InputDocument> stickers, InputContentInfoCompat inputContent, int ttl, MessageObject editingMessageObject, boolean notify, int scheduleDate) {
        SendingMediaInfo info = new SendingMediaInfo();
        info.path = imageFilePath;
        info.uri = imageUri;
        if (caption != null) {
            info.caption = caption.toString();
        }
        info.entities = entities;
        info.ttl = ttl;
        if (stickers != null && !stickers.isEmpty()) {
            info.masks = new ArrayList<>(stickers);
        }
        ArrayList<SendingMediaInfo> infos = new ArrayList<>();
        infos.add(info);
        prepareSendingMedia(accountInstance, infos, dialog_id, reply_to_msg, inputContent, false, false, editingMessageObject, notify, scheduleDate, false);
    }

    public static void prepareSendingBotContextResult(final AccountInstance accountInstance, final TLRPC.BotInlineResult result, final HashMap<String, String> params, final long dialog_id, final MessageObject reply_to_msg, final boolean notify, final int scheduleDate) {
        if (result == null) {
            return;
        }
        if (result.send_message instanceof TLRPC.TL_botInlineMessageMediaAuto) {
            new Thread(new Runnable() {
                @Override
                public final void run() {
                    SendMessagesHelper.lambda$prepareSendingBotContextResult$53(dialog_id, result, accountInstance, params, reply_to_msg, notify, scheduleDate);
                }
            }).run();
            return;
        }
        if (!(result.send_message instanceof TLRPC.TL_botInlineMessageText)) {
            if (!(result.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue)) {
                if (result.send_message instanceof TLRPC.TL_botInlineMessageMediaGeo) {
                    if (result.send_message.period != 0) {
                        TLRPC.TL_messageMediaGeoLive location = new TLRPC.TL_messageMediaGeoLive();
                        location.period = result.send_message.period;
                        location.geo = result.send_message.geo;
                        accountInstance.getSendMessagesHelper().sendMessage(location, dialog_id, reply_to_msg, result.send_message.reply_markup, params, notify, scheduleDate);
                        return;
                    }
                    TLRPC.TL_messageMediaGeo location2 = new TLRPC.TL_messageMediaGeo();
                    location2.geo = result.send_message.geo;
                    accountInstance.getSendMessagesHelper().sendMessage(location2, dialog_id, reply_to_msg, result.send_message.reply_markup, params, notify, scheduleDate);
                    return;
                }
                if (result.send_message instanceof TLRPC.TL_botInlineMessageMediaContact) {
                    TLRPC.User user = new TLRPC.TL_user();
                    user.phone = result.send_message.phone_number;
                    user.first_name = result.send_message.first_name;
                    user.last_name = result.send_message.last_name;
                    TLRPC.TL_restrictionReason reason = new TLRPC.TL_restrictionReason();
                    reason.text = result.send_message.vcard;
                    reason.platform = "";
                    reason.reason = "";
                    user.restriction_reason.add(reason);
                    accountInstance.getSendMessagesHelper().sendMessage(user, dialog_id, reply_to_msg, result.send_message.reply_markup, params, notify, scheduleDate);
                    return;
                }
                return;
            }
            TLRPC.TL_messageMediaVenue venue = new TLRPC.TL_messageMediaVenue();
            venue.geo = result.send_message.geo;
            venue.address = result.send_message.address;
            venue.title = result.send_message.title;
            venue.provider = result.send_message.provider;
            venue.venue_id = result.send_message.venue_id;
            String str = result.send_message.venue_type;
            venue.venue_id = str;
            venue.venue_type = str;
            if (venue.venue_type == null) {
                venue.venue_type = "";
            }
            accountInstance.getSendMessagesHelper().sendMessage(venue, dialog_id, reply_to_msg, result.send_message.reply_markup, params, notify, scheduleDate);
            return;
        }
        TLRPC.WebPage webPage = null;
        if (((int) dialog_id) == 0) {
            int a = 0;
            while (true) {
                if (a >= result.send_message.entities.size()) {
                    break;
                }
                TLRPC.MessageEntity entity = result.send_message.entities.get(a);
                if (!(entity instanceof TLRPC.TL_messageEntityUrl)) {
                    a++;
                } else {
                    webPage = new TLRPC.TL_webPagePending();
                    webPage.url = result.send_message.message.substring(entity.offset, entity.offset + entity.length);
                    break;
                }
            }
        }
        accountInstance.getSendMessagesHelper().sendMessage(result.send_message.message, dialog_id, reply_to_msg, webPage, !result.send_message.no_webpage, result.send_message.entities, result.send_message.reply_markup, params, notify, scheduleDate);
    }

    public static void lambda$prepareSendingBotContextResult$53(final long dialog_id, final TLRPC.BotInlineResult result, final AccountInstance accountInstance, final HashMap params, final MessageObject reply_to_msg, final boolean notify, final int scheduleDate) {
        TLRPC.TL_document document;
        TLRPC.TL_photo photo;
        TLRPC.TL_game game;
        String finalPath;
        char c;
        char c2;
        Bitmap bitmap;
        TLRPC.TL_photo photo2;
        boolean isEncrypted = ((int) dialog_id) == 0;
        String finalPath2 = null;
        if ("game".equals(result.type)) {
            if (((int) dialog_id) == 0) {
                return;
            }
            TLRPC.TL_game game2 = new TLRPC.TL_game();
            game2.title = result.title;
            game2.description = result.description;
            game2.short_name = result.id;
            game2.photo = result.photo;
            if (game2.photo == null) {
                game2.photo = new TLRPC.TL_photoEmpty();
            }
            if (result.document instanceof TLRPC.TL_document) {
                game2.document = result.document;
                game2.flags |= 1;
            }
            document = null;
            photo = null;
            game = game2;
        } else if (result instanceof TLRPC.TL_botInlineMediaResult) {
            if (result.document != null) {
                if (!(result.document instanceof TLRPC.TL_document)) {
                    document = null;
                    photo = null;
                    game = null;
                } else {
                    TLRPC.TL_document document2 = (TLRPC.TL_document) result.document;
                    document = document2;
                    photo = null;
                    game = null;
                }
            } else if (result.photo == null) {
                document = null;
                photo = null;
                game = null;
            } else if (!(result.photo instanceof TLRPC.TL_photo)) {
                document = null;
                photo = null;
                game = null;
            } else {
                TLRPC.TL_photo photo3 = (TLRPC.TL_photo) result.photo;
                document = null;
                photo = photo3;
                game = null;
            }
        } else if (result.content == null) {
            document = null;
            photo = null;
            game = null;
        } else {
            File f = new File(FileLoader.getDirectory(4), Utilities.MD5(result.content.url) + "." + ImageLoader.getHttpUrlExtension(result.content.url, "file"));
            if (f.exists()) {
                finalPath = f.getAbsolutePath();
            } else {
                finalPath = result.content.url;
            }
            String finalPath3 = result.type;
            document = null;
            photo = null;
            game = null;
            switch (finalPath3.hashCode()) {
                case -1890252483:
                    if (finalPath3.equals("sticker")) {
                        c = 4;
                        break;
                    }
                    c = 65535;
                    break;
                case 102340:
                    if (finalPath3.equals("gif")) {
                        c = 5;
                        break;
                    }
                    c = 65535;
                    break;
                case 3143036:
                    if (finalPath3.equals("file")) {
                        c = 2;
                        break;
                    }
                    c = 65535;
                    break;
                case 93166550:
                    if (finalPath3.equals(MimeTypes.BASE_TYPE_AUDIO)) {
                        c = 0;
                        break;
                    }
                    c = 65535;
                    break;
                case 106642994:
                    if (finalPath3.equals("photo")) {
                        c = 6;
                        break;
                    }
                    c = 65535;
                    break;
                case 112202875:
                    if (finalPath3.equals(MimeTypes.BASE_TYPE_VIDEO)) {
                        c = 3;
                        break;
                    }
                    c = 65535;
                    break;
                case 112386354:
                    if (finalPath3.equals("voice")) {
                        c = 1;
                        break;
                    }
                    c = 65535;
                    break;
                default:
                    c = 65535;
                    break;
            }
            switch (c) {
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                    TLRPC.TL_document document3 = new TLRPC.TL_document();
                    document3.id = 0L;
                    document3.size = 0;
                    document3.dc_id = 0;
                    document3.mime_type = result.content.mime_type;
                    document3.file_reference = new byte[0];
                    document3.date = accountInstance.getConnectionsManager().getCurrentTime();
                    TLRPC.TL_documentAttributeFilename fileName = new TLRPC.TL_documentAttributeFilename();
                    document3.attributes.add(fileName);
                    String str = result.type;
                    switch (str.hashCode()) {
                        case -1890252483:
                            if (str.equals("sticker")) {
                                c2 = 5;
                                break;
                            }
                            c2 = 65535;
                            break;
                        case 102340:
                            if (str.equals("gif")) {
                                c2 = 0;
                                break;
                            }
                            c2 = 65535;
                            break;
                        case 3143036:
                            if (str.equals("file")) {
                                c2 = 3;
                                break;
                            }
                            c2 = 65535;
                            break;
                        case 93166550:
                            if (str.equals(MimeTypes.BASE_TYPE_AUDIO)) {
                                c2 = 2;
                                break;
                            }
                            c2 = 65535;
                            break;
                        case 112202875:
                            if (str.equals(MimeTypes.BASE_TYPE_VIDEO)) {
                                c2 = 4;
                                break;
                            }
                            c2 = 65535;
                            break;
                        case 112386354:
                            if (str.equals("voice")) {
                                c2 = 1;
                                break;
                            }
                            c2 = 65535;
                            break;
                        default:
                            c2 = 65535;
                            break;
                    }
                    if (c2 == 0) {
                        fileName.file_name = "animation.gif";
                        if (finalPath.endsWith("mp4")) {
                            document3.mime_type = MimeTypes.VIDEO_MP4;
                            document3.attributes.add(new TLRPC.TL_documentAttributeAnimated());
                        } else {
                            document3.mime_type = "image/gif";
                        }
                        int side = isEncrypted ? 90 : 320;
                        try {
                            if (finalPath.endsWith("mp4")) {
                                bitmap = ThumbnailUtils.createVideoThumbnail(finalPath, 1);
                            } else {
                                bitmap = ImageLoader.loadBitmap(finalPath, null, side, side, true);
                            }
                            if (bitmap != null) {
                                TLRPC.PhotoSize thumb = ImageLoader.scaleAndSaveImage(bitmap, side, side, side > 90 ? 80 : 55, false);
                                if (thumb != null) {
                                    document3.thumbs.add(thumb);
                                    document3.flags |= 1;
                                }
                                bitmap.recycle();
                            }
                        } catch (Throwable e) {
                            FileLog.e(e);
                        }
                    } else if (c2 == 1) {
                        TLRPC.TL_documentAttributeAudio audio = new TLRPC.TL_documentAttributeAudio();
                        audio.duration = MessageObject.getInlineResultDuration(result);
                        audio.voice = true;
                        fileName.file_name = "audio.ogg";
                        document3.attributes.add(audio);
                    } else if (c2 == 2) {
                        TLRPC.TL_documentAttributeAudio audio2 = new TLRPC.TL_documentAttributeAudio();
                        audio2.duration = MessageObject.getInlineResultDuration(result);
                        audio2.title = result.title;
                        audio2.flags |= 1;
                        if (result.description != null) {
                            audio2.performer = result.description;
                            audio2.flags |= 2;
                        }
                        fileName.file_name = "audio.mp3";
                        document3.attributes.add(audio2);
                    } else if (c2 == 3) {
                        int idx = result.content.mime_type.lastIndexOf(47);
                        if (idx != -1) {
                            fileName.file_name = "file." + result.content.mime_type.substring(idx + 1);
                        } else {
                            fileName.file_name = "file";
                        }
                    } else if (c2 == 4) {
                        fileName.file_name = "video.mp4";
                        TLRPC.TL_documentAttributeVideo attributeVideo = new TLRPC.TL_documentAttributeVideo();
                        int[] wh = MessageObject.getInlineResultWidthAndHeight(result);
                        attributeVideo.w = wh[0];
                        attributeVideo.h = wh[1];
                        attributeVideo.duration = MessageObject.getInlineResultDuration(result);
                        attributeVideo.supports_streaming = true;
                        document3.attributes.add(attributeVideo);
                        try {
                            if (result.thumb != null) {
                                String thumbPath = new File(FileLoader.getDirectory(4), Utilities.MD5(result.thumb.url) + "." + ImageLoader.getHttpUrlExtension(result.thumb.url, "jpg")).getAbsolutePath();
                                Bitmap bitmap2 = ImageLoader.loadBitmap(thumbPath, null, 90.0f, 90.0f, true);
                                if (bitmap2 != null) {
                                    TLRPC.PhotoSize thumb2 = ImageLoader.scaleAndSaveImage(bitmap2, 90.0f, 90.0f, 55, false);
                                    if (thumb2 != null) {
                                        document3.thumbs.add(thumb2);
                                        document3.flags |= 1;
                                    }
                                    bitmap2.recycle();
                                }
                            }
                        } catch (Throwable e2) {
                            FileLog.e(e2);
                        }
                    } else if (c2 == 5) {
                        TLRPC.TL_documentAttributeSticker attributeSticker = new TLRPC.TL_documentAttributeSticker();
                        attributeSticker.alt = "";
                        attributeSticker.stickerset = new TLRPC.TL_inputStickerSetEmpty();
                        document3.attributes.add(attributeSticker);
                        TLRPC.TL_documentAttributeImageSize attributeImageSize = new TLRPC.TL_documentAttributeImageSize();
                        int[] wh2 = MessageObject.getInlineResultWidthAndHeight(result);
                        attributeImageSize.w = wh2[0];
                        attributeImageSize.h = wh2[1];
                        document3.attributes.add(attributeImageSize);
                        fileName.file_name = "sticker.webp";
                        try {
                            if (result.thumb != null) {
                                String thumbPath2 = new File(FileLoader.getDirectory(4), Utilities.MD5(result.thumb.url) + "." + ImageLoader.getHttpUrlExtension(result.thumb.url, "webp")).getAbsolutePath();
                                Bitmap bitmap3 = ImageLoader.loadBitmap(thumbPath2, null, 90.0f, 90.0f, true);
                                if (bitmap3 != null) {
                                    TLRPC.PhotoSize thumb3 = ImageLoader.scaleAndSaveImage(bitmap3, 90.0f, 90.0f, 55, false);
                                    if (thumb3 != null) {
                                        document3.thumbs.add(thumb3);
                                        document3.flags |= 1;
                                    }
                                    bitmap3.recycle();
                                }
                            }
                        } catch (Throwable e3) {
                            FileLog.e(e3);
                        }
                    }
                    if (fileName.file_name == null) {
                        fileName.file_name = "file";
                    }
                    if (document3.mime_type == null) {
                        document3.mime_type = "application/octet-stream";
                    }
                    if (document3.thumbs.isEmpty()) {
                        TLRPC.PhotoSize thumb4 = new TLRPC.TL_photoSize();
                        int[] wh3 = MessageObject.getInlineResultWidthAndHeight(result);
                        thumb4.w = wh3[0];
                        thumb4.h = wh3[1];
                        thumb4.size = 0;
                        thumb4.location = new TLRPC.TL_fileLocationUnavailable();
                        thumb4.type = "x";
                        document3.thumbs.add(thumb4);
                        document3.flags |= 1;
                    }
                    finalPath2 = finalPath;
                    document = document3;
                    break;
                case 6:
                    if (!f.exists()) {
                        photo2 = null;
                    } else {
                        photo2 = accountInstance.getSendMessagesHelper().generatePhotoSizes(finalPath, null, false);
                    }
                    if (photo2 != null) {
                        photo = photo2;
                        finalPath2 = finalPath;
                        break;
                    } else {
                        TLRPC.TL_photo photo4 = new TLRPC.TL_photo();
                        photo4.date = accountInstance.getConnectionsManager().getCurrentTime();
                        photo4.file_reference = new byte[0];
                        TLRPC.TL_photoSize photoSize = new TLRPC.TL_photoSize();
                        int[] wh4 = MessageObject.getInlineResultWidthAndHeight(result);
                        photoSize.w = wh4[0];
                        photoSize.h = wh4[1];
                        photoSize.size = 1;
                        photoSize.location = new TLRPC.TL_fileLocationUnavailable();
                        photoSize.type = "x";
                        photo4.sizes.add(photoSize);
                        photo = photo4;
                        finalPath2 = finalPath;
                        break;
                    }
                default:
                    finalPath2 = finalPath;
                    break;
            }
        }
        final String finalPathFinal = finalPath2;
        final TLRPC.TL_document finalDocument = document;
        final TLRPC.TL_photo finalPhoto = photo;
        final TLRPC.TL_game finalGame = game;
        if (params != null && result.content != null) {
            params.put("originalPath", result.content.url);
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.lambda$null$52(TLRPC.TL_document.this, accountInstance, finalPathFinal, dialog_id, reply_to_msg, result, params, notify, scheduleDate, finalPhoto, finalGame);
            }
        });
    }

    public static void lambda$null$52(TLRPC.TL_document finalDocument, AccountInstance accountInstance, String finalPathFinal, long dialog_id, MessageObject reply_to_msg, TLRPC.BotInlineResult result, HashMap params, boolean notify, int scheduleDate, TLRPC.TL_photo finalPhoto, TLRPC.TL_game finalGame) {
        if (finalDocument != null) {
            accountInstance.getSendMessagesHelper().sendMessage(finalDocument, null, finalPathFinal, dialog_id, reply_to_msg, result.send_message.message, result.send_message.entities, result.send_message.reply_markup, params, notify, scheduleDate, 0, result);
        } else if (finalPhoto != null) {
            accountInstance.getSendMessagesHelper().sendMessage(finalPhoto, result.content != null ? result.content.url : null, dialog_id, reply_to_msg, result.send_message.message, result.send_message.entities, result.send_message.reply_markup, params, notify, scheduleDate, 0, result);
        } else if (finalGame != null) {
            accountInstance.getSendMessagesHelper().sendMessage(finalGame, dialog_id, result.send_message.reply_markup, params, notify, scheduleDate);
        }
    }

    private static String getTrimmedString(String src) {
        String result = src.trim();
        if (result.length() == 0) {
            return result;
        }
        while (src.startsWith("\n")) {
            src = src.substring(1);
        }
        while (src.endsWith("\n")) {
            src = src.substring(0, src.length() - 1);
        }
        return src;
    }

    public static void prepareSendingText(final AccountInstance accountInstance, final String text, final long dialog_id, final boolean notify, final int scheduleDate) {
        accountInstance.getMessagesStorage().getStorageQueue().postRunnable(new Runnable() {
            @Override
            public final void run() {
                Utilities.stageQueue.postRunnable(new Runnable() {
                    @Override
                    public final void run() {
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public final void run() {
                                SendMessagesHelper.lambda$null$54(r1, r2, r3, r5, r6);
                            }
                        });
                    }
                });
            }
        });
    }

    public static void lambda$null$54(String text, AccountInstance accountInstance, long dialog_id, boolean notify, int scheduleDate) {
        String textFinal = getTrimmedString(text);
        if (textFinal.length() != 0) {
            int count = (int) Math.ceil(textFinal.length() / 4096.0f);
            for (int a = 0; a < count; a++) {
                String mess = textFinal.substring(a * 4096, Math.min((a + 1) * 4096, textFinal.length()));
                accountInstance.getSendMessagesHelper().sendMessage(mess, dialog_id, null, null, true, null, null, null, notify, scheduleDate);
            }
        }
    }

    public static void ensureMediaThumbExists(boolean isEncrypted, TLObject object, String path, Uri uri, long startTime) {
        Bitmap thumb;
        boolean smallExists;
        Bitmap bitmap;
        TLRPC.PhotoSize size;
        if (object instanceof TLRPC.TL_photo) {
            TLRPC.TL_photo photo = (TLRPC.TL_photo) object;
            TLRPC.PhotoSize smallSize = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 90);
            if (smallSize instanceof TLRPC.TL_photoStrippedSize) {
                smallExists = true;
            } else {
                File smallFile = FileLoader.getPathToAttach(smallSize, true);
                smallExists = smallFile.exists();
            }
            TLRPC.PhotoSize bigSize = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, AndroidUtilities.getPhotoSize());
            File bigFile = FileLoader.getPathToAttach(bigSize, false);
            boolean bigExists = bigFile.exists();
            if (!smallExists || !bigExists) {
                Bitmap bitmap2 = ImageLoader.loadBitmap(path, uri, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), true);
                if (bitmap2 != null) {
                    bitmap = bitmap2;
                } else {
                    bitmap = ImageLoader.loadBitmap(path, uri, 800.0f, 800.0f, true);
                }
                if (!bigExists) {
                    TLRPC.PhotoSize size2 = ImageLoader.scaleAndSaveImage(bigSize, bitmap, AndroidUtilities.getPhotoSize(), AndroidUtilities.getPhotoSize(), 80, false, 101, 101, false);
                    if (size2 != bigSize) {
                        photo.sizes.add(0, size2);
                    }
                }
                if (!smallExists && (size = ImageLoader.scaleAndSaveImage(smallSize, bitmap, 90.0f, 90.0f, 55, true)) != smallSize) {
                    photo.sizes.add(0, size);
                }
                return;
            }
            return;
        }
        if (object instanceof TLRPC.TL_document) {
            TLRPC.TL_document document = (TLRPC.TL_document) object;
            if ((MessageObject.isVideoDocument(document) || MessageObject.isNewGifDocument(document)) && MessageObject.isDocumentHasThumb(document)) {
                TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 320);
                if (photoSize instanceof TLRPC.TL_photoStrippedSize) {
                    return;
                }
                File smallFile2 = FileLoader.getPathToAttach(photoSize, true);
                if (!smallFile2.exists()) {
                    Bitmap thumb2 = createVideoThumbnail(path, startTime);
                    if (thumb2 != null) {
                        thumb = thumb2;
                    } else {
                        thumb = ThumbnailUtils.createVideoThumbnail(path, 1);
                    }
                    int side = isEncrypted ? 90 : 320;
                    document.thumbs.set(0, ImageLoader.scaleAndSaveImage(photoSize, thumb, side, side, side > 90 ? 80 : 55, false));
                }
            }
        }
    }

    private static String getKeyForPhotoSize(TLRPC.PhotoSize photoSize, Bitmap[] bitmap, boolean blur) {
        int photoWidth;
        if (photoSize == null) {
            return null;
        }
        if (AndroidUtilities.isTablet()) {
            photoWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f);
        } else {
            int maxPhotoWidth = photoSize.w;
            if (maxPhotoWidth >= photoSize.h) {
                photoWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(64.0f);
            } else {
                photoWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f);
            }
        }
        int photoHeight = AndroidUtilities.dp(100.0f) + photoWidth;
        if (photoWidth > AndroidUtilities.getPhotoSize()) {
            photoWidth = AndroidUtilities.getPhotoSize();
        }
        if (photoHeight > AndroidUtilities.getPhotoSize()) {
            photoHeight = AndroidUtilities.getPhotoSize();
        }
        float scale = photoSize.w / photoWidth;
        int w = (int) (photoSize.w / scale);
        int h = (int) (photoSize.h / scale);
        if (w == 0) {
            w = AndroidUtilities.dp(150.0f);
        }
        if (h == 0) {
            h = AndroidUtilities.dp(150.0f);
        }
        if (h > photoHeight) {
            float scale2 = h;
            h = photoHeight;
            w = (int) (w / (scale2 / h));
        } else if (h < AndroidUtilities.dp(120.0f)) {
            h = AndroidUtilities.dp(120.0f);
            float hScale = photoSize.h / h;
            if (photoSize.w / hScale < photoWidth) {
                w = (int) (photoSize.w / hScale);
            }
        }
        if (bitmap != null) {
            try {
                BitmapFactory.Options opts = new BitmapFactory.Options();
                opts.inJustDecodeBounds = true;
                File file = FileLoader.getPathToAttach(photoSize);
                FileInputStream is = new FileInputStream(file);
                BitmapFactory.decodeStream(is, null, opts);
                is.close();
                float photoW = opts.outWidth;
                float photoH = opts.outHeight;
                float scaleFactor = Math.max(photoW / w, photoH / h);
                if (scaleFactor < 1.0f) {
                    scaleFactor = 1.0f;
                }
                opts.inJustDecodeBounds = false;
                opts.inSampleSize = (int) scaleFactor;
                opts.inPreferredConfig = Bitmap.Config.RGB_565;
                if (Build.VERSION.SDK_INT >= 21) {
                    FileInputStream is2 = new FileInputStream(file);
                    bitmap[0] = BitmapFactory.decodeStream(is2, null, opts);
                    is2.close();
                }
            } catch (Throwable th) {
            }
        }
        return String.format(Locale.US, blur ? "%d_%d@%d_%d_b" : "%d_%d@%d_%d", Long.valueOf(photoSize.location.volume_id), Integer.valueOf(photoSize.location.local_id), Integer.valueOf((int) (w / AndroidUtilities.density)), Integer.valueOf((int) (h / AndroidUtilities.density)));
    }

    public static void prepareSendingMedia(final AccountInstance accountInstance, final ArrayList<SendingMediaInfo> media, final long dialog_id, final MessageObject reply_to_msg, final InputContentInfoCompat inputContent, final boolean forceDocument, final boolean groupPhotos, final MessageObject editingMessageObject, final boolean notify, final int scheduleDate, final boolean blnOriginalImg) {
        if (media.isEmpty()) {
            return;
        }
        mediaSendQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.lambda$prepareSendingMedia$63(media, dialog_id, accountInstance, forceDocument, groupPhotos, blnOriginalImg, editingMessageObject, reply_to_msg, notify, scheduleDate, inputContent);
            }
        });
    }

    public static void lambda$prepareSendingMedia$63(ArrayList arrayList, final long j, final AccountInstance accountInstance, boolean z, boolean z2, final boolean z3, final MessageObject messageObject, final MessageObject messageObject2, final boolean z4, final int i, InputContentInfoCompat inputContentInfoCompat) {
        int i2;
        String str;
        String str2;
        String str3;
        String str4;
        HashMap hashMap;
        HashMap hashMap2;
        String str5;
        String str6;
        String str7;
        String str8;
        String str9;
        String str10;
        String str11;
        TLRPC.TL_photo tL_photo;
        String str12;
        String str13;
        String str14;
        String str15;
        long j2;
        int i3;
        ArrayList arrayList2;
        int i4;
        long j3;
        boolean z5;
        int i5;
        Object obj;
        String str16;
        String str17;
        boolean z6;
        String str18;
        boolean z7;
        Object obj2;
        Object obj3;
        String str19;
        String str20;
        int i6;
        String str21;
        HashMap hashMap3;
        String str22;
        String str23;
        ArrayList arrayList3;
        String str24;
        String str25;
        Object obj4;
        int i7;
        String str26;
        String str27;
        Object obj5;
        String str28;
        TLRPC.TL_photo tL_photo2;
        String str29;
        String str30;
        String str31;
        long j4;
        int i8;
        String str32;
        long j5;
        Object obj6;
        String sb;
        VideoEditedInfo createCompressionSettings;
        String str33;
        HashMap hashMap4;
        int i9;
        long j6;
        SendingMediaInfo sendingMediaInfo;
        HashMap hashMap5;
        String str34;
        boolean z8;
        long j7;
        Object obj7;
        Object obj8;
        Object obj9;
        int i10;
        String str35;
        String str36;
        String str37;
        boolean z9;
        int i11;
        TLRPC.TL_document tL_document;
        Bitmap bitmap;
        Bitmap bitmap2;
        String str38;
        Bitmap bitmap3;
        String str39;
        int i12;
        long j8;
        int i13;
        boolean z10;
        int i14;
        int size;
        TLRPC.TL_documentAttributeVideo tL_documentAttributeVideo;
        boolean z11;
        boolean z12;
        TLRPC.TL_photo tL_photo3;
        long j9;
        long j10;
        int i15;
        Uri uri;
        File file;
        ArrayList arrayList4;
        Object obj10;
        HashMap hashMap6;
        int i16;
        ArrayList arrayList5;
        SendingMediaInfo sendingMediaInfo2;
        File file2;
        File file3;
        File file4;
        int i17;
        Object obj11;
        Bitmap loadBitmap;
        ArrayList arrayList6 = arrayList;
        boolean z13 = z3;
        long currentTimeMillis = System.currentTimeMillis();
        int size2 = arrayList.size();
        final boolean z14 = ((int) j) == 0;
        if (z14) {
            TLRPC.EncryptedChat encryptedChat = accountInstance.getMessagesController().getEncryptedChat(Integer.valueOf((int) (j >> 32)));
            if (encryptedChat != null) {
                i2 = AndroidUtilities.getPeerLayerVersion(encryptedChat.layer);
                String str40 = "_ori";
                String str41 = ".webp";
                String str42 = ".gif";
                String str43 = "_";
                if (!z14 && i2 < 73) {
                    str = "_";
                    str2 = ".gif";
                    str3 = "_ori";
                    str4 = ".webp";
                } else if (!z || !z2) {
                    str = "_";
                    str2 = ".gif";
                    str3 = "_ori";
                    str4 = ".webp";
                } else {
                    HashMap hashMap7 = new HashMap();
                    int i18 = 0;
                    while (i18 < size2) {
                        final SendingMediaInfo sendingMediaInfo3 = (SendingMediaInfo) arrayList6.get(i18);
                        if (sendingMediaInfo3.searchImage != null || sendingMediaInfo3.isVideo) {
                            hashMap2 = hashMap7;
                            str5 = str43;
                            str6 = str42;
                            str7 = str40;
                            str8 = str41;
                        } else {
                            String str44 = sendingMediaInfo3.path;
                            String str45 = sendingMediaInfo3.path;
                            if (str45 == null) {
                                str9 = str44;
                                if (sendingMediaInfo3.uri != null) {
                                    str45 = AndroidUtilities.getPath(sendingMediaInfo3.uri);
                                    str10 = sendingMediaInfo3.uri.toString();
                                    if (str45 != null) {
                                        if (str45.endsWith(str42)) {
                                            hashMap2 = hashMap7;
                                            str5 = str43;
                                            str6 = str42;
                                            str7 = str40;
                                            str8 = str41;
                                        } else if (str45.endsWith(str41)) {
                                            hashMap2 = hashMap7;
                                            str5 = str43;
                                            str6 = str42;
                                            str7 = str40;
                                            str8 = str41;
                                        }
                                    }
                                    String str46 = str42;
                                    String str47 = str41;
                                    if (!ImageLoader.shouldSendImageAsDocument(sendingMediaInfo3.path, sendingMediaInfo3.uri)) {
                                        str5 = str43;
                                        str7 = str40;
                                        str6 = str46;
                                        str8 = str47;
                                        hashMap2 = hashMap7;
                                    } else {
                                        if (str45 == null && sendingMediaInfo3.uri != null) {
                                            if (MediaController.isGif(sendingMediaInfo3.uri)) {
                                                str5 = str43;
                                                str7 = str40;
                                                str6 = str46;
                                                str8 = str47;
                                                hashMap2 = hashMap7;
                                            } else if (MediaController.isWebp(sendingMediaInfo3.uri)) {
                                                str5 = str43;
                                                str7 = str40;
                                                str6 = str46;
                                                str8 = str47;
                                                hashMap2 = hashMap7;
                                            }
                                        }
                                        if (str45 != null) {
                                            File file5 = new File(str45);
                                            if (!z13) {
                                                str15 = str10 + file5.length() + str43 + file5.lastModified();
                                            } else {
                                                str15 = str10 + file5.length() + str43 + file5.lastModified() + str40;
                                            }
                                            str11 = str15;
                                        } else {
                                            str11 = null;
                                        }
                                        TLRPC.TL_photo tL_photo4 = null;
                                        String str48 = null;
                                        if (z14 || sendingMediaInfo3.ttl != 0) {
                                            str5 = str43;
                                            str7 = str40;
                                            str6 = str46;
                                            str8 = str47;
                                            tL_photo = null;
                                            str12 = null;
                                        } else {
                                            Object[] sentFile = accountInstance.getMessagesStorage().getSentFile(str11, !z14 ? 0 : 3);
                                            if (sentFile != null) {
                                                tL_photo4 = (TLRPC.TL_photo) sentFile[0];
                                                str48 = (String) sentFile[1];
                                            }
                                            if (tL_photo4 != null || sendingMediaInfo3.uri == null) {
                                                str13 = str43;
                                                tL_photo = tL_photo4;
                                                str14 = str48;
                                            } else {
                                                str13 = str43;
                                                Object[] sentFile2 = accountInstance.getMessagesStorage().getSentFile(AndroidUtilities.getPath(sendingMediaInfo3.uri), !z14 ? 0 : 3);
                                                if (sentFile2 == null) {
                                                    tL_photo = tL_photo4;
                                                    str14 = str48;
                                                } else {
                                                    tL_photo = (TLRPC.TL_photo) sentFile2[0];
                                                    str14 = (String) sentFile2[1];
                                                }
                                            }
                                            str5 = str13;
                                            str6 = str46;
                                            str7 = str40;
                                            str8 = str47;
                                            ensureMediaThumbExists(z14, tL_photo, sendingMediaInfo3.path, sendingMediaInfo3.uri, 0L);
                                            str12 = str14;
                                        }
                                        final MediaSendPrepareWorker mediaSendPrepareWorker = new MediaSendPrepareWorker();
                                        hashMap7.put(sendingMediaInfo3, mediaSendPrepareWorker);
                                        if (tL_photo != null) {
                                            mediaSendPrepareWorker.parentObject = str12;
                                            mediaSendPrepareWorker.photo = tL_photo;
                                            hashMap2 = hashMap7;
                                        } else {
                                            mediaSendPrepareWorker.sync = new CountDownLatch(1);
                                            hashMap2 = hashMap7;
                                            mediaSendThreadPool.execute(new Runnable() {
                                                @Override
                                                public final void run() {
                                                    SendMessagesHelper.lambda$null$57(SendMessagesHelper.MediaSendPrepareWorker.this, accountInstance, sendingMediaInfo3, z3, z14);
                                                }
                                            });
                                        }
                                    }
                                }
                            } else {
                                str9 = str44;
                            }
                            str10 = str9;
                            if (str45 != null) {
                            }
                            String str462 = str42;
                            String str472 = str41;
                            if (!ImageLoader.shouldSendImageAsDocument(sendingMediaInfo3.path, sendingMediaInfo3.uri)) {
                            }
                        }
                        i18++;
                        z13 = z3;
                        hashMap7 = hashMap2;
                        str43 = str5;
                        str42 = str6;
                        str40 = str7;
                        str41 = str8;
                    }
                    str = str43;
                    str2 = str42;
                    str3 = str40;
                    str4 = str41;
                    hashMap = hashMap7;
                    long j11 = 0;
                    j2 = 0;
                    String str49 = null;
                    ArrayList arrayList7 = null;
                    i3 = 0;
                    ArrayList arrayList8 = null;
                    int i19 = 0;
                    ArrayList arrayList9 = null;
                    ArrayList arrayList10 = null;
                    while (i3 < size2) {
                        final SendingMediaInfo sendingMediaInfo4 = (SendingMediaInfo) arrayList6.get(i3);
                        if (z2) {
                            if (z14) {
                            }
                            if (size2 > 1 && i19 % 10 == 0) {
                                long nextLong = Utilities.random.nextLong();
                                j2 = nextLong;
                                i4 = 0;
                                j3 = nextLong;
                                int i20 = size2;
                                ArrayList arrayList11 = arrayList8;
                                if (sendingMediaInfo4.searchImage == null) {
                                    int i21 = i3;
                                    ArrayList arrayList12 = arrayList10;
                                    int i22 = i2;
                                    if (sendingMediaInfo4.searchImage.type == 1) {
                                        final HashMap hashMap8 = new HashMap();
                                        TLRPC.TL_document tL_document2 = null;
                                        final String str50 = null;
                                        if (sendingMediaInfo4.searchImage.document instanceof TLRPC.TL_document) {
                                            tL_document2 = (TLRPC.TL_document) sendingMediaInfo4.searchImage.document;
                                            file = FileLoader.getPathToAttach(tL_document2, true);
                                        } else {
                                            file = new File(FileLoader.getDirectory(4), Utilities.MD5(sendingMediaInfo4.searchImage.imageUrl) + "." + ImageLoader.getHttpUrlExtension(sendingMediaInfo4.searchImage.imageUrl, "jpg"));
                                        }
                                        if (tL_document2 != null) {
                                            arrayList4 = arrayList7;
                                            obj10 = "originalPath";
                                            hashMap6 = hashMap;
                                            i16 = i21;
                                            arrayList5 = arrayList12;
                                            sendingMediaInfo2 = sendingMediaInfo4;
                                            file2 = file;
                                        } else {
                                            File file6 = null;
                                            TLRPC.TL_document tL_document3 = new TLRPC.TL_document();
                                            arrayList4 = arrayList7;
                                            obj10 = "originalPath";
                                            tL_document3.id = 0L;
                                            tL_document3.file_reference = new byte[0];
                                            tL_document3.date = accountInstance.getConnectionsManager().getCurrentTime();
                                            TLRPC.TL_documentAttributeFilename tL_documentAttributeFilename = new TLRPC.TL_documentAttributeFilename();
                                            tL_documentAttributeFilename.file_name = "animation.gif";
                                            tL_document3.attributes.add(tL_documentAttributeFilename);
                                            tL_document3.size = sendingMediaInfo4.searchImage.size;
                                            tL_document3.dc_id = 0;
                                            if (file.toString().endsWith("mp4")) {
                                                tL_document3.mime_type = MimeTypes.VIDEO_MP4;
                                                tL_document3.attributes.add(new TLRPC.TL_documentAttributeAnimated());
                                            } else {
                                                tL_document3.mime_type = "image/gif";
                                            }
                                            if (file.exists()) {
                                                file6 = file;
                                                file3 = file;
                                            } else {
                                                file3 = null;
                                            }
                                            if (file6 != null) {
                                                file4 = file6;
                                            } else {
                                                File file7 = new File(FileLoader.getDirectory(4), Utilities.MD5(sendingMediaInfo4.searchImage.thumbUrl) + "." + ImageLoader.getHttpUrlExtension(sendingMediaInfo4.searchImage.thumbUrl, "jpg"));
                                                if (file7.exists()) {
                                                    file4 = file7;
                                                } else {
                                                    file4 = null;
                                                }
                                            }
                                            if (file4 == null) {
                                                hashMap6 = hashMap;
                                                i16 = i21;
                                                arrayList5 = arrayList12;
                                                sendingMediaInfo2 = sendingMediaInfo4;
                                            } else {
                                                try {
                                                    if (!z14) {
                                                        try {
                                                            if (sendingMediaInfo4.ttl == 0) {
                                                                i17 = 320;
                                                                if (!file4.getAbsolutePath().endsWith("mp4")) {
                                                                    loadBitmap = ThumbnailUtils.createVideoThumbnail(file4.getAbsolutePath(), 1);
                                                                    obj11 = null;
                                                                } else {
                                                                    obj11 = null;
                                                                    loadBitmap = ImageLoader.loadBitmap(file4.getAbsolutePath(), null, i17, i17, true);
                                                                }
                                                                if (loadBitmap == null) {
                                                                    try {
                                                                        hashMap6 = hashMap;
                                                                        sendingMediaInfo2 = sendingMediaInfo4;
                                                                        i16 = i21;
                                                                        arrayList5 = arrayList12;
                                                                        try {
                                                                            TLRPC.PhotoSize scaleAndSaveImage = ImageLoader.scaleAndSaveImage(loadBitmap, i17, i17, i17 > 90 ? 80 : 55, z14, file4.getAbsolutePath().endsWith(".png"));
                                                                            if (scaleAndSaveImage != null) {
                                                                                tL_document3.thumbs.add(scaleAndSaveImage);
                                                                                tL_document3.flags |= 1;
                                                                            }
                                                                            loadBitmap.recycle();
                                                                        } catch (Exception e) {
                                                                            e = e;
                                                                            FileLog.e(e);
                                                                            if (!tL_document3.thumbs.isEmpty()) {
                                                                            }
                                                                            tL_document2 = tL_document3;
                                                                            file2 = file3;
                                                                            final TLRPC.TL_document tL_document4 = tL_document2;
                                                                            String str51 = sendingMediaInfo2.searchImage.imageUrl;
                                                                            final String file8 = file2 != null ? sendingMediaInfo2.searchImage.imageUrl : file2.toString();
                                                                            if (sendingMediaInfo2.searchImage.imageUrl != null) {
                                                                            }
                                                                            final SendingMediaInfo sendingMediaInfo5 = sendingMediaInfo2;
                                                                            AndroidUtilities.runOnUIThread(new Runnable() {
                                                                                @Override
                                                                                public final void run() {
                                                                                    SendMessagesHelper.lambda$null$58(MessageObject.this, accountInstance, tL_document4, file8, hashMap8, str50, j, messageObject2, sendingMediaInfo5, z4, i);
                                                                                }
                                                                            });
                                                                            z5 = z14;
                                                                            i19 = i4;
                                                                            str23 = str3;
                                                                            str31 = str4;
                                                                            hashMap3 = hashMap6;
                                                                            i8 = i16;
                                                                            arrayList10 = arrayList5;
                                                                            arrayList7 = arrayList4;
                                                                            arrayList9 = arrayList9;
                                                                            arrayList8 = arrayList11;
                                                                            i5 = i22;
                                                                            obj = null;
                                                                            j4 = j3;
                                                                            str22 = str;
                                                                            str25 = str2;
                                                                            i3 = i8 + 1;
                                                                            arrayList6 = arrayList;
                                                                            str4 = str31;
                                                                            size2 = i20;
                                                                            hashMap = hashMap3;
                                                                            str2 = str25;
                                                                            str = str22;
                                                                            str3 = str23;
                                                                            z14 = z5;
                                                                            j11 = j4;
                                                                            i2 = i5;
                                                                        }
                                                                    } catch (Exception e2) {
                                                                        e = e2;
                                                                        hashMap6 = hashMap;
                                                                        i16 = i21;
                                                                        arrayList5 = arrayList12;
                                                                        sendingMediaInfo2 = sendingMediaInfo4;
                                                                        FileLog.e(e);
                                                                        if (!tL_document3.thumbs.isEmpty()) {
                                                                        }
                                                                        tL_document2 = tL_document3;
                                                                        file2 = file3;
                                                                        final TLRPC.TL_document tL_document42 = tL_document2;
                                                                        String str512 = sendingMediaInfo2.searchImage.imageUrl;
                                                                        final String file82 = file2 != null ? sendingMediaInfo2.searchImage.imageUrl : file2.toString();
                                                                        if (sendingMediaInfo2.searchImage.imageUrl != null) {
                                                                        }
                                                                        final SendingMediaInfo sendingMediaInfo52 = sendingMediaInfo2;
                                                                        AndroidUtilities.runOnUIThread(new Runnable() {
                                                                            @Override
                                                                            public final void run() {
                                                                                SendMessagesHelper.lambda$null$58(MessageObject.this, accountInstance, tL_document42, file82, hashMap8, str50, j, messageObject2, sendingMediaInfo52, z4, i);
                                                                            }
                                                                        });
                                                                        z5 = z14;
                                                                        i19 = i4;
                                                                        str23 = str3;
                                                                        str31 = str4;
                                                                        hashMap3 = hashMap6;
                                                                        i8 = i16;
                                                                        arrayList10 = arrayList5;
                                                                        arrayList7 = arrayList4;
                                                                        arrayList9 = arrayList9;
                                                                        arrayList8 = arrayList11;
                                                                        i5 = i22;
                                                                        obj = null;
                                                                        j4 = j3;
                                                                        str22 = str;
                                                                        str25 = str2;
                                                                        i3 = i8 + 1;
                                                                        arrayList6 = arrayList;
                                                                        str4 = str31;
                                                                        size2 = i20;
                                                                        hashMap = hashMap3;
                                                                        str2 = str25;
                                                                        str = str22;
                                                                        str3 = str23;
                                                                        z14 = z5;
                                                                        j11 = j4;
                                                                        i2 = i5;
                                                                    }
                                                                } else {
                                                                    hashMap6 = hashMap;
                                                                    i16 = i21;
                                                                    arrayList5 = arrayList12;
                                                                    sendingMediaInfo2 = sendingMediaInfo4;
                                                                }
                                                            }
                                                        } catch (Exception e3) {
                                                            e = e3;
                                                            hashMap6 = hashMap;
                                                            i16 = i21;
                                                            arrayList5 = arrayList12;
                                                            sendingMediaInfo2 = sendingMediaInfo4;
                                                            FileLog.e(e);
                                                            if (!tL_document3.thumbs.isEmpty()) {
                                                            }
                                                            tL_document2 = tL_document3;
                                                            file2 = file3;
                                                            final TLRPC.TL_document tL_document422 = tL_document2;
                                                            String str5122 = sendingMediaInfo2.searchImage.imageUrl;
                                                            final String file822 = file2 != null ? sendingMediaInfo2.searchImage.imageUrl : file2.toString();
                                                            if (sendingMediaInfo2.searchImage.imageUrl != null) {
                                                            }
                                                            final SendingMediaInfo sendingMediaInfo522 = sendingMediaInfo2;
                                                            AndroidUtilities.runOnUIThread(new Runnable() {
                                                                @Override
                                                                public final void run() {
                                                                    SendMessagesHelper.lambda$null$58(MessageObject.this, accountInstance, tL_document422, file822, hashMap8, str50, j, messageObject2, sendingMediaInfo522, z4, i);
                                                                }
                                                            });
                                                            z5 = z14;
                                                            i19 = i4;
                                                            str23 = str3;
                                                            str31 = str4;
                                                            hashMap3 = hashMap6;
                                                            i8 = i16;
                                                            arrayList10 = arrayList5;
                                                            arrayList7 = arrayList4;
                                                            arrayList9 = arrayList9;
                                                            arrayList8 = arrayList11;
                                                            i5 = i22;
                                                            obj = null;
                                                            j4 = j3;
                                                            str22 = str;
                                                            str25 = str2;
                                                            i3 = i8 + 1;
                                                            arrayList6 = arrayList;
                                                            str4 = str31;
                                                            size2 = i20;
                                                            hashMap = hashMap3;
                                                            str2 = str25;
                                                            str = str22;
                                                            str3 = str23;
                                                            z14 = z5;
                                                            j11 = j4;
                                                            i2 = i5;
                                                        }
                                                    }
                                                    if (!file4.getAbsolutePath().endsWith("mp4")) {
                                                    }
                                                    if (loadBitmap == null) {
                                                    }
                                                } catch (Exception e4) {
                                                    e = e4;
                                                    hashMap6 = hashMap;
                                                    i16 = i21;
                                                    arrayList5 = arrayList12;
                                                }
                                                i17 = 90;
                                            }
                                            if (!tL_document3.thumbs.isEmpty()) {
                                                TLRPC.TL_photoSize tL_photoSize = new TLRPC.TL_photoSize();
                                                tL_photoSize.w = sendingMediaInfo2.searchImage.width;
                                                tL_photoSize.h = sendingMediaInfo2.searchImage.height;
                                                tL_photoSize.size = 0;
                                                tL_photoSize.location = new TLRPC.TL_fileLocationUnavailable();
                                                tL_photoSize.type = "x";
                                                tL_document3.thumbs.add(tL_photoSize);
                                                tL_document3.flags |= 1;
                                            }
                                            tL_document2 = tL_document3;
                                            file2 = file3;
                                        }
                                        final TLRPC.TL_document tL_document4222 = tL_document2;
                                        String str51222 = sendingMediaInfo2.searchImage.imageUrl;
                                        final String file8222 = file2 != null ? sendingMediaInfo2.searchImage.imageUrl : file2.toString();
                                        if (sendingMediaInfo2.searchImage.imageUrl != null) {
                                            hashMap8.put(obj10, sendingMediaInfo2.searchImage.imageUrl);
                                        }
                                        final SendingMediaInfo sendingMediaInfo5222 = sendingMediaInfo2;
                                        AndroidUtilities.runOnUIThread(new Runnable() {
                                            @Override
                                            public final void run() {
                                                SendMessagesHelper.lambda$null$58(MessageObject.this, accountInstance, tL_document4222, file8222, hashMap8, str50, j, messageObject2, sendingMediaInfo5222, z4, i);
                                            }
                                        });
                                        z5 = z14;
                                        i19 = i4;
                                        str23 = str3;
                                        str31 = str4;
                                        hashMap3 = hashMap6;
                                        i8 = i16;
                                        arrayList10 = arrayList5;
                                        arrayList7 = arrayList4;
                                        arrayList9 = arrayList9;
                                        arrayList8 = arrayList11;
                                        i5 = i22;
                                        obj = null;
                                        j4 = j3;
                                        str22 = str;
                                        str25 = str2;
                                    } else {
                                        ArrayList arrayList13 = arrayList9;
                                        boolean z15 = z14;
                                        ArrayList arrayList14 = arrayList7;
                                        HashMap hashMap9 = hashMap;
                                        int i23 = i21;
                                        boolean z16 = true;
                                        TLRPC.TL_photo tL_photo5 = null;
                                        final String str52 = null;
                                        if (sendingMediaInfo4.searchImage.photo instanceof TLRPC.TL_photo) {
                                            tL_photo5 = (TLRPC.TL_photo) sendingMediaInfo4.searchImage.photo;
                                        } else if (!z15) {
                                            int i24 = sendingMediaInfo4.ttl;
                                        }
                                        if (tL_photo5 != null) {
                                            z11 = z3;
                                            z12 = z15;
                                            tL_photo3 = tL_photo5;
                                        } else {
                                            File file9 = new File(FileLoader.getDirectory(4), Utilities.MD5(sendingMediaInfo4.searchImage.imageUrl) + "." + ImageLoader.getHttpUrlExtension(sendingMediaInfo4.searchImage.imageUrl, "jpg"));
                                            if (!file9.exists() || file9.length() == 0) {
                                                z11 = z3;
                                                z12 = z15;
                                                uri = null;
                                            } else {
                                                z11 = z3;
                                                z12 = z15;
                                                uri = null;
                                                tL_photo5 = accountInstance.getSendMessagesHelper().generatePhotoSizes(file9.toString(), null, z11);
                                                if (tL_photo5 != null) {
                                                    z16 = false;
                                                }
                                            }
                                            if (tL_photo5 == null) {
                                                File file10 = new File(FileLoader.getDirectory(4), Utilities.MD5(sendingMediaInfo4.searchImage.thumbUrl) + "." + ImageLoader.getHttpUrlExtension(sendingMediaInfo4.searchImage.thumbUrl, "jpg"));
                                                if (file10.exists()) {
                                                    tL_photo5 = accountInstance.getSendMessagesHelper().generatePhotoSizes(file10.toString(), uri, z11);
                                                }
                                                if (tL_photo5 == null) {
                                                    TLRPC.TL_photo tL_photo6 = new TLRPC.TL_photo();
                                                    tL_photo6.date = accountInstance.getConnectionsManager().getCurrentTime();
                                                    tL_photo6.file_reference = new byte[0];
                                                    TLRPC.TL_photoSize tL_photoSize2 = new TLRPC.TL_photoSize();
                                                    tL_photoSize2.w = sendingMediaInfo4.searchImage.width;
                                                    tL_photoSize2.h = sendingMediaInfo4.searchImage.height;
                                                    tL_photoSize2.size = 0;
                                                    tL_photoSize2.location = new TLRPC.TL_fileLocationUnavailable();
                                                    tL_photoSize2.type = "x";
                                                    tL_photo6.sizes.add(tL_photoSize2);
                                                    tL_photo3 = tL_photo6;
                                                } else {
                                                    tL_photo3 = tL_photo5;
                                                }
                                            } else {
                                                tL_photo3 = tL_photo5;
                                            }
                                        }
                                        if (tL_photo3 == null) {
                                            j9 = j3;
                                        } else {
                                            final TLRPC.TL_photo tL_photo7 = tL_photo3;
                                            final boolean z17 = z16;
                                            final HashMap hashMap10 = new HashMap();
                                            if (sendingMediaInfo4.searchImage.imageUrl != null) {
                                                hashMap10.put("originalPath", sendingMediaInfo4.searchImage.imageUrl);
                                            }
                                            if (!z2) {
                                                j10 = j3;
                                                i15 = i23;
                                            } else {
                                                int i25 = i4 + 1;
                                                StringBuilder sb2 = new StringBuilder();
                                                sb2.append("");
                                                j10 = j3;
                                                sb2.append(j10);
                                                hashMap10.put("groupId", sb2.toString());
                                                if (i25 != 10) {
                                                    i15 = i23;
                                                    if (i15 != i20 - 1) {
                                                        i4 = i25;
                                                    }
                                                } else {
                                                    i15 = i23;
                                                }
                                                hashMap10.put("final", "1");
                                                j2 = 0;
                                                i4 = i25;
                                            }
                                            j9 = j10;
                                            i23 = i15;
                                            AndroidUtilities.runOnUIThread(new Runnable() {
                                                @Override
                                                public final void run() {
                                                    SendMessagesHelper.lambda$null$59(MessageObject.this, accountInstance, tL_photo7, z17, sendingMediaInfo4, hashMap10, str52, j, messageObject2, z4, i);
                                                }
                                            });
                                        }
                                        i19 = i4;
                                        z5 = z12;
                                        str22 = str;
                                        str25 = str2;
                                        str23 = str3;
                                        str31 = str4;
                                        hashMap3 = hashMap9;
                                        i8 = i23;
                                        arrayList10 = arrayList12;
                                        arrayList7 = arrayList14;
                                        arrayList9 = arrayList13;
                                        arrayList8 = arrayList11;
                                        i5 = i22;
                                        j4 = j9;
                                        obj = null;
                                    }
                                } else {
                                    int i26 = i3;
                                    ArrayList arrayList15 = arrayList10;
                                    int i27 = i2;
                                    ArrayList arrayList16 = arrayList9;
                                    boolean z18 = z14;
                                    ArrayList arrayList17 = arrayList7;
                                    HashMap hashMap11 = hashMap;
                                    long j12 = j3;
                                    if (sendingMediaInfo4.isVideo) {
                                        String str53 = null;
                                        if (z) {
                                            createCompressionSettings = null;
                                        } else {
                                            createCompressionSettings = sendingMediaInfo4.videoEditedInfo != null ? sendingMediaInfo4.videoEditedInfo : createCompressionSettings(sendingMediaInfo4.path);
                                        }
                                        if (!z) {
                                            if (createCompressionSettings != null || sendingMediaInfo4.path.endsWith("mp4")) {
                                                String str54 = sendingMediaInfo4.path;
                                                String str55 = sendingMediaInfo4.path;
                                                File file11 = new File(str55);
                                                StringBuilder sb3 = new StringBuilder();
                                                sb3.append(str55);
                                                sb3.append(file11.length());
                                                String str56 = str;
                                                sb3.append(str56);
                                                sb3.append(file11.lastModified());
                                                String sb4 = sb3.toString();
                                                if (createCompressionSettings == null) {
                                                    str34 = sb4;
                                                    z8 = false;
                                                    j7 = 0;
                                                } else {
                                                    boolean z19 = createCompressionSettings.muted;
                                                    StringBuilder sb5 = new StringBuilder();
                                                    sb5.append(sb4);
                                                    sb5.append(createCompressionSettings.estimatedDuration);
                                                    sb5.append(str56);
                                                    sb5.append(createCompressionSettings.startTime);
                                                    sb5.append(str56);
                                                    sb5.append(createCompressionSettings.endTime);
                                                    sb5.append(createCompressionSettings.muted ? "_m" : "");
                                                    String sb6 = sb5.toString();
                                                    if (createCompressionSettings.resultWidth != createCompressionSettings.originalWidth) {
                                                        sb6 = sb6 + str56 + createCompressionSettings.resultWidth;
                                                    }
                                                    str34 = sb6;
                                                    z8 = z19;
                                                    j7 = createCompressionSettings.startTime >= 0 ? createCompressionSettings.startTime : 0L;
                                                }
                                                TLRPC.TL_document tL_document5 = null;
                                                if (z18 || sendingMediaInfo4.ttl != 0) {
                                                    str33 = str56;
                                                    obj7 = "final";
                                                    obj8 = "1";
                                                    obj9 = "groupId";
                                                    i10 = 1;
                                                    str35 = str54;
                                                    str36 = MimeTypes.VIDEO_MP4;
                                                } else {
                                                    Object[] sentFile3 = accountInstance.getMessagesStorage().getSentFile(str34, !z18 ? 2 : 5);
                                                    if (sentFile3 == null) {
                                                        str33 = str56;
                                                        obj7 = "final";
                                                        obj8 = "1";
                                                        obj9 = "groupId";
                                                        i10 = 1;
                                                        str35 = str54;
                                                        str36 = MimeTypes.VIDEO_MP4;
                                                    } else {
                                                        TLRPC.TL_document tL_document6 = (TLRPC.TL_document) sentFile3[0];
                                                        str37 = (String) sentFile3[1];
                                                        String str57 = sendingMediaInfo4.path;
                                                        str33 = str56;
                                                        obj9 = "groupId";
                                                        str35 = str54;
                                                        str36 = MimeTypes.VIDEO_MP4;
                                                        obj7 = "final";
                                                        obj8 = "1";
                                                        i10 = 1;
                                                        ensureMediaThumbExists(z18, tL_document6, str57, null, j7);
                                                        tL_document5 = tL_document6;
                                                        if (tL_document5 == null) {
                                                            z9 = z18;
                                                            i11 = i27;
                                                            tL_document = tL_document5;
                                                            bitmap = null;
                                                        } else {
                                                            Bitmap createVideoThumbnail = createVideoThumbnail(sendingMediaInfo4.path, j7);
                                                            if (createVideoThumbnail == null) {
                                                                createVideoThumbnail = ThumbnailUtils.createVideoThumbnail(sendingMediaInfo4.path, i10);
                                                            }
                                                            TLRPC.PhotoSize photoSize = null;
                                                            if (createVideoThumbnail == null) {
                                                                z9 = z18;
                                                            } else {
                                                                int max = (z18 || sendingMediaInfo4.ttl != 0) ? 90 : Math.max(createVideoThumbnail.getWidth(), createVideoThumbnail.getHeight());
                                                                float f = max;
                                                                float f2 = max;
                                                                int i28 = max > 90 ? 80 : 55;
                                                                z9 = z18;
                                                                photoSize = ImageLoader.scaleAndSaveImage(createVideoThumbnail, f, f2, i28, z9);
                                                                str53 = getKeyForPhotoSize(photoSize, null, true);
                                                            }
                                                            TLRPC.TL_document tL_document7 = new TLRPC.TL_document();
                                                            tL_document7.file_reference = new byte[0];
                                                            if (photoSize != null) {
                                                                tL_document7.thumbs.add(photoSize);
                                                                tL_document7.flags |= 1;
                                                            }
                                                            tL_document7.mime_type = str36;
                                                            accountInstance.getUserConfig().saveConfig(false);
                                                            if (z9) {
                                                                i11 = i27;
                                                                if (i11 >= 66) {
                                                                    tL_documentAttributeVideo = new TLRPC.TL_documentAttributeVideo();
                                                                } else {
                                                                    tL_documentAttributeVideo = new TLRPC.TL_documentAttributeVideo_layer65();
                                                                }
                                                            } else {
                                                                i11 = i27;
                                                                tL_documentAttributeVideo = new TLRPC.TL_documentAttributeVideo();
                                                                tL_documentAttributeVideo.supports_streaming = true;
                                                            }
                                                            tL_document7.attributes.add(tL_documentAttributeVideo);
                                                            if (createCompressionSettings != null && createCompressionSettings.needConvert()) {
                                                                if (createCompressionSettings.muted) {
                                                                    fillVideoAttribute(sendingMediaInfo4.path, tL_documentAttributeVideo, createCompressionSettings);
                                                                    createCompressionSettings.originalWidth = tL_documentAttributeVideo.w;
                                                                    createCompressionSettings.originalHeight = tL_documentAttributeVideo.h;
                                                                } else {
                                                                    tL_documentAttributeVideo.duration = (int) (createCompressionSettings.estimatedDuration / 1000);
                                                                }
                                                                if (createCompressionSettings.rotationValue == 90 || createCompressionSettings.rotationValue == 270) {
                                                                    tL_documentAttributeVideo.w = createCompressionSettings.resultHeight;
                                                                    tL_documentAttributeVideo.h = createCompressionSettings.resultWidth;
                                                                } else {
                                                                    tL_documentAttributeVideo.w = createCompressionSettings.resultWidth;
                                                                    tL_documentAttributeVideo.h = createCompressionSettings.resultHeight;
                                                                }
                                                                tL_document7.size = (int) createCompressionSettings.estimatedSize;
                                                            } else {
                                                                if (file11.exists()) {
                                                                    tL_document7.size = (int) file11.length();
                                                                }
                                                                fillVideoAttribute(sendingMediaInfo4.path, tL_documentAttributeVideo, null);
                                                            }
                                                            tL_document = tL_document7;
                                                            bitmap = createVideoThumbnail;
                                                        }
                                                        if (createCompressionSettings != null && createCompressionSettings.muted) {
                                                            z10 = false;
                                                            i14 = 0;
                                                            size = tL_document.attributes.size();
                                                            while (true) {
                                                                if (i14 >= size) {
                                                                    break;
                                                                }
                                                                if (!(tL_document.attributes.get(i14) instanceof TLRPC.TL_documentAttributeAnimated)) {
                                                                    i14++;
                                                                } else {
                                                                    z10 = true;
                                                                    break;
                                                                }
                                                            }
                                                            if (!z10) {
                                                                tL_document.attributes.add(new TLRPC.TL_documentAttributeAnimated());
                                                            }
                                                        }
                                                        if (createCompressionSettings != null && createCompressionSettings.needConvert()) {
                                                            File file12 = new File(FileLoader.getDirectory(4), "-2147483648_" + SharedConfig.getLastLocalId() + ".mp4");
                                                            SharedConfig.saveConfig();
                                                            str35 = file12.getAbsolutePath();
                                                        }
                                                        final TLRPC.TL_document tL_document8 = tL_document;
                                                        final String str58 = str37;
                                                        final String str59 = str35;
                                                        final HashMap hashMap12 = new HashMap();
                                                        bitmap2 = bitmap;
                                                        str38 = str53;
                                                        if (str34 != null) {
                                                            hashMap12.put("originalPath", str34);
                                                        }
                                                        if (!z8 || !z2) {
                                                            bitmap3 = bitmap2;
                                                            str39 = str38;
                                                            i12 = i26;
                                                            j8 = j12;
                                                            i13 = i4;
                                                        } else {
                                                            int i29 = i4 + 1;
                                                            StringBuilder sb7 = new StringBuilder();
                                                            sb7.append("");
                                                            bitmap3 = bitmap2;
                                                            str39 = str38;
                                                            j8 = j12;
                                                            sb7.append(j8);
                                                            hashMap12.put(obj9, sb7.toString());
                                                            if (i29 != 10) {
                                                                i12 = i26;
                                                                if (i12 != i20 - 1) {
                                                                    i13 = i29;
                                                                }
                                                            } else {
                                                                i12 = i26;
                                                            }
                                                            hashMap12.put(obj7, obj8);
                                                            j2 = 0;
                                                            i13 = i29;
                                                        }
                                                        z5 = z9;
                                                        obj = null;
                                                        final VideoEditedInfo videoEditedInfo = createCompressionSettings;
                                                        i9 = i12;
                                                        i5 = i11;
                                                        j6 = j8;
                                                        final Bitmap bitmap4 = bitmap3;
                                                        final String str60 = str39;
                                                        AndroidUtilities.runOnUIThread(new Runnable() {
                                                            @Override
                                                            public final void run() {
                                                                SendMessagesHelper.lambda$null$60(bitmap4, str60, messageObject, accountInstance, videoEditedInfo, tL_document8, str59, hashMap12, str58, j, messageObject2, sendingMediaInfo4, z4, i);
                                                            }
                                                        });
                                                        hashMap5 = hashMap11;
                                                        i4 = i13;
                                                        i19 = i4;
                                                        hashMap3 = hashMap5;
                                                        str25 = str2;
                                                        str23 = str3;
                                                        str31 = str4;
                                                        str22 = str33;
                                                        arrayList10 = arrayList15;
                                                        i8 = i9;
                                                        arrayList7 = arrayList17;
                                                        arrayList9 = arrayList16;
                                                        arrayList8 = arrayList11;
                                                        j4 = j6;
                                                    }
                                                }
                                                str37 = null;
                                                if (tL_document5 == null) {
                                                }
                                                if (createCompressionSettings != null) {
                                                    z10 = false;
                                                    i14 = 0;
                                                    size = tL_document.attributes.size();
                                                    while (true) {
                                                        if (i14 >= size) {
                                                        }
                                                        i14++;
                                                    }
                                                    if (!z10) {
                                                    }
                                                }
                                                if (createCompressionSettings != null) {
                                                    File file122 = new File(FileLoader.getDirectory(4), "-2147483648_" + SharedConfig.getLastLocalId() + ".mp4");
                                                    SharedConfig.saveConfig();
                                                    str35 = file122.getAbsolutePath();
                                                }
                                                final TLRPC.TL_document tL_document82 = tL_document;
                                                final String str582 = str37;
                                                final String str592 = str35;
                                                final HashMap hashMap122 = new HashMap();
                                                bitmap2 = bitmap;
                                                str38 = str53;
                                                if (str34 != null) {
                                                }
                                                if (!z8) {
                                                }
                                                bitmap3 = bitmap2;
                                                str39 = str38;
                                                i12 = i26;
                                                j8 = j12;
                                                i13 = i4;
                                                z5 = z9;
                                                obj = null;
                                                final VideoEditedInfo videoEditedInfo2 = createCompressionSettings;
                                                i9 = i12;
                                                i5 = i11;
                                                j6 = j8;
                                                final Bitmap bitmap42 = bitmap3;
                                                final String str602 = str39;
                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                    @Override
                                                    public final void run() {
                                                        SendMessagesHelper.lambda$null$60(bitmap42, str602, messageObject, accountInstance, videoEditedInfo2, tL_document82, str592, hashMap122, str582, j, messageObject2, sendingMediaInfo4, z4, i);
                                                    }
                                                });
                                                hashMap5 = hashMap11;
                                                i4 = i13;
                                                i19 = i4;
                                                hashMap3 = hashMap5;
                                                str25 = str2;
                                                str23 = str3;
                                                str31 = str4;
                                                str22 = str33;
                                                arrayList10 = arrayList15;
                                                i8 = i9;
                                                arrayList7 = arrayList17;
                                                arrayList9 = arrayList16;
                                                arrayList8 = arrayList11;
                                                j4 = j6;
                                            } else {
                                                z5 = z18;
                                                str33 = str;
                                                hashMap4 = hashMap11;
                                                i9 = i26;
                                                i5 = i27;
                                                j6 = j12;
                                                obj = null;
                                                sendingMediaInfo = sendingMediaInfo4;
                                            }
                                        } else {
                                            z5 = z18;
                                            str33 = str;
                                            hashMap4 = hashMap11;
                                            i9 = i26;
                                            i5 = i27;
                                            j6 = j12;
                                            obj = null;
                                            sendingMediaInfo = sendingMediaInfo4;
                                        }
                                        SendingMediaInfo sendingMediaInfo6 = sendingMediaInfo;
                                        hashMap5 = hashMap4;
                                        prepareSendingDocumentInternal(accountInstance, sendingMediaInfo6.path, sendingMediaInfo6.path, null, null, j, messageObject2, sendingMediaInfo6.caption, sendingMediaInfo6.entities, messageObject, z, z4, i);
                                        i19 = i4;
                                        hashMap3 = hashMap5;
                                        str25 = str2;
                                        str23 = str3;
                                        str31 = str4;
                                        str22 = str33;
                                        arrayList10 = arrayList15;
                                        i8 = i9;
                                        arrayList7 = arrayList17;
                                        arrayList9 = arrayList16;
                                        arrayList8 = arrayList11;
                                        j4 = j6;
                                    } else {
                                        z5 = z18;
                                        String str61 = str;
                                        i5 = i27;
                                        obj = null;
                                        String str62 = sendingMediaInfo4.path;
                                        String str63 = sendingMediaInfo4.path;
                                        if (str63 == null && sendingMediaInfo4.uri != null) {
                                            str63 = AndroidUtilities.getPath(sendingMediaInfo4.uri);
                                            str62 = sendingMediaInfo4.uri.toString();
                                        }
                                        if (z) {
                                            str16 = str2;
                                            str17 = str4;
                                        } else if (ImageLoader.shouldSendImageAsDocument(sendingMediaInfo4.path, sendingMediaInfo4.uri)) {
                                            str16 = str2;
                                            str17 = str4;
                                        } else {
                                            if (str63 == null) {
                                                str16 = str2;
                                                str17 = str4;
                                            } else {
                                                str16 = str2;
                                                if (str63.endsWith(str16)) {
                                                    str17 = str4;
                                                } else {
                                                    str17 = str4;
                                                }
                                                if (str63.endsWith(str16)) {
                                                    str49 = "gif";
                                                } else {
                                                    str49 = "webp";
                                                }
                                                str18 = str63;
                                                z6 = true;
                                                if (!z6) {
                                                    if (arrayList11 != null) {
                                                        arrayList8 = arrayList11;
                                                        arrayList10 = arrayList15;
                                                        arrayList7 = arrayList17;
                                                        arrayList9 = arrayList16;
                                                    } else {
                                                        arrayList8 = new ArrayList();
                                                        arrayList7 = new ArrayList();
                                                        arrayList9 = new ArrayList();
                                                        arrayList10 = new ArrayList();
                                                    }
                                                    arrayList8.add(str18);
                                                    arrayList7.add(str62);
                                                    arrayList9.add(sendingMediaInfo4.caption);
                                                    arrayList10.add(sendingMediaInfo4.entities);
                                                    str31 = str17;
                                                    str25 = str16;
                                                    i19 = i4;
                                                    hashMap3 = hashMap11;
                                                    str23 = str3;
                                                    str22 = str61;
                                                    i8 = i26;
                                                    j4 = j12;
                                                } else {
                                                    if (str18 != null) {
                                                        File file13 = new File(str18);
                                                        z7 = z3;
                                                        if (!z7) {
                                                            StringBuilder sb8 = new StringBuilder();
                                                            sb8.append(str62);
                                                            i6 = i26;
                                                            sb8.append(file13.length());
                                                            str20 = str61;
                                                            sb8.append(str20);
                                                            obj2 = "originalPath";
                                                            obj6 = "1";
                                                            sb8.append(file13.lastModified());
                                                            sb = sb8.toString();
                                                            str19 = str3;
                                                        } else {
                                                            i6 = i26;
                                                            obj2 = "originalPath";
                                                            obj6 = "1";
                                                            str20 = str61;
                                                            StringBuilder sb9 = new StringBuilder();
                                                            sb9.append(str62);
                                                            sb9.append(file13.length());
                                                            sb9.append(str20);
                                                            sb9.append(file13.lastModified());
                                                            str19 = str3;
                                                            sb9.append(str19);
                                                            sb = sb9.toString();
                                                        }
                                                        str21 = sb;
                                                        obj3 = obj6;
                                                    } else {
                                                        z7 = z3;
                                                        obj2 = "originalPath";
                                                        obj3 = "1";
                                                        str19 = str3;
                                                        str20 = str61;
                                                        i6 = i26;
                                                        str21 = null;
                                                    }
                                                    TLRPC.TL_photo tL_photo8 = null;
                                                    if (hashMap11 != null) {
                                                        MediaSendPrepareWorker mediaSendPrepareWorker2 = (MediaSendPrepareWorker) hashMap11.get(sendingMediaInfo4);
                                                        TLRPC.TL_photo tL_photo9 = mediaSendPrepareWorker2.photo;
                                                        hashMap3 = hashMap11;
                                                        String str64 = mediaSendPrepareWorker2.parentObject;
                                                        if (tL_photo9 == null) {
                                                            try {
                                                                mediaSendPrepareWorker2.sync.await();
                                                            } catch (Exception e5) {
                                                                FileLog.e(e5);
                                                            }
                                                            tL_photo9 = mediaSendPrepareWorker2.photo;
                                                            str64 = mediaSendPrepareWorker2.parentObject;
                                                        }
                                                        str29 = str64;
                                                        str22 = str20;
                                                        str23 = str19;
                                                        arrayList3 = arrayList11;
                                                        str24 = str17;
                                                        str25 = str16;
                                                        obj4 = obj3;
                                                        i7 = i6;
                                                        str26 = str21;
                                                        tL_photo2 = tL_photo9;
                                                        Object obj12 = obj2;
                                                        str27 = str18;
                                                        obj5 = obj12;
                                                    } else {
                                                        hashMap3 = hashMap11;
                                                        String str65 = null;
                                                        if (z5 || sendingMediaInfo4.ttl != 0) {
                                                            str22 = str20;
                                                            str23 = str19;
                                                            arrayList3 = arrayList11;
                                                            str24 = str17;
                                                            str25 = str16;
                                                            obj4 = obj3;
                                                            i7 = i6;
                                                            str26 = str21;
                                                            Object obj13 = obj2;
                                                            str27 = str18;
                                                            obj5 = obj13;
                                                            str28 = null;
                                                        } else {
                                                            Object[] sentFile4 = accountInstance.getMessagesStorage().getSentFile(str21, !z5 ? 0 : 3);
                                                            if (sentFile4 != null) {
                                                                tL_photo8 = (TLRPC.TL_photo) sentFile4[0];
                                                                str65 = (String) sentFile4[1];
                                                            }
                                                            if (tL_photo8 == null && sendingMediaInfo4.uri != null) {
                                                                TLRPC.TL_photo tL_photo10 = tL_photo8;
                                                                Object[] sentFile5 = accountInstance.getMessagesStorage().getSentFile(AndroidUtilities.getPath(sendingMediaInfo4.uri), !z5 ? 0 : 3);
                                                                if (sentFile5 == null) {
                                                                    tL_photo8 = tL_photo10;
                                                                    str30 = str65;
                                                                } else {
                                                                    tL_photo8 = (TLRPC.TL_photo) sentFile5[0];
                                                                    str30 = (String) sentFile5[1];
                                                                }
                                                            } else {
                                                                tL_photo8 = tL_photo8;
                                                                str30 = str65;
                                                            }
                                                            str22 = str20;
                                                            str25 = str16;
                                                            i7 = i6;
                                                            str23 = str19;
                                                            arrayList3 = arrayList11;
                                                            str24 = str17;
                                                            obj4 = obj3;
                                                            str26 = str21;
                                                            Object obj14 = obj2;
                                                            str27 = str18;
                                                            obj5 = obj14;
                                                            ensureMediaThumbExists(z5, tL_photo8, sendingMediaInfo4.path, sendingMediaInfo4.uri, 0L);
                                                            str28 = str30;
                                                        }
                                                        if (tL_photo8 != null) {
                                                            tL_photo2 = tL_photo8;
                                                            str29 = str28;
                                                        } else {
                                                            TLRPC.TL_photo generatePhotoSizes = accountInstance.getSendMessagesHelper().generatePhotoSizes(sendingMediaInfo4.path, sendingMediaInfo4.uri, z7);
                                                            if (z5 && sendingMediaInfo4.canDeleteAfter) {
                                                                new File(sendingMediaInfo4.path).delete();
                                                            }
                                                            tL_photo2 = generatePhotoSizes;
                                                            str29 = str28;
                                                        }
                                                    }
                                                    if (tL_photo2 != null) {
                                                        final TLRPC.TL_photo tL_photo11 = tL_photo2;
                                                        final String str66 = str29;
                                                        final HashMap hashMap13 = new HashMap();
                                                        final Bitmap[] bitmapArr = new Bitmap[1];
                                                        final String[] strArr = new String[1];
                                                        boolean z20 = (sendingMediaInfo4.masks == null || sendingMediaInfo4.masks.isEmpty()) ? false : true;
                                                        tL_photo2.has_stickers = z20;
                                                        if (z20) {
                                                            SerializedData serializedData = new SerializedData((sendingMediaInfo4.masks.size() * 20) + 4);
                                                            serializedData.writeInt32(sendingMediaInfo4.masks.size());
                                                            int i30 = 0;
                                                            while (true) {
                                                                TLRPC.TL_photo tL_photo12 = tL_photo2;
                                                                if (i30 >= sendingMediaInfo4.masks.size()) {
                                                                    break;
                                                                }
                                                                sendingMediaInfo4.masks.get(i30).serializeToStream(serializedData);
                                                                i30++;
                                                                tL_photo2 = tL_photo12;
                                                            }
                                                            hashMap13.put("masks", Utilities.bytesToHex(serializedData.toByteArray()));
                                                            serializedData.cleanup();
                                                        }
                                                        if (str26 != null) {
                                                            hashMap13.put(obj5, str26);
                                                        }
                                                        if (z2) {
                                                            try {
                                                            } catch (Exception e6) {
                                                                e = e6;
                                                                FileLog.e(e);
                                                                if (!z2) {
                                                                }
                                                                ArrayList arrayList18 = arrayList3;
                                                                j4 = j5;
                                                                str31 = str24;
                                                                i8 = i7;
                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                    @Override
                                                                    public final void run() {
                                                                        SendMessagesHelper.lambda$null$61(bitmapArr, strArr, messageObject, accountInstance, tL_photo11, hashMap13, str66, j, messageObject2, sendingMediaInfo4, z4, i);
                                                                    }
                                                                });
                                                                i19 = i4;
                                                                arrayList10 = arrayList15;
                                                                arrayList7 = arrayList17;
                                                                arrayList9 = arrayList16;
                                                                arrayList8 = arrayList18;
                                                                i3 = i8 + 1;
                                                                arrayList6 = arrayList;
                                                                str4 = str31;
                                                                size2 = i20;
                                                                hashMap = hashMap3;
                                                                str2 = str25;
                                                                str = str22;
                                                                str3 = str23;
                                                                z14 = z5;
                                                                j11 = j4;
                                                                i2 = i5;
                                                            }
                                                            if (arrayList.size() != 1) {
                                                                if (!z2) {
                                                                    str32 = str26;
                                                                    j5 = j12;
                                                                } else {
                                                                    int i31 = i4 + 1;
                                                                    StringBuilder sb10 = new StringBuilder();
                                                                    sb10.append("");
                                                                    str32 = str26;
                                                                    j5 = j12;
                                                                    sb10.append(j5);
                                                                    hashMap13.put("groupId", sb10.toString());
                                                                    if (i31 == 10 || i7 == i20 - 1) {
                                                                        hashMap13.put("final", obj4);
                                                                        j2 = 0;
                                                                        i4 = i31;
                                                                    } else {
                                                                        i4 = i31;
                                                                    }
                                                                }
                                                                ArrayList arrayList182 = arrayList3;
                                                                j4 = j5;
                                                                str31 = str24;
                                                                i8 = i7;
                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                    @Override
                                                                    public final void run() {
                                                                        SendMessagesHelper.lambda$null$61(bitmapArr, strArr, messageObject, accountInstance, tL_photo11, hashMap13, str66, j, messageObject2, sendingMediaInfo4, z4, i);
                                                                    }
                                                                });
                                                                i19 = i4;
                                                                arrayList10 = arrayList15;
                                                                arrayList7 = arrayList17;
                                                                arrayList9 = arrayList16;
                                                                arrayList8 = arrayList182;
                                                            }
                                                        }
                                                        TLRPC.PhotoSize closestPhotoSizeWithSize = FileLoader.getClosestPhotoSizeWithSize(tL_photo11.sizes, AndroidUtilities.getPhotoSize());
                                                        if (closestPhotoSizeWithSize != null) {
                                                            try {
                                                                strArr[0] = getKeyForPhotoSize(closestPhotoSizeWithSize, bitmapArr, false);
                                                            } catch (Exception e7) {
                                                                e = e7;
                                                                FileLog.e(e);
                                                                if (!z2) {
                                                                }
                                                                ArrayList arrayList1822 = arrayList3;
                                                                j4 = j5;
                                                                str31 = str24;
                                                                i8 = i7;
                                                                AndroidUtilities.runOnUIThread(new Runnable() {
                                                                    @Override
                                                                    public final void run() {
                                                                        SendMessagesHelper.lambda$null$61(bitmapArr, strArr, messageObject, accountInstance, tL_photo11, hashMap13, str66, j, messageObject2, sendingMediaInfo4, z4, i);
                                                                    }
                                                                });
                                                                i19 = i4;
                                                                arrayList10 = arrayList15;
                                                                arrayList7 = arrayList17;
                                                                arrayList9 = arrayList16;
                                                                arrayList8 = arrayList1822;
                                                                i3 = i8 + 1;
                                                                arrayList6 = arrayList;
                                                                str4 = str31;
                                                                size2 = i20;
                                                                hashMap = hashMap3;
                                                                str2 = str25;
                                                                str = str22;
                                                                str3 = str23;
                                                                z14 = z5;
                                                                j11 = j4;
                                                                i2 = i5;
                                                            }
                                                        }
                                                        if (!z2) {
                                                        }
                                                        ArrayList arrayList18222 = arrayList3;
                                                        j4 = j5;
                                                        str31 = str24;
                                                        i8 = i7;
                                                        AndroidUtilities.runOnUIThread(new Runnable() {
                                                            @Override
                                                            public final void run() {
                                                                SendMessagesHelper.lambda$null$61(bitmapArr, strArr, messageObject, accountInstance, tL_photo11, hashMap13, str66, j, messageObject2, sendingMediaInfo4, z4, i);
                                                            }
                                                        });
                                                        i19 = i4;
                                                        arrayList10 = arrayList15;
                                                        arrayList7 = arrayList17;
                                                        arrayList9 = arrayList16;
                                                        arrayList8 = arrayList18222;
                                                    } else {
                                                        String str67 = str26;
                                                        String str68 = str27;
                                                        str31 = str24;
                                                        ArrayList arrayList19 = arrayList3;
                                                        j4 = j12;
                                                        i8 = i7;
                                                        if (arrayList19 != null) {
                                                            arrayList8 = arrayList19;
                                                            arrayList10 = arrayList15;
                                                            arrayList7 = arrayList17;
                                                            arrayList9 = arrayList16;
                                                        } else {
                                                            arrayList8 = new ArrayList();
                                                            arrayList7 = new ArrayList();
                                                            arrayList9 = new ArrayList();
                                                            arrayList10 = new ArrayList();
                                                        }
                                                        arrayList8.add(str68);
                                                        arrayList7.add(str67);
                                                        arrayList9.add(sendingMediaInfo4.caption);
                                                        arrayList10.add(sendingMediaInfo4.entities);
                                                        i19 = i4;
                                                    }
                                                }
                                            }
                                            if (str63 == null && sendingMediaInfo4.uri != null) {
                                                if (MediaController.isGif(sendingMediaInfo4.uri)) {
                                                    str62 = sendingMediaInfo4.uri.toString();
                                                    str49 = "gif";
                                                    str18 = MediaController.copyFileToCache(sendingMediaInfo4.uri, "gif");
                                                    z6 = true;
                                                } else if (MediaController.isWebp(sendingMediaInfo4.uri)) {
                                                    str62 = sendingMediaInfo4.uri.toString();
                                                    str49 = "webp";
                                                    str18 = MediaController.copyFileToCache(sendingMediaInfo4.uri, "webp");
                                                    z6 = true;
                                                }
                                                if (!z6) {
                                                }
                                            }
                                            str18 = str63;
                                            z6 = false;
                                            if (!z6) {
                                            }
                                        }
                                        str49 = str63 != null ? FileLoader.getFileExtension(new File(str63)) : "";
                                        str18 = str63;
                                        z6 = true;
                                        if (!z6) {
                                        }
                                    }
                                }
                                i3 = i8 + 1;
                                arrayList6 = arrayList;
                                str4 = str31;
                                size2 = i20;
                                hashMap = hashMap3;
                                str2 = str25;
                                str = str22;
                                str3 = str23;
                                z14 = z5;
                                j11 = j4;
                                i2 = i5;
                            }
                        }
                        i4 = i19;
                        j3 = j11;
                        int i202 = size2;
                        ArrayList arrayList112 = arrayList8;
                        if (sendingMediaInfo4.searchImage == null) {
                        }
                        i3 = i8 + 1;
                        arrayList6 = arrayList;
                        str4 = str31;
                        size2 = i202;
                        hashMap = hashMap3;
                        str2 = str25;
                        str = str22;
                        str3 = str23;
                        z14 = z5;
                        j11 = j4;
                        i2 = i5;
                    }
                    ArrayList arrayList20 = arrayList10;
                    ArrayList arrayList21 = arrayList9;
                    ArrayList arrayList22 = arrayList7;
                    arrayList2 = arrayList8;
                    if (j2 != 0) {
                        final long j13 = j2;
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public final void run() {
                                SendMessagesHelper.lambda$null$62(AccountInstance.this, j13, i);
                            }
                        });
                    }
                    if (inputContentInfoCompat != null) {
                        inputContentInfoCompat.releasePermission();
                    }
                    if (arrayList2 == null && !arrayList2.isEmpty()) {
                        int i32 = 0;
                        while (i32 < arrayList2.size()) {
                            ArrayList arrayList23 = arrayList22;
                            ArrayList arrayList24 = arrayList21;
                            ArrayList arrayList25 = arrayList20;
                            prepareSendingDocumentInternal(accountInstance, (String) arrayList2.get(i32), (String) arrayList23.get(i32), null, str49, j, messageObject2, (CharSequence) arrayList24.get(i32), (ArrayList) arrayList25.get(i32), messageObject, z, z4, i);
                            i32++;
                            arrayList22 = arrayList23;
                            arrayList20 = arrayList25;
                            arrayList21 = arrayList24;
                            arrayList2 = arrayList2;
                        }
                    }
                    if (BuildVars.LOGS_ENABLED) {
                        FileLog.d("total send time = " + (System.currentTimeMillis() - currentTimeMillis));
                        return;
                    }
                    return;
                }
                hashMap = null;
                long j112 = 0;
                j2 = 0;
                String str492 = null;
                ArrayList arrayList72 = null;
                i3 = 0;
                ArrayList arrayList82 = null;
                int i192 = 0;
                ArrayList arrayList92 = null;
                ArrayList arrayList102 = null;
                while (i3 < size2) {
                }
                ArrayList arrayList202 = arrayList102;
                ArrayList arrayList212 = arrayList92;
                ArrayList arrayList222 = arrayList72;
                arrayList2 = arrayList82;
                if (j2 != 0) {
                }
                if (inputContentInfoCompat != null) {
                }
                if (arrayList2 == null) {
                }
                if (BuildVars.LOGS_ENABLED) {
                }
            }
        }
        i2 = 0;
        String str402 = "_ori";
        String str412 = ".webp";
        String str422 = ".gif";
        String str432 = "_";
        if (!z14) {
        }
        if (!z) {
        }
        str = "_";
        str2 = ".gif";
        str3 = "_ori";
        str4 = ".webp";
        hashMap = null;
        long j1122 = 0;
        j2 = 0;
        String str4922 = null;
        ArrayList arrayList722 = null;
        i3 = 0;
        ArrayList arrayList822 = null;
        int i1922 = 0;
        ArrayList arrayList922 = null;
        ArrayList arrayList1022 = null;
        while (i3 < size2) {
        }
        ArrayList arrayList2022 = arrayList1022;
        ArrayList arrayList2122 = arrayList922;
        ArrayList arrayList2222 = arrayList722;
        arrayList2 = arrayList822;
        if (j2 != 0) {
        }
        if (inputContentInfoCompat != null) {
        }
        if (arrayList2 == null) {
        }
        if (BuildVars.LOGS_ENABLED) {
        }
    }

    public static void lambda$null$57(MediaSendPrepareWorker worker, AccountInstance accountInstance, SendingMediaInfo info, boolean blnOriginalImg, boolean isEncrypted) {
        worker.photo = accountInstance.getSendMessagesHelper().generatePhotoSizes(info.path, info.uri, blnOriginalImg);
        if (isEncrypted && info.canDeleteAfter) {
            new File(info.path).delete();
        }
        worker.sync.countDown();
    }

    public static void lambda$null$58(MessageObject editingMessageObject, AccountInstance accountInstance, TLRPC.TL_document documentFinal, String pathFinal, HashMap params, String parentFinal, long dialog_id, MessageObject reply_to_msg, SendingMediaInfo info, boolean notify, int scheduleDate) {
        if (editingMessageObject == null) {
            accountInstance.getSendMessagesHelper().sendMessage(documentFinal, null, pathFinal, dialog_id, reply_to_msg, info.caption, info.entities, null, params, notify, scheduleDate, 0, parentFinal);
        } else {
            accountInstance.getSendMessagesHelper().editMessageMedia(editingMessageObject, null, null, documentFinal, pathFinal, params, false, parentFinal);
        }
    }

    public static void lambda$null$59(MessageObject editingMessageObject, AccountInstance accountInstance, TLRPC.TL_photo photoFinal, boolean needDownloadHttpFinal, SendingMediaInfo info, HashMap params, String parentFinal, long dialog_id, MessageObject reply_to_msg, boolean notify, int scheduleDate) {
        if (editingMessageObject != null) {
            accountInstance.getSendMessagesHelper().editMessageMedia(editingMessageObject, photoFinal, null, null, needDownloadHttpFinal ? info.searchImage.imageUrl : null, params, false, parentFinal);
        } else {
            accountInstance.getSendMessagesHelper().sendMessage(photoFinal, needDownloadHttpFinal ? info.searchImage.imageUrl : null, dialog_id, reply_to_msg, info.caption, info.entities, null, params, notify, scheduleDate, info.ttl, parentFinal);
        }
    }

    public static void lambda$null$60(Bitmap thumbFinal, String thumbKeyFinal, MessageObject editingMessageObject, AccountInstance accountInstance, VideoEditedInfo videoEditedInfo, TLRPC.TL_document videoFinal, String finalPath, HashMap params, String parentFinal, long dialog_id, MessageObject reply_to_msg, SendingMediaInfo info, boolean notify, int scheduleDate) {
        if (thumbFinal != null && thumbKeyFinal != null) {
            ImageLoader.getInstance().putImageToCache(new BitmapDrawable(thumbFinal), thumbKeyFinal);
        }
        if (editingMessageObject != null) {
            accountInstance.getSendMessagesHelper().editMessageMedia(editingMessageObject, null, videoEditedInfo, videoFinal, finalPath, params, false, parentFinal);
        } else {
            accountInstance.getSendMessagesHelper().sendMessage(videoFinal, videoEditedInfo, finalPath, dialog_id, reply_to_msg, info.caption, info.entities, null, params, notify, scheduleDate, info.ttl, parentFinal);
        }
    }

    public static void lambda$null$61(Bitmap[] bitmapFinal, String[] keyFinal, MessageObject editingMessageObject, AccountInstance accountInstance, TLRPC.TL_photo photoFinal, HashMap params, String parentFinal, long dialog_id, MessageObject reply_to_msg, SendingMediaInfo info, boolean notify, int scheduleDate) {
        if (bitmapFinal[0] != null && keyFinal[0] != null) {
            ImageLoader.getInstance().putImageToCache(new BitmapDrawable(bitmapFinal[0]), keyFinal[0]);
        }
        if (editingMessageObject == null) {
            accountInstance.getSendMessagesHelper().sendMessage(photoFinal, null, dialog_id, reply_to_msg, info.caption, info.entities, null, params, notify, scheduleDate, info.ttl, parentFinal);
        } else {
            accountInstance.getSendMessagesHelper().editMessageMedia(editingMessageObject, photoFinal, null, null, null, params, false, parentFinal);
        }
    }

    public static void lambda$null$62(AccountInstance accountInstance, long lastGroupIdFinal, int scheduleDate) {
        SendMessagesHelper instance = accountInstance.getSendMessagesHelper();
        ArrayList<DelayedMessage> arrayList = instance.delayedMessages.get("group_" + lastGroupIdFinal);
        if (arrayList != null && !arrayList.isEmpty()) {
            DelayedMessage message = arrayList.get(0);
            MessageObject prevMessage = message.messageObjects.get(message.messageObjects.size() - 1);
            message.finalGroupMessage = prevMessage.getId();
            prevMessage.messageOwner.params.put("final", "1");
            TLRPC.TL_messages_messages messagesRes = new TLRPC.TL_messages_messages();
            messagesRes.messages.add(prevMessage.messageOwner);
            accountInstance.getMessagesStorage().putMessages((TLRPC.messages_Messages) messagesRes, message.peer, -2, 0, false, scheduleDate != 0);
            instance.sendReadyToSendGroup(message, true, true);
        }
    }

    private static void fillVideoAttribute(String videoPath, TLRPC.TL_documentAttributeVideo attributeVideo, VideoEditedInfo videoEditedInfo) {
        String rotation;
        boolean infoObtained = false;
        MediaMetadataRetriever mediaMetadataRetriever = null;
        try {
            try {
                try {
                    MediaMetadataRetriever mediaMetadataRetriever2 = new MediaMetadataRetriever();
                    mediaMetadataRetriever2.setDataSource(videoPath);
                    String width = mediaMetadataRetriever2.extractMetadata(18);
                    if (width != null) {
                        attributeVideo.w = Integer.parseInt(width);
                    }
                    String height = mediaMetadataRetriever2.extractMetadata(19);
                    if (height != null) {
                        attributeVideo.h = Integer.parseInt(height);
                    }
                    String duration = mediaMetadataRetriever2.extractMetadata(9);
                    if (duration != null) {
                        attributeVideo.duration = (int) Math.ceil(((float) Long.parseLong(duration)) / 1000.0f);
                    }
                    if (Build.VERSION.SDK_INT >= 17 && (rotation = mediaMetadataRetriever2.extractMetadata(24)) != null) {
                        int val = Utilities.parseInt(rotation).intValue();
                        if (videoEditedInfo != null) {
                            videoEditedInfo.rotationValue = val;
                        } else if (val == 90 || val == 270) {
                            int temp = attributeVideo.w;
                            attributeVideo.w = attributeVideo.h;
                            attributeVideo.h = temp;
                        }
                    }
                    infoObtained = true;
                    mediaMetadataRetriever2.release();
                } catch (Exception e) {
                    FileLog.e(e);
                }
            } catch (Exception e2) {
                FileLog.e(e2);
                if (0 != 0) {
                    mediaMetadataRetriever.release();
                }
            }
            if (!infoObtained) {
                try {
                    MediaPlayer mp = MediaPlayer.create(ApplicationLoader.applicationContext, Uri.fromFile(new File(videoPath)));
                    if (mp != null) {
                        attributeVideo.duration = (int) Math.ceil(mp.getDuration() / 1000.0f);
                        attributeVideo.w = mp.getVideoWidth();
                        attributeVideo.h = mp.getVideoHeight();
                        mp.release();
                    }
                } catch (Exception e3) {
                    FileLog.e(e3);
                }
            }
        } catch (Throwable th) {
            if (0 != 0) {
                try {
                    mediaMetadataRetriever.release();
                } catch (Exception e4) {
                    FileLog.e(e4);
                }
            }
            throw th;
        }
    }

    private static Bitmap createVideoThumbnail(String filePath, long time) {
        Bitmap bitmap = null;
        MediaMetadataRetriever retriever = new MediaMetadataRetriever();
        try {
            try {
                retriever.setDataSource(filePath);
                bitmap = retriever.getFrameAtTime(time, 1);
                retriever.release();
            } catch (RuntimeException e) {
            }
        } catch (Exception e2) {
            retriever.release();
        } catch (Throwable th) {
            try {
                retriever.release();
            } catch (RuntimeException e3) {
            }
            throw th;
        }
        if (bitmap == null) {
            return null;
        }
        return bitmap;
    }

    private static VideoEditedInfo createCompressionSettings(String videoPath) {
        int compressionsCount;
        long videoFramesSize;
        long videoFramesSize2;
        float maxSize;
        int targetBitrate;
        int[] params = new int[9];
        AnimatedFileDrawable.getVideoInfo(videoPath, params);
        if (params[0] == 0) {
            if (BuildVars.LOGS_ENABLED) {
                FileLog.d("video hasn't avc1 atom");
            }
            return null;
        }
        int originalBitrate = params[3];
        int bitrate = params[3];
        float videoDuration = params[4];
        long videoFramesSize3 = params[6];
        long audioFramesSize = params[5];
        int videoFramerate = params[7];
        if (bitrate > 900000) {
            bitrate = 900000;
        }
        if (Build.VERSION.SDK_INT < 18) {
            try {
                MediaCodecInfo codecInfo = MediaController.selectCodec("video/avc");
                if (codecInfo == null) {
                    if (BuildVars.LOGS_ENABLED) {
                        FileLog.d("no codec info for video/avc");
                    }
                    return null;
                }
                String name = codecInfo.getName();
                if (!name.equals("OMX.google.h264.encoder") && !name.equals("OMX.ST.VFM.H264Enc") && !name.equals("OMX.Exynos.avc.enc") && !name.equals("OMX.MARVELL.VIDEO.HW.CODA7542ENCODER") && !name.equals("OMX.MARVELL.VIDEO.H264ENCODER") && !name.equals("OMX.k3.video.encoder.avc") && !name.equals("OMX.TI.DUCATI1.VIDEO.H264E")) {
                    if (MediaController.selectColorFormat(codecInfo, "video/avc") == 0) {
                        if (BuildVars.LOGS_ENABLED) {
                            FileLog.d("no color format for video/avc");
                        }
                        return null;
                    }
                }
                if (BuildVars.LOGS_ENABLED) {
                    FileLog.d("unsupported encoder = " + name);
                }
                return null;
            } catch (Exception e) {
                return null;
            }
        }
        VideoEditedInfo videoEditedInfo = new VideoEditedInfo();
        videoEditedInfo.startTime = -1L;
        videoEditedInfo.endTime = -1L;
        videoEditedInfo.bitrate = bitrate;
        videoEditedInfo.originalPath = videoPath;
        videoEditedInfo.framerate = videoFramerate;
        videoEditedInfo.estimatedDuration = (long) Math.ceil(videoDuration);
        int i = params[1];
        videoEditedInfo.originalWidth = i;
        videoEditedInfo.resultWidth = i;
        int i2 = params[2];
        videoEditedInfo.originalHeight = i2;
        videoEditedInfo.resultHeight = i2;
        videoEditedInfo.rotationValue = params[8];
        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
        int selectedCompression = preferences.getInt("compress_video2", 1);
        if (videoEditedInfo.originalWidth > 1280 || videoEditedInfo.originalHeight > 1280) {
            compressionsCount = 5;
        } else if (videoEditedInfo.originalWidth > 848 || videoEditedInfo.originalHeight > 848) {
            compressionsCount = 4;
        } else if (videoEditedInfo.originalWidth > 640 || videoEditedInfo.originalHeight > 640) {
            compressionsCount = 3;
        } else if (videoEditedInfo.originalWidth > 480 || videoEditedInfo.originalHeight > 480) {
            compressionsCount = 2;
        } else {
            compressionsCount = 1;
        }
        if (selectedCompression >= compressionsCount) {
            selectedCompression = compressionsCount - 1;
        }
        if (selectedCompression != compressionsCount - 1) {
            if (selectedCompression != 0) {
                if (selectedCompression == 1) {
                    maxSize = 640.0f;
                    targetBitrate = 900000;
                } else if (selectedCompression == 2) {
                    maxSize = 848.0f;
                    targetBitrate = 1100000;
                } else {
                    targetBitrate = 2500000;
                    maxSize = 1280.0f;
                }
            } else {
                maxSize = 432.0f;
                targetBitrate = 400000;
            }
            videoFramesSize = videoFramesSize3;
            float scale = maxSize / (videoEditedInfo.originalWidth > videoEditedInfo.originalHeight ? videoEditedInfo.originalWidth : videoEditedInfo.originalHeight);
            videoEditedInfo.resultWidth = Math.round((videoEditedInfo.originalWidth * scale) / 2.0f) * 2;
            videoEditedInfo.resultHeight = Math.round((videoEditedInfo.originalHeight * scale) / 2.0f) * 2;
            if (bitrate != 0) {
                bitrate = Math.min(targetBitrate, (int) (originalBitrate / scale));
                videoFramesSize2 = ((bitrate / 8) * videoDuration) / 1000.0f;
                if (selectedCompression != compressionsCount - 1) {
                    videoEditedInfo.resultWidth = videoEditedInfo.originalWidth;
                    videoEditedInfo.resultHeight = videoEditedInfo.originalHeight;
                    videoEditedInfo.bitrate = originalBitrate;
                    videoEditedInfo.estimatedSize = (int) new File(videoPath).length();
                } else {
                    videoEditedInfo.bitrate = bitrate;
                    videoEditedInfo.estimatedSize = (int) (audioFramesSize + videoFramesSize2);
                    videoEditedInfo.estimatedSize += (videoEditedInfo.estimatedSize / 32768) * 16;
                }
                if (videoEditedInfo.estimatedSize == 0) {
                    videoEditedInfo.estimatedSize = 1L;
                }
                return videoEditedInfo;
            }
        } else {
            videoFramesSize = videoFramesSize3;
        }
        videoFramesSize2 = videoFramesSize;
        if (selectedCompression != compressionsCount - 1) {
        }
        if (videoEditedInfo.estimatedSize == 0) {
        }
        return videoEditedInfo;
    }

    public static void prepareSendingVideo(final AccountInstance accountInstance, final String videoPath, final long estimatedSize, final long duration, final int width, final int height, final VideoEditedInfo info, final long dialog_id, final MessageObject reply_to_msg, final CharSequence caption, final ArrayList<TLRPC.MessageEntity> entities, final int ttl, final MessageObject editingMessageObject, final boolean notify, final int scheduleDate) {
        if (videoPath == null || videoPath.length() == 0) {
            return;
        }
        new Thread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.lambda$prepareSendingVideo$65(VideoEditedInfo.this, videoPath, dialog_id, duration, ttl, accountInstance, height, width, estimatedSize, caption, editingMessageObject, reply_to_msg, entities, notify, scheduleDate);
            }
        }).start();
    }

    public static void lambda$prepareSendingVideo$65(VideoEditedInfo info, String videoPath, final long dialog_id, long duration, final int ttl, final AccountInstance accountInstance, int height, int width, long estimatedSize, CharSequence caption, final MessageObject editingMessageObject, final MessageObject reply_to_msg, final ArrayList entities, final boolean notify, final int scheduleDate) {
        boolean isRound;
        boolean isEncrypted;
        VideoEditedInfo videoEditedInfo;
        String path;
        boolean isRound2;
        String originalPath;
        long startTime;
        TLRPC.TL_document document;
        long startTime2;
        TLRPC.TL_document document2;
        Bitmap thumb;
        String thumbKey;
        String path2;
        TLRPC.TL_documentAttributeVideo attributeVideo;
        int i;
        int i2;
        VideoEditedInfo videoEditedInfo2 = info != null ? info : createCompressionSettings(videoPath);
        boolean isEncrypted2 = ((int) dialog_id) == 0;
        boolean isRound3 = videoEditedInfo2 != null && videoEditedInfo2.roundVideo;
        String thumbKey2 = null;
        if (videoEditedInfo2 != null || videoPath.endsWith("mp4")) {
            isRound = isRound3;
            isEncrypted = isEncrypted2;
            videoEditedInfo = videoEditedInfo2;
        } else if (!isRound3) {
            prepareSendingDocumentInternal(accountInstance, videoPath, videoPath, null, null, dialog_id, reply_to_msg, caption, entities, editingMessageObject, false, notify, scheduleDate);
            return;
        } else {
            isRound = isRound3;
            isEncrypted = isEncrypted2;
            videoEditedInfo = videoEditedInfo2;
        }
        File temp = new File(videoPath);
        String originalPath2 = videoPath + temp.length() + "_" + temp.lastModified();
        final VideoEditedInfo videoEditedInfo3 = videoEditedInfo;
        if (videoEditedInfo3 == null) {
            path = videoPath;
            isRound2 = isRound;
            originalPath = originalPath2;
            startTime = 0;
        } else {
            isRound2 = isRound;
            if (isRound2) {
                path = videoPath;
            } else {
                StringBuilder sb = new StringBuilder();
                sb.append(originalPath2);
                sb.append(duration);
                sb.append("_");
                path = videoPath;
                sb.append(videoEditedInfo3.startTime);
                sb.append("_");
                sb.append(videoEditedInfo3.endTime);
                sb.append(videoEditedInfo3.muted ? "_m" : "");
                originalPath2 = sb.toString();
                if (videoEditedInfo3.resultWidth != videoEditedInfo3.originalWidth) {
                    originalPath2 = originalPath2 + "_" + videoEditedInfo3.resultWidth;
                }
            }
            long startTime3 = videoEditedInfo3.startTime >= 0 ? videoEditedInfo3.startTime : 0L;
            originalPath = originalPath2;
            startTime = startTime3;
        }
        String parentObject = null;
        boolean isEncrypted3 = isEncrypted;
        if (isEncrypted3 || ttl != 0) {
            document = null;
            startTime2 = startTime;
        } else {
            MessagesStorage messagesStorage = accountInstance.getMessagesStorage();
            if (!isEncrypted3) {
                document = null;
                i2 = 2;
            } else {
                document = null;
                i2 = 5;
            }
            Object[] sentData = messagesStorage.getSentFile(originalPath, i2);
            if (sentData == null) {
                startTime2 = startTime;
            } else {
                TLRPC.TL_document document3 = (TLRPC.TL_document) sentData[0];
                String parentObject2 = (String) sentData[1];
                startTime2 = startTime;
                ensureMediaThumbExists(isEncrypted3, document3, videoPath, null, startTime2);
                document2 = document3;
                parentObject = parentObject2;
                if (document2 != null) {
                    Bitmap thumb2 = createVideoThumbnail(videoPath, startTime2);
                    if (thumb2 == null) {
                        thumb2 = ThumbnailUtils.createVideoThumbnail(videoPath, 1);
                    }
                    int side = (isEncrypted3 || ttl != 0) ? 90 : 320;
                    TLRPC.PhotoSize size = ImageLoader.scaleAndSaveImage(thumb2, side, side, side > 90 ? 80 : 55, isEncrypted3);
                    if (thumb2 != null && size != null) {
                        if (!isRound2) {
                            thumb2 = null;
                        } else if (!isEncrypted3) {
                            Utilities.blurBitmap(thumb2, 3, Build.VERSION.SDK_INT < 21 ? 0 : 1, thumb2.getWidth(), thumb2.getHeight(), thumb2.getRowBytes());
                            thumbKey2 = String.format(size.location.volume_id + "_" + size.location.local_id + "@%d_%d_b", Integer.valueOf((int) (AndroidUtilities.roundMessageSize / AndroidUtilities.density)), Integer.valueOf((int) (AndroidUtilities.roundMessageSize / AndroidUtilities.density)));
                        } else {
                            Utilities.blurBitmap(thumb2, 7, Build.VERSION.SDK_INT < 21 ? 0 : 1, thumb2.getWidth(), thumb2.getHeight(), thumb2.getRowBytes());
                            thumbKey2 = String.format(size.location.volume_id + "_" + size.location.local_id + "@%d_%d_b2", Integer.valueOf((int) (AndroidUtilities.roundMessageSize / AndroidUtilities.density)), Integer.valueOf((int) (AndroidUtilities.roundMessageSize / AndroidUtilities.density)));
                        }
                    }
                    TLRPC.TL_document document4 = new TLRPC.TL_document();
                    if (size != null) {
                        document4.thumbs.add(size);
                        document4.flags |= 1;
                    }
                    document4.file_reference = new byte[0];
                    document4.mime_type = MimeTypes.VIDEO_MP4;
                    accountInstance.getUserConfig().saveConfig(false);
                    if (isEncrypted3) {
                        int high_id = (int) (dialog_id >> 32);
                        TLRPC.EncryptedChat encryptedChat = accountInstance.getMessagesController().getEncryptedChat(Integer.valueOf(high_id));
                        if (encryptedChat == null) {
                            return;
                        }
                        if (AndroidUtilities.getPeerLayerVersion(encryptedChat.layer) >= 66) {
                            attributeVideo = new TLRPC.TL_documentAttributeVideo();
                        } else {
                            attributeVideo = new TLRPC.TL_documentAttributeVideo_layer65();
                        }
                    } else {
                        attributeVideo = new TLRPC.TL_documentAttributeVideo();
                        attributeVideo.supports_streaming = true;
                    }
                    attributeVideo.round_message = isRound2;
                    document4.attributes.add(attributeVideo);
                    if (videoEditedInfo3 == null || !videoEditedInfo3.needConvert()) {
                        thumb = thumb2;
                        if (temp.exists()) {
                            document4.size = (int) temp.length();
                        }
                        fillVideoAttribute(videoPath, attributeVideo, null);
                    } else {
                        if (videoEditedInfo3.muted) {
                            document4.attributes.add(new TLRPC.TL_documentAttributeAnimated());
                            fillVideoAttribute(videoPath, attributeVideo, videoEditedInfo3);
                            videoEditedInfo3.originalWidth = attributeVideo.w;
                            videoEditedInfo3.originalHeight = attributeVideo.h;
                            thumb = thumb2;
                        } else {
                            thumb = thumb2;
                            attributeVideo.duration = (int) (duration / 1000);
                        }
                        if (videoEditedInfo3.rotationValue == 90) {
                            i = width;
                        } else if (videoEditedInfo3.rotationValue == 270) {
                            i = width;
                        } else {
                            attributeVideo.w = width;
                            attributeVideo.h = height;
                            document4.size = (int) estimatedSize;
                        }
                        attributeVideo.w = height;
                        attributeVideo.h = i;
                        document4.size = (int) estimatedSize;
                    }
                    document2 = document4;
                    thumbKey = thumbKey2;
                } else {
                    thumb = null;
                    thumbKey = null;
                }
                if (videoEditedInfo3 == null && videoEditedInfo3.needConvert()) {
                    String fileName = "-2147483648_" + SharedConfig.getLastLocalId() + ".mp4";
                    File cacheFile = new File(FileLoader.getDirectory(4), fileName);
                    SharedConfig.saveConfig();
                    path2 = cacheFile.getAbsolutePath();
                } else {
                    path2 = path;
                }
                final TLRPC.TL_document videoFinal = document2;
                final String parentFinal = parentObject;
                final String finalPath = path2;
                final HashMap<String, String> params = new HashMap<>();
                final Bitmap thumbFinal = thumb;
                final String thumbKeyFinal = thumbKey;
                final String captionFinal = caption == null ? caption.toString() : "";
                if (originalPath != null) {
                    params.put("originalPath", originalPath);
                }
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        SendMessagesHelper.lambda$null$64(thumbFinal, thumbKeyFinal, editingMessageObject, accountInstance, videoEditedInfo3, videoFinal, finalPath, params, parentFinal, dialog_id, reply_to_msg, captionFinal, entities, notify, scheduleDate, ttl);
                    }
                });
            }
        }
        document2 = document;
        if (document2 != null) {
        }
        if (videoEditedInfo3 == null) {
        }
        path2 = path;
        final TLRPC.TL_document videoFinal2 = document2;
        final String parentFinal2 = parentObject;
        final String finalPath2 = path2;
        final HashMap params2 = new HashMap<>();
        final Bitmap thumbFinal2 = thumb;
        final String thumbKeyFinal2 = thumbKey;
        if (caption == null) {
        }
        if (originalPath != null) {
        }
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                SendMessagesHelper.lambda$null$64(thumbFinal2, thumbKeyFinal2, editingMessageObject, accountInstance, videoEditedInfo3, videoFinal2, finalPath2, params2, parentFinal2, dialog_id, reply_to_msg, captionFinal, entities, notify, scheduleDate, ttl);
            }
        });
    }

    public static void lambda$null$64(Bitmap thumbFinal, String thumbKeyFinal, MessageObject editingMessageObject, AccountInstance accountInstance, VideoEditedInfo videoEditedInfo, TLRPC.TL_document videoFinal, String finalPath, HashMap params, String parentFinal, long dialog_id, MessageObject reply_to_msg, String captionFinal, ArrayList entities, boolean notify, int scheduleDate, int ttl) {
        if (thumbFinal != null && thumbKeyFinal != null) {
            ImageLoader.getInstance().putImageToCache(new BitmapDrawable(thumbFinal), thumbKeyFinal);
        }
        if (editingMessageObject != null) {
            accountInstance.getSendMessagesHelper().editMessageMedia(editingMessageObject, null, videoEditedInfo, videoFinal, finalPath, params, false, parentFinal);
        } else {
            accountInstance.getSendMessagesHelper().sendMessage(videoFinal, videoEditedInfo, finalPath, dialog_id, reply_to_msg, captionFinal, entities, null, params, notify, scheduleDate, ttl, parentFinal);
        }
    }
}