盛康基办.apk(点击下载) / MessageObject.java


package im.guobwnxjuc.messenger;

import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.text.Layout;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
import android.text.style.URLSpan;
import android.text.util.Linkify;
import android.util.Base64;
import android.util.SparseArray;
import android.view.View;
import androidx.recyclerview.widget.ItemTouchHelper;
import com.blankj.utilcode.util.GsonUtils;
import com.google.android.exoplayer2.util.MimeTypes;
import com.king.zxing.util.CodeUtils;
import com.king.zxing.util.LogUtils;
import im.guobwnxjuc.javaBean.PayBillOverBean;
import im.guobwnxjuc.messenger.Emoji;
import im.guobwnxjuc.messenger.browser.Browser;
import im.guobwnxjuc.phoneformat.PhoneFormat;
import im.guobwnxjuc.tgnet.ConnectionsManager;
import im.guobwnxjuc.tgnet.SerializedData;
import im.guobwnxjuc.tgnet.TLJsonResolve;
import im.guobwnxjuc.tgnet.TLObject;
import im.guobwnxjuc.tgnet.TLRPC;
import im.guobwnxjuc.tgnet.TLRPCContacts;
import im.guobwnxjuc.tgnet.TLRPCRedpacket;
import im.guobwnxjuc.ui.actionbar.BaseFragment;
import im.guobwnxjuc.ui.actionbar.Theme;
import im.guobwnxjuc.ui.components.TextStyleSpan;
import im.guobwnxjuc.ui.components.TypefaceSpan;
import im.guobwnxjuc.ui.components.URLSpanBotCommand;
import im.guobwnxjuc.ui.components.URLSpanBrowser;
import im.guobwnxjuc.ui.components.URLSpanMono;
import im.guobwnxjuc.ui.components.URLSpanNoUnderline;
import im.guobwnxjuc.ui.components.URLSpanNoUnderlineBold;
import im.guobwnxjuc.ui.components.URLSpanReplacement;
import im.guobwnxjuc.ui.components.URLSpanUserMention;
import im.guobwnxjuc.ui.hui.packet.bean.RedpacketBean;
import im.guobwnxjuc.ui.hui.packet.bean.RedpacketResponse;
import im.guobwnxjuc.ui.hui.sysnotify.SysNotifyAtTextClickableSpan;
import im.guobwnxjuc.ui.hui.transfer.bean.TransferResponse;
import im.guobwnxjuc.ui.utils.number.MoneyUtil;
import im.guobwnxjuc.ui.utils.number.NumberUtil;
import java.io.BufferedReader;
import java.io.File;
import java.io.StringReader;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.slf4j.Marker;

public class MessageObject {
    private static final int LINES_PER_BLOCK = 10;
    public static final int MESSAGE_SEND_STATE_EDITING = 3;
    public static final int MESSAGE_SEND_STATE_SENDING = 1;
    public static final int MESSAGE_SEND_STATE_SEND_ERROR = 2;
    public static final int MESSAGE_SEND_STATE_SENT = 0;
    public static final int POSITION_FLAG_BOTTOM = 8;
    public static final int POSITION_FLAG_LEFT = 1;
    public static final int POSITION_FLAG_RIGHT = 2;
    public static final int POSITION_FLAG_TOP = 4;
    public static final int TYPE_ANIMATED_STICKER = 15;
    public static final int TYPE_CARD = 103;
    public static final int TYPE_LIVE = 207;
    public static final int TYPE_PAYBILL = 104;
    public static final int TYPE_POLL = 17;
    public static final int TYPE_REDPKG = 101;
    public static final int TYPE_ROUND_VIDEO = 5;
    public static final int TYPE_STICKER = 13;
    public static final int TYPE_SYSTEM_NOTIFY = 105;
    public static final int TYPE_TRANSF = 102;
    static final String[] excludeWords = {" vs. ", " vs ", " versus ", " ft. ", " ft ", " featuring ", " feat. ", " feat ", " presents ", " pres. ", " pres ", " and ", " & ", " . "};
    public static Pattern instagramUrlPattern;
    public static Pattern urlPattern;
    public static Pattern videoTimeUrlPattern;
    public boolean attachPathExists;
    public int audioPlayerDuration;
    public float audioProgress;
    public int audioProgressMs;
    public int audioProgressSec;
    public StringBuilder botButtonsLayout;
    public float bufferedProgress;
    public boolean cancelEditing;
    public CharSequence caption;
    public int contentType;
    public int currentAccount;
    public TLRPC.TL_channelAdminLogEvent currentEvent;
    public String customReplyName;
    public String dateKey;
    public Delegate delegate;
    public boolean deleted;
    public CharSequence editingMessage;
    public ArrayList<TLRPC.MessageEntity> editingMessageEntities;
    public TLRPC.Document emojiAnimatedSticker;
    public String emojiAnimatedStickerColor;
    private int emojiOnlyCount;
    ArrayList<TLRPC.MessageEntity> entitiesCopy;
    public long eventId;
    public float forceSeekTo;
    public boolean forceUpdate;
    private float generatedWithDensity;
    private int generatedWithMinSize;
    public float gifState;
    public boolean hadAnimationNotReadyLoading;
    public boolean hasRtl;
    public boolean isDateObject;
    public boolean isRestrictedMessage;
    private int isRoundVideoCached;
    public int lastLineWidth;
    private boolean layoutCreated;
    public int linesCount;
    public CharSequence linkDescription;
    public boolean localChannel;
    public boolean localEdit;
    public long localGroupId;
    public String localName;
    public long localSentGroupId;
    public int localType;
    public String localUserName;
    public boolean mediaExists;
    public TLRPC.Message messageOwner;
    public CharSequence messageText;
    public String monthKey;
    public ArrayList<TLRPC.PhotoSize> photoThumbs;
    public ArrayList<TLRPC.PhotoSize> photoThumbs2;
    public TLObject photoThumbsObject;
    public TLObject photoThumbsObject2;
    public long pollLastCheckTime;
    public boolean pollVisibleOnScreen;
    public String previousAttachPath;
    public String previousCaption;
    public ArrayList<TLRPC.MessageEntity> previousCaptionEntities;
    public TLRPC.MessageMedia previousMedia;
    public MessageObject replyMessageObject;
    public boolean resendAsIs;
    public boolean scheduled;
    public int textHeight;
    public ArrayList<TextLayoutBlock> textLayoutBlocks;
    public int textWidth;
    public float textXOffset;
    public int transHeight;
    public int transWidth;
    public int type;
    public boolean useCustomPhoto;
    public CharSequence vCardData;
    public VideoEditedInfo videoEditedInfo;
    public boolean viewsReloaded;
    public int wantedBotKeyboardWidth;

    public interface Delegate {
        void onClickRed();
    }

    public void checkForScam() {
    }

    public static class VCardData {
        private String company;
        private ArrayList<String> emails = new ArrayList<>();
        private ArrayList<String> phones = new ArrayList<>();

        public static CharSequence parse(String str) {
            byte[] decodeQuotedPrintable;
            try {
                BufferedReader bufferedReader = new BufferedReader(new StringReader(str));
                boolean z = false;
                VCardData vCardData = null;
                String str2 = null;
                while (true) {
                    String readLine = bufferedReader.readLine();
                    if (readLine == null) {
                        try {
                            break;
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                    } else if (!readLine.startsWith("PHOTO")) {
                        if (readLine.indexOf(58) >= 0) {
                            if (readLine.startsWith("BEGIN:VCARD")) {
                                vCardData = new VCardData();
                            } else if (readLine.startsWith("END:VCARD") && vCardData != null) {
                                z = true;
                            }
                        }
                        if (str2 != null) {
                            readLine = str2 + readLine;
                            str2 = null;
                        }
                        if (!readLine.contains("=QUOTED-PRINTABLE") || !readLine.endsWith("=")) {
                            int indexOf = readLine.indexOf(LogUtils.COLON);
                            int i = 2;
                            String[] strArr = indexOf >= 0 ? new String[]{readLine.substring(0, indexOf), readLine.substring(indexOf + 1).trim()} : new String[]{readLine.trim()};
                            if (strArr.length >= 2 && vCardData != null) {
                                if (strArr[0].startsWith("ORG")) {
                                    String[] split = strArr[0].split(";");
                                    int length = split.length;
                                    int i2 = 0;
                                    String str3 = null;
                                    String str4 = null;
                                    while (i2 < length) {
                                        String[] split2 = split[i2].split("=");
                                        if (split2.length == i) {
                                            if (split2[0].equals("CHARSET")) {
                                                str4 = split2[1];
                                            } else if (split2[0].equals("ENCODING")) {
                                                str3 = split2[1];
                                            }
                                        }
                                        i2++;
                                        i = 2;
                                    }
                                    vCardData.company = strArr[1];
                                    if (!(str3 == null || !str3.equalsIgnoreCase("QUOTED-PRINTABLE") || (decodeQuotedPrintable = AndroidUtilities.decodeQuotedPrintable(AndroidUtilities.getStringBytes(vCardData.company))) == null || decodeQuotedPrintable.length == 0)) {
                                        vCardData.company = new String(decodeQuotedPrintable, str4);
                                    }
                                    vCardData.company = vCardData.company.replace(';', ' ');
                                } else if (strArr[0].startsWith("TEL")) {
                                    if (strArr[1].length() > 0) {
                                        vCardData.phones.add(strArr[1]);
                                    }
                                } else if (strArr[0].startsWith("EMAIL")) {
                                    String str5 = strArr[1];
                                    if (str5.length() > 0) {
                                        vCardData.emails.add(str5);
                                    }
                                }
                            }
                        } else {
                            str2 = readLine.substring(0, readLine.length() - 1);
                        }
                    }
                }
                bufferedReader.close();
                if (!z) {
                    return null;
                }
                StringBuilder sb = new StringBuilder();
                for (int i3 = 0; i3 < vCardData.phones.size(); i3++) {
                    if (sb.length() > 0) {
                        sb.append('\n');
                    }
                    String str6 = vCardData.phones.get(i3);
                    if (str6.contains("#") || str6.contains("*")) {
                        sb.append(str6);
                    } else {
                        sb.append(PhoneFormat.getInstance().format(str6));
                    }
                }
                for (int i4 = 0; i4 < vCardData.emails.size(); i4++) {
                    if (sb.length() > 0) {
                        sb.append('\n');
                    }
                    sb.append(PhoneFormat.getInstance().format(vCardData.emails.get(i4)));
                }
                if (!TextUtils.isEmpty(vCardData.company)) {
                    if (sb.length() > 0) {
                        sb.append('\n');
                    }
                    sb.append(vCardData.company);
                }
                return sb;
            } catch (Throwable unused) {
                return null;
            }
        }
    }

    public static class TextLayoutBlock {
        public int charactersEnd;
        public int charactersOffset;
        public byte directionFlags;
        public int height;
        public int heightByOffset;
        public StaticLayout textLayout;
        public float textYOffset;

        public boolean isRtl() {
            byte b = this.directionFlags;
            return (b & 1) != 0 && (b & 2) == 0;
        }
    }

    public static class GroupedMessagePosition {
        public float aspectRatio;
        public boolean edge;
        public int flags;
        public boolean last;
        public int leftSpanOffset;
        public byte maxX;
        public byte maxY;
        public byte minX;
        public byte minY;
        public float ph;
        public int pw;
        public float[] siblingHeights;
        public int spanSize;

        public void set(int i, int i2, int i3, int i4, int i5, float f, int i6) {
            this.minX = (byte) i;
            this.maxX = (byte) i2;
            this.minY = (byte) i3;
            this.maxY = (byte) i4;
            this.pw = i5;
            this.spanSize = i5;
            this.ph = f;
            this.flags = (byte) i6;
        }
    }

    public static class GroupedMessages {
        private int firstSpanAdditionalSize = ItemTouchHelper.Callback.DEFAULT_DRAG_ANIMATION_DURATION;
        public long groupId;
        public boolean hasSibling;
        private int maxSizeWidth = CodeUtils.DEFAULT_REQ_HEIGHT;
        public ArrayList<MessageObject> messages = new ArrayList<>();
        public ArrayList<GroupedMessagePosition> posArray = new ArrayList<>();
        public HashMap<MessageObject, GroupedMessagePosition> positions = new HashMap<>();

        public int getMaxSizeWidth() {
            return this.maxSizeWidth;
        }

        private class MessageGroupedLayoutAttempt {
            public float[] heights;
            public int[] lineCounts;

            public MessageGroupedLayoutAttempt(int i, int i2, float f, float f2) {
                this.lineCounts = new int[]{i, i2};
                this.heights = new float[]{f, f2};
            }

            public MessageGroupedLayoutAttempt(int i, int i2, int i3, float f, float f2, float f3) {
                this.lineCounts = new int[]{i, i2, i3};
                this.heights = new float[]{f, f2, f3};
            }

            public MessageGroupedLayoutAttempt(int i, int i2, int i3, int i4, float f, float f2, float f3, float f4) {
                this.lineCounts = new int[]{i, i2, i3, i4};
                this.heights = new float[]{f, f2, f3, f4};
            }
        }

        private float multiHeight(float[] fArr, int i, int i2) {
            float f = 0.0f;
            while (i < i2) {
                f += fArr[i];
                i++;
            }
            return ((float) this.maxSizeWidth) / f;
        }

        /* JADX WARNING: Code restructure failed: missing block: B:178:0x071f, code lost:
            if (r6.lineCounts[2] > r6.lineCounts[3]) goto L_0x0723;
         */
        public void calculate() {
            boolean z;
            int i;
            int i2;
            int i3;
            int i4;
            float[] fArr;
            int i5;
            int i6;
            int i7;
            float f;
            int i8;
            int i9;
            float f2;
            this.posArray.clear();
            this.positions.clear();
            int size = this.messages.size();
            if (size > 1) {
                StringBuilder sb = new StringBuilder();
                this.hasSibling = false;
                int i10 = 0;
                boolean z2 = false;
                float f3 = 1.0f;
                boolean z3 = false;
                boolean z4 = false;
                while (i10 < size) {
                    MessageObject messageObject = this.messages.get(i10);
                    if (i10 == 0) {
                        z4 = messageObject.isOutOwner();
                        z2 = !z4 && (!(messageObject.messageOwner.fwd_from == null || messageObject.messageOwner.fwd_from.saved_from_peer == null) || (messageObject.messageOwner.from_id > 0 && (messageObject.messageOwner.to_id.channel_id != 0 || messageObject.messageOwner.to_id.chat_id != 0 || (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame) || (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice))));
                    }
                    TLRPC.PhotoSize closestPhotoSizeWithSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
                    GroupedMessagePosition groupedMessagePosition = new GroupedMessagePosition();
                    groupedMessagePosition.last = i10 == size + -1;
                    if (closestPhotoSizeWithSize == null) {
                        f2 = 1.0f;
                    } else {
                        f2 = ((float) closestPhotoSizeWithSize.w) / ((float) closestPhotoSizeWithSize.h);
                    }
                    groupedMessagePosition.aspectRatio = f2;
                    if (groupedMessagePosition.aspectRatio > 1.2f) {
                        sb.append("w");
                    } else if (groupedMessagePosition.aspectRatio < 0.8f) {
                        sb.append("n");
                    } else {
                        sb.append("q");
                    }
                    f3 += groupedMessagePosition.aspectRatio;
                    if (groupedMessagePosition.aspectRatio > 2.0f) {
                        z3 = true;
                    }
                    this.positions.put(messageObject, groupedMessagePosition);
                    this.posArray.add(groupedMessagePosition);
                    i10++;
                }
                if (z2) {
                    this.maxSizeWidth -= 50;
                    this.firstSpanAdditionalSize += 50;
                }
                int dp = AndroidUtilities.dp(120.0f);
                int dp2 = (int) (((float) AndroidUtilities.dp(120.0f)) / (((float) Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y)) / ((float) this.maxSizeWidth)));
                int i11 = this.maxSizeWidth;
                int dp3 = (int) (((float) AndroidUtilities.dp(40.0f)) / (((float) Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y)) / ((float) i11)));
                float f4 = ((float) i11) / 814.0f;
                float f5 = f3 / ((float) size);
                float dp4 = ((float) AndroidUtilities.dp(100.0f)) / 814.0f;
                int i12 = 3;
                if (z3 || !(size == 2 || size == 3 || size == 4)) {
                    z = z4;
                    int size2 = this.posArray.size();
                    float[] fArr2 = new float[size2];
                    for (int i13 = 0; i13 < size; i13++) {
                        if (f5 > 1.1f) {
                            fArr2[i13] = Math.max(1.0f, this.posArray.get(i13).aspectRatio);
                        } else {
                            fArr2[i13] = Math.min(1.0f, this.posArray.get(i13).aspectRatio);
                        }
                        fArr2[i13] = Math.max(0.66667f, Math.min(1.7f, fArr2[i13]));
                    }
                    ArrayList arrayList = new ArrayList();
                    int i14 = 1;
                    while (i14 < size2) {
                        int i15 = size2 - i14;
                        if (i14 > i12 || i15 > i12) {
                            i9 = size;
                        } else {
                            i9 = size;
                            arrayList.add(new MessageGroupedLayoutAttempt(i14, i15, multiHeight(fArr2, 0, i14), multiHeight(fArr2, i14, size2)));
                        }
                        i14++;
                        size = i9;
                        i12 = 3;
                    }
                    i = size;
                    int i16 = 3;
                    int i17 = 1;
                    while (i17 < size2 - 1) {
                        int i18 = 1;
                        while (true) {
                            int i19 = size2 - i17;
                            if (i18 >= i19) {
                                break;
                            }
                            int i20 = i19 - i18;
                            if (i17 <= i16) {
                                if (i18 <= (f5 < 0.85f ? 4 : 3) && i20 <= i16) {
                                    int i21 = i17 + i18;
                                    i8 = i18;
                                    f = dp4;
                                    arrayList.add(new MessageGroupedLayoutAttempt(i17, i18, i20, multiHeight(fArr2, 0, i17), multiHeight(fArr2, i17, i21), multiHeight(fArr2, i21, size2)));
                                    i18 = i8 + 1;
                                    dp4 = f;
                                    i16 = 3;
                                }
                            }
                            i8 = i18;
                            f = dp4;
                            i18 = i8 + 1;
                            dp4 = f;
                            i16 = 3;
                        }
                        i17++;
                        i16 = 3;
                    }
                    int i22 = 1;
                    while (i22 < size2 - 2) {
                        int i23 = 1;
                        while (true) {
                            int i24 = size2 - i22;
                            if (i23 >= i24) {
                                break;
                            }
                            int i25 = 1;
                            while (true) {
                                int i26 = i24 - i23;
                                if (i25 >= i26) {
                                    break;
                                }
                                int i27 = i26 - i25;
                                if (i22 > 3 || i23 > 3 || i25 > 3 || i27 > 3) {
                                    i6 = i25;
                                    i5 = i24;
                                    i4 = size2;
                                    fArr = fArr2;
                                    i7 = dp2;
                                } else {
                                    float multiHeight = multiHeight(fArr2, 0, i22);
                                    int i28 = i22 + i23;
                                    float multiHeight2 = multiHeight(fArr2, i22, i28);
                                    int i29 = i28 + i25;
                                    float multiHeight3 = multiHeight(fArr2, i28, i29);
                                    float multiHeight4 = multiHeight(fArr2, i29, size2);
                                    i4 = size2;
                                    i6 = i25;
                                    i5 = i24;
                                    fArr = fArr2;
                                    i7 = dp2;
                                    arrayList.add(new MessageGroupedLayoutAttempt(i22, i23, i25, i27, multiHeight, multiHeight2, multiHeight3, multiHeight4));
                                }
                                i25 = i6 + 1;
                                dp2 = i7;
                                i24 = i5;
                                fArr2 = fArr;
                                size2 = i4;
                            }
                            i23++;
                            fArr2 = fArr2;
                        }
                        i22++;
                        fArr2 = fArr2;
                    }
                    float f6 = (float) ((this.maxSizeWidth / 3) * 4);
                    MessageGroupedLayoutAttempt messageGroupedLayoutAttempt = null;
                    float f7 = 0.0f;
                    for (int i30 = 0; i30 < arrayList.size(); i30++) {
                        MessageGroupedLayoutAttempt messageGroupedLayoutAttempt2 = (MessageGroupedLayoutAttempt) arrayList.get(i30);
                        float f8 = Float.MAX_VALUE;
                        float f9 = 0.0f;
                        for (int i31 = 0; i31 < messageGroupedLayoutAttempt2.heights.length; i31++) {
                            f9 += messageGroupedLayoutAttempt2.heights[i31];
                            if (messageGroupedLayoutAttempt2.heights[i31] < f8) {
                                f8 = messageGroupedLayoutAttempt2.heights[i31];
                            }
                        }
                        float abs = Math.abs(f9 - f6);
                        if (messageGroupedLayoutAttempt2.lineCounts.length > 1) {
                            if (messageGroupedLayoutAttempt2.lineCounts[0] <= messageGroupedLayoutAttempt2.lineCounts[1] && (messageGroupedLayoutAttempt2.lineCounts.length <= 2 || messageGroupedLayoutAttempt2.lineCounts[1] <= messageGroupedLayoutAttempt2.lineCounts[2])) {
                                if (messageGroupedLayoutAttempt2.lineCounts.length > 3) {
                                }
                            }
                            abs *= 1.2f;
                        }
                        if (f8 < ((float) dp2)) {
                            abs *= 1.5f;
                        }
                        if (messageGroupedLayoutAttempt == null || abs < f7) {
                            messageGroupedLayoutAttempt = messageGroupedLayoutAttempt2;
                            f7 = abs;
                        }
                    }
                    if (messageGroupedLayoutAttempt != null) {
                        i2 = 0;
                        int i32 = 0;
                        int i33 = 0;
                        while (i33 < messageGroupedLayoutAttempt.lineCounts.length) {
                            int i34 = messageGroupedLayoutAttempt.lineCounts[i33];
                            float f10 = messageGroupedLayoutAttempt.heights[i33];
                            int i35 = this.maxSizeWidth;
                            int i36 = i34 - 1;
                            i2 = Math.max(i2, i36);
                            int i37 = i35;
                            GroupedMessagePosition groupedMessagePosition2 = null;
                            for (int i38 = 0; i38 < i34; i38++) {
                                int i39 = (int) (fArr2[i32] * f10);
                                i37 -= i39;
                                GroupedMessagePosition groupedMessagePosition3 = this.posArray.get(i32);
                                int i40 = i33 == 0 ? 4 : 0;
                                if (i33 == messageGroupedLayoutAttempt.lineCounts.length - 1) {
                                    i40 |= 8;
                                }
                                if (i38 == 0) {
                                    i40 |= 1;
                                    if (z) {
                                        groupedMessagePosition2 = groupedMessagePosition3;
                                    }
                                }
                                if (i38 == i36) {
                                    i40 |= 2;
                                    if (!z) {
                                        i3 = i40;
                                        groupedMessagePosition2 = groupedMessagePosition3;
                                        groupedMessagePosition3.set(i38, i38, i33, i33, i39, Math.max(dp4, f10 / 814.0f), i3);
                                        i32++;
                                    }
                                }
                                i3 = i40;
                                groupedMessagePosition3.set(i38, i38, i33, i33, i39, Math.max(dp4, f10 / 814.0f), i3);
                                i32++;
                            }
                            groupedMessagePosition2.pw += i37;
                            groupedMessagePosition2.spanSize += i37;
                            i33++;
                        }
                    } else {
                        return;
                    }
                } else {
                    if (size == 2) {
                        GroupedMessagePosition groupedMessagePosition4 = this.posArray.get(0);
                        GroupedMessagePosition groupedMessagePosition5 = this.posArray.get(1);
                        String sb2 = sb.toString();
                        if (sb2.equals("ww")) {
                            z = z4;
                            double d = (double) f4;
                            Double.isNaN(d);
                            if (((double) f5) > d * 1.4d && ((double) (groupedMessagePosition4.aspectRatio - groupedMessagePosition5.aspectRatio)) < 0.2d) {
                                float round = ((float) Math.round(Math.min(((float) this.maxSizeWidth) / groupedMessagePosition4.aspectRatio, Math.min(((float) this.maxSizeWidth) / groupedMessagePosition5.aspectRatio, 407.0f)))) / 814.0f;
                                groupedMessagePosition4.set(0, 0, 0, 0, this.maxSizeWidth, round, 7);
                                groupedMessagePosition5.set(0, 0, 1, 1, this.maxSizeWidth, round, 11);
                                i2 = 0;
                                i = size;
                            }
                        } else {
                            z = z4;
                        }
                        if (sb2.equals("ww") || sb2.equals("qq")) {
                            int i41 = this.maxSizeWidth / 2;
                            float f11 = (float) i41;
                            float round2 = ((float) Math.round(Math.min(f11 / groupedMessagePosition4.aspectRatio, Math.min(f11 / groupedMessagePosition5.aspectRatio, 814.0f)))) / 814.0f;
                            groupedMessagePosition4.set(0, 0, 0, 0, i41, round2, 13);
                            groupedMessagePosition5.set(1, 1, 0, 0, i41, round2, 14);
                        } else {
                            int i42 = this.maxSizeWidth;
                            int max = (int) Math.max(((float) i42) * 0.4f, (float) Math.round((((float) i42) / groupedMessagePosition4.aspectRatio) / ((1.0f / groupedMessagePosition4.aspectRatio) + (1.0f / groupedMessagePosition5.aspectRatio))));
                            int i43 = this.maxSizeWidth - max;
                            if (i43 < dp2) {
                                max -= dp2 - i43;
                                i43 = dp2;
                            }
                            float min = Math.min(814.0f, (float) Math.round(Math.min(((float) i43) / groupedMessagePosition4.aspectRatio, ((float) max) / groupedMessagePosition5.aspectRatio))) / 814.0f;
                            groupedMessagePosition4.set(0, 0, 0, 0, i43, min, 13);
                            groupedMessagePosition5.set(1, 1, 0, 0, max, min, 14);
                        }
                    } else {
                        z = z4;
                        if (size == 3) {
                            GroupedMessagePosition groupedMessagePosition6 = this.posArray.get(0);
                            GroupedMessagePosition groupedMessagePosition7 = this.posArray.get(1);
                            GroupedMessagePosition groupedMessagePosition8 = this.posArray.get(2);
                            if (sb.charAt(0) == 'n') {
                                float min2 = Math.min(407.0f, (float) Math.round((groupedMessagePosition7.aspectRatio * ((float) this.maxSizeWidth)) / (groupedMessagePosition8.aspectRatio + groupedMessagePosition7.aspectRatio)));
                                float f12 = 814.0f - min2;
                                int max2 = (int) Math.max((float) dp2, Math.min(((float) this.maxSizeWidth) * 0.5f, (float) Math.round(Math.min(groupedMessagePosition8.aspectRatio * min2, groupedMessagePosition7.aspectRatio * f12))));
                                int round3 = Math.round(Math.min((groupedMessagePosition6.aspectRatio * 814.0f) + ((float) dp3), (float) (this.maxSizeWidth - max2)));
                                groupedMessagePosition6.set(0, 0, 0, 1, round3, 1.0f, 13);
                                float f13 = f12 / 814.0f;
                                groupedMessagePosition7.set(1, 1, 0, 0, max2, f13, 6);
                                float f14 = min2 / 814.0f;
                                groupedMessagePosition8.set(0, 1, 1, 1, max2, f14, 10);
                                groupedMessagePosition8.spanSize = this.maxSizeWidth;
                                groupedMessagePosition6.siblingHeights = new float[]{f14, f13};
                                if (z) {
                                    groupedMessagePosition6.spanSize = this.maxSizeWidth - max2;
                                } else {
                                    groupedMessagePosition7.spanSize = this.maxSizeWidth - round3;
                                    groupedMessagePosition8.leftSpanOffset = round3;
                                }
                                this.hasSibling = true;
                            } else {
                                float round4 = ((float) Math.round(Math.min(((float) this.maxSizeWidth) / groupedMessagePosition6.aspectRatio, 537.24005f))) / 814.0f;
                                groupedMessagePosition6.set(0, 1, 0, 0, this.maxSizeWidth, round4, 7);
                                int i44 = this.maxSizeWidth / 2;
                                float f15 = (float) i44;
                                float min3 = Math.min(814.0f - round4, (float) Math.round(Math.min(f15 / groupedMessagePosition7.aspectRatio, f15 / groupedMessagePosition8.aspectRatio))) / 814.0f;
                                if (min3 < dp4) {
                                    min3 = dp4;
                                }
                                groupedMessagePosition7.set(0, 0, 1, 1, i44, min3, 9);
                                groupedMessagePosition8.set(1, 1, 1, 1, i44, min3, 10);
                            }
                            i = size;
                            i2 = 1;
                        } else if (size == 4) {
                            GroupedMessagePosition groupedMessagePosition9 = this.posArray.get(0);
                            GroupedMessagePosition groupedMessagePosition10 = this.posArray.get(1);
                            GroupedMessagePosition groupedMessagePosition11 = this.posArray.get(2);
                            GroupedMessagePosition groupedMessagePosition12 = this.posArray.get(3);
                            if (sb.charAt(0) == 'w') {
                                float round5 = ((float) Math.round(Math.min(((float) this.maxSizeWidth) / groupedMessagePosition9.aspectRatio, 537.24005f))) / 814.0f;
                                groupedMessagePosition9.set(0, 2, 0, 0, this.maxSizeWidth, round5, 7);
                                float round6 = (float) Math.round(((float) this.maxSizeWidth) / ((groupedMessagePosition10.aspectRatio + groupedMessagePosition11.aspectRatio) + groupedMessagePosition12.aspectRatio));
                                float f16 = (float) dp2;
                                int max3 = (int) Math.max(f16, Math.min(((float) this.maxSizeWidth) * 0.4f, groupedMessagePosition10.aspectRatio * round6));
                                int max4 = (int) Math.max(Math.max(f16, ((float) this.maxSizeWidth) * 0.33f), groupedMessagePosition12.aspectRatio * round6);
                                int i45 = (this.maxSizeWidth - max3) - max4;
                                if (i45 < AndroidUtilities.dp(58.0f)) {
                                    int dp5 = AndroidUtilities.dp(58.0f) - i45;
                                    i45 = AndroidUtilities.dp(58.0f);
                                    int i46 = dp5 / 2;
                                    max3 -= i46;
                                    max4 -= dp5 - i46;
                                }
                                float min4 = Math.min(814.0f - round5, round6) / 814.0f;
                                if (min4 < dp4) {
                                    min4 = dp4;
                                }
                                groupedMessagePosition10.set(0, 0, 1, 1, max3, min4, 9);
                                groupedMessagePosition11.set(1, 1, 1, 1, i45, min4, 8);
                                groupedMessagePosition12.set(2, 2, 1, 1, max4, min4, 10);
                                i2 = 2;
                                i = size;
                            } else {
                                int max5 = Math.max(dp2, Math.round(814.0f / (((1.0f / groupedMessagePosition10.aspectRatio) + (1.0f / groupedMessagePosition11.aspectRatio)) + (1.0f / groupedMessagePosition12.aspectRatio))));
                                float f17 = (float) dp;
                                float f18 = (float) max5;
                                float min5 = Math.min(0.33f, Math.max(f17, f18 / groupedMessagePosition10.aspectRatio) / 814.0f);
                                float min6 = Math.min(0.33f, Math.max(f17, f18 / groupedMessagePosition11.aspectRatio) / 814.0f);
                                float f19 = (1.0f - min5) - min6;
                                int round7 = Math.round(Math.min((814.0f * groupedMessagePosition9.aspectRatio) + ((float) dp3), (float) (this.maxSizeWidth - max5)));
                                groupedMessagePosition9.set(0, 0, 0, 2, round7, min5 + min6 + f19, 13);
                                groupedMessagePosition10.set(1, 1, 0, 0, max5, min5, 6);
                                groupedMessagePosition11.set(0, 1, 1, 1, max5, min6, 2);
                                groupedMessagePosition11.spanSize = this.maxSizeWidth;
                                groupedMessagePosition12.set(0, 1, 2, 2, max5, f19, 10);
                                groupedMessagePosition12.spanSize = this.maxSizeWidth;
                                if (z) {
                                    groupedMessagePosition9.spanSize = this.maxSizeWidth - max5;
                                } else {
                                    groupedMessagePosition10.spanSize = this.maxSizeWidth - round7;
                                    groupedMessagePosition11.leftSpanOffset = round7;
                                    groupedMessagePosition12.leftSpanOffset = round7;
                                }
                                groupedMessagePosition9.siblingHeights = new float[]{min5, min6, f19};
                                this.hasSibling = true;
                            }
                        } else {
                            i = size;
                            i2 = 0;
                        }
                    }
                    i2 = 1;
                    i = size;
                }
                for (int i47 = 0; i47 < i; i47++) {
                    GroupedMessagePosition groupedMessagePosition13 = this.posArray.get(i47);
                    if (z) {
                        if (groupedMessagePosition13.minX == 0) {
                            groupedMessagePosition13.spanSize += this.firstSpanAdditionalSize;
                        }
                        if ((groupedMessagePosition13.flags & 2) != 0) {
                            groupedMessagePosition13.edge = true;
                        }
                    } else {
                        if (groupedMessagePosition13.maxX == i2 || (groupedMessagePosition13.flags & 2) != 0) {
                            groupedMessagePosition13.spanSize += this.firstSpanAdditionalSize;
                        }
                        if ((groupedMessagePosition13.flags & 1) != 0) {
                            groupedMessagePosition13.edge = true;
                        }
                    }
                    MessageObject messageObject2 = this.messages.get(i47);
                    if (!z && messageObject2.needDrawAvatarInternal()) {
                        if (groupedMessagePosition13.edge) {
                            if (groupedMessagePosition13.spanSize != 1000) {
                                groupedMessagePosition13.spanSize += 108;
                            }
                            groupedMessagePosition13.pw += 108;
                        } else if ((groupedMessagePosition13.flags & 2) != 0) {
                            if (groupedMessagePosition13.spanSize != 1000) {
                                groupedMessagePosition13.spanSize -= 108;
                            } else if (groupedMessagePosition13.leftSpanOffset != 0) {
                                groupedMessagePosition13.leftSpanOffset += 108;
                            }
                        }
                    }
                    if (z || !messageObject2.needDrawAvatar()) {
                        if (z && messageObject2.needDrawAvatar()) {
                            if (groupedMessagePosition13.edge) {
                                if (groupedMessagePosition13.spanSize != 1000) {
                                    groupedMessagePosition13.spanSize += 108;
                                }
                                groupedMessagePosition13.pw += 108;
                            } else {
                                if ((groupedMessagePosition13.flags & 1) != 0) {
                                    if (groupedMessagePosition13.spanSize != 1000) {
                                        groupedMessagePosition13.spanSize -= 108;
                                    } else if (groupedMessagePosition13.leftSpanOffset != 0) {
                                        groupedMessagePosition13.leftSpanOffset += 108;
                                    }
                                }
                            }
                        }
                    } else if (groupedMessagePosition13.edge) {
                        if (groupedMessagePosition13.spanSize != 1000) {
                            groupedMessagePosition13.spanSize += 108;
                        }
                        groupedMessagePosition13.pw += 108;
                    } else if ((groupedMessagePosition13.flags & 2) != 0) {
                        if (groupedMessagePosition13.spanSize != 1000) {
                            groupedMessagePosition13.spanSize -= 108;
                        } else if (groupedMessagePosition13.leftSpanOffset != 0) {
                            groupedMessagePosition13.leftSpanOffset += 108;
                        }
                    }
                }
            }
        }
    }

    public MessageObject(int i, TLRPC.Message message, String str, String str2, String str3, boolean z, boolean z2, boolean z3) {
        this.type = 1000;
        this.forceSeekTo = -1.0f;
        this.entitiesCopy = new ArrayList<>();
        this.localType = z ? 2 : 1;
        this.currentAccount = i;
        this.localName = str2;
        this.localUserName = str3;
        this.messageText = str;
        this.messageOwner = message;
        this.localChannel = z2;
        this.localEdit = z3;
    }

    public MessageObject(int i, TLRPC.Message message, AbstractMap<Integer, TLRPC.User> abstractMap, boolean z) {
        this(i, message, abstractMap, (AbstractMap<Integer, TLRPC.Chat>) null, z);
    }

    public MessageObject(int i, TLRPC.Message message, SparseArray<TLRPC.User> sparseArray, boolean z) {
        this(i, message, sparseArray, (SparseArray<TLRPC.Chat>) null, z);
    }

    public MessageObject(int i, TLRPC.Message message, boolean z) {
        this(i, message, null, null, null, null, null, z, 0);
    }

    public MessageObject(int i, TLRPC.Message message, MessageObject messageObject, boolean z) {
        this(i, message, messageObject, null, null, null, null, z, 0);
    }

    public MessageObject(int i, TLRPC.Message message, AbstractMap<Integer, TLRPC.User> abstractMap, AbstractMap<Integer, TLRPC.Chat> abstractMap2, boolean z) {
        this(i, message, abstractMap, abstractMap2, z, 0);
    }

    public MessageObject(int i, TLRPC.Message message, SparseArray<TLRPC.User> sparseArray, SparseArray<TLRPC.Chat> sparseArray2, boolean z) {
        this(i, message, null, null, null, sparseArray, sparseArray2, z, 0);
    }

    public MessageObject(int i, TLRPC.Message message, AbstractMap<Integer, TLRPC.User> abstractMap, AbstractMap<Integer, TLRPC.Chat> abstractMap2, boolean z, long j) {
        this(i, message, null, abstractMap, abstractMap2, null, null, z, j);
    }

    public MessageObject(int i, TLRPC.Message message, MessageObject messageObject, AbstractMap<Integer, TLRPC.User> abstractMap, AbstractMap<Integer, TLRPC.Chat> abstractMap2, SparseArray<TLRPC.User> sparseArray, SparseArray<TLRPC.Chat> sparseArray2, boolean z, long j) {
        TLRPC.User user;
        SparseArray<TLRPC.Chat> sparseArray3;
        AbstractMap<Integer, TLRPC.Chat> abstractMap3;
        TextPaint textPaint;
        this.type = 1000;
        this.forceSeekTo = -1.0f;
        this.entitiesCopy = new ArrayList<>();
        Theme.createChatResources(null, true);
        this.currentAccount = i;
        this.messageOwner = message;
        this.replyMessageObject = messageObject;
        this.eventId = j;
        if (message.replyMessage != null) {
            this.replyMessageObject = new MessageObject(this.currentAccount, message.replyMessage, null, abstractMap, abstractMap2, sparseArray, sparseArray2, false, j);
        }
        if (message.from_id > 0) {
            if (abstractMap != null) {
                user = abstractMap.get(Integer.valueOf(message.from_id));
            } else {
                user = sparseArray != null ? sparseArray.get(message.from_id) : null;
            }
            user = user == null ? MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(message.from_id)) : user;
            abstractMap3 = abstractMap2;
            sparseArray3 = sparseArray2;
        } else {
            abstractMap3 = abstractMap2;
            sparseArray3 = sparseArray2;
            user = null;
        }
        updateMessageText(abstractMap, abstractMap3, sparseArray, sparseArray3);
        if (isMediaEmpty()) {
            this.messageText = updateMetionText(this.messageText, this.messageOwner.entities);
        }
        setType();
        measureInlineBotButtons();
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.setTimeInMillis(((long) this.messageOwner.date) * 1000);
        int i2 = gregorianCalendar.get(6);
        int i3 = gregorianCalendar.get(1);
        int i4 = gregorianCalendar.get(2);
        this.dateKey = String.format("%d_%02d_%02d", Integer.valueOf(i3), Integer.valueOf(i4), Integer.valueOf(i2));
        this.monthKey = String.format("%d_%02d", Integer.valueOf(i3), Integer.valueOf(i4));
        createMessageSendInfo();
        generateCaption();
        if (z) {
            if (this.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                textPaint = Theme.chat_msgGameTextPaint;
            } else {
                textPaint = Theme.chat_msgTextPaint;
            }
            int[] iArr = SharedConfig.allowBigEmoji ? new int[1] : null;
            this.messageText = Emoji.replaceEmoji(this.messageText, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20.0f), false, iArr);
            checkEmojiOnly(iArr);
            this.emojiAnimatedSticker = null;
            if (this.emojiOnlyCount == 1 && !(message.media instanceof TLRPC.TL_messageMediaWebPage) && message.entities.isEmpty()) {
                CharSequence charSequence = this.messageText;
                int indexOf = TextUtils.indexOf(charSequence, "🏻");
                if (indexOf >= 0) {
                    this.emojiAnimatedStickerColor = "_c1";
                    charSequence = charSequence.subSequence(0, indexOf);
                } else {
                    int indexOf2 = TextUtils.indexOf(charSequence, "🏼");
                    if (indexOf2 >= 0) {
                        this.emojiAnimatedStickerColor = "_c2";
                        charSequence = charSequence.subSequence(0, indexOf2);
                    } else {
                        int indexOf3 = TextUtils.indexOf(charSequence, "🏽");
                        if (indexOf3 >= 0) {
                            this.emojiAnimatedStickerColor = "_c3";
                            charSequence = charSequence.subSequence(0, indexOf3);
                        } else {
                            int indexOf4 = TextUtils.indexOf(charSequence, "🏾");
                            if (indexOf4 >= 0) {
                                this.emojiAnimatedStickerColor = "_c4";
                                charSequence = charSequence.subSequence(0, indexOf4);
                            } else {
                                int indexOf5 = TextUtils.indexOf(charSequence, "🏿");
                                if (indexOf5 >= 0) {
                                    this.emojiAnimatedStickerColor = "_c5";
                                    charSequence = charSequence.subSequence(0, indexOf5);
                                } else {
                                    this.emojiAnimatedStickerColor = "";
                                }
                            }
                        }
                    }
                }
                this.emojiAnimatedSticker = MediaDataController.getInstance(this.currentAccount).getEmojiAnimatedSticker(charSequence);
            }
            if (this.emojiAnimatedSticker == null) {
                generateLayout(user);
            } else {
                this.type = 1000;
                if (isSticker()) {
                    this.type = 13;
                } else if (isAnimatedSticker()) {
                    this.type = 15;
                }
            }
        }
        this.layoutCreated = z;
        generateThumbs(false);
        checkMediaExistance();
    }

    public void renderText() {
        entityCopy(this.messageOwner.entities);
        addEntitiesToText(this.messageText, false);
    }

    private void entityCopy(ArrayList<TLRPC.MessageEntity> arrayList) {
        if (arrayList != null && arrayList.size() != 0) {
            this.entitiesCopy.clear();
            Iterator<TLRPC.MessageEntity> it = arrayList.iterator();
            while (it.hasNext()) {
                TLRPC.MessageEntity next = it.next();
                if (next instanceof TLRPC.TL_messageEntityTextUrl) {
                    TLRPC.TL_messageEntityTextUrl tL_messageEntityTextUrl = new TLRPC.TL_messageEntityTextUrl();
                    tL_messageEntityTextUrl.offset = next.offset;
                    tL_messageEntityTextUrl.length = next.length;
                    tL_messageEntityTextUrl.url = next.url;
                    this.entitiesCopy.add(tL_messageEntityTextUrl);
                } else if (next instanceof TLRPC.TL_messageEntityBotCommand) {
                    TLRPC.TL_messageEntityBotCommand tL_messageEntityBotCommand = new TLRPC.TL_messageEntityBotCommand();
                    tL_messageEntityBotCommand.offset = next.offset;
                    tL_messageEntityBotCommand.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityBotCommand);
                } else if (next instanceof TLRPC.TL_messageEntityEmail) {
                    TLRPC.TL_messageEntityEmail tL_messageEntityEmail = new TLRPC.TL_messageEntityEmail();
                    tL_messageEntityEmail.offset = next.offset;
                    tL_messageEntityEmail.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityEmail);
                } else if (next instanceof TLRPC.TL_messageEntityPre) {
                    TLRPC.TL_messageEntityPre tL_messageEntityPre = new TLRPC.TL_messageEntityPre();
                    tL_messageEntityPre.offset = next.offset;
                    tL_messageEntityPre.length = next.length;
                    tL_messageEntityPre.language = next.language;
                    this.entitiesCopy.add(tL_messageEntityPre);
                } else if (next instanceof TLRPC.TL_messageEntityUnknown) {
                    TLRPC.TL_messageEntityUnknown tL_messageEntityUnknown = new TLRPC.TL_messageEntityUnknown();
                    tL_messageEntityUnknown.offset = next.offset;
                    tL_messageEntityUnknown.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityUnknown);
                } else if (next instanceof TLRPC.TL_messageEntityUrl) {
                    TLRPC.TL_messageEntityUrl tL_messageEntityUrl = new TLRPC.TL_messageEntityUrl();
                    tL_messageEntityUrl.offset = next.offset;
                    tL_messageEntityUrl.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityUrl);
                } else if (next instanceof TLRPC.TL_messageEntityItalic) {
                    TLRPC.TL_messageEntityItalic tL_messageEntityItalic = new TLRPC.TL_messageEntityItalic();
                    tL_messageEntityItalic.offset = next.offset;
                    tL_messageEntityItalic.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityItalic);
                } else if (next instanceof TLRPC.TL_messageEntityMention) {
                    TLRPC.TL_messageEntityMention tL_messageEntityMention = new TLRPC.TL_messageEntityMention();
                    tL_messageEntityMention.offset = next.offset;
                    tL_messageEntityMention.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityMention);
                } else if (next instanceof TLRPC.TL_messageEntityMentionName) {
                    TLRPC.TL_messageEntityMentionName tL_messageEntityMentionName = new TLRPC.TL_messageEntityMentionName();
                    tL_messageEntityMentionName.offset = next.offset;
                    tL_messageEntityMentionName.length = next.length;
                    tL_messageEntityMentionName.user_id = ((TLRPC.TL_messageEntityMentionName) next).user_id;
                    this.entitiesCopy.add(tL_messageEntityMentionName);
                } else if (next instanceof TLRPC.TL_inputMessageEntityMentionName) {
                    TLRPC.TL_inputMessageEntityMentionName tL_inputMessageEntityMentionName = new TLRPC.TL_inputMessageEntityMentionName();
                    tL_inputMessageEntityMentionName.offset = next.offset;
                    tL_inputMessageEntityMentionName.length = next.length;
                    tL_inputMessageEntityMentionName.user_id = ((TLRPC.TL_inputMessageEntityMentionName) next).user_id;
                    this.entitiesCopy.add(tL_inputMessageEntityMentionName);
                } else if (next instanceof TLRPC.TL_messageEntityCashtag) {
                    TLRPC.TL_messageEntityCashtag tL_messageEntityCashtag = new TLRPC.TL_messageEntityCashtag();
                    tL_messageEntityCashtag.offset = next.offset;
                    tL_messageEntityCashtag.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityCashtag);
                } else if (next instanceof TLRPC.TL_messageEntityBold) {
                    TLRPC.TL_messageEntityBold tL_messageEntityBold = new TLRPC.TL_messageEntityBold();
                    tL_messageEntityBold.offset = next.offset;
                    tL_messageEntityBold.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityBold);
                } else if (next instanceof TLRPC.TL_messageEntityHashtag) {
                    TLRPC.TL_messageEntityHashtag tL_messageEntityHashtag = new TLRPC.TL_messageEntityHashtag();
                    tL_messageEntityHashtag.offset = next.offset;
                    tL_messageEntityHashtag.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityHashtag);
                } else if (next instanceof TLRPC.TL_messageEntityCode) {
                    TLRPC.TL_messageEntityCode tL_messageEntityCode = new TLRPC.TL_messageEntityCode();
                    tL_messageEntityCode.offset = next.offset;
                    tL_messageEntityCode.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityCode);
                } else if (next instanceof TLRPC.TL_messageEntityStrike) {
                    TLRPC.TL_messageEntityStrike tL_messageEntityStrike = new TLRPC.TL_messageEntityStrike();
                    tL_messageEntityStrike.offset = next.offset;
                    tL_messageEntityStrike.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityStrike);
                } else if (next instanceof TLRPC.TL_messageEntityBlockquote) {
                    TLRPC.TL_messageEntityBlockquote tL_messageEntityBlockquote = new TLRPC.TL_messageEntityBlockquote();
                    tL_messageEntityBlockquote.offset = next.offset;
                    tL_messageEntityBlockquote.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityBlockquote);
                } else if (next instanceof TLRPC.TL_messageEntityUnderline) {
                    TLRPC.TL_messageEntityUnderline tL_messageEntityUnderline = new TLRPC.TL_messageEntityUnderline();
                    tL_messageEntityUnderline.offset = next.offset;
                    tL_messageEntityUnderline.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityUnderline);
                } else if (next instanceof TLRPC.TL_messageEntityPhone) {
                    TLRPC.TL_messageEntityPhone tL_messageEntityPhone = new TLRPC.TL_messageEntityPhone();
                    tL_messageEntityPhone.offset = next.offset;
                    tL_messageEntityPhone.length = next.length;
                    this.entitiesCopy.add(tL_messageEntityPhone);
                }
            }
        }
    }

    public CharSequence updateMetionText(CharSequence charSequence, ArrayList<TLRPC.MessageEntity> arrayList) {
        if (arrayList == null || arrayList.isEmpty()) {
            return charSequence;
        }
        SpannableString valueOf = SpannableString.valueOf(charSequence);
        CharSequence spannableString = new SpannableString("");
        URLSpan[] uRLSpanArr = (URLSpan[]) valueOf.getSpans(0, charSequence.length(), URLSpan.class);
        ArrayList arrayList2 = new ArrayList();
        entityCopy(arrayList);
        Collections.sort(this.entitiesCopy, $$Lambda$MessageObject$RoXctYTPtrJUUTy3iiEkN93VyjI.INSTANCE);
        int size = this.entitiesCopy.size();
        for (int i = 0; i < size; i++) {
            TLRPC.MessageEntity messageEntity = this.entitiesCopy.get(i);
            if (messageEntity.length > 0 && messageEntity.offset >= 0 && messageEntity.offset < charSequence.length()) {
                if (messageEntity.offset + messageEntity.length > charSequence.length()) {
                    messageEntity.length = charSequence.length() - messageEntity.offset;
                }
                boolean z = messageEntity instanceof TLRPC.TL_messageEntityBold;
                if ((z || (messageEntity instanceof TLRPC.TL_messageEntityItalic) || (messageEntity instanceof TLRPC.TL_messageEntityStrike) || (messageEntity instanceof TLRPC.TL_messageEntityUnderline) || (messageEntity instanceof TLRPC.TL_messageEntityBlockquote) || (messageEntity instanceof TLRPC.TL_messageEntityCode) || (messageEntity instanceof TLRPC.TL_messageEntityPre) || (messageEntity instanceof TLRPC.TL_messageEntityMentionName) || (messageEntity instanceof TLRPC.TL_inputMessageEntityMentionName) || (messageEntity instanceof TLRPC.TL_messageEntityTextUrl)) && uRLSpanArr != null && uRLSpanArr.length > 0) {
                    for (int i2 = 0; i2 < uRLSpanArr.length; i2++) {
                        if (uRLSpanArr[i2] != null) {
                            int spanStart = valueOf.getSpanStart(uRLSpanArr[i2]);
                            int spanEnd = valueOf.getSpanEnd(uRLSpanArr[i2]);
                            if ((messageEntity.offset <= spanStart && messageEntity.offset + messageEntity.length >= spanStart) || (messageEntity.offset <= spanEnd && messageEntity.offset + messageEntity.length >= spanEnd)) {
                                valueOf.removeSpan(uRLSpanArr[i2]);
                                uRLSpanArr[i2] = null;
                            }
                        }
                    }
                }
                TextStyleSpan.TextStyleRun textStyleRun = new TextStyleSpan.TextStyleRun();
                textStyleRun.start = messageEntity.offset;
                textStyleRun.end = textStyleRun.start + messageEntity.length;
                if (messageEntity instanceof TLRPC.TL_messageEntityStrike) {
                    textStyleRun.flags = 8;
                } else if (messageEntity instanceof TLRPC.TL_messageEntityUnderline) {
                    textStyleRun.flags = 16;
                } else if (messageEntity instanceof TLRPC.TL_messageEntityBlockquote) {
                    textStyleRun.flags = 32;
                } else if (z) {
                    textStyleRun.flags = 1;
                } else if (messageEntity instanceof TLRPC.TL_messageEntityItalic) {
                    textStyleRun.flags = 2;
                } else if ((messageEntity instanceof TLRPC.TL_messageEntityCode) || (messageEntity instanceof TLRPC.TL_messageEntityPre)) {
                    textStyleRun.flags = 4;
                } else if (messageEntity instanceof TLRPC.TL_messageEntityMentionName) {
                    textStyleRun.flags = 64;
                    textStyleRun.urlEntity = messageEntity;
                } else if (messageEntity instanceof TLRPC.TL_inputMessageEntityMentionName) {
                    textStyleRun.flags = 64;
                    textStyleRun.urlEntity = messageEntity;
                }
                int size2 = arrayList2.size();
                int i3 = 0;
                while (i3 < size2) {
                    TextStyleSpan.TextStyleRun textStyleRun2 = (TextStyleSpan.TextStyleRun) arrayList2.get(i3);
                    if (textStyleRun.start > textStyleRun2.start) {
                        if (textStyleRun.start < textStyleRun2.end) {
                            if (textStyleRun.end < textStyleRun2.end) {
                                TextStyleSpan.TextStyleRun textStyleRun3 = new TextStyleSpan.TextStyleRun(textStyleRun);
                                textStyleRun3.merge(textStyleRun2);
                                int i4 = i3 + 1;
                                arrayList2.add(i4, textStyleRun3);
                                TextStyleSpan.TextStyleRun textStyleRun4 = new TextStyleSpan.TextStyleRun(textStyleRun2);
                                textStyleRun4.start = textStyleRun.end;
                                i3 = i4 + 1;
                                size2 = size2 + 1 + 1;
                                arrayList2.add(i3, textStyleRun4);
                            } else if (textStyleRun.end >= textStyleRun2.end) {
                                TextStyleSpan.TextStyleRun textStyleRun5 = new TextStyleSpan.TextStyleRun(textStyleRun);
                                textStyleRun5.merge(textStyleRun2);
                                textStyleRun5.end = textStyleRun2.end;
                                i3++;
                                size2++;
                                arrayList2.add(i3, textStyleRun5);
                            }
                            int i5 = textStyleRun.start;
                            textStyleRun.start = textStyleRun2.end;
                            textStyleRun2.end = i5;
                        }
                    } else if (textStyleRun2.start < textStyleRun.end) {
                        int i6 = textStyleRun2.start;
                        if (textStyleRun.end == textStyleRun2.end) {
                            textStyleRun2.merge(textStyleRun);
                        } else if (textStyleRun.end < textStyleRun2.end) {
                            TextStyleSpan.TextStyleRun textStyleRun6 = new TextStyleSpan.TextStyleRun(textStyleRun2);
                            textStyleRun6.merge(textStyleRun);
                            textStyleRun6.end = textStyleRun.end;
                            i3++;
                            size2++;
                            arrayList2.add(i3, textStyleRun6);
                            textStyleRun2.start = textStyleRun.end;
                        } else {
                            TextStyleSpan.TextStyleRun textStyleRun7 = new TextStyleSpan.TextStyleRun(textStyleRun);
                            textStyleRun7.start = textStyleRun2.end;
                            i3++;
                            size2++;
                            arrayList2.add(i3, textStyleRun7);
                            textStyleRun2.merge(textStyleRun);
                        }
                        textStyleRun.end = i6;
                    }
                    i3++;
                }
                if (textStyleRun.start < textStyleRun.end) {
                    arrayList2.add(textStyleRun);
                }
            }
        }
        int size3 = arrayList2.size();
        for (int i7 = 0; i7 < size3; i7++) {
            TextStyleSpan.TextStyleRun textStyleRun8 = (TextStyleSpan.TextStyleRun) arrayList2.get(i7);
            if (textStyleRun8.urlEntity instanceof TLRPC.TL_messageEntityMentionName) {
                TLRPC.User user = MessagesController.getInstance(UserConfig.selectedAccount).getUser(Integer.valueOf(((TLRPC.TL_messageEntityMentionName) textStyleRun8.urlEntity).user_id));
                if (user != null) {
                    if (TextUtils.isEmpty(spannableString)) {
                        spannableString = charSequence;
                    }
                    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(spannableString);
                    String str = "@" + UserObject.getName(user);
                    if (textStyleRun8.start < 0) {
                        textStyleRun8.start = 0;
                    }
                    spannableStringBuilder.replace(textStyleRun8.start, textStyleRun8.end, (CharSequence) str);
                    int i8 = textStyleRun8.end;
                    textStyleRun8.end = textStyleRun8.start + str.length();
                    int i9 = i8 - textStyleRun8.end;
                    for (int i10 = 0; i10 < this.entitiesCopy.size(); i10++) {
                        TLRPC.MessageEntity messageEntity2 = this.entitiesCopy.get(i10);
                        if (messageEntity2.offset >= textStyleRun8.start) {
                            if (messageEntity2.offset == textStyleRun8.start) {
                                messageEntity2.length = str.length();
                            } else {
                                messageEntity2.offset -= i9;
                            }
                        }
                    }
                    for (int i11 = i7; i11 < size3; i11++) {
                        TextStyleSpan.TextStyleRun textStyleRun9 = (TextStyleSpan.TextStyleRun) arrayList2.get(i11);
                        textStyleRun9.start -= i9;
                        textStyleRun9.end -= i9;
                    }
                    valueOf = SpannableString.valueOf(spannableStringBuilder);
                }
                spannableString = SpannableString.valueOf(valueOf);
            }
        }
        return (!TextUtils.isEmpty(spannableString) || TextUtils.isEmpty(charSequence)) ? spannableString : SpannableString.valueOf(charSequence);
    }

    static /* synthetic */ int lambda$updateMetionText$0(TLRPC.MessageEntity messageEntity, TLRPC.MessageEntity messageEntity2) {
        if (messageEntity.offset > messageEntity2.offset) {
            return 1;
        }
        return messageEntity.offset < messageEntity2.offset ? -1 : 0;
    }

    public SpannableStringBuilder updateMetionText2(CharSequence charSequence, ArrayList<TLRPC.MessageEntity> arrayList, BaseFragment baseFragment) {
        TLRPC.User user;
        if (arrayList == null || arrayList.isEmpty()) {
            return new SpannableStringBuilder(charSequence);
        }
        SpannableString valueOf = SpannableString.valueOf(charSequence);
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("");
        URLSpan[] uRLSpanArr = (URLSpan[]) valueOf.getSpans(0, charSequence.length(), URLSpan.class);
        ArrayList arrayList2 = new ArrayList();
        entityCopy(arrayList);
        Collections.sort(this.entitiesCopy, $$Lambda$MessageObject$k4KjGN1X99UgK9z_xZA7JvLQs5I.INSTANCE);
        int size = this.entitiesCopy.size();
        for (int i = 0; i < size; i++) {
            TLRPC.MessageEntity messageEntity = this.entitiesCopy.get(i);
            if (messageEntity.length > 0 && messageEntity.offset >= 0 && messageEntity.offset < charSequence.length()) {
                if (messageEntity.offset + messageEntity.length > charSequence.length()) {
                    messageEntity.length = charSequence.length() - messageEntity.offset;
                }
                boolean z = messageEntity instanceof TLRPC.TL_messageEntityBold;
                if ((z || (messageEntity instanceof TLRPC.TL_messageEntityItalic) || (messageEntity instanceof TLRPC.TL_messageEntityStrike) || (messageEntity instanceof TLRPC.TL_messageEntityUnderline) || (messageEntity instanceof TLRPC.TL_messageEntityBlockquote) || (messageEntity instanceof TLRPC.TL_messageEntityCode) || (messageEntity instanceof TLRPC.TL_messageEntityPre) || (messageEntity instanceof TLRPC.TL_messageEntityMentionName) || (messageEntity instanceof TLRPC.TL_inputMessageEntityMentionName) || (messageEntity instanceof TLRPC.TL_messageEntityTextUrl)) && uRLSpanArr != null && uRLSpanArr.length > 0) {
                    for (int i2 = 0; i2 < uRLSpanArr.length; i2++) {
                        if (uRLSpanArr[i2] != null) {
                            int spanStart = valueOf.getSpanStart(uRLSpanArr[i2]);
                            int spanEnd = valueOf.getSpanEnd(uRLSpanArr[i2]);
                            if ((messageEntity.offset <= spanStart && messageEntity.offset + messageEntity.length >= spanStart) || (messageEntity.offset <= spanEnd && messageEntity.offset + messageEntity.length >= spanEnd)) {
                                valueOf.removeSpan(uRLSpanArr[i2]);
                                uRLSpanArr[i2] = null;
                            }
                        }
                    }
                }
                TextStyleSpan.TextStyleRun textStyleRun = new TextStyleSpan.TextStyleRun();
                textStyleRun.start = messageEntity.offset;
                textStyleRun.end = textStyleRun.start + messageEntity.length;
                if (messageEntity instanceof TLRPC.TL_messageEntityStrike) {
                    textStyleRun.flags = 8;
                } else if (messageEntity instanceof TLRPC.TL_messageEntityUnderline) {
                    textStyleRun.flags = 16;
                } else if (messageEntity instanceof TLRPC.TL_messageEntityBlockquote) {
                    textStyleRun.flags = 32;
                } else if (z) {
                    textStyleRun.flags = 1;
                } else if (messageEntity instanceof TLRPC.TL_messageEntityItalic) {
                    textStyleRun.flags = 2;
                } else if ((messageEntity instanceof TLRPC.TL_messageEntityCode) || (messageEntity instanceof TLRPC.TL_messageEntityPre)) {
                    textStyleRun.flags = 4;
                } else if (messageEntity instanceof TLRPC.TL_messageEntityMentionName) {
                    textStyleRun.flags = 64;
                    textStyleRun.urlEntity = messageEntity;
                } else if (messageEntity instanceof TLRPC.TL_inputMessageEntityMentionName) {
                    textStyleRun.flags = 64;
                    textStyleRun.urlEntity = messageEntity;
                }
                int size2 = arrayList2.size();
                int i3 = 0;
                while (i3 < size2) {
                    TextStyleSpan.TextStyleRun textStyleRun2 = (TextStyleSpan.TextStyleRun) arrayList2.get(i3);
                    if (textStyleRun.start > textStyleRun2.start) {
                        if (textStyleRun.start < textStyleRun2.end) {
                            if (textStyleRun.end < textStyleRun2.end) {
                                TextStyleSpan.TextStyleRun textStyleRun3 = new TextStyleSpan.TextStyleRun(textStyleRun);
                                textStyleRun3.merge(textStyleRun2);
                                int i4 = i3 + 1;
                                arrayList2.add(i4, textStyleRun3);
                                TextStyleSpan.TextStyleRun textStyleRun4 = new TextStyleSpan.TextStyleRun(textStyleRun2);
                                textStyleRun4.start = textStyleRun.end;
                                i3 = i4 + 1;
                                size2 = size2 + 1 + 1;
                                arrayList2.add(i3, textStyleRun4);
                            } else if (textStyleRun.end >= textStyleRun2.end) {
                                TextStyleSpan.TextStyleRun textStyleRun5 = new TextStyleSpan.TextStyleRun(textStyleRun);
                                textStyleRun5.merge(textStyleRun2);
                                textStyleRun5.end = textStyleRun2.end;
                                i3++;
                                size2++;
                                arrayList2.add(i3, textStyleRun5);
                            }
                            int i5 = textStyleRun.start;
                            textStyleRun.start = textStyleRun2.end;
                            textStyleRun2.end = i5;
                        }
                    } else if (textStyleRun2.start < textStyleRun.end) {
                        int i6 = textStyleRun2.start;
                        if (textStyleRun.end == textStyleRun2.end) {
                            textStyleRun2.merge(textStyleRun);
                        } else if (textStyleRun.end < textStyleRun2.end) {
                            TextStyleSpan.TextStyleRun textStyleRun6 = new TextStyleSpan.TextStyleRun(textStyleRun2);
                            textStyleRun6.merge(textStyleRun);
                            textStyleRun6.end = textStyleRun.end;
                            i3++;
                            size2++;
                            arrayList2.add(i3, textStyleRun6);
                            textStyleRun2.start = textStyleRun.end;
                        } else {
                            TextStyleSpan.TextStyleRun textStyleRun7 = new TextStyleSpan.TextStyleRun(textStyleRun);
                            textStyleRun7.start = textStyleRun2.end;
                            i3++;
                            size2++;
                            arrayList2.add(i3, textStyleRun7);
                            textStyleRun2.merge(textStyleRun);
                        }
                        textStyleRun.end = i6;
                    }
                    i3++;
                }
                if (textStyleRun.start < textStyleRun.end) {
                    arrayList2.add(textStyleRun);
                }
            }
        }
        int size3 = arrayList2.size();
        int i7 = 0;
        SpannableStringBuilder spannableStringBuilder2 = spannableStringBuilder;
        while (i7 < size3) {
            TextStyleSpan.TextStyleRun textStyleRun8 = (TextStyleSpan.TextStyleRun) arrayList2.get(i7);
            if ((textStyleRun8.urlEntity instanceof TLRPC.TL_messageEntityMentionName) && (user = MessagesController.getInstance(UserConfig.selectedAccount).getUser(Integer.valueOf(((TLRPC.TL_messageEntityMentionName) textStyleRun8.urlEntity).user_id))) != null) {
                boolean isEmpty = TextUtils.isEmpty(spannableStringBuilder2);
                SpannableStringBuilder spannableStringBuilder3 = spannableStringBuilder2;
                if (isEmpty) {
                    spannableStringBuilder3 = charSequence;
                }
                SpannableStringBuilder spannableStringBuilder4 = new SpannableStringBuilder(spannableStringBuilder3);
                String str = "@" + UserObject.getName(user) + " ";
                spannableStringBuilder4.replace(textStyleRun8.start, textStyleRun8.end, (CharSequence) str);
                int i8 = textStyleRun8.end;
                textStyleRun8.end = textStyleRun8.start + str.length();
                spannableStringBuilder4.setSpan(new ForegroundColorSpan(-13915656), textStyleRun8.start, textStyleRun8.end, 33);
                spannableStringBuilder4.setSpan(new SysNotifyAtTextClickableSpan(user.id, baseFragment), textStyleRun8.start, textStyleRun8.end, 33);
                int i9 = i8 - textStyleRun8.end;
                for (int i10 = 0; i10 < this.entitiesCopy.size(); i10++) {
                    TLRPC.MessageEntity messageEntity2 = this.entitiesCopy.get(i10);
                    if (messageEntity2.offset >= textStyleRun8.start) {
                        if (messageEntity2.offset == textStyleRun8.start) {
                            messageEntity2.length = str.length();
                        } else {
                            messageEntity2.offset -= i9;
                        }
                    }
                }
                for (int i11 = i7; i11 < size3; i11++) {
                    TextStyleSpan.TextStyleRun textStyleRun9 = (TextStyleSpan.TextStyleRun) arrayList2.get(i11);
                    textStyleRun9.start -= i9;
                    textStyleRun9.end -= i9;
                }
                spannableStringBuilder2 = spannableStringBuilder4;
            }
            i7++;
            spannableStringBuilder2 = spannableStringBuilder2;
        }
        if (!TextUtils.isEmpty(spannableStringBuilder2) || TextUtils.isEmpty(charSequence)) {
            return spannableStringBuilder2;
        }
        return SpannableStringBuilder.valueOf(charSequence);
    }

    static /* synthetic */ int lambda$updateMetionText2$1(TLRPC.MessageEntity messageEntity, TLRPC.MessageEntity messageEntity2) {
        if (messageEntity.offset > messageEntity2.offset) {
            return 1;
        }
        return messageEntity.offset < messageEntity2.offset ? -1 : 0;
    }

    private void createDateArray(int i, TLRPC.TL_channelAdminLogEvent tL_channelAdminLogEvent, ArrayList<MessageObject> arrayList, HashMap<String, ArrayList<MessageObject>> hashMap) {
        if (hashMap.get(this.dateKey) == null) {
            hashMap.put(this.dateKey, new ArrayList<>());
            TLRPC.TL_message tL_message = new TLRPC.TL_message();
            tL_message.message = LocaleController.formatDateChat((long) tL_channelAdminLogEvent.date);
            tL_message.id = 0;
            tL_message.date = tL_channelAdminLogEvent.date;
            MessageObject messageObject = new MessageObject(i, tL_message, false);
            messageObject.type = 10;
            messageObject.contentType = 1;
            messageObject.isDateObject = true;
            arrayList.add(messageObject);
        }
    }

    private void checkEmojiOnly(int[] iArr) {
        TextPaint textPaint;
        int i;
        if (iArr != null) {
            if (iArr[0] >= 1 && iArr[0] <= 3) {
                int i2 = iArr[0];
                if (i2 == 1) {
                    textPaint = Theme.chat_msgTextPaintOneEmoji;
                    i = AndroidUtilities.dp(32.0f);
                    this.emojiOnlyCount = 1;
                } else if (i2 != 2) {
                    textPaint = Theme.chat_msgTextPaintThreeEmoji;
                    i = AndroidUtilities.dp(24.0f);
                    this.emojiOnlyCount = 3;
                } else {
                    textPaint = Theme.chat_msgTextPaintTwoEmoji;
                    int dp = AndroidUtilities.dp(28.0f);
                    this.emojiOnlyCount = 2;
                    i = dp;
                }
                CharSequence charSequence = this.messageText;
                Emoji.EmojiSpan[] emojiSpanArr = (Emoji.EmojiSpan[]) ((Spannable) charSequence).getSpans(0, charSequence.length(), Emoji.EmojiSpan.class);
                if (emojiSpanArr != null && emojiSpanArr.length > 0) {
                    for (Emoji.EmojiSpan emojiSpan : emojiSpanArr) {
                        emojiSpan.replaceFontMetrics(textPaint.getFontMetricsInt(), i);
                    }
                }
            }
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:109:0x03f5  */
    /* JADX WARNING: Removed duplicated region for block: B:110:0x03f8  */
    /* JADX WARNING: Removed duplicated region for block: B:114:0x0412  */
    /* JADX WARNING: Removed duplicated region for block: B:125:0x0441  */
    /* JADX WARNING: Removed duplicated region for block: B:126:0x0444  */
    /* JADX WARNING: Removed duplicated region for block: B:244:0x069b  */
    /* JADX WARNING: Removed duplicated region for block: B:249:0x06af  */
    /* JADX WARNING: Removed duplicated region for block: B:252:0x06b5 A[LOOP:0: B:230:0x066e->B:252:0x06b5, LOOP_END] */
    /* JADX WARNING: Removed duplicated region for block: B:518:0x0edc  */
    /* JADX WARNING: Removed duplicated region for block: B:521:0x0f27  */
    /* JADX WARNING: Removed duplicated region for block: B:528:0x0f46  */
    /* JADX WARNING: Removed duplicated region for block: B:538:0x0fa8  */
    /* JADX WARNING: Removed duplicated region for block: B:541:0x0fae  */
    /* JADX WARNING: Removed duplicated region for block: B:557:0x06cf A[EDGE_INSN: B:557:0x06cf->B:254:0x06cf ?: BREAK  , SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:559:? A[RETURN, SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:64:0x0328  */
    /* JADX WARNING: Removed duplicated region for block: B:75:0x0354  */
    /* JADX WARNING: Removed duplicated region for block: B:91:0x03a2  */
    /* JADX WARNING: Removed duplicated region for block: B:98:0x03c6  */
    public MessageObject(int i, TLRPC.TL_channelAdminLogEvent tL_channelAdminLogEvent, ArrayList<MessageObject> arrayList, HashMap<String, ArrayList<MessageObject>> hashMap, TLRPC.Chat chat, int[] iArr) {
        TLRPC.Message message;
        ArrayList<MessageObject> arrayList2;
        TextPaint textPaint;
        String str;
        String str2;
        int i2;
        String str3;
        int i3;
        String str4;
        int i4;
        String str5;
        StringBuilder sb;
        boolean z;
        char c;
        String str6;
        int i5;
        boolean z2;
        StringBuilder sb2;
        String str7;
        int i6;
        this.type = 1000;
        this.forceSeekTo = -1.0f;
        this.entitiesCopy = new ArrayList<>();
        this.currentEvent = tL_channelAdminLogEvent;
        this.currentAccount = i;
        TLRPC.User user = tL_channelAdminLogEvent.user_id > 0 ? MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(tL_channelAdminLogEvent.user_id)) : null;
        GregorianCalendar gregorianCalendar = new GregorianCalendar();
        gregorianCalendar.setTimeInMillis(((long) tL_channelAdminLogEvent.date) * 1000);
        int i7 = gregorianCalendar.get(6);
        int i8 = gregorianCalendar.get(1);
        int i9 = gregorianCalendar.get(2);
        this.dateKey = String.format("%d_%02d_%02d", Integer.valueOf(i8), Integer.valueOf(i9), Integer.valueOf(i7));
        this.monthKey = String.format("%d_%02d", Integer.valueOf(i8), Integer.valueOf(i9));
        TLRPC.TL_peerChannel tL_peerChannel = new TLRPC.TL_peerChannel();
        tL_peerChannel.channel_id = chat.id;
        if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionChangeTitle) {
            String str8 = ((TLRPC.TL_channelAdminLogEventActionChangeTitle) tL_channelAdminLogEvent.action).new_value;
            if (chat.megagroup) {
                this.messageText = replaceWithLink(LocaleController.formatString("EventLogEditedGroupTitle", R.string.EventLogEditedGroupTitle, str8), "un1", user);
            } else {
                this.messageText = replaceWithLink(LocaleController.formatString("EventLogEditedChannelTitle", R.string.EventLogEditedChannelTitle, str8), "un1", user);
            }
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionChangePhoto) {
            this.messageOwner = new TLRPC.TL_messageService();
            if (tL_channelAdminLogEvent.action.new_photo instanceof TLRPC.TL_photoEmpty) {
                this.messageOwner.action = new TLRPC.TL_messageActionChatDeletePhoto();
                if (chat.megagroup) {
                    this.messageText = replaceWithLink(LocaleController.getString("EventLogRemovedWGroupPhoto", R.string.EventLogRemovedWGroupPhoto), "un1", user);
                } else {
                    this.messageText = replaceWithLink(LocaleController.getString("EventLogRemovedChannelPhoto", R.string.EventLogRemovedChannelPhoto), "un1", user);
                }
            } else {
                this.messageOwner.action = new TLRPC.TL_messageActionChatEditPhoto();
                this.messageOwner.action.photo = tL_channelAdminLogEvent.action.new_photo;
                if (chat.megagroup) {
                    this.messageText = replaceWithLink(LocaleController.getString("EventLogEditedGroupPhoto", R.string.EventLogEditedGroupPhoto), "un1", user);
                } else {
                    this.messageText = replaceWithLink(LocaleController.getString("EventLogEditedChannelPhoto", R.string.EventLogEditedChannelPhoto), "un1", user);
                }
            }
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionParticipantJoin) {
            if (chat.megagroup) {
                this.messageText = replaceWithLink(LocaleController.getString("EventLogGroupJoined", R.string.EventLogGroupJoined), "un1", user);
            } else {
                this.messageText = replaceWithLink(LocaleController.getString("EventLogChannelJoined", R.string.EventLogChannelJoined), "un1", user);
            }
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionParticipantLeave) {
            TLRPC.TL_messageService tL_messageService = new TLRPC.TL_messageService();
            this.messageOwner = tL_messageService;
            tL_messageService.action = new TLRPC.TL_messageActionChatDeleteUser();
            this.messageOwner.action.user_id = tL_channelAdminLogEvent.user_id;
            if (chat.megagroup) {
                this.messageText = replaceWithLink(LocaleController.getString("EventLogLeftGroup", R.string.EventLogLeftGroup), "un1", user);
            } else {
                this.messageText = replaceWithLink(LocaleController.getString("EventLogLeftChannel", R.string.EventLogLeftChannel), "un1", user);
            }
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionParticipantInvite) {
            TLRPC.TL_messageService tL_messageService2 = new TLRPC.TL_messageService();
            this.messageOwner = tL_messageService2;
            tL_messageService2.action = new TLRPC.TL_messageActionChatAddUser();
            TLObject user2 = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(tL_channelAdminLogEvent.action.participant.user_id));
            if (tL_channelAdminLogEvent.action.participant.user_id != this.messageOwner.from_id) {
                CharSequence replaceWithLink = replaceWithLink(LocaleController.getString("EventLogAdded", R.string.EventLogAdded), "un2", user2);
                this.messageText = replaceWithLink;
                this.messageText = replaceWithLink(replaceWithLink, "un1", user);
            } else if (chat.megagroup) {
                this.messageText = replaceWithLink(LocaleController.getString("EventLogGroupJoined", R.string.EventLogGroupJoined), "un1", user);
            } else {
                this.messageText = replaceWithLink(LocaleController.getString("EventLogChannelJoined", R.string.EventLogChannelJoined), "un1", user);
            }
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionParticipantToggleAdmin) {
            this.messageOwner = new TLRPC.TL_message();
            TLRPC.User user3 = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(tL_channelAdminLogEvent.action.prev_participant.user_id));
            if ((tL_channelAdminLogEvent.action.prev_participant instanceof TLRPC.TL_channelParticipantCreator) || !(tL_channelAdminLogEvent.action.new_participant instanceof TLRPC.TL_channelParticipantCreator)) {
                String string = LocaleController.getString("EventLogPromoted", R.string.EventLogPromoted);
                StringBuilder sb3 = new StringBuilder(String.format(string, getUserName(user3, this.messageOwner.entities, string.indexOf("%1$s"))));
                sb3.append("\n");
                TLRPC.TL_chatAdminRights tL_chatAdminRights = tL_channelAdminLogEvent.action.prev_participant.admin_rights;
                TLRPC.TL_chatAdminRights tL_chatAdminRights2 = tL_channelAdminLogEvent.action.new_participant.admin_rights;
                tL_chatAdminRights = tL_chatAdminRights == null ? new TLRPC.TL_chatAdminRights() : tL_chatAdminRights;
                tL_chatAdminRights2 = tL_chatAdminRights2 == null ? new TLRPC.TL_chatAdminRights() : tL_chatAdminRights2;
                if (!TextUtils.equals(tL_channelAdminLogEvent.action.prev_participant.rank, tL_channelAdminLogEvent.action.new_participant.rank)) {
                    if (TextUtils.isEmpty(tL_channelAdminLogEvent.action.new_participant.rank)) {
                        sb3.append('\n');
                        sb3.append('-');
                        sb3.append(' ');
                        sb3.append(LocaleController.getString("EventLogPromotedRemovedTitle", R.string.EventLogPromotedRemovedTitle));
                    } else {
                        sb3.append('\n');
                        sb3.append('+');
                        sb3.append(' ');
                        sb3.append(LocaleController.formatString("EventLogPromotedTitle", R.string.EventLogPromotedTitle, tL_channelAdminLogEvent.action.new_participant.rank));
                        if (tL_chatAdminRights.change_info != tL_chatAdminRights2.change_info) {
                            sb3.append('\n');
                            sb3.append(tL_chatAdminRights2.change_info ? '+' : '-');
                            sb3.append(' ');
                            if (chat.megagroup) {
                                i6 = R.string.EventLogPromotedChangeGroupInfo;
                                str7 = "EventLogPromotedChangeGroupInfo";
                            } else {
                                i6 = R.string.EventLogPromotedChangeChannelInfo;
                                str7 = "EventLogPromotedChangeChannelInfo";
                            }
                            sb3.append(LocaleController.getString(str7, i6));
                        }
                        if (!chat.megagroup) {
                            if (tL_chatAdminRights.post_messages != tL_chatAdminRights2.post_messages) {
                                sb3.append('\n');
                                sb3.append(tL_chatAdminRights2.post_messages ? '+' : '-');
                                sb3.append(' ');
                                sb3.append(LocaleController.getString("EventLogPromotedPostMessages", R.string.EventLogPromotedPostMessages));
                            }
                            if (tL_chatAdminRights.edit_messages != tL_chatAdminRights2.edit_messages) {
                                sb3.append('\n');
                                sb3.append(tL_chatAdminRights2.edit_messages ? '+' : '-');
                                sb3.append(' ');
                                sb3.append(LocaleController.getString("EventLogPromotedEditMessages", R.string.EventLogPromotedEditMessages));
                            }
                        }
                        if (tL_chatAdminRights.delete_messages != tL_chatAdminRights2.delete_messages) {
                            sb3.append('\n');
                            sb3.append(tL_chatAdminRights2.delete_messages ? '+' : '-');
                            sb3.append(' ');
                            sb3.append(LocaleController.getString("EventLogPromotedDeleteMessages", R.string.EventLogPromotedDeleteMessages));
                        }
                        if (tL_chatAdminRights.add_admins != tL_chatAdminRights2.add_admins) {
                            sb3.append('\n');
                            sb3.append(tL_chatAdminRights2.add_admins ? '+' : '-');
                            sb3.append(' ');
                            sb3.append(LocaleController.getString("EventLogPromotedAddAdmins", R.string.EventLogPromotedAddAdmins));
                        }
                        if (chat.megagroup && tL_chatAdminRights.ban_users != tL_chatAdminRights2.ban_users) {
                            sb3.append('\n');
                            sb3.append(!tL_chatAdminRights2.ban_users ? '+' : '-');
                            sb3.append(' ');
                            sb3.append(LocaleController.getString("EventLogPromotedBanUsers", R.string.EventLogPromotedBanUsers));
                        }
                        if (tL_chatAdminRights.invite_users != tL_chatAdminRights2.invite_users) {
                            sb3.append('\n');
                            sb3.append(tL_chatAdminRights2.invite_users ? '+' : '-');
                            sb3.append(' ');
                            sb3.append(LocaleController.getString("EventLogPromotedAddUsers", R.string.EventLogPromotedAddUsers));
                        }
                        if (chat.megagroup && tL_chatAdminRights.pin_messages != tL_chatAdminRights2.pin_messages) {
                            sb3.append('\n');
                            sb3.append(!tL_chatAdminRights2.pin_messages ? '+' : '-');
                            sb3.append(' ');
                            sb3.append(LocaleController.getString("EventLogPromotedPinMessages", R.string.EventLogPromotedPinMessages));
                        }
                        sb2 = sb3;
                    }
                }
                if (tL_chatAdminRights.change_info != tL_chatAdminRights2.change_info) {
                }
                if (!chat.megagroup) {
                }
                if (tL_chatAdminRights.delete_messages != tL_chatAdminRights2.delete_messages) {
                }
                if (tL_chatAdminRights.add_admins != tL_chatAdminRights2.add_admins) {
                }
                sb3.append('\n');
                sb3.append(!tL_chatAdminRights2.ban_users ? '+' : '-');
                sb3.append(' ');
                sb3.append(LocaleController.getString("EventLogPromotedBanUsers", R.string.EventLogPromotedBanUsers));
                if (tL_chatAdminRights.invite_users != tL_chatAdminRights2.invite_users) {
                }
                sb3.append('\n');
                sb3.append(!tL_chatAdminRights2.pin_messages ? '+' : '-');
                sb3.append(' ');
                sb3.append(LocaleController.getString("EventLogPromotedPinMessages", R.string.EventLogPromotedPinMessages));
                sb2 = sb3;
            } else {
                String string2 = LocaleController.getString("EventLogChangedOwnership", R.string.EventLogChangedOwnership);
                sb2 = new StringBuilder(String.format(string2, getUserName(user3, this.messageOwner.entities, string2.indexOf("%1$s"))));
            }
            this.messageText = sb2.toString();
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionDefaultBannedRights) {
            TLRPC.TL_channelAdminLogEventActionDefaultBannedRights tL_channelAdminLogEventActionDefaultBannedRights = (TLRPC.TL_channelAdminLogEventActionDefaultBannedRights) tL_channelAdminLogEvent.action;
            this.messageOwner = new TLRPC.TL_message();
            TLRPC.TL_chatBannedRights tL_chatBannedRights = tL_channelAdminLogEventActionDefaultBannedRights.prev_banned_rights;
            TLRPC.TL_chatBannedRights tL_chatBannedRights2 = tL_channelAdminLogEventActionDefaultBannedRights.new_banned_rights;
            StringBuilder sb4 = new StringBuilder(LocaleController.getString("EventLogDefaultPermissions", R.string.EventLogDefaultPermissions));
            tL_chatBannedRights = tL_chatBannedRights == null ? new TLRPC.TL_chatBannedRights() : tL_chatBannedRights;
            tL_chatBannedRights2 = tL_chatBannedRights2 == null ? new TLRPC.TL_chatBannedRights() : tL_chatBannedRights2;
            if (tL_chatBannedRights.send_messages != tL_chatBannedRights2.send_messages) {
                sb4.append('\n');
                sb4.append('\n');
                sb4.append(!tL_chatBannedRights2.send_messages ? '+' : '-');
                sb4.append(' ');
                sb4.append(LocaleController.getString("EventLogRestrictedSendMessages", R.string.EventLogRestrictedSendMessages));
                z2 = true;
            } else {
                z2 = false;
            }
            if (!(tL_chatBannedRights.send_stickers == tL_chatBannedRights2.send_stickers && tL_chatBannedRights.send_inline == tL_chatBannedRights2.send_inline && tL_chatBannedRights.send_gifs == tL_chatBannedRights2.send_gifs && tL_chatBannedRights.send_games == tL_chatBannedRights2.send_games)) {
                if (!z2) {
                    sb4.append('\n');
                    z2 = true;
                }
                sb4.append('\n');
                sb4.append(!tL_chatBannedRights2.send_stickers ? '+' : '-');
                sb4.append(' ');
                sb4.append(LocaleController.getString("EventLogRestrictedSendStickers", R.string.EventLogRestrictedSendStickers));
            }
            if (tL_chatBannedRights.send_media != tL_chatBannedRights2.send_media) {
                if (!z2) {
                    sb4.append('\n');
                    z2 = true;
                }
                sb4.append('\n');
                sb4.append(!tL_chatBannedRights2.send_media ? '+' : '-');
                sb4.append(' ');
                sb4.append(LocaleController.getString("EventLogRestrictedSendMedia", R.string.EventLogRestrictedSendMedia));
            }
            if (tL_chatBannedRights.send_polls != tL_chatBannedRights2.send_polls) {
                if (!z2) {
                    sb4.append('\n');
                    z2 = true;
                }
                sb4.append('\n');
                sb4.append(!tL_chatBannedRights2.send_polls ? '+' : '-');
                sb4.append(' ');
                sb4.append(LocaleController.getString("EventLogRestrictedSendPolls", R.string.EventLogRestrictedSendPolls));
            }
            if (tL_chatBannedRights.embed_links != tL_chatBannedRights2.embed_links) {
                if (!z2) {
                    sb4.append('\n');
                    z2 = true;
                }
                sb4.append('\n');
                sb4.append(!tL_chatBannedRights2.embed_links ? '+' : '-');
                sb4.append(' ');
                sb4.append(LocaleController.getString("EventLogRestrictedSendEmbed", R.string.EventLogRestrictedSendEmbed));
            }
            if (tL_chatBannedRights.change_info != tL_chatBannedRights2.change_info) {
                if (!z2) {
                    sb4.append('\n');
                    z2 = true;
                }
                sb4.append('\n');
                sb4.append(!tL_chatBannedRights2.change_info ? '+' : '-');
                sb4.append(' ');
                sb4.append(LocaleController.getString("EventLogRestrictedChangeInfo", R.string.EventLogRestrictedChangeInfo));
            }
            if (tL_chatBannedRights.invite_users != tL_chatBannedRights2.invite_users) {
                if (!z2) {
                    sb4.append('\n');
                    z2 = true;
                }
                sb4.append('\n');
                sb4.append(!tL_chatBannedRights2.invite_users ? '+' : '-');
                sb4.append(' ');
                sb4.append(LocaleController.getString("EventLogRestrictedInviteUsers", R.string.EventLogRestrictedInviteUsers));
            }
            if (tL_chatBannedRights.pin_messages != tL_chatBannedRights2.pin_messages) {
                if (!z2) {
                    sb4.append('\n');
                }
                sb4.append('\n');
                sb4.append(!tL_chatBannedRights2.pin_messages ? '+' : '-');
                sb4.append(' ');
                sb4.append(LocaleController.getString("EventLogRestrictedPinMessages", R.string.EventLogRestrictedPinMessages));
            }
            this.messageText = sb4.toString();
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionParticipantToggleBan) {
            this.messageOwner = new TLRPC.TL_message();
            TLRPC.User user4 = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(tL_channelAdminLogEvent.action.prev_participant.user_id));
            TLRPC.TL_chatBannedRights tL_chatBannedRights3 = tL_channelAdminLogEvent.action.prev_participant.banned_rights;
            TLRPC.TL_chatBannedRights tL_chatBannedRights4 = tL_channelAdminLogEvent.action.new_participant.banned_rights;
            if (!chat.megagroup || (tL_chatBannedRights4 != null && tL_chatBannedRights4.view_messages && (tL_chatBannedRights4 == null || tL_chatBannedRights3 == null || tL_chatBannedRights4.until_date == tL_chatBannedRights3.until_date))) {
                if (tL_chatBannedRights4 == null || (tL_chatBannedRights3 != null && !tL_chatBannedRights4.view_messages)) {
                    str5 = LocaleController.getString("EventLogChannelUnrestricted", R.string.EventLogChannelUnrestricted);
                } else {
                    str5 = LocaleController.getString("EventLogChannelRestricted", R.string.EventLogChannelRestricted);
                }
                this.messageText = String.format(str5, getUserName(user4, this.messageOwner.entities, str5.indexOf("%1$s")));
            } else {
                if (tL_chatBannedRights4 == null || AndroidUtilities.isBannedForever(tL_chatBannedRights4)) {
                    sb = new StringBuilder(LocaleController.getString("UserRestrictionsUntilForever", R.string.UserRestrictionsUntilForever));
                } else {
                    sb = new StringBuilder();
                    int i10 = tL_chatBannedRights4.until_date - tL_channelAdminLogEvent.date;
                    int i11 = ((i10 / 60) / 60) / 24;
                    int i12 = i10 - (((i11 * 60) * 60) * 24);
                    int i13 = (i12 / 60) / 60;
                    int i14 = (i12 - ((i13 * 60) * 60)) / 60;
                    int i15 = 3;
                    int i16 = 0;
                    int i17 = 0;
                    while (i16 < i15) {
                        if (i16 == 0) {
                            if (i11 != 0) {
                                str6 = LocaleController.formatPluralString("Days", i11);
                            }
                            str6 = null;
                            if (str6 == null) {
                                if (sb.length() > 0) {
                                    i5 = i13;
                                    sb.append(", ");
                                } else {
                                    i5 = i13;
                                }
                                sb.append(str6);
                            } else {
                                i5 = i13;
                            }
                            if (i17 != 2) {
                                break;
                            }
                            i16++;
                            i13 = i5;
                            i15 = 3;
                            i17 = i17;
                            i11 = i11;
                        } else if (i16 == 1) {
                            if (i13 != 0) {
                                str6 = LocaleController.formatPluralString("Hours", i13);
                            }
                            str6 = null;
                            if (str6 == null) {
                            }
                            if (i17 != 2) {
                            }
                        } else {
                            if (i14 != 0) {
                                str6 = LocaleController.formatPluralString("Minutes", i14);
                            }
                            str6 = null;
                            if (str6 == null) {
                            }
                            if (i17 != 2) {
                            }
                        }
                        i17++;
                        if (str6 == null) {
                        }
                        if (i17 != 2) {
                        }
                    }
                }
                String string3 = LocaleController.getString("EventLogRestrictedUntil", R.string.EventLogRestrictedUntil);
                StringBuilder sb5 = new StringBuilder(String.format(string3, getUserName(user4, this.messageOwner.entities, string3.indexOf("%1$s")), sb.toString()));
                tL_chatBannedRights3 = tL_chatBannedRights3 == null ? new TLRPC.TL_chatBannedRights() : tL_chatBannedRights3;
                tL_chatBannedRights4 = tL_chatBannedRights4 == null ? new TLRPC.TL_chatBannedRights() : tL_chatBannedRights4;
                if (tL_chatBannedRights3.view_messages != tL_chatBannedRights4.view_messages) {
                    sb5.append('\n');
                    sb5.append('\n');
                    sb5.append(!tL_chatBannedRights4.view_messages ? '+' : '-');
                    sb5.append(' ');
                    sb5.append(LocaleController.getString("EventLogRestrictedReadMessages", R.string.EventLogRestrictedReadMessages));
                    z = true;
                } else {
                    z = false;
                }
                if (tL_chatBannedRights3.send_messages != tL_chatBannedRights4.send_messages) {
                    if (!z) {
                        sb5.append('\n');
                        z = true;
                    }
                    sb5.append('\n');
                    sb5.append(!tL_chatBannedRights4.send_messages ? '+' : '-');
                    sb5.append(' ');
                    sb5.append(LocaleController.getString("EventLogRestrictedSendMessages", R.string.EventLogRestrictedSendMessages));
                }
                if (!(tL_chatBannedRights3.send_stickers == tL_chatBannedRights4.send_stickers && tL_chatBannedRights3.send_inline == tL_chatBannedRights4.send_inline && tL_chatBannedRights3.send_gifs == tL_chatBannedRights4.send_gifs && tL_chatBannedRights3.send_games == tL_chatBannedRights4.send_games)) {
                    if (!z) {
                        sb5.append('\n');
                        z = true;
                    }
                    sb5.append('\n');
                    sb5.append(!tL_chatBannedRights4.send_stickers ? '+' : '-');
                    sb5.append(' ');
                    sb5.append(LocaleController.getString("EventLogRestrictedSendStickers", R.string.EventLogRestrictedSendStickers));
                }
                if (tL_chatBannedRights3.send_media != tL_chatBannedRights4.send_media) {
                    if (!z) {
                        sb5.append('\n');
                        z = true;
                    }
                    sb5.append('\n');
                    sb5.append(!tL_chatBannedRights4.send_media ? '+' : '-');
                    sb5.append(' ');
                    sb5.append(LocaleController.getString("EventLogRestrictedSendMedia", R.string.EventLogRestrictedSendMedia));
                }
                if (tL_chatBannedRights3.send_polls != tL_chatBannedRights4.send_polls) {
                    if (!z) {
                        sb5.append('\n');
                        z = true;
                    }
                    sb5.append('\n');
                    sb5.append(!tL_chatBannedRights4.send_polls ? '+' : '-');
                    sb5.append(' ');
                    sb5.append(LocaleController.getString("EventLogRestrictedSendPolls", R.string.EventLogRestrictedSendPolls));
                }
                if (tL_chatBannedRights3.embed_links != tL_chatBannedRights4.embed_links) {
                    if (!z) {
                        sb5.append('\n');
                        z = true;
                    }
                    sb5.append('\n');
                    sb5.append(!tL_chatBannedRights4.embed_links ? '+' : '-');
                    sb5.append(' ');
                    sb5.append(LocaleController.getString("EventLogRestrictedSendEmbed", R.string.EventLogRestrictedSendEmbed));
                }
                if (tL_chatBannedRights3.change_info != tL_chatBannedRights4.change_info) {
                    if (!z) {
                        sb5.append('\n');
                        z = true;
                    }
                    sb5.append('\n');
                    sb5.append(!tL_chatBannedRights4.change_info ? '+' : '-');
                    sb5.append(' ');
                    sb5.append(LocaleController.getString("EventLogRestrictedChangeInfo", R.string.EventLogRestrictedChangeInfo));
                }
                if (tL_chatBannedRights3.invite_users != tL_chatBannedRights4.invite_users) {
                    if (!z) {
                        sb5.append('\n');
                        z = true;
                    }
                    sb5.append('\n');
                    sb5.append(!tL_chatBannedRights4.invite_users ? '+' : '-');
                    sb5.append(' ');
                    sb5.append(LocaleController.getString("EventLogRestrictedInviteUsers", R.string.EventLogRestrictedInviteUsers));
                }
                if (tL_chatBannedRights3.pin_messages != tL_chatBannedRights4.pin_messages) {
                    if (!z) {
                        c = '\n';
                        sb5.append('\n');
                    } else {
                        c = '\n';
                    }
                    sb5.append(c);
                    sb5.append(!tL_chatBannedRights4.pin_messages ? '+' : '-');
                    sb5.append(' ');
                    sb5.append(LocaleController.getString("EventLogRestrictedPinMessages", R.string.EventLogRestrictedPinMessages));
                }
                this.messageText = sb5.toString();
            }
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionUpdatePinned) {
            if (user != null && user.id == 136817688 && tL_channelAdminLogEvent.action.message.fwd_from != null) {
                TLObject chat2 = MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(tL_channelAdminLogEvent.action.message.fwd_from.channel_id));
                if (tL_channelAdminLogEvent.action.message instanceof TLRPC.TL_messageEmpty) {
                    this.messageText = replaceWithLink(LocaleController.getString("EventLogUnpinnedMessages", R.string.EventLogUnpinnedMessages), "un1", chat2);
                } else {
                    this.messageText = replaceWithLink(LocaleController.getString("EventLogPinnedMessages", R.string.EventLogPinnedMessages), "un1", chat2);
                }
            } else if (tL_channelAdminLogEvent.action.message instanceof TLRPC.TL_messageEmpty) {
                this.messageText = replaceWithLink(LocaleController.getString("EventLogUnpinnedMessages", R.string.EventLogUnpinnedMessages), "un1", user);
            } else {
                this.messageText = replaceWithLink(LocaleController.getString("EventLogPinnedMessages", R.string.EventLogPinnedMessages), "un1", user);
            }
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionStopPoll) {
            this.messageText = replaceWithLink(LocaleController.getString("EventLogStopPoll", R.string.EventLogStopPoll), "un1", user);
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionToggleSignatures) {
            if (((TLRPC.TL_channelAdminLogEventActionToggleSignatures) tL_channelAdminLogEvent.action).new_value) {
                this.messageText = replaceWithLink(LocaleController.getString("EventLogToggledSignaturesOn", R.string.EventLogToggledSignaturesOn), "un1", user);
            } else {
                this.messageText = replaceWithLink(LocaleController.getString("EventLogToggledSignaturesOff", R.string.EventLogToggledSignaturesOff), "un1", user);
            }
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionToggleInvites) {
            if (((TLRPC.TL_channelAdminLogEventActionToggleInvites) tL_channelAdminLogEvent.action).new_value) {
                this.messageText = replaceWithLink(LocaleController.getString("EventLogToggledInvitesOn", R.string.EventLogToggledInvitesOn), "un1", user);
            } else {
                this.messageText = replaceWithLink(LocaleController.getString("EventLogToggledInvitesOff", R.string.EventLogToggledInvitesOff), "un1", user);
            }
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionDeleteMessage) {
            this.messageText = replaceWithLink(LocaleController.getString("EventLogDeletedMessages", R.string.EventLogDeletedMessages), "un1", user);
        } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionChangeLinkedChat) {
            int i18 = ((TLRPC.TL_channelAdminLogEventActionChangeLinkedChat) tL_channelAdminLogEvent.action).new_value;
            int i19 = ((TLRPC.TL_channelAdminLogEventActionChangeLinkedChat) tL_channelAdminLogEvent.action).prev_value;
            if (chat.megagroup) {
                if (i18 == 0) {
                    TLObject chat3 = MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(i19));
                    CharSequence replaceWithLink2 = replaceWithLink(LocaleController.getString("EventLogRemovedLinkedChannel", R.string.EventLogRemovedLinkedChannel), "un1", user);
                    this.messageText = replaceWithLink2;
                    this.messageText = replaceWithLink(replaceWithLink2, "un2", chat3);
                } else {
                    TLObject chat4 = MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(i18));
                    CharSequence replaceWithLink3 = replaceWithLink(LocaleController.getString("EventLogChangedLinkedChannel", R.string.EventLogChangedLinkedChannel), "un1", user);
                    this.messageText = replaceWithLink3;
                    this.messageText = replaceWithLink(replaceWithLink3, "un2", chat4);
                }
            } else if (i18 == 0) {
                TLObject chat5 = MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(i19));
                CharSequence replaceWithLink4 = replaceWithLink(LocaleController.getString("EventLogRemovedLinkedGroup", R.string.EventLogRemovedLinkedGroup), "un1", user);
                this.messageText = replaceWithLink4;
                this.messageText = replaceWithLink(replaceWithLink4, "un2", chat5);
            } else {
                TLObject chat6 = MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(i18));
                CharSequence replaceWithLink5 = replaceWithLink(LocaleController.getString("EventLogChangedLinkedGroup", R.string.EventLogChangedLinkedGroup), "un1", user);
                this.messageText = replaceWithLink5;
                this.messageText = replaceWithLink(replaceWithLink5, "un2", chat6);
            }
        } else if (!(tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionTogglePreHistoryHidden)) {
            if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionChangeAbout) {
                if (chat.megagroup) {
                    i4 = R.string.EventLogEditedGroupDescription;
                    str4 = "EventLogEditedGroupDescription";
                } else {
                    i4 = R.string.EventLogEditedChannelDescription;
                    str4 = "EventLogEditedChannelDescription";
                }
                this.messageText = replaceWithLink(LocaleController.getString(str4, i4), "un1", user);
                message = new TLRPC.TL_message();
                message.out = false;
                message.unread = false;
                message.from_id = tL_channelAdminLogEvent.user_id;
                message.to_id = tL_peerChannel;
                message.date = tL_channelAdminLogEvent.date;
                message.message = ((TLRPC.TL_channelAdminLogEventActionChangeAbout) tL_channelAdminLogEvent.action).new_value;
                if (!TextUtils.isEmpty(((TLRPC.TL_channelAdminLogEventActionChangeAbout) tL_channelAdminLogEvent.action).prev_value)) {
                    message.media = new TLRPC.TL_messageMediaWebPage();
                    message.media.webpage = new TLRPC.TL_webPage();
                    message.media.webpage.flags = 10;
                    message.media.webpage.display_url = "";
                    message.media.webpage.url = "";
                    message.media.webpage.site_name = LocaleController.getString("EventLogPreviousGroupDescription", R.string.EventLogPreviousGroupDescription);
                    message.media.webpage.description = ((TLRPC.TL_channelAdminLogEventActionChangeAbout) tL_channelAdminLogEvent.action).prev_value;
                } else {
                    message.media = new TLRPC.TL_messageMediaEmpty();
                }
            } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionChangeUsername) {
                String str9 = ((TLRPC.TL_channelAdminLogEventActionChangeUsername) tL_channelAdminLogEvent.action).new_value;
                if (!TextUtils.isEmpty(str9)) {
                    if (chat.megagroup) {
                        i3 = R.string.EventLogChangedGroupLink;
                        str3 = "EventLogChangedGroupLink";
                    } else {
                        i3 = R.string.EventLogChangedChannelLink;
                        str3 = "EventLogChangedChannelLink";
                    }
                    this.messageText = replaceWithLink(LocaleController.getString(str3, i3), "un1", user);
                } else {
                    if (chat.megagroup) {
                        i2 = R.string.EventLogRemovedGroupLink;
                        str2 = "EventLogRemovedGroupLink";
                    } else {
                        i2 = R.string.EventLogRemovedChannelLink;
                        str2 = "EventLogRemovedChannelLink";
                    }
                    this.messageText = replaceWithLink(LocaleController.getString(str2, i2), "un1", user);
                }
                TLRPC.TL_message tL_message = new TLRPC.TL_message();
                tL_message.out = false;
                tL_message.unread = false;
                tL_message.from_id = tL_channelAdminLogEvent.user_id;
                tL_message.to_id = tL_peerChannel;
                tL_message.date = tL_channelAdminLogEvent.date;
                if (!TextUtils.isEmpty(str9)) {
                    tL_message.message = "https://" + MessagesController.getInstance(this.currentAccount).linkPrefix + "/" + str9;
                } else {
                    tL_message.message = "";
                }
                TLRPC.TL_messageEntityUrl tL_messageEntityUrl = new TLRPC.TL_messageEntityUrl();
                tL_messageEntityUrl.offset = 0;
                tL_messageEntityUrl.length = tL_message.message.length();
                tL_message.entities.add(tL_messageEntityUrl);
                if (!TextUtils.isEmpty(((TLRPC.TL_channelAdminLogEventActionChangeUsername) tL_channelAdminLogEvent.action).prev_value)) {
                    tL_message.media = new TLRPC.TL_messageMediaWebPage();
                    tL_message.media.webpage = new TLRPC.TL_webPage();
                    tL_message.media.webpage.flags = 10;
                    tL_message.media.webpage.display_url = "";
                    tL_message.media.webpage.url = "";
                    tL_message.media.webpage.site_name = LocaleController.getString("EventLogPreviousLink", R.string.EventLogPreviousLink);
                    tL_message.media.webpage.description = "https://" + MessagesController.getInstance(this.currentAccount).linkPrefix + "/" + ((TLRPC.TL_channelAdminLogEventActionChangeUsername) tL_channelAdminLogEvent.action).prev_value;
                } else {
                    tL_message.media = new TLRPC.TL_messageMediaEmpty();
                }
                message = tL_message;
            } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionEditMessage) {
                message = new TLRPC.TL_message();
                message.out = false;
                message.unread = false;
                message.from_id = tL_channelAdminLogEvent.user_id;
                message.to_id = tL_peerChannel;
                message.date = tL_channelAdminLogEvent.date;
                TLRPC.Message message2 = ((TLRPC.TL_channelAdminLogEventActionEditMessage) tL_channelAdminLogEvent.action).new_message;
                TLRPC.Message message3 = ((TLRPC.TL_channelAdminLogEventActionEditMessage) tL_channelAdminLogEvent.action).prev_message;
                if (message2.media == null || (message2.media instanceof TLRPC.TL_messageMediaEmpty) || (message2.media instanceof TLRPC.TL_messageMediaWebPage)) {
                    this.messageText = replaceWithLink(LocaleController.getString("EventLogEditedMessages", R.string.EventLogEditedMessages), "un1", user);
                    message.message = message2.message;
                    message.media = new TLRPC.TL_messageMediaWebPage();
                    message.media.webpage = new TLRPC.TL_webPage();
                    message.media.webpage.site_name = LocaleController.getString("EventLogOriginalMessages", R.string.EventLogOriginalMessages);
                    if (TextUtils.isEmpty(message3.message)) {
                        message.media.webpage.description = LocaleController.getString("EventLogOriginalCaptionEmpty", R.string.EventLogOriginalCaptionEmpty);
                    } else {
                        message.media.webpage.description = message3.message;
                    }
                } else {
                    boolean z3 = !TextUtils.equals(message2.message, message3.message);
                    if (((message2.media.getClass() == message3.media.getClass() && (message2.media.photo == null || message3.media.photo == null || message2.media.photo.id == message3.media.photo.id) && (message2.media.document == null || message3.media.document == null || message2.media.document.id == message3.media.document.id)) ? false : true) && z3) {
                        this.messageText = replaceWithLink(LocaleController.getString("EventLogEditedMediaCaption", R.string.EventLogEditedMediaCaption), "un1", user);
                    } else if (z3) {
                        this.messageText = replaceWithLink(LocaleController.getString("EventLogEditedCaption", R.string.EventLogEditedCaption), "un1", user);
                    } else {
                        this.messageText = replaceWithLink(LocaleController.getString("EventLogEditedMedia", R.string.EventLogEditedMedia), "un1", user);
                    }
                    message.media = message2.media;
                    if (z3) {
                        message.media.webpage = new TLRPC.TL_webPage();
                        message.media.webpage.site_name = LocaleController.getString("EventLogOriginalCaption", R.string.EventLogOriginalCaption);
                        if (TextUtils.isEmpty(message3.message)) {
                            message.media.webpage.description = LocaleController.getString("EventLogOriginalCaptionEmpty", R.string.EventLogOriginalCaptionEmpty);
                        } else {
                            message.media.webpage.description = message3.message;
                        }
                    }
                }
                message.reply_markup = message2.reply_markup;
                if (message.media.webpage != null) {
                    message.media.webpage.flags = 10;
                    message.media.webpage.display_url = "";
                    message.media.webpage.url = "";
                }
            } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionChangeStickerSet) {
                TLRPC.InputStickerSet inputStickerSet = ((TLRPC.TL_channelAdminLogEventActionChangeStickerSet) tL_channelAdminLogEvent.action).new_stickerset;
                TLRPC.InputStickerSet inputStickerSet2 = ((TLRPC.TL_channelAdminLogEventActionChangeStickerSet) tL_channelAdminLogEvent.action).new_stickerset;
                if (inputStickerSet == null || (inputStickerSet instanceof TLRPC.TL_inputStickerSetEmpty)) {
                    this.messageText = replaceWithLink(LocaleController.getString("EventLogRemovedStickersSet", R.string.EventLogRemovedStickersSet), "un1", user);
                } else {
                    this.messageText = replaceWithLink(LocaleController.getString("EventLogChangedStickersSet", R.string.EventLogChangedStickersSet), "un1", user);
                }
            } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionChangeLocation) {
                TLRPC.TL_channelAdminLogEventActionChangeLocation tL_channelAdminLogEventActionChangeLocation = (TLRPC.TL_channelAdminLogEventActionChangeLocation) tL_channelAdminLogEvent.action;
                if (tL_channelAdminLogEventActionChangeLocation.new_value instanceof TLRPC.TL_channelLocationEmpty) {
                    this.messageText = replaceWithLink(LocaleController.getString("EventLogRemovedLocation", R.string.EventLogRemovedLocation), "un1", user);
                } else {
                    this.messageText = replaceWithLink(LocaleController.formatString("EventLogChangedLocation", R.string.EventLogChangedLocation, ((TLRPC.TL_channelLocation) tL_channelAdminLogEventActionChangeLocation.new_value).address), "un1", user);
                }
            } else if (tL_channelAdminLogEvent.action instanceof TLRPC.TL_channelAdminLogEventActionToggleSlowMode) {
                TLRPC.TL_channelAdminLogEventActionToggleSlowMode tL_channelAdminLogEventActionToggleSlowMode = (TLRPC.TL_channelAdminLogEventActionToggleSlowMode) tL_channelAdminLogEvent.action;
                if (tL_channelAdminLogEventActionToggleSlowMode.new_value == 0) {
                    this.messageText = replaceWithLink(LocaleController.getString("EventLogToggledSlowmodeOff", R.string.EventLogToggledSlowmodeOff), "un1", user);
                } else {
                    if (tL_channelAdminLogEventActionToggleSlowMode.new_value < 60) {
                        str = LocaleController.formatPluralString("Seconds", tL_channelAdminLogEventActionToggleSlowMode.new_value);
                    } else if (tL_channelAdminLogEventActionToggleSlowMode.new_value < 3600) {
                        str = LocaleController.formatPluralString("Minutes", tL_channelAdminLogEventActionToggleSlowMode.new_value / 60);
                    } else {
                        str = LocaleController.formatPluralString("Hours", (tL_channelAdminLogEventActionToggleSlowMode.new_value / 60) / 60);
                    }
                    this.messageText = replaceWithLink(LocaleController.formatString("EventLogToggledSlowmodeOn", R.string.EventLogToggledSlowmodeOn, str), "un1", user);
                }
            } else {
                this.messageText = "unsupported " + tL_channelAdminLogEvent.action;
            }
            if (this.messageOwner == null) {
                this.messageOwner = new TLRPC.TL_messageService();
            }
            this.messageOwner.message = this.messageText.toString();
            this.messageOwner.from_id = tL_channelAdminLogEvent.user_id;
            this.messageOwner.date = tL_channelAdminLogEvent.date;
            TLRPC.Message message4 = this.messageOwner;
            int i20 = iArr[0];
            iArr[0] = i20 + 1;
            message4.id = i20;
            this.eventId = tL_channelAdminLogEvent.id;
            this.messageOwner.out = false;
            this.messageOwner.to_id = new TLRPC.TL_peerChannel();
            this.messageOwner.to_id.channel_id = chat.id;
            this.messageOwner.unread = false;
            if (chat.megagroup) {
                this.messageOwner.flags |= Integer.MIN_VALUE;
            }
            MediaController instance = MediaController.getInstance();
            if (tL_channelAdminLogEvent.action.message != null && !(tL_channelAdminLogEvent.action.message instanceof TLRPC.TL_messageEmpty)) {
                message = tL_channelAdminLogEvent.action.message;
            }
            if (message == null) {
                message.out = false;
                int i21 = iArr[0];
                iArr[0] = i21 + 1;
                message.id = i21;
                message.reply_to_msg_id = 0;
                message.flags &= -32769;
                if (chat.megagroup) {
                    message.flags |= Integer.MIN_VALUE;
                }
                MessageObject messageObject = new MessageObject(this.currentAccount, message, (AbstractMap<Integer, TLRPC.User>) null, (AbstractMap<Integer, TLRPC.Chat>) null, true, this.eventId);
                if (messageObject.contentType >= 0) {
                    if (instance.isPlayingMessage(messageObject)) {
                        MessageObject playingMessageObject = instance.getPlayingMessageObject();
                        messageObject.audioProgress = playingMessageObject.audioProgress;
                        messageObject.audioProgressSec = playingMessageObject.audioProgressSec;
                    }
                    arrayList2 = arrayList;
                    createDateArray(this.currentAccount, tL_channelAdminLogEvent, arrayList2, hashMap);
                    arrayList2.add(arrayList.size() - 1, messageObject);
                } else {
                    arrayList2 = arrayList;
                    this.contentType = -1;
                }
            } else {
                arrayList2 = arrayList;
            }
            if (this.contentType < 0) {
                createDateArray(this.currentAccount, tL_channelAdminLogEvent, arrayList2, hashMap);
                arrayList2.add(arrayList.size() - 1, this);
                if (this.messageText == null) {
                    this.messageText = "";
                }
                setType();
                measureInlineBotButtons();
                generateCaption();
                if (this.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                    textPaint = Theme.chat_msgGameTextPaint;
                } else {
                    textPaint = Theme.chat_msgTextPaint;
                }
                int[] iArr2 = SharedConfig.allowBigEmoji ? new int[1] : null;
                this.messageText = Emoji.replaceEmoji(this.messageText, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20.0f), false, iArr2);
                checkEmojiOnly(iArr2);
                if (instance.isPlayingMessage(this)) {
                    MessageObject playingMessageObject2 = instance.getPlayingMessageObject();
                    this.audioProgress = playingMessageObject2.audioProgress;
                    this.audioProgressSec = playingMessageObject2.audioProgressSec;
                }
                generateLayout(user);
                this.layoutCreated = true;
                generateThumbs(false);
                checkMediaExistance();
                return;
            }
            return;
        } else if (((TLRPC.TL_channelAdminLogEventActionTogglePreHistoryHidden) tL_channelAdminLogEvent.action).new_value) {
            this.messageText = replaceWithLink(LocaleController.getString("EventLogToggledInvitesHistoryOff", R.string.EventLogToggledInvitesHistoryOff), "un1", user);
        } else {
            this.messageText = replaceWithLink(LocaleController.getString("EventLogToggledInvitesHistoryOn", R.string.EventLogToggledInvitesHistoryOn), "un1", user);
        }
        message = null;
        if (this.messageOwner == null) {
        }
        this.messageOwner.message = this.messageText.toString();
        this.messageOwner.from_id = tL_channelAdminLogEvent.user_id;
        this.messageOwner.date = tL_channelAdminLogEvent.date;
        TLRPC.Message message42 = this.messageOwner;
        int i202 = iArr[0];
        iArr[0] = i202 + 1;
        message42.id = i202;
        this.eventId = tL_channelAdminLogEvent.id;
        this.messageOwner.out = false;
        this.messageOwner.to_id = new TLRPC.TL_peerChannel();
        this.messageOwner.to_id.channel_id = chat.id;
        this.messageOwner.unread = false;
        if (chat.megagroup) {
        }
        MediaController instance2 = MediaController.getInstance();
        message = tL_channelAdminLogEvent.action.message;
        if (message == null) {
        }
        if (this.contentType < 0) {
        }
    }

    private String getUserName(TLRPC.User user, ArrayList<TLRPC.MessageEntity> arrayList, int i) {
        String formatName = user == null ? "" : ContactsController.formatName(user.first_name, user.last_name);
        if (i >= 0) {
            TLRPC.TL_messageEntityMentionName tL_messageEntityMentionName = new TLRPC.TL_messageEntityMentionName();
            tL_messageEntityMentionName.user_id = user.id;
            tL_messageEntityMentionName.offset = i;
            tL_messageEntityMentionName.length = formatName.length();
            arrayList.add(tL_messageEntityMentionName);
        }
        if (TextUtils.isEmpty(user.username)) {
            return formatName;
        }
        if (i >= 0) {
            TLRPC.TL_messageEntityMentionName tL_messageEntityMentionName2 = new TLRPC.TL_messageEntityMentionName();
            tL_messageEntityMentionName2.user_id = user.id;
            tL_messageEntityMentionName2.offset = i + formatName.length() + 2;
            tL_messageEntityMentionName2.length = user.username.length() + 1;
            arrayList.add(tL_messageEntityMentionName2);
        }
        return String.format("%1$s (@%2$s)", formatName, user.username);
    }

    public void applyNewText() {
        TextPaint textPaint;
        if (!TextUtils.isEmpty(this.messageOwner.message)) {
            int[] iArr = null;
            TLRPC.User user = isFromUser() ? MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(this.messageOwner.from_id)) : null;
            this.messageText = this.messageOwner.message;
            if (this.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                textPaint = Theme.chat_msgGameTextPaint;
            } else {
                textPaint = Theme.chat_msgTextPaint;
            }
            if (SharedConfig.allowBigEmoji) {
                iArr = new int[1];
            }
            this.messageText = Emoji.replaceEmoji(this.messageText, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20.0f), false, iArr);
            checkEmojiOnly(iArr);
            generateLayout(user);
        }
    }

    public void generateGameMessageText(TLRPC.User user) {
        if (user == null && this.messageOwner.from_id > 0) {
            user = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(this.messageOwner.from_id));
        }
        TLRPC.TL_game tL_game = null;
        MessageObject messageObject = this.replyMessageObject;
        if (!(messageObject == null || messageObject.messageOwner.media == null || this.replyMessageObject.messageOwner.media.game == null)) {
            tL_game = this.replyMessageObject.messageOwner.media.game;
        }
        if (tL_game != null) {
            if (user == null || user.id != UserConfig.getInstance(this.currentAccount).getClientUserId()) {
                this.messageText = replaceWithLink(LocaleController.formatString("ActionUserScoredInGame", R.string.ActionUserScoredInGame, LocaleController.formatPluralString("Points", this.messageOwner.action.score)), "un1", user);
            } else {
                this.messageText = LocaleController.formatString("ActionYouScoredInGame", R.string.ActionYouScoredInGame, LocaleController.formatPluralString("Points", this.messageOwner.action.score));
            }
            this.messageText = replaceWithLink(this.messageText, "un2", tL_game);
        } else if (user == null || user.id != UserConfig.getInstance(this.currentAccount).getClientUserId()) {
            this.messageText = replaceWithLink(LocaleController.formatString("ActionUserScored", R.string.ActionUserScored, LocaleController.formatPluralString("Points", this.messageOwner.action.score)), "un1", user);
        } else {
            this.messageText = LocaleController.formatString("ActionYouScored", R.string.ActionYouScored, LocaleController.formatPluralString("Points", this.messageOwner.action.score));
        }
    }

    public boolean hasValidReplyMessageObject() {
        MessageObject messageObject = this.replyMessageObject;
        if (messageObject != null) {
            TLRPC.Message message = messageObject.messageOwner;
            return !(message instanceof TLRPC.TL_messageEmpty) && !(message.action instanceof TLRPC.TL_messageActionHistoryClear);
        }
    }

    public void generatePaymentSentMessageText(TLRPC.User user) {
        if (user == null) {
            user = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf((int) getDialogId()));
        }
        String firstName = user != null ? UserObject.getFirstName(user) : "";
        MessageObject messageObject = this.replyMessageObject;
        if (messageObject == null || !(messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice)) {
            this.messageText = LocaleController.formatString("PaymentSuccessfullyPaidNoItem", R.string.PaymentSuccessfullyPaidNoItem, LocaleController.getInstance().formatCurrencyString(this.messageOwner.action.total_amount, this.messageOwner.action.currency), firstName);
        } else {
            this.messageText = LocaleController.formatString("PaymentSuccessfullyPaid", R.string.PaymentSuccessfullyPaid, LocaleController.getInstance().formatCurrencyString(this.messageOwner.action.total_amount, this.messageOwner.action.currency), firstName, this.replyMessageObject.messageOwner.media.title);
        }
    }

    public void generatePinMessageText(TLRPC.User user, TLRPC.Chat chat) {
        if (user == null && chat == 0) {
            if (this.messageOwner.from_id > 0) {
                user = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(this.messageOwner.from_id));
            }
            if (user == null) {
                chat = MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(this.messageOwner.to_id.channel_id));
            }
        }
        MessageObject messageObject = this.replyMessageObject;
        if (messageObject != null) {
            TLRPC.Message message = messageObject.messageOwner;
            if (!(message instanceof TLRPC.TL_messageEmpty) && !(message.action instanceof TLRPC.TL_messageActionHistoryClear)) {
                if (this.replyMessageObject.isMusic()) {
                    String string = LocaleController.getString("ActionPinnedMusic", R.string.ActionPinnedMusic);
                    TLRPC.Chat chat2 = user;
                    if (user == null) {
                        chat2 = chat;
                    }
                    this.messageText = replaceWithLink(string, "un1", chat2);
                    return;
                } else if (this.replyMessageObject.isVideo()) {
                    String string2 = LocaleController.getString("ActionPinnedVideo", R.string.ActionPinnedVideo);
                    TLRPC.Chat chat3 = user;
                    if (user == null) {
                        chat3 = chat;
                    }
                    this.messageText = replaceWithLink(string2, "un1", chat3);
                    return;
                } else if (this.replyMessageObject.isGif()) {
                    String string3 = LocaleController.getString("ActionPinnedGif", R.string.ActionPinnedGif);
                    TLRPC.Chat chat4 = user;
                    if (user == null) {
                        chat4 = chat;
                    }
                    this.messageText = replaceWithLink(string3, "un1", chat4);
                    return;
                } else if (this.replyMessageObject.isVoice()) {
                    String string4 = LocaleController.getString("ActionPinnedVoice", R.string.ActionPinnedVoice);
                    TLRPC.Chat chat5 = user;
                    if (user == null) {
                        chat5 = chat;
                    }
                    this.messageText = replaceWithLink(string4, "un1", chat5);
                    return;
                } else if (this.replyMessageObject.isRoundVideo()) {
                    String string5 = LocaleController.getString("ActionPinnedRound", R.string.ActionPinnedRound);
                    TLRPC.Chat chat6 = user;
                    if (user == null) {
                        chat6 = chat;
                    }
                    this.messageText = replaceWithLink(string5, "un1", chat6);
                    return;
                } else if (this.replyMessageObject.isSticker() || this.replyMessageObject.isAnimatedSticker()) {
                    String string6 = LocaleController.getString("ActionPinnedSticker", R.string.ActionPinnedSticker);
                    TLRPC.Chat chat7 = user;
                    if (user == null) {
                        chat7 = chat;
                    }
                    this.messageText = replaceWithLink(string6, "un1", chat7);
                    return;
                } else if (this.replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                    String string7 = LocaleController.getString("ActionPinnedFile", R.string.ActionPinnedFile);
                    TLRPC.Chat chat8 = user;
                    if (user == null) {
                        chat8 = chat;
                    }
                    this.messageText = replaceWithLink(string7, "un1", chat8);
                    return;
                } else if (this.replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo) {
                    String string8 = LocaleController.getString("ActionPinnedGeo", R.string.ActionPinnedGeo);
                    TLRPC.Chat chat9 = user;
                    if (user == null) {
                        chat9 = chat;
                    }
                    this.messageText = replaceWithLink(string8, "un1", chat9);
                    return;
                } else if (this.replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
                    String string9 = LocaleController.getString("ActionPinnedGeoLive", R.string.ActionPinnedGeoLive);
                    TLRPC.Chat chat10 = user;
                    if (user == null) {
                        chat10 = chat;
                    }
                    this.messageText = replaceWithLink(string9, "un1", chat10);
                    return;
                } else if (this.replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                    String string10 = LocaleController.getString("ActionPinnedContact", R.string.ActionPinnedContact);
                    TLRPC.Chat chat11 = user;
                    if (user == null) {
                        chat11 = chat;
                    }
                    this.messageText = replaceWithLink(string10, "un1", chat11);
                    return;
                } else if (this.replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPoll) {
                    String string11 = LocaleController.getString("ActionPinnedPoll", R.string.ActionPinnedPoll);
                    TLRPC.Chat chat12 = user;
                    if (user == null) {
                        chat12 = chat;
                    }
                    this.messageText = replaceWithLink(string11, "un1", chat12);
                    return;
                } else if (this.replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                    String string12 = LocaleController.getString("ActionPinnedPhoto", R.string.ActionPinnedPhoto);
                    TLRPC.Chat chat13 = user;
                    if (user == null) {
                        chat13 = chat;
                    }
                    this.messageText = replaceWithLink(string12, "un1", chat13);
                    return;
                } else if (this.replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                    String formatString = LocaleController.formatString("ActionPinnedGame", R.string.ActionPinnedGame, "🎮 " + this.replyMessageObject.messageOwner.media.game.title);
                    TLRPC.Chat chat14 = user;
                    if (user == null) {
                        chat14 = chat;
                    }
                    CharSequence replaceWithLink = replaceWithLink(formatString, "un1", chat14);
                    this.messageText = replaceWithLink;
                    this.messageText = Emoji.replaceEmoji(replaceWithLink, Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20.0f), false);
                    return;
                } else {
                    CharSequence charSequence = this.replyMessageObject.messageText;
                    if (charSequence == null || charSequence.length() <= 0) {
                        String string13 = LocaleController.getString("ActionPinnedNoText", R.string.ActionPinnedNoText);
                        TLRPC.Chat chat15 = user;
                        if (user == null) {
                            chat15 = chat;
                        }
                        this.messageText = replaceWithLink(string13, "un1", chat15);
                        return;
                    }
                    CharSequence charSequence2 = this.replyMessageObject.messageText;
                    if (charSequence2.length() > 20) {
                        charSequence2 = ((Object) charSequence2.subSequence(0, 20)) + "...";
                    }
                    String formatString2 = LocaleController.formatString("ActionPinnedText", R.string.ActionPinnedText, Emoji.replaceEmoji(charSequence2, Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20.0f), false));
                    TLRPC.Chat chat16 = user;
                    if (user == null) {
                        chat16 = chat;
                    }
                    this.messageText = replaceWithLink(formatString2, "un1", chat16);
                    return;
                }
            }
        }
        String string14 = LocaleController.getString("ActionPinnedNoText", R.string.ActionPinnedNoText);
        TLRPC.Chat chat17 = user;
        if (user == null) {
            chat17 = chat;
        }
        this.messageText = replaceWithLink(string14, "un1", chat17);
    }

    public static void updateReactions(TLRPC.Message message, TLRPC.TL_messageReactions tL_messageReactions) {
        if (message != null && tL_messageReactions != null) {
            if (tL_messageReactions.min && message.reactions != null) {
                int size = message.reactions.results.size();
                int i = 0;
                int i2 = 0;
                while (true) {
                    if (i2 >= size) {
                        break;
                    }
                    TLRPC.TL_reactionCount tL_reactionCount = message.reactions.results.get(i2);
                    if (tL_reactionCount.chosen) {
                        int size2 = tL_messageReactions.results.size();
                        while (true) {
                            if (i >= size2) {
                                break;
                            }
                            TLRPC.TL_reactionCount tL_reactionCount2 = tL_messageReactions.results.get(i);
                            if (tL_reactionCount.reaction.equals(tL_reactionCount2.reaction)) {
                                tL_reactionCount2.chosen = true;
                                break;
                            }
                            i++;
                        }
                    } else {
                        i2++;
                    }
                }
            }
            message.reactions = tL_messageReactions;
            message.flags |= 1048576;
        }
    }

    public boolean hasReactions() {
        return this.messageOwner.reactions != null && !this.messageOwner.reactions.results.isEmpty();
    }

    public static void updatePollResults(TLRPC.TL_messageMediaPoll tL_messageMediaPoll, TLRPC.TL_pollResults tL_pollResults) {
        if ((tL_pollResults.flags & 2) != 0) {
            byte[] bArr = null;
            int i = 0;
            if (tL_pollResults.min && tL_messageMediaPoll.results.results != null) {
                int size = tL_messageMediaPoll.results.results.size();
                int i2 = 0;
                while (true) {
                    if (i2 >= size) {
                        break;
                    }
                    TLRPC.TL_pollAnswerVoters tL_pollAnswerVoters = tL_messageMediaPoll.results.results.get(i2);
                    if (tL_pollAnswerVoters.chosen) {
                        bArr = tL_pollAnswerVoters.option;
                        break;
                    }
                    i2++;
                }
            }
            tL_messageMediaPoll.results.results = tL_pollResults.results;
            if (bArr != null) {
                int size2 = tL_messageMediaPoll.results.results.size();
                while (true) {
                    if (i >= size2) {
                        break;
                    }
                    TLRPC.TL_pollAnswerVoters tL_pollAnswerVoters2 = tL_messageMediaPoll.results.results.get(i);
                    if (Arrays.equals(tL_pollAnswerVoters2.option, bArr)) {
                        tL_pollAnswerVoters2.chosen = true;
                        break;
                    }
                    i++;
                }
            }
            tL_messageMediaPoll.results.flags |= 2;
        }
        if ((tL_pollResults.flags & 4) != 0) {
            tL_messageMediaPoll.results.total_voters = tL_pollResults.total_voters;
            tL_messageMediaPoll.results.flags |= 4;
        }
    }

    public boolean isPollClosed() {
        if (this.type != 17) {
            return false;
        }
        return ((TLRPC.TL_messageMediaPoll) this.messageOwner.media).poll.closed;
    }

    public boolean isVoted() {
        if (this.type != 17) {
            return false;
        }
        TLRPC.TL_messageMediaPoll tL_messageMediaPoll = (TLRPC.TL_messageMediaPoll) this.messageOwner.media;
        if (tL_messageMediaPoll.results != null && !tL_messageMediaPoll.results.results.isEmpty()) {
            int size = tL_messageMediaPoll.results.results.size();
            for (int i = 0; i < size; i++) {
                if (tL_messageMediaPoll.results.results.get(i).chosen) {
                    return true;
                }
            }
        }
        return false;
    }

    public long getPollId() {
        if (this.type != 17) {
            return 0;
        }
        return ((TLRPC.TL_messageMediaPoll) this.messageOwner.media).poll.id;
    }

    private TLRPC.Photo getPhotoWithId(TLRPC.WebPage webPage, long j) {
        if (!(webPage == null || webPage.cached_page == null)) {
            if (webPage.photo != null && webPage.photo.id == j) {
                return webPage.photo;
            }
            for (int i = 0; i < webPage.cached_page.photos.size(); i++) {
                TLRPC.Photo photo = webPage.cached_page.photos.get(i);
                if (photo.id == j) {
                    return photo;
                }
            }
        }
        return null;
    }

    private TLRPC.Document getDocumentWithId(TLRPC.WebPage webPage, long j) {
        if (!(webPage == null || webPage.cached_page == null)) {
            if (webPage.document != null && webPage.document.id == j) {
                return webPage.document;
            }
            for (int i = 0; i < webPage.cached_page.documents.size(); i++) {
                TLRPC.Document document = webPage.cached_page.documents.get(i);
                if (document.id == j) {
                    return document;
                }
            }
        }
        return null;
    }

    private MessageObject getMessageObjectForBlock(TLRPC.WebPage webPage, TLRPC.PageBlock pageBlock) {
        TLRPC.TL_message tL_message;
        if (pageBlock instanceof TLRPC.TL_pageBlockPhoto) {
            TLRPC.Photo photoWithId = getPhotoWithId(webPage, ((TLRPC.TL_pageBlockPhoto) pageBlock).photo_id);
            if (photoWithId == webPage.photo) {
                return this;
            }
            tL_message = new TLRPC.TL_message();
            tL_message.media = new TLRPC.TL_messageMediaPhoto();
            tL_message.media.photo = photoWithId;
        } else if (pageBlock instanceof TLRPC.TL_pageBlockVideo) {
            TLRPC.TL_pageBlockVideo tL_pageBlockVideo = (TLRPC.TL_pageBlockVideo) pageBlock;
            if (getDocumentWithId(webPage, tL_pageBlockVideo.video_id) == webPage.document) {
                return this;
            }
            TLRPC.TL_message tL_message2 = new TLRPC.TL_message();
            tL_message2.media = new TLRPC.TL_messageMediaDocument();
            tL_message2.media.document = getDocumentWithId(webPage, tL_pageBlockVideo.video_id);
            tL_message = tL_message2;
        } else {
            tL_message = null;
        }
        tL_message.message = "";
        tL_message.realId = getId();
        tL_message.id = Utilities.random.nextInt();
        tL_message.date = this.messageOwner.date;
        tL_message.to_id = this.messageOwner.to_id;
        tL_message.out = this.messageOwner.out;
        tL_message.from_id = this.messageOwner.from_id;
        return new MessageObject(this.currentAccount, tL_message, false);
    }

    public ArrayList<MessageObject> getWebPagePhotos(ArrayList<MessageObject> arrayList, ArrayList<TLRPC.PageBlock> arrayList2) {
        if (arrayList == null) {
            arrayList = new ArrayList<>();
        }
        if (!(this.messageOwner.media == null || this.messageOwner.media.webpage == null)) {
            TLRPC.WebPage webPage = this.messageOwner.media.webpage;
            if (webPage.cached_page == null) {
                return arrayList;
            }
            if (arrayList2 == null) {
                arrayList2 = webPage.cached_page.blocks;
            }
            for (int i = 0; i < arrayList2.size(); i++) {
                TLRPC.PageBlock pageBlock = arrayList2.get(i);
                if (pageBlock instanceof TLRPC.TL_pageBlockSlideshow) {
                    TLRPC.TL_pageBlockSlideshow tL_pageBlockSlideshow = (TLRPC.TL_pageBlockSlideshow) pageBlock;
                    for (int i2 = 0; i2 < tL_pageBlockSlideshow.items.size(); i2++) {
                        arrayList.add(getMessageObjectForBlock(webPage, tL_pageBlockSlideshow.items.get(i2)));
                    }
                } else if (pageBlock instanceof TLRPC.TL_pageBlockCollage) {
                    TLRPC.TL_pageBlockCollage tL_pageBlockCollage = (TLRPC.TL_pageBlockCollage) pageBlock;
                    for (int i3 = 0; i3 < tL_pageBlockCollage.items.size(); i3++) {
                        arrayList.add(getMessageObjectForBlock(webPage, tL_pageBlockCollage.items.get(i3)));
                    }
                }
            }
        }
        return arrayList;
    }

    public void createMessageSendInfo() {
        String str;
        if (this.messageOwner.message == null) {
            return;
        }
        if ((this.messageOwner.id < 0 || isEditing()) && this.messageOwner.params != null) {
            String str2 = this.messageOwner.params.get("ve");
            if (str2 != null && (isVideo() || isNewGif() || isRoundVideo())) {
                VideoEditedInfo videoEditedInfo2 = new VideoEditedInfo();
                this.videoEditedInfo = videoEditedInfo2;
                if (!videoEditedInfo2.parseString(str2)) {
                    this.videoEditedInfo = null;
                } else {
                    this.videoEditedInfo.roundVideo = isRoundVideo();
                }
            }
            if (this.messageOwner.send_state == 3 && (str = this.messageOwner.params.get("prevMedia")) != null) {
                SerializedData serializedData = new SerializedData(Base64.decode(str, 0));
                this.previousMedia = TLRPC.MessageMedia.TLdeserialize(serializedData, serializedData.readInt32(false), false);
                this.previousCaption = serializedData.readString(false);
                this.previousAttachPath = serializedData.readString(false);
                int readInt32 = serializedData.readInt32(false);
                this.previousCaptionEntities = new ArrayList<>(readInt32);
                for (int i = 0; i < readInt32; i++) {
                    this.previousCaptionEntities.add(TLRPC.MessageEntity.TLdeserialize(serializedData, serializedData.readInt32(false), false));
                }
                serializedData.cleanup();
            }
        }
    }

    public void measureInlineBotButtons() {
        int i;
        CharSequence charSequence;
        this.wantedBotKeyboardWidth = 0;
        if ((this.messageOwner.reply_markup instanceof TLRPC.TL_replyInlineMarkup) || (this.messageOwner.reactions != null && !this.messageOwner.reactions.results.isEmpty())) {
            Theme.createChatResources(null, true);
            StringBuilder sb = this.botButtonsLayout;
            if (sb == null) {
                this.botButtonsLayout = new StringBuilder();
            } else {
                sb.setLength(0);
            }
        }
        if (this.messageOwner.reply_markup instanceof TLRPC.TL_replyInlineMarkup) {
            for (int i2 = 0; i2 < this.messageOwner.reply_markup.rows.size(); i2++) {
                TLRPC.TL_keyboardButtonRow tL_keyboardButtonRow = this.messageOwner.reply_markup.rows.get(i2);
                int size = tL_keyboardButtonRow.buttons.size();
                int i3 = 0;
                for (int i4 = 0; i4 < size; i4++) {
                    TLRPC.KeyboardButton keyboardButton = tL_keyboardButtonRow.buttons.get(i4);
                    StringBuilder sb2 = this.botButtonsLayout;
                    sb2.append(i2);
                    sb2.append(i4);
                    if (!(keyboardButton instanceof TLRPC.TL_keyboardButtonBuy) || (this.messageOwner.media.flags & 4) == 0) {
                        charSequence = Emoji.replaceEmoji(keyboardButton.text, Theme.chat_msgBotButtonPaint.getFontMetricsInt(), AndroidUtilities.dp(15.0f), false);
                    } else {
                        charSequence = LocaleController.getString("PaymentReceipt", R.string.PaymentReceipt);
                    }
                    StaticLayout staticLayout = new StaticLayout(charSequence, Theme.chat_msgBotButtonPaint, AndroidUtilities.dp(2000.0f), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
                    if (staticLayout.getLineCount() > 0) {
                        float lineWidth = staticLayout.getLineWidth(0);
                        float lineLeft = staticLayout.getLineLeft(0);
                        if (lineLeft < lineWidth) {
                            lineWidth -= lineLeft;
                        }
                        i3 = Math.max(i3, ((int) Math.ceil((double) lineWidth)) + AndroidUtilities.dp(4.0f));
                    }
                }
                this.wantedBotKeyboardWidth = Math.max(this.wantedBotKeyboardWidth, ((i3 + AndroidUtilities.dp(12.0f)) * size) + (AndroidUtilities.dp(5.0f) * (size - 1)));
            }
        } else if (this.messageOwner.reactions != null) {
            int size2 = this.messageOwner.reactions.results.size();
            for (int i5 = 0; i5 < size2; i5++) {
                TLRPC.TL_reactionCount tL_reactionCount = this.messageOwner.reactions.results.get(i5);
                StringBuilder sb3 = this.botButtonsLayout;
                sb3.append(0);
                sb3.append(i5);
                StaticLayout staticLayout2 = new StaticLayout(Emoji.replaceEmoji(String.format("%d %s", Integer.valueOf(tL_reactionCount.count), tL_reactionCount.reaction), Theme.chat_msgBotButtonPaint.getFontMetricsInt(), AndroidUtilities.dp(15.0f), false), Theme.chat_msgBotButtonPaint, AndroidUtilities.dp(2000.0f), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
                if (staticLayout2.getLineCount() > 0) {
                    float lineWidth2 = staticLayout2.getLineWidth(0);
                    float lineLeft2 = staticLayout2.getLineLeft(0);
                    if (lineLeft2 < lineWidth2) {
                        lineWidth2 -= lineLeft2;
                    }
                    i = Math.max(0, ((int) Math.ceil((double) lineWidth2)) + AndroidUtilities.dp(4.0f));
                } else {
                    i = 0;
                }
                this.wantedBotKeyboardWidth = Math.max(this.wantedBotKeyboardWidth, ((i + AndroidUtilities.dp(12.0f)) * size2) + (AndroidUtilities.dp(5.0f) * (size2 - 1)));
            }
        }
    }

    public boolean isFcmMessage() {
        return this.localType != 0;
    }

    public void setDelegate(Delegate delegate2) {
        this.delegate = delegate2;
    }

    public String setMoneyFormat(String str) {
        if (!NumberUtil.isNumber(str)) {
            return "";
        }
        if (!str.contains(".")) {
            return MoneyUtil.formatToString(new BigDecimal(String.valueOf(str)).multiply(new BigDecimal("1")).toString(), 0);
        }
        String[] split = str.split("\\.");
        String str2 = split[0];
        String str3 = split[1];
        String formatToString = MoneyUtil.formatToString(new BigDecimal(String.valueOf(str2)).multiply(new BigDecimal("1")).toString(), 0);
        if (str3.length() > 8) {
            str3 = str3.substring(0, 8);
        }
        return formatToString + "." + str3;
    }

    /* JADX INFO: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARNING: Code restructure failed: missing block: B:487:0x0ec6, code lost:
        if (r0.equals("1") != false) goto L_0x0eca;
     */
    /* JADX WARNING: Removed duplicated region for block: B:490:0x0ecc  */
    /* JADX WARNING: Removed duplicated region for block: B:495:0x0f0a  */
    private void updateMessageText(AbstractMap<Integer, TLRPC.User> abstractMap, AbstractMap<Integer, TLRPC.Chat> abstractMap2, SparseArray<TLRPC.User> sparseArray, SparseArray<TLRPC.Chat> sparseArray2) {
        TLRPC.User user;
        TLRPC.User user2;
        String str;
        String str2;
        TLRPC.User user3;
        TLRPC.User user4;
        String formatCallDuration;
        String charSequence;
        int indexOf;
        TLRPC.Chat chat;
        String str3;
        TLObject tLObject;
        TLObject tLObject2;
        TLRPC.User user5;
        if (this.messageOwner.from_id > 0) {
            if (abstractMap != null) {
                user5 = abstractMap.get(Integer.valueOf(this.messageOwner.from_id));
            } else {
                user5 = sparseArray != null ? sparseArray.get(this.messageOwner.from_id) : null;
            }
            if (user5 == null) {
                user5 = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(this.messageOwner.from_id));
            }
            user = user5;
        } else {
            user = null;
        }
        TLRPC.Message message = this.messageOwner;
        char c = 0;
        if (!(message instanceof TLRPC.TL_messageService)) {
            this.isRestrictedMessage = false;
            String restrictionReason = MessagesController.getRestrictionReason(message.restriction_reason);
            if (!TextUtils.isEmpty(restrictionReason)) {
                this.messageText = restrictionReason;
                this.isRestrictedMessage = true;
            } else if (isMediaEmpty()) {
                this.messageText = this.messageOwner.message;
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaPoll) {
                this.messageText = LocaleController.getString("Poll", R.string.Poll);
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                if (this.messageOwner.media.ttl_seconds == 0 || (this.messageOwner instanceof TLRPC.TL_message_secret)) {
                    this.messageText = LocaleController.getString("AttachPhoto", R.string.AttachPhoto);
                } else {
                    this.messageText = LocaleController.getString("AttachDestructingPhoto", R.string.AttachDestructingPhoto);
                }
            } else if (isVideo() || ((this.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) && (getDocument() instanceof TLRPC.TL_documentEmpty) && this.messageOwner.media.ttl_seconds != 0)) {
                if (this.messageOwner.media.ttl_seconds == 0 || (this.messageOwner instanceof TLRPC.TL_message_secret)) {
                    this.messageText = LocaleController.getString("AttachVideo", R.string.AttachVideo);
                } else {
                    this.messageText = LocaleController.getString("AttachDestructingVideo", R.string.AttachDestructingVideo);
                }
            } else if (isVoice()) {
                this.messageText = LocaleController.getString("AttachAudio", R.string.AttachAudio);
            } else if (isRoundVideo()) {
                this.messageText = LocaleController.getString("AttachRound", R.string.AttachRound);
            } else if ((this.messageOwner.media instanceof TLRPC.TL_messageMediaGeo) || (this.messageOwner.media instanceof TLRPC.TL_messageMediaVenue)) {
                this.messageText = LocaleController.getString("AttachLocation", R.string.AttachLocation);
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
                this.messageText = LocaleController.getString("AttachLiveLocation", R.string.AttachLiveLocation);
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                this.messageText = LocaleController.getString("AttachContact", R.string.AttachContact);
                if (!TextUtils.isEmpty(this.messageOwner.media.vcard)) {
                    this.vCardData = VCardData.parse(this.messageOwner.media.vcard);
                }
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                this.messageText = this.messageOwner.message;
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) {
                this.messageText = this.messageOwner.media.description;
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaUnsupported) {
                this.messageText = LocaleController.getString("UnsupportedMedia", R.string.UnsupportedMedia);
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                if (isSticker() || isAnimatedSticker()) {
                    String strickerChar = getStrickerChar();
                    if (strickerChar == null || strickerChar.length() <= 0) {
                        this.messageText = LocaleController.getString("AttachSticker", R.string.AttachSticker);
                    } else {
                        this.messageText = String.format("%s %s", strickerChar, LocaleController.getString("AttachSticker", R.string.AttachSticker));
                    }
                } else if (isMusic()) {
                    this.messageText = LocaleController.getString("AttachMusic", R.string.AttachMusic);
                } else if (isGif()) {
                    this.messageText = LocaleController.getString("AttachGif", R.string.AttachGif);
                } else {
                    String documentFileName = FileLoader.getDocumentFileName(getDocument());
                    if (documentFileName == null || documentFileName.length() <= 0) {
                        this.messageText = LocaleController.getString("AttachDocument", R.string.AttachDocument);
                    } else {
                        this.messageText = documentFileName;
                    }
                }
            } else if (this.messageOwner.media instanceof TLRPCRedpacket.CL_messagesPayBillOverMedia) {
                TLRPCRedpacket.CL_messagesPayBillOverMedia cL_messagesPayBillOverMedia = (TLRPCRedpacket.CL_messagesPayBillOverMedia) this.messageOwner.media;
                PayBillOverBean payBillOverBean = (PayBillOverBean) GsonUtils.fromJson(TLJsonResolve.getData(cL_messagesPayBillOverMedia.data), PayBillOverBean.class);
                if (payBillOverBean.coin_code.contains("-")) {
                    str = payBillOverBean.coin_code.split("-")[0];
                } else {
                    str = payBillOverBean.coin_code;
                }
                String str4 = "0";
                switch (cL_messagesPayBillOverMedia.deal_code) {
                    case 1:
                    case 3:
                    case 4:
                    case 6:
                        StringBuilder sb = new StringBuilder();
                        sb.append(LocaleController.getString("PayBillSuccessfullyTransferredOut", R.string.PayBillSuccessfullyTransferredOut));
                        if (!TextUtils.isEmpty(payBillOverBean.deal_amount)) {
                            str4 = payBillOverBean.deal_amount;
                        }
                        sb.append(str4);
                        sb.append(LocaleController.getString("PayBillA", R.string.PayBillA));
                        sb.append(str);
                        sb.append(LocaleController.getString("PayBillClickToView", R.string.PayBillClickToView));
                        str2 = sb.toString();
                        break;
                    case 2:
                    case 7:
                        StringBuilder sb2 = new StringBuilder();
                        sb2.append(LocaleController.getString("PayBillRogerThat", R.string.PayBillRogerThat));
                        if (!TextUtils.isEmpty(payBillOverBean.deal_amount)) {
                            str4 = payBillOverBean.deal_amount;
                        }
                        sb2.append(str4);
                        sb2.append(LocaleController.getString("PayBillA", R.string.PayBillA));
                        sb2.append(str);
                        sb2.append(LocaleController.getString("PayBillTransferInView", R.string.PayBillTransferInView));
                        str2 = sb2.toString();
                        break;
                    case 5:
                        StringBuilder sb3 = new StringBuilder();
                        sb3.append(LocaleController.getString("PayBillRogerThat", R.string.PayBillRogerThat));
                        if (!TextUtils.isEmpty(payBillOverBean.deal_amount)) {
                            str4 = payBillOverBean.deal_amount;
                        }
                        sb3.append(str4);
                        sb3.append(LocaleController.getString("PayBillA", R.string.PayBillA));
                        sb3.append(str);
                        sb3.append(LocaleController.getString("PayBillReturnClickToView", R.string.PayBillReturnClickToView));
                        str2 = sb3.toString();
                        break;
                    case 8:
                        if (!TextUtils.isEmpty(payBillOverBean.deal_type)) {
                            String str5 = payBillOverBean.deal_type;
                            int hashCode = str5.hashCode();
                            if (hashCode != 49) {
                                if (hashCode == 50 && str5.equals("2")) {
                                    c = 1;
                                    if (c == 0) {
                                        if (c == 1) {
                                            StringBuilder sb4 = new StringBuilder();
                                            sb4.append(LocaleController.getString("PayBillCommissionBuy2", R.string.PayBillCommissionBuy2));
                                            if (!TextUtils.isEmpty(payBillOverBean.deal_num)) {
                                                str4 = payBillOverBean.deal_num;
                                            }
                                            sb4.append(setMoneyFormat(str4));
                                            sb4.append(LocaleController.getString("PayBillA", R.string.PayBillA));
                                            sb4.append(str);
                                            sb4.append(LocaleController.getString("PayBillClickToView", R.string.PayBillClickToView));
                                            str2 = sb4.toString();
                                            break;
                                        }
                                    } else {
                                        StringBuilder sb5 = new StringBuilder();
                                        sb5.append(LocaleController.getString("PayBillCommissionBuy2", R.string.PayBillCommissionBuy2));
                                        if (!TextUtils.isEmpty(payBillOverBean.deal_amount)) {
                                            str4 = payBillOverBean.deal_amount;
                                        }
                                        sb5.append(setMoneyFormat(str4));
                                        sb5.append(LocaleController.getString("PayBillA", R.string.PayBillA));
                                        sb5.append(str);
                                        sb5.append(LocaleController.getString("PayBillClickToView", R.string.PayBillClickToView));
                                        str2 = sb5.toString();
                                        break;
                                    }
                                }
                            } else {
                                break;
                            }
                            c = 65535;
                            if (c == 0) {
                            }
                        }
                        str2 = "";
                        break;
                    case 9:
                        StringBuilder sb6 = new StringBuilder();
                        sb6.append(LocaleController.getString("PayBillCommissionSell2", R.string.PayBillCommissionSell2));
                        if (!TextUtils.isEmpty(payBillOverBean.deal_num)) {
                            str4 = payBillOverBean.deal_num;
                        }
                        sb6.append(setMoneyFormat(str4));
                        sb6.append(LocaleController.getString("PayBillA", R.string.PayBillA));
                        sb6.append(str);
                        sb6.append(LocaleController.getString("PayBillClickToView", R.string.PayBillClickToView));
                        str2 = sb6.toString();
                        break;
                    case 10:
                        StringBuilder sb7 = new StringBuilder();
                        sb7.append(LocaleController.getString("PayBillCommissionReturn2", R.string.PayBillCommissionReturn2));
                        if (!TextUtils.isEmpty(payBillOverBean.deal_amount)) {
                            str4 = payBillOverBean.deal_amount;
                        }
                        sb7.append(setMoneyFormat(str4));
                        sb7.append(LocaleController.getString("PayBillA", R.string.PayBillA));
                        sb7.append(str);
                        sb7.append(LocaleController.getString("PayBillReturnClickToView", R.string.PayBillReturnClickToView));
                        str2 = sb7.toString();
                        break;
                    case 11:
                        StringBuilder sb8 = new StringBuilder();
                        sb8.append(LocaleController.getString("PayBillFiatCurrencyBuy2", R.string.PayBillFiatCurrencyBuy2));
                        if (!TextUtils.isEmpty(payBillOverBean.deal_num)) {
                            str4 = payBillOverBean.deal_num;
                        }
                        sb8.append(str4);
                        sb8.append(LocaleController.getString("PayBillA", R.string.PayBillA));
                        sb8.append(str);
                        sb8.append(LocaleController.getString("PayBillClickToView", R.string.PayBillClickToView));
                        str2 = sb8.toString();
                        break;
                    case 12:
                        StringBuilder sb9 = new StringBuilder();
                        sb9.append(LocaleController.getString("PayBillFiatCurrencySell2", R.string.PayBillFiatCurrencySell2));
                        if (!TextUtils.isEmpty(payBillOverBean.deal_num)) {
                            str4 = payBillOverBean.deal_num;
                        }
                        sb9.append(str4);
                        sb9.append(LocaleController.getString("PayBillA", R.string.PayBillA));
                        sb9.append(str);
                        sb9.append(LocaleController.getString("PayBillClickToView", R.string.PayBillClickToView));
                        str2 = sb9.toString();
                        break;
                    default:
                        str2 = "";
                        break;
                }
                this.messageText = str2;
            } else if (this.messageOwner.media instanceof TLRPCRedpacket.CL_messagesRpkTransferMedia) {
                TLRPCRedpacket.CL_messagesRpkTransferMedia cL_messagesRpkTransferMedia = (TLRPCRedpacket.CL_messagesRpkTransferMedia) this.messageOwner.media;
                if (cL_messagesRpkTransferMedia.trans == 0) {
                    T t = cL_messagesRpkTransferMedia.data != null ? TLJsonResolve.parse(cL_messagesRpkTransferMedia.data, RedpacketResponse.class).model : null;
                    if (t != null) {
                        RedpacketBean red = t.getRed();
                        this.messageText = "[红包]" + red.getRemarks();
                    } else {
                        this.messageText = "[红包]红包消息";
                    }
                } else if (cL_messagesRpkTransferMedia.trans == 1 || cL_messagesRpkTransferMedia.trans == 2) {
                    T t2 = cL_messagesRpkTransferMedia.data != null ? TLJsonResolve.parse(cL_messagesRpkTransferMedia.data, TransferResponse.class).model : null;
                    if (t2 != null) {
                        TransferResponse.Status state = t2.getState();
                        if (isOutOwner()) {
                            if (state == TransferResponse.Status.WAITING) {
                                this.messageText = "[彩币转账]等待对方收款";
                            } else if (state == TransferResponse.Status.RECEIVED) {
                                if (t2.getInitiatorUserIdInt() == UserConfig.getInstance(UserConfig.selectedAccount).clientUserId) {
                                    this.messageText = "[彩币转账]朋友已确认收款";
                                } else {
                                    this.messageText = "[彩币转账]你已确认收款";
                                }
                            } else if (state == TransferResponse.Status.REFUSED) {
                                if (t2.getInitiatorUserIdInt() == UserConfig.getInstance(UserConfig.selectedAccount).clientUserId) {
                                    this.messageText = "[彩币转账]钱已被朋友退还";
                                } else {
                                    this.messageText = "[彩币转账]你已将钱退还";
                                }
                            } else if (state == TransferResponse.Status.TIMEOUT) {
                                this.messageText = "[彩币转账]钱已退还";
                            }
                        } else if (state == TransferResponse.Status.WAITING) {
                            this.messageText = "[彩币转账]请你确认收款";
                        } else if (state == TransferResponse.Status.RECEIVED) {
                            if (t2.getInitiatorUserIdInt() == UserConfig.getInstance(UserConfig.selectedAccount).clientUserId) {
                                this.messageText = "[彩币转账]朋友已确认收款";
                            } else {
                                this.messageText = "[彩币转账]你已确认收款";
                            }
                        } else if (state == TransferResponse.Status.REFUSED) {
                            if (t2.getInitiatorUserIdInt() == UserConfig.getInstance(UserConfig.selectedAccount).clientUserId) {
                                this.messageText = "[彩币转账]钱已被朋友退还";
                            } else {
                                this.messageText = "[彩币转账]你已将钱退还";
                            }
                        } else if (state == TransferResponse.Status.TIMEOUT) {
                            this.messageText = "[彩币转账]钱已退还";
                        }
                    } else {
                        this.messageText = "[CG转账]转账消息";
                    }
                }
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaShareContact) {
                TLRPC.TL_messageMediaShareContact tL_messageMediaShareContact = (TLRPC.TL_messageMediaShareContact) this.messageOwner.media;
                TLRPC.User user6 = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(tL_messageMediaShareContact.user_id));
                if (user6 != null) {
                    if (isOutOwner()) {
                        this.messageText = String.format(LocaleController.getString(R.string.share_contact_recomment) + "%s", user6.first_name);
                    } else {
                        this.messageText = String.format(LocaleController.getString(R.string.share_contact_recomment_to_you) + "%s", user6.first_name);
                    }
                } else if (!(abstractMap == null || (user2 = abstractMap.get(Integer.valueOf(tL_messageMediaShareContact.user_id))) == null)) {
                    if (isOutOwner()) {
                        this.messageText = String.format(LocaleController.getString(R.string.share_contact_recomment) + "%s", user2.first_name);
                    } else {
                        this.messageText = String.format(LocaleController.getString(R.string.share_contact_recomment_to_you) + "%s", user2.first_name);
                    }
                }
            } else {
                boolean z = this.messageOwner.media instanceof TLRPC.TL_messageMediaShare;
            }
        } else if (message.action != null) {
            if (this.messageOwner.action instanceof TLRPCRedpacket.CL_messagesActionReceivedRpkTransfer) {
                TLRPCRedpacket.CL_messagesActionReceivedRpkTransfer cL_messagesActionReceivedRpkTransfer = (TLRPCRedpacket.CL_messagesActionReceivedRpkTransfer) this.messageOwner.action;
                MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(cL_messagesActionReceivedRpkTransfer.receiver.user_id));
                TLRPC.User user7 = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(cL_messagesActionReceivedRpkTransfer.sender.user_id));
                T t3 = TLJsonResolve.parse(cL_messagesActionReceivedRpkTransfer.data, RedpacketResponse.class).model;
                if (user != null) {
                    int parseInt = (cL_messagesActionReceivedRpkTransfer.sender.user_id != UserConfig.getInstance(UserConfig.selectedAccount).clientUserId || t3 == null || t3.getRed() == null || TextUtils.isEmpty(t3.getRed().getStatus()) || !isFromChat()) ? -1 : Integer.parseInt(t3.getRed().getStatus());
                    if (isOut()) {
                        this.messageText = replaceWithLink("  您领取了un的红包", "un", user7, parseInt, new ClickableSpan() {
                            /* class im.guobwnxjuc.messenger.MessageObject.AnonymousClass1 */

                            public void onClick(View view) {
                                if (MessageObject.this.delegate != null) {
                                    MessageObject.this.delegate.onClickRed();
                                }
                            }

                            public void updateDrawState(TextPaint textPaint) {
                                textPaint.setUnderlineText(false);
                            }
                        });
                    } else if (user7 == null || user7.id != UserConfig.getInstance(UserConfig.selectedAccount).clientUserId) {
                        CharSequence replaceWithLink = replaceWithLink("  un1领取了un2的红包", "un1", user, true);
                        this.messageText = replaceWithLink;
                        this.messageText = replaceWithLink(replaceWithLink, "un2", user7, parseInt, new ClickableSpan() {
                            /* class im.guobwnxjuc.messenger.MessageObject.AnonymousClass3 */

                            public void onClick(View view) {
                                if (MessageObject.this.delegate != null) {
                                    MessageObject.this.delegate.onClickRed();
                                }
                            }

                            public void updateDrawState(TextPaint textPaint) {
                                textPaint.setUnderlineText(false);
                            }
                        });
                    } else {
                        this.messageText = replaceWithLink("  un领取了您的红包", "un", user, parseInt, new ClickableSpan() {
                            /* class im.guobwnxjuc.messenger.MessageObject.AnonymousClass2 */

                            public void onClick(View view) {
                                if (MessageObject.this.delegate != null) {
                                    MessageObject.this.delegate.onClickRed();
                                }
                            }

                            public void updateDrawState(TextPaint textPaint) {
                                textPaint.setUnderlineText(false);
                            }
                        });
                    }
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionCustomAction) {
                if ("MUTUALCONTACTS".equals(this.messageOwner.action.message)) {
                    this.messageText = LocaleController.getString("MutualContactsText", R.string.MutualContactsText);
                } else {
                    this.messageText = this.messageOwner.action.message;
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionChatCreate) {
                if (isOut()) {
                    this.messageText = LocaleController.getString("ActionYouCreateGroup", R.string.ActionYouCreateGroup);
                } else {
                    this.messageText = replaceWithLink(LocaleController.getString("ActionCreateGroup", R.string.ActionCreateGroup), "un1", user);
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
                if (this.messageOwner.action.user_id != this.messageOwner.from_id) {
                    if (abstractMap != null) {
                        tLObject2 = (TLRPC.User) abstractMap.get(Integer.valueOf(this.messageOwner.action.user_id));
                    } else {
                        tLObject2 = sparseArray != null ? (TLRPC.User) sparseArray.get(this.messageOwner.action.user_id) : null;
                    }
                    if (tLObject2 == null) {
                        tLObject2 = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(this.messageOwner.action.user_id));
                    }
                    if (isOut()) {
                        this.messageText = replaceWithLink(LocaleController.getString("ActionYouKickUser", R.string.ActionYouKickUser), "un2", tLObject2);
                    } else if (this.messageOwner.action.user_id == UserConfig.getInstance(this.currentAccount).getClientUserId()) {
                        this.messageText = replaceWithLink(LocaleController.getString("ActionKickUserYou", R.string.ActionKickUserYou), "un1", user);
                    } else {
                        CharSequence replaceWithLink2 = replaceWithLink(LocaleController.getString("ActionKickUser", R.string.ActionKickUser), "un2", tLObject2);
                        this.messageText = replaceWithLink2;
                        this.messageText = replaceWithLink(replaceWithLink2, "un1", user);
                    }
                } else if (isOut()) {
                    this.messageText = LocaleController.getString("ActionYouLeftUser", R.string.ActionYouLeftUser);
                } else {
                    this.messageText = replaceWithLink(LocaleController.getString("ActionLeftUser", R.string.ActionLeftUser), "un1", user);
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionChatAddUser) {
                int i = this.messageOwner.action.user_id;
                if (i == 0 && this.messageOwner.action.users.size() == 1) {
                    i = this.messageOwner.action.users.get(0).intValue();
                }
                if (i != 0) {
                    if (abstractMap != null) {
                        tLObject = (TLRPC.User) abstractMap.get(Integer.valueOf(i));
                    } else {
                        tLObject = sparseArray != null ? (TLRPC.User) sparseArray.get(i) : null;
                    }
                    if (tLObject == null) {
                        tLObject = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(i));
                    }
                    if (i == this.messageOwner.from_id) {
                        if (this.messageOwner.to_id.channel_id != 0 && !isMegagroup()) {
                            this.messageText = LocaleController.getString("ChannelJoined", R.string.ChannelJoined);
                        } else if (this.messageOwner.to_id.channel_id == 0 || !isMegagroup()) {
                            if (isOut()) {
                                this.messageText = LocaleController.getString("ActionAddUserSelfYou", R.string.ActionAddUserSelfYou);
                            } else {
                                this.messageText = replaceWithLink(LocaleController.getString("ActionAddUserSelf", R.string.ActionAddUserSelf), "un1", user);
                            }
                        } else if (i == UserConfig.getInstance(this.currentAccount).getClientUserId()) {
                            this.messageText = LocaleController.getString("ChannelMegaJoined", R.string.ChannelMegaJoined);
                        } else {
                            this.messageText = replaceWithLink(LocaleController.getString("ActionAddUserSelfMega", R.string.ActionAddUserSelfMega), "un1", user);
                        }
                    } else if (isOut()) {
                        this.messageText = replaceWithLink(LocaleController.getString("ActionYouAddUser", R.string.ActionYouAddUser), "un2", tLObject);
                    } else if (i != UserConfig.getInstance(this.currentAccount).getClientUserId()) {
                        CharSequence replaceWithLink3 = replaceWithLink(LocaleController.getString("ActionAddUser", R.string.ActionAddUser), "un2", tLObject);
                        this.messageText = replaceWithLink3;
                        this.messageText = replaceWithLink(replaceWithLink3, "un1", user);
                    } else if (this.messageOwner.to_id.channel_id == 0) {
                        this.messageText = replaceWithLink(LocaleController.getString("ActionAddUserYou", R.string.ActionAddUserYou), "un1", user);
                    } else if (isMegagroup()) {
                        this.messageText = replaceWithLink(LocaleController.getString("MegaAddedBy", R.string.MegaAddedBy), "un1", user);
                    } else {
                        this.messageText = replaceWithLink(LocaleController.getString("ChannelAddedBy", R.string.ChannelAddedBy), "un1", user);
                    }
                } else if (isOut()) {
                    this.messageText = replaceWithLink(LocaleController.getString("ActionYouAddUser", R.string.ActionYouAddUser), "un2", this.messageOwner.action.users, abstractMap, sparseArray);
                } else {
                    CharSequence replaceWithLink4 = replaceWithLink(LocaleController.getString("ActionAddUser", R.string.ActionAddUser), "un2", this.messageOwner.action.users, abstractMap, sparseArray);
                    this.messageText = replaceWithLink4;
                    this.messageText = replaceWithLink(replaceWithLink4, "un1", user);
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionChatJoinedByLink) {
                if (isOut()) {
                    this.messageText = LocaleController.getString("ActionInviteYou", R.string.ActionInviteYou);
                } else {
                    this.messageText = replaceWithLink(LocaleController.getString("ActionInviteUser", R.string.ActionInviteUser), "un1", user);
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto) {
                if (this.messageOwner.to_id.channel_id != 0 && !isMegagroup()) {
                    this.messageText = LocaleController.getString("ActionChannelChangedPhoto", R.string.ActionChannelChangedPhoto);
                } else if (isOut()) {
                    this.messageText = LocaleController.getString("ActionYouChangedPhoto", R.string.ActionYouChangedPhoto);
                } else {
                    this.messageText = replaceWithLink(LocaleController.getString("ActionChangedPhoto", R.string.ActionChangedPhoto), "un1", user);
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionChatEditTitle) {
                if (this.messageOwner.to_id.channel_id != 0 && !isMegagroup()) {
                    this.messageText = LocaleController.getString("ActionChannelChangedTitle", R.string.ActionChannelChangedTitle).replace("un2", this.messageOwner.action.title);
                } else if (isOut()) {
                    this.messageText = LocaleController.getString("ActionYouChangedTitle", R.string.ActionYouChangedTitle).replace("un2", this.messageOwner.action.title);
                } else {
                    this.messageText = replaceWithLink(LocaleController.getString("ActionChangedTitle", R.string.ActionChangedTitle).replace("un2", this.messageOwner.action.title), "un1", user);
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
                if (this.messageOwner.to_id.channel_id != 0 && !isMegagroup()) {
                    this.messageText = LocaleController.getString("ActionChannelRemovedPhoto", R.string.ActionChannelRemovedPhoto);
                } else if (isOut()) {
                    this.messageText = LocaleController.getString("ActionYouRemovedPhoto", R.string.ActionYouRemovedPhoto);
                } else {
                    this.messageText = replaceWithLink(LocaleController.getString("ActionRemovedPhoto", R.string.ActionRemovedPhoto), "un1", user);
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionTTLChange) {
                if (this.messageOwner.action.ttl != 0) {
                    if (isOut()) {
                        this.messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, LocaleController.formatTTLString(this.messageOwner.action.ttl));
                    } else {
                        this.messageText = LocaleController.formatString("MessageLifetimeChanged", R.string.MessageLifetimeChanged, UserObject.getFirstName(user), LocaleController.formatTTLString(this.messageOwner.action.ttl));
                    }
                } else if (isOut()) {
                    this.messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
                } else {
                    this.messageText = LocaleController.formatString("MessageLifetimeRemoved", R.string.MessageLifetimeRemoved, UserObject.getFirstName(user));
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
                long j = ((long) this.messageOwner.date) * 1000;
                String formatString = (LocaleController.getInstance().formatterDay == null || LocaleController.getInstance().formatterYear == null) ? "" + this.messageOwner.date : LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(j), LocaleController.getInstance().formatterDay.format(j));
                TLRPC.User currentUser = UserConfig.getInstance(this.currentAccount).getCurrentUser();
                if (currentUser == null) {
                    if (abstractMap != null) {
                        currentUser = abstractMap.get(Integer.valueOf(this.messageOwner.to_id.user_id));
                    } else if (sparseArray != null) {
                        currentUser = sparseArray.get(this.messageOwner.to_id.user_id);
                    }
                    if (currentUser == null) {
                        currentUser = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(this.messageOwner.to_id.user_id));
                    }
                }
                if (currentUser != null) {
                    str3 = UserObject.getFirstName(currentUser);
                } else {
                    str3 = "";
                }
                this.messageText = LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, str3, formatString, this.messageOwner.action.title, this.messageOwner.action.address);
            } else if ((this.messageOwner.action instanceof TLRPC.TL_messageActionUserJoined) || (this.messageOwner.action instanceof TLRPC.TL_messageActionContactSignUp)) {
                this.messageText = LocaleController.formatString("NotificationContactJoined", R.string.NotificationContactJoined, UserObject.getName(user));
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
                this.messageText = LocaleController.formatString("NotificationContactNewPhoto", R.string.NotificationContactNewPhoto, UserObject.getName(user));
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction) {
                if (this.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages) {
                    if (isOut()) {
                        this.messageText = LocaleController.formatString("ActionTakeScreenshootYou", R.string.ActionTakeScreenshootYou, new Object[0]);
                    } else {
                        this.messageText = replaceWithLink(LocaleController.getString("ActionTakeScreenshoot", R.string.ActionTakeScreenshoot), "un1", user);
                    }
                } else if (this.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
                    TLRPC.TL_decryptedMessageActionSetMessageTTL tL_decryptedMessageActionSetMessageTTL = (TLRPC.TL_decryptedMessageActionSetMessageTTL) this.messageOwner.action.encryptedAction;
                    if (tL_decryptedMessageActionSetMessageTTL.ttl_seconds != 0) {
                        if (isOut()) {
                            this.messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, LocaleController.formatTTLString(tL_decryptedMessageActionSetMessageTTL.ttl_seconds));
                        } else {
                            this.messageText = LocaleController.formatString("MessageLifetimeChanged", R.string.MessageLifetimeChanged, UserObject.getFirstName(user), LocaleController.formatTTLString(tL_decryptedMessageActionSetMessageTTL.ttl_seconds));
                        }
                    } else if (isOut()) {
                        this.messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
                    } else {
                        this.messageText = LocaleController.formatString("MessageLifetimeRemoved", R.string.MessageLifetimeRemoved, UserObject.getFirstName(user));
                    }
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionScreenshotTaken) {
                if (isOut()) {
                    this.messageText = LocaleController.formatString("ActionTakeScreenshootYou", R.string.ActionTakeScreenshootYou, new Object[0]);
                } else {
                    this.messageText = replaceWithLink(LocaleController.getString("ActionTakeScreenshoot", R.string.ActionTakeScreenshoot), "un1", user);
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionCreatedBroadcastList) {
                this.messageText = LocaleController.formatString("YouCreatedBroadcastList", R.string.YouCreatedBroadcastList, new Object[0]);
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionChannelCreate) {
                if (isMegagroup()) {
                    this.messageText = LocaleController.getString("ActionCreateMega", R.string.ActionCreateMega);
                } else {
                    this.messageText = LocaleController.getString("ActionCreateChannel", R.string.ActionCreateChannel);
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
                this.messageText = LocaleController.getString("ActionMigrateFromGroup", R.string.ActionMigrateFromGroup);
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionChannelMigrateFrom) {
                this.messageText = LocaleController.getString("ActionMigrateFromGroup", R.string.ActionMigrateFromGroup);
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionPinMessage) {
                if (user == null) {
                    if (abstractMap2 != null) {
                        chat = abstractMap2.get(Integer.valueOf(this.messageOwner.to_id.channel_id));
                    } else if (sparseArray2 != null) {
                        chat = sparseArray2.get(this.messageOwner.to_id.channel_id);
                    }
                    generatePinMessageText(user, chat);
                }
                chat = null;
                generatePinMessageText(user, chat);
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionLiveStart_layer105) {
                TLRPC.TL_messageActionLiveStart_layer105 tL_messageActionLiveStart_layer105 = (TLRPC.TL_messageActionLiveStart_layer105) this.messageOwner.action;
                TLRPC.User user8 = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(tL_messageActionLiveStart_layer105.live_user));
                if (user8 != null) {
                    StringBuilder sb10 = new StringBuilder();
                    sb10.append(user8.first_name.length() > 6 ? user8.first_name.substring(0, 6) + "..." : user8.first_name);
                    sb10.append(LocaleController.getString(R.string.live_start_live));
                    sb10.append(": ");
                    sb10.append(tL_messageActionLiveStart_layer105.live_name);
                    this.messageText = sb10.toString();
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionLiveStop_layer105) {
                this.messageText = LocaleController.getString(R.string.live_end_live) + ": " + ((TLRPC.TL_messageActionLiveStop_layer105) this.messageOwner.action).live_name;
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionHistoryClear) {
                this.messageText = LocaleController.getString("HistoryCleared", R.string.HistoryCleared);
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionGameScore) {
                generateGameMessageText(user);
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall) {
                TLRPC.TL_messageActionPhoneCall tL_messageActionPhoneCall = (TLRPC.TL_messageActionPhoneCall) this.messageOwner.action;
                boolean z2 = tL_messageActionPhoneCall.reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed;
                if (this.messageOwner.from_id == UserConfig.getInstance(this.currentAccount).getClientUserId()) {
                    if (z2) {
                        this.messageText = LocaleController.getString("CallMessageOutgoingMissed", R.string.CallMessageOutgoingMissed);
                    } else {
                        this.messageText = LocaleController.getString("CallMessageOutgoing", R.string.CallMessageOutgoing);
                    }
                } else if (z2) {
                    this.messageText = LocaleController.getString("CallMessageIncomingMissed", R.string.CallMessageIncomingMissed);
                } else if (tL_messageActionPhoneCall.reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy) {
                    this.messageText = LocaleController.getString("CallMessageIncomingDeclined", R.string.CallMessageIncomingDeclined);
                } else {
                    this.messageText = LocaleController.getString("CallMessageIncoming", R.string.CallMessageIncoming);
                }
                if ((tL_messageActionPhoneCall.flags & 4) != 0) {
                    this.messageText = "[" + LocaleController.getString("AutoDownloadVideosOn", R.string.AutoDownloadVideosOn) + LocaleController.getString("Calls", R.string.Calls) + "]";
                } else {
                    this.messageText = "[" + LocaleController.getString("visual_call_voice", R.string.visual_call_voice) + LocaleController.getString("Calls", R.string.Calls) + "]";
                }
                if (tL_messageActionPhoneCall.duration > 0 && (indexOf = (charSequence = this.messageText.toString()).indexOf((formatCallDuration = LocaleController.formatCallDuration(tL_messageActionPhoneCall.duration)))) != -1) {
                    SpannableString spannableString = new SpannableString(this.messageText);
                    int length = formatCallDuration.length() + indexOf;
                    if (indexOf > 0 && charSequence.charAt(indexOf - 1) == '(') {
                        indexOf--;
                    }
                    if (length < charSequence.length() && charSequence.charAt(length) == ')') {
                        length++;
                    }
                    spannableString.setSpan(new TypefaceSpan(Typeface.DEFAULT), indexOf, length, 0);
                    this.messageText = spannableString;
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionPaymentSent) {
                int dialogId = (int) getDialogId();
                if (abstractMap != null) {
                    user4 = abstractMap.get(Integer.valueOf(dialogId));
                } else {
                    user4 = sparseArray != null ? sparseArray.get(dialogId) : null;
                }
                if (user4 == null) {
                    user4 = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(dialogId));
                }
                generatePaymentSentMessageText(user4);
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionBotAllowed) {
                String str6 = ((TLRPC.TL_messageActionBotAllowed) this.messageOwner.action).domain;
                String string = LocaleController.getString("ActionBotAllowed", R.string.ActionBotAllowed);
                int indexOf2 = string.indexOf("%1$s");
                SpannableString spannableString2 = new SpannableString(String.format(string, str6));
                if (indexOf2 >= 0) {
                    spannableString2.setSpan(new URLSpanNoUnderlineBold("http://" + str6), indexOf2, str6.length() + indexOf2, 33);
                }
                this.messageText = spannableString2;
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionSecureValuesSent) {
                TLRPC.TL_messageActionSecureValuesSent tL_messageActionSecureValuesSent = (TLRPC.TL_messageActionSecureValuesSent) this.messageOwner.action;
                StringBuilder sb11 = new StringBuilder();
                int size = tL_messageActionSecureValuesSent.types.size();
                for (int i2 = 0; i2 < size; i2++) {
                    TLRPC.SecureValueType secureValueType = tL_messageActionSecureValuesSent.types.get(i2);
                    if (sb11.length() > 0) {
                        sb11.append(", ");
                    }
                    if (secureValueType instanceof TLRPC.TL_secureValueTypePhone) {
                        sb11.append(LocaleController.getString("ActionBotDocumentPhone", R.string.ActionBotDocumentPhone));
                    } else if (secureValueType instanceof TLRPC.TL_secureValueTypeEmail) {
                        sb11.append(LocaleController.getString("ActionBotDocumentEmail", R.string.ActionBotDocumentEmail));
                    } else if (secureValueType instanceof TLRPC.TL_secureValueTypeAddress) {
                        sb11.append(LocaleController.getString("ActionBotDocumentAddress", R.string.ActionBotDocumentAddress));
                    } else if (secureValueType instanceof TLRPC.TL_secureValueTypePersonalDetails) {
                        sb11.append(LocaleController.getString("ActionBotDocumentIdentity", R.string.ActionBotDocumentIdentity));
                    } else if (secureValueType instanceof TLRPC.TL_secureValueTypePassport) {
                        sb11.append(LocaleController.getString("ActionBotDocumentPassport", R.string.ActionBotDocumentPassport));
                    } else if (secureValueType instanceof TLRPC.TL_secureValueTypeDriverLicense) {
                        sb11.append(LocaleController.getString("ActionBotDocumentDriverLicence", R.string.ActionBotDocumentDriverLicence));
                    } else if (secureValueType instanceof TLRPC.TL_secureValueTypeIdentityCard) {
                        sb11.append(LocaleController.getString("ActionBotDocumentIdentityCard", R.string.ActionBotDocumentIdentityCard));
                    } else if (secureValueType instanceof TLRPC.TL_secureValueTypeUtilityBill) {
                        sb11.append(LocaleController.getString("ActionBotDocumentUtilityBill", R.string.ActionBotDocumentUtilityBill));
                    } else if (secureValueType instanceof TLRPC.TL_secureValueTypeBankStatement) {
                        sb11.append(LocaleController.getString("ActionBotDocumentBankStatement", R.string.ActionBotDocumentBankStatement));
                    } else if (secureValueType instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
                        sb11.append(LocaleController.getString("ActionBotDocumentRentalAgreement", R.string.ActionBotDocumentRentalAgreement));
                    } else if (secureValueType instanceof TLRPC.TL_secureValueTypeInternalPassport) {
                        sb11.append(LocaleController.getString("ActionBotDocumentInternalPassport", R.string.ActionBotDocumentInternalPassport));
                    } else if (secureValueType instanceof TLRPC.TL_secureValueTypePassportRegistration) {
                        sb11.append(LocaleController.getString("ActionBotDocumentPassportRegistration", R.string.ActionBotDocumentPassportRegistration));
                    } else if (secureValueType instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
                        sb11.append(LocaleController.getString("ActionBotDocumentTemporaryRegistration", R.string.ActionBotDocumentTemporaryRegistration));
                    }
                }
                if (this.messageOwner.to_id != null) {
                    if (abstractMap != null) {
                        user3 = abstractMap.get(Integer.valueOf(this.messageOwner.to_id.user_id));
                    } else {
                        user3 = sparseArray != null ? sparseArray.get(this.messageOwner.to_id.user_id) : null;
                    }
                    if (user3 == null) {
                        user3 = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(this.messageOwner.to_id.user_id));
                    }
                } else {
                    user3 = null;
                }
                this.messageText = LocaleController.formatString("ActionBotDocuments", R.string.ActionBotDocuments, UserObject.getFirstName(user3), sb11.toString());
            }
        }
        if (this.messageText == null) {
            this.messageText = "";
        }
    }

    public void setType() {
        int i = this.type;
        this.isRoundVideoCached = 0;
        TLRPC.Message message = this.messageOwner;
        if ((message instanceof TLRPC.TL_message) || (message instanceof TLRPC.TL_messageForwarded_old2)) {
            if (this.isRestrictedMessage) {
                this.type = 0;
            } else if (this.emojiAnimatedSticker != null) {
                if (isSticker()) {
                    this.type = 13;
                } else {
                    this.type = 15;
                }
            } else if (isMediaEmpty()) {
                this.type = 0;
                if (TextUtils.isEmpty(this.messageText) && this.eventId == 0) {
                    this.messageText = "Empty message";
                }
            } else if (this.messageOwner.media.ttl_seconds != 0 && ((this.messageOwner.media.photo instanceof TLRPC.TL_photoEmpty) || (getDocument() instanceof TLRPC.TL_documentEmpty))) {
                this.contentType = 1;
                this.type = 10;
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                this.type = 1;
            } else if ((this.messageOwner.media instanceof TLRPC.TL_messageMediaGeo) || (this.messageOwner.media instanceof TLRPC.TL_messageMediaVenue) || (this.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive)) {
                this.type = 4;
            } else if (isRoundVideo()) {
                this.type = 5;
            } else if (isVideo()) {
                this.type = 3;
            } else if (isVoice()) {
                this.type = 2;
            } else if (isMusic()) {
                this.type = 14;
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
                this.type = 12;
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaPoll) {
                this.type = 17;
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaUnsupported) {
                this.type = 0;
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                TLRPC.Document document = getDocument();
                if (document == null || document.mime_type == null) {
                    this.type = 9;
                } else if (isGifDocument(document)) {
                    this.type = 8;
                } else if (isSticker()) {
                    this.type = 13;
                } else if (isAnimatedSticker()) {
                    this.type = 15;
                } else {
                    this.type = 9;
                }
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                this.type = 0;
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) {
                this.type = 0;
            } else if (this.messageOwner.media instanceof TLRPCRedpacket.CL_messagesRpkTransferMedia) {
                TLRPCRedpacket.CL_messagesRpkTransferMedia cL_messagesRpkTransferMedia = (TLRPCRedpacket.CL_messagesRpkTransferMedia) this.messageOwner.media;
                if (cL_messagesRpkTransferMedia.trans == 0) {
                    this.type = 101;
                } else if (cL_messagesRpkTransferMedia.trans == 1 || cL_messagesRpkTransferMedia.trans == 2) {
                    this.type = 102;
                }
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaShareContact) {
                this.type = 103;
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaShare) {
                this.type = TYPE_LIVE;
            } else if (this.messageOwner.media instanceof TLRPCRedpacket.CL_messagesPayBillOverMedia) {
                this.contentType = 5;
                this.type = 104;
            } else if (this.messageOwner.media instanceof TLRPCContacts.TL_messageMediaSysNotify) {
                this.type = 105;
            }
        } else if (message instanceof TLRPC.TL_messageService) {
            if (message.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
                this.type = 0;
            } else if ((this.messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto) || (this.messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto)) {
                this.contentType = 1;
                this.type = 11;
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageEncryptedAction) {
                if ((this.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages) || (this.messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL)) {
                    this.contentType = 1;
                    this.type = 10;
                } else {
                    this.contentType = -1;
                    this.type = -1;
                }
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionHistoryClear) {
                this.contentType = -1;
                this.type = -1;
            } else if (this.messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall) {
                this.type = 16;
            } else {
                this.contentType = 1;
                this.type = 10;
            }
        }
        if (i != 1000 && i != this.type) {
            updateMessageText(MessagesController.getInstance(this.currentAccount).getUsers(), MessagesController.getInstance(this.currentAccount).getChats(), null, null);
            if (isMediaEmpty()) {
                this.messageText = updateMetionText(this.messageText, this.messageOwner.entities);
            }
            generateThumbs(false);
        }
    }

    public boolean checkLayout() {
        CharSequence charSequence;
        TextPaint textPaint;
        if (!(this.type != 0 || this.messageOwner.to_id == null || (charSequence = this.messageText) == null || charSequence.length() == 0)) {
            if (this.layoutCreated) {
                if (Math.abs(this.generatedWithMinSize - (AndroidUtilities.isTablet() ? AndroidUtilities.getMinTabletSide() : AndroidUtilities.displaySize.x)) > AndroidUtilities.dp(52.0f) || this.generatedWithDensity != AndroidUtilities.density) {
                    this.layoutCreated = false;
                }
            }
            if (!this.layoutCreated) {
                this.layoutCreated = true;
                int[] iArr = null;
                TLRPC.User user = isFromUser() ? MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(this.messageOwner.from_id)) : null;
                if (this.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                    textPaint = Theme.chat_msgGameTextPaint;
                } else {
                    textPaint = Theme.chat_msgTextPaint;
                }
                if (SharedConfig.allowBigEmoji) {
                    iArr = new int[1];
                }
                this.messageText = Emoji.replaceEmoji(this.messageText, textPaint.getFontMetricsInt(), AndroidUtilities.dp(20.0f), false, iArr);
                checkEmojiOnly(iArr);
                generateLayout(user);
                return true;
            }
        }
        return false;
    }

    public void resetLayout() {
        this.layoutCreated = false;
    }

    public String getMimeType() {
        TLRPC.Document document = getDocument();
        if (document != null) {
            return document.mime_type;
        }
        if (this.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) {
            TLRPC.WebDocument webDocument = ((TLRPC.TL_messageMediaInvoice) this.messageOwner.media).photo;
            if (webDocument != null) {
                return webDocument.mime_type;
            }
            return "";
        } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
            return "image/jpeg";
        } else {
            if (!(this.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) || this.messageOwner.media.webpage.photo == null) {
                return "";
            }
            return "image/jpeg";
        }
    }

    public boolean canPreviewDocument() {
        return canPreviewDocument(getDocument());
    }

    public static boolean isGifDocument(WebFile webFile) {
        return webFile != null && (webFile.mime_type.equals("image/gif") || isNewGifDocument(webFile));
    }

    public static boolean isGifDocument(TLRPC.Document document) {
        return (document == null || document.mime_type == null || (!document.mime_type.equals("image/gif") && !isNewGifDocument(document))) ? false : true;
    }

    public static boolean isDocumentHasThumb(TLRPC.Document document) {
        if (document != null && !document.thumbs.isEmpty()) {
            int size = document.thumbs.size();
            for (int i = 0; i < size; i++) {
                TLRPC.PhotoSize photoSize = document.thumbs.get(i);
                if (!(photoSize == null || (photoSize instanceof TLRPC.TL_photoSizeEmpty) || (photoSize.location instanceof TLRPC.TL_fileLocationUnavailable))) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean canPreviewDocument(TLRPC.Document document) {
        if (!(document == null || document.mime_type == null)) {
            String lowerCase = document.mime_type.toLowerCase();
            if (isDocumentHasThumb(document) && (lowerCase.equals("image/png") || lowerCase.equals("image/jpg") || lowerCase.equals("image/jpeg"))) {
                for (int i = 0; i < document.attributes.size(); i++) {
                    TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i);
                    if (documentAttribute instanceof TLRPC.TL_documentAttributeImageSize) {
                        TLRPC.TL_documentAttributeImageSize tL_documentAttributeImageSize = (TLRPC.TL_documentAttributeImageSize) documentAttribute;
                        if (tL_documentAttributeImageSize.w >= 6000 || tL_documentAttributeImageSize.h >= 6000) {
                            return false;
                        }
                        return true;
                    }
                }
            } else if (BuildVars.DEBUG_PRIVATE_VERSION) {
                String documentFileName = FileLoader.getDocumentFileName(document);
                if (!documentFileName.startsWith("tg_secret_sticker") || !documentFileName.endsWith("json")) {
                    return false;
                }
                return true;
            }
        }
        return false;
    }

    public static boolean isRoundVideoDocument(TLRPC.Document document) {
        if (document != null && MimeTypes.VIDEO_MP4.equals(document.mime_type)) {
            boolean z = false;
            int i = 0;
            int i2 = 0;
            for (int i3 = 0; i3 < document.attributes.size(); i3++) {
                TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i3);
                if (documentAttribute instanceof TLRPC.TL_documentAttributeVideo) {
                    i = documentAttribute.w;
                    i2 = documentAttribute.w;
                    z = documentAttribute.round_message;
                }
            }
            if (!z || i > 1280 || i2 > 1280) {
                return false;
            }
            return true;
        }
        return false;
    }

    public static boolean isNewGifDocument(WebFile webFile) {
        if (webFile != null && MimeTypes.VIDEO_MP4.equals(webFile.mime_type)) {
            int i = 0;
            int i2 = 0;
            for (int i3 = 0; i3 < webFile.attributes.size(); i3++) {
                TLRPC.DocumentAttribute documentAttribute = webFile.attributes.get(i3);
                if (!(documentAttribute instanceof TLRPC.TL_documentAttributeAnimated) && (documentAttribute instanceof TLRPC.TL_documentAttributeVideo)) {
                    i = documentAttribute.w;
                    i2 = documentAttribute.w;
                }
            }
            if (i > 1280 || i2 > 1280) {
                return false;
            }
            return true;
        }
        return false;
    }

    public static boolean isNewGifDocument(TLRPC.Document document) {
        if (document != null && MimeTypes.VIDEO_MP4.equals(document.mime_type)) {
            boolean z = false;
            int i = 0;
            int i2 = 0;
            for (int i3 = 0; i3 < document.attributes.size(); i3++) {
                TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i3);
                if (documentAttribute instanceof TLRPC.TL_documentAttributeAnimated) {
                    z = true;
                } else if (documentAttribute instanceof TLRPC.TL_documentAttributeVideo) {
                    i = documentAttribute.w;
                    i2 = documentAttribute.w;
                }
            }
            if (!z || i > 1280 || i2 > 1280) {
                return false;
            }
            return true;
        }
        return false;
    }

    public void generateThumbs(boolean z) {
        ArrayList<TLRPC.PhotoSize> arrayList;
        ArrayList<TLRPC.PhotoSize> arrayList2;
        ArrayList<TLRPC.PhotoSize> arrayList3;
        ArrayList<TLRPC.PhotoSize> arrayList4;
        ArrayList<TLRPC.PhotoSize> arrayList5;
        ArrayList<TLRPC.PhotoSize> arrayList6;
        TLRPC.Message message = this.messageOwner;
        if (message instanceof TLRPC.TL_messageService) {
            if (message.action instanceof TLRPC.TL_messageActionChatEditPhoto) {
                TLRPC.Photo photo = this.messageOwner.action.photo;
                if (!z) {
                    this.photoThumbs = new ArrayList<>(photo.sizes);
                } else {
                    ArrayList<TLRPC.PhotoSize> arrayList7 = this.photoThumbs;
                    if (arrayList7 != null && !arrayList7.isEmpty()) {
                        for (int i = 0; i < this.photoThumbs.size(); i++) {
                            TLRPC.PhotoSize photoSize = this.photoThumbs.get(i);
                            int i2 = 0;
                            while (true) {
                                if (i2 >= photo.sizes.size()) {
                                    break;
                                }
                                TLRPC.PhotoSize photoSize2 = photo.sizes.get(i2);
                                if (!(photoSize2 instanceof TLRPC.TL_photoSizeEmpty) && photoSize2.type.equals(photoSize.type)) {
                                    photoSize.location = photoSize2.location;
                                    break;
                                }
                                i2++;
                            }
                        }
                    }
                }
                if (photo.dc_id != 0) {
                    int size = this.photoThumbs.size();
                    for (int i3 = 0; i3 < size; i3++) {
                        TLRPC.FileLocation fileLocation = this.photoThumbs.get(i3).location;
                        fileLocation.dc_id = photo.dc_id;
                        fileLocation.file_reference = photo.file_reference;
                    }
                }
                this.photoThumbsObject = this.messageOwner.action.photo;
            }
        } else if (this.emojiAnimatedSticker != null) {
            if (TextUtils.isEmpty(this.emojiAnimatedStickerColor) && isDocumentHasThumb(this.emojiAnimatedSticker)) {
                if (!z || (arrayList6 = this.photoThumbs) == null) {
                    ArrayList<TLRPC.PhotoSize> arrayList8 = new ArrayList<>();
                    this.photoThumbs = arrayList8;
                    arrayList8.addAll(this.emojiAnimatedSticker.thumbs);
                } else if (arrayList6 != null && !arrayList6.isEmpty()) {
                    updatePhotoSizeLocations(this.photoThumbs, this.emojiAnimatedSticker.thumbs);
                }
                this.photoThumbsObject = this.emojiAnimatedSticker;
            }
        } else if (message.media != null && !(this.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
            if (this.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
                TLRPC.Photo photo2 = this.messageOwner.media.photo;
                if (!z || !((arrayList5 = this.photoThumbs) == null || arrayList5.size() == photo2.sizes.size())) {
                    this.photoThumbs = new ArrayList<>(photo2.sizes);
                } else {
                    ArrayList<TLRPC.PhotoSize> arrayList9 = this.photoThumbs;
                    if (arrayList9 != null && !arrayList9.isEmpty()) {
                        for (int i4 = 0; i4 < this.photoThumbs.size(); i4++) {
                            TLRPC.PhotoSize photoSize3 = this.photoThumbs.get(i4);
                            if (photoSize3 != null) {
                                int i5 = 0;
                                while (true) {
                                    if (i5 >= photo2.sizes.size()) {
                                        break;
                                    }
                                    TLRPC.PhotoSize photoSize4 = photo2.sizes.get(i5);
                                    if (!(photoSize4 == null || (photoSize4 instanceof TLRPC.TL_photoSizeEmpty) || !photoSize4.type.equals(photoSize3.type))) {
                                        photoSize3.location = photoSize4.location;
                                        break;
                                    }
                                    i5++;
                                }
                            }
                        }
                    }
                }
                this.photoThumbsObject = this.messageOwner.media.photo;
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
                TLRPC.Document document = getDocument();
                if (isDocumentHasThumb(document)) {
                    if (!z || (arrayList4 = this.photoThumbs) == null) {
                        ArrayList<TLRPC.PhotoSize> arrayList10 = new ArrayList<>();
                        this.photoThumbs = arrayList10;
                        arrayList10.addAll(document.thumbs);
                    } else if (arrayList4 != null && !arrayList4.isEmpty()) {
                        updatePhotoSizeLocations(this.photoThumbs, document.thumbs);
                    }
                    this.photoThumbsObject = document;
                }
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
                TLRPC.Document document2 = this.messageOwner.media.game.document;
                if (document2 != null && isDocumentHasThumb(document2)) {
                    if (!z) {
                        ArrayList<TLRPC.PhotoSize> arrayList11 = new ArrayList<>();
                        this.photoThumbs = arrayList11;
                        arrayList11.addAll(document2.thumbs);
                    } else {
                        ArrayList<TLRPC.PhotoSize> arrayList12 = this.photoThumbs;
                        if (arrayList12 != null && !arrayList12.isEmpty()) {
                            updatePhotoSizeLocations(this.photoThumbs, document2.thumbs);
                        }
                    }
                    this.photoThumbsObject = document2;
                }
                TLRPC.Photo photo3 = this.messageOwner.media.game.photo;
                if (photo3 != null) {
                    if (!z || (arrayList3 = this.photoThumbs2) == null) {
                        this.photoThumbs2 = new ArrayList<>(photo3.sizes);
                    } else if (!arrayList3.isEmpty()) {
                        updatePhotoSizeLocations(this.photoThumbs2, photo3.sizes);
                    }
                    this.photoThumbsObject2 = photo3;
                }
                if (this.photoThumbs == null && (arrayList2 = this.photoThumbs2) != null) {
                    this.photoThumbs = arrayList2;
                    this.photoThumbs2 = null;
                    this.photoThumbsObject = this.photoThumbsObject2;
                    this.photoThumbsObject2 = null;
                }
            } else if (this.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
                TLRPC.Photo photo4 = this.messageOwner.media.webpage.photo;
                TLRPC.Document document3 = this.messageOwner.media.webpage.document;
                if (photo4 != null) {
                    if (!z || (arrayList = this.photoThumbs) == null) {
                        this.photoThumbs = new ArrayList<>(photo4.sizes);
                    } else if (!arrayList.isEmpty()) {
                        updatePhotoSizeLocations(this.photoThumbs, photo4.sizes);
                    }
                    this.photoThumbsObject = photo4;
                } else if (document3 != null && isDocumentHasThumb(document3)) {
                    if (!z) {
                        ArrayList<TLRPC.PhotoSize> arrayList13 = new ArrayList<>();
                        this.photoThumbs = arrayList13;
                        arrayList13.addAll(document3.thumbs);
                    } else {
                        ArrayList<TLRPC.PhotoSize> arrayList14 = this.photoThumbs;
                        if (arrayList14 != null && !arrayList14.isEmpty()) {
                            updatePhotoSizeLocations(this.photoThumbs, document3.thumbs);
                        }
                    }
                    this.photoThumbsObject = document3;
                }
            }
        }
    }

    private static void updatePhotoSizeLocations(ArrayList<TLRPC.PhotoSize> arrayList, ArrayList<TLRPC.PhotoSize> arrayList2) {
        int size = arrayList.size();
        for (int i = 0; i < size; i++) {
            TLRPC.PhotoSize photoSize = arrayList.get(i);
            int size2 = arrayList2.size();
            int i2 = 0;
            while (true) {
                if (i2 >= size2) {
                    break;
                }
                TLRPC.PhotoSize photoSize2 = arrayList2.get(i2);
                if (!((photoSize2 instanceof TLRPC.TL_photoSizeEmpty) || (photoSize2 instanceof TLRPC.TL_photoCachedSize) || !photoSize2.type.equals(photoSize.type))) {
                    photoSize.location = photoSize2.location;
                    break;
                }
                i2++;
            }
        }
    }

    public CharSequence replaceWithLink(CharSequence charSequence, String str, ArrayList<Integer> arrayList, AbstractMap<Integer, TLRPC.User> abstractMap, SparseArray<TLRPC.User> sparseArray) {
        if (TextUtils.indexOf(charSequence, str) < 0) {
            return charSequence;
        }
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("");
        for (int i = 0; i < arrayList.size(); i++) {
            TLRPC.User user = null;
            if (abstractMap != null) {
                user = abstractMap.get(arrayList.get(i));
            } else if (sparseArray != null) {
                user = sparseArray.get(arrayList.get(i).intValue());
            }
            if (user == null) {
                user = MessagesController.getInstance(this.currentAccount).getUser(arrayList.get(i));
            }
            if (user != null) {
                String name = UserObject.getName(user);
                int length = spannableStringBuilder.length();
                if (spannableStringBuilder.length() != 0) {
                    spannableStringBuilder.append((CharSequence) ", ");
                }
                spannableStringBuilder.append((CharSequence) name);
                spannableStringBuilder.setSpan(new URLSpanNoUnderlineBold("" + user.id), length, name.length() + length, 33);
            }
        }
        return TextUtils.replace(charSequence, new String[]{str}, new CharSequence[]{spannableStringBuilder});
    }

    public CharSequence replaceWithLink(CharSequence charSequence, String str, TLObject tLObject, int i, ClickableSpan clickableSpan) {
        String str2;
        String str3;
        int indexOf = TextUtils.indexOf(charSequence, str);
        if (indexOf < 0) {
            return charSequence;
        }
        if (tLObject instanceof TLRPC.User) {
            TLRPC.User user = (TLRPC.User) tLObject;
            if (user.id == UserConfig.getInstance(UserConfig.selectedAccount).clientUserId) {
                str3 = LocaleController.getString("YouSelf", R.string.YouSelf);
            } else {
                str3 = UserObject.getName(user);
            }
            str2 = "" + user.id;
        } else if (tLObject instanceof TLRPC.Chat) {
            TLRPC.Chat chat = (TLRPC.Chat) tLObject;
            str3 = chat.title;
            str2 = "" + (-chat.id);
        } else if (tLObject instanceof TLRPC.TL_game) {
            str3 = ((TLRPC.TL_game) tLObject).title;
            str2 = "game";
        } else {
            str2 = "0";
            str3 = "";
        }
        String charSequence2 = TextUtils.ellipsize(str3.replace('\n', ' '), Theme.chat_actionTextPaint, (float) AndroidUtilities.dp(150.0f), TextUtils.TruncateAt.END).toString();
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(TextUtils.replace(charSequence, new String[]{str}, new String[]{charSequence2}));
        Drawable drawable = Theme.chat_redpkgSamllIcon;
        if (drawable == null) {
            Theme.chat_redpkgSamllIcon = ApplicationLoader.applicationContext.getResources().getDrawable(R.mipmap.ic_red_small).mutate();
            drawable = Theme.chat_redpkgSamllIcon;
        }
        drawable.setBounds(0, 0, AndroidUtilities.dp(16.0f), AndroidUtilities.dp(18.0f));
        spannableStringBuilder.setSpan(new ImageSpan(drawable), 0, 1, 33);
        spannableStringBuilder.setSpan(new URLSpanNoUnderlineBold("" + str2), indexOf, charSequence2.length() + indexOf, 33);
        spannableStringBuilder.setSpan(new ForegroundColorSpan(Theme.getColor(Theme.key_chat_redpacketLinkServiceText)), indexOf, charSequence2.length() + indexOf, 33);
        if (clickableSpan != null) {
            spannableStringBuilder.setSpan(clickableSpan, spannableStringBuilder.length() - 2, spannableStringBuilder.length(), 33);
            spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#FFFE5548")), spannableStringBuilder.length() - 2, spannableStringBuilder.length(), 33);
        }
        if (i == 1) {
            spannableStringBuilder.append((CharSequence) ",您的红包已被领完");
        }
        return spannableStringBuilder;
    }

    public CharSequence replaceWithLink(CharSequence charSequence, String str, TLObject tLObject) {
        return replaceWithLink(charSequence, str, tLObject, false);
    }

    public CharSequence replaceWithLink(CharSequence charSequence, String str, TLObject tLObject, boolean z) {
        String str2;
        String str3;
        if (charSequence == null) {
            return "";
        }
        int indexOf = TextUtils.indexOf(charSequence, str);
        if (indexOf < 0) {
            return charSequence;
        }
        if (tLObject instanceof TLRPC.User) {
            TLRPC.User user = (TLRPC.User) tLObject;
            str3 = UserObject.getName(user);
            str2 = "" + user.id;
        } else if (tLObject instanceof TLRPC.Chat) {
            TLRPC.Chat chat = (TLRPC.Chat) tLObject;
            str3 = chat.title;
            str2 = "" + (-chat.id);
        } else if (tLObject instanceof TLRPC.TL_game) {
            str3 = ((TLRPC.TL_game) tLObject).title;
            str2 = "game";
        } else {
            str2 = "0";
            str3 = "";
        }
        String replace = str3.replace('\n', ' ');
        if (z) {
            replace = TextUtils.ellipsize(replace, Theme.chat_actionTextPaint, (float) AndroidUtilities.dp(150.0f), TextUtils.TruncateAt.END).toString();
        }
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(TextUtils.replace(charSequence, new String[]{str}, new String[]{replace}));
        spannableStringBuilder.setSpan(new URLSpanNoUnderlineBold("" + str2), indexOf, replace.length() + indexOf, 33);
        if (z) {
            spannableStringBuilder.setSpan(new ForegroundColorSpan(Theme.getColor(Theme.key_chat_redpacketLinkServiceText)), indexOf, replace.length() + indexOf, 33);
        }
        return spannableStringBuilder;
    }

    public String getExtension() {
        String fileName = getFileName();
        int lastIndexOf = fileName.lastIndexOf(46);
        String substring = lastIndexOf != -1 ? fileName.substring(lastIndexOf + 1) : null;
        if (substring == null || substring.length() == 0) {
            substring = getDocument().mime_type;
        }
        if (substring == null) {
            substring = "";
        }
        return substring.toUpperCase();
    }

    public String getFileName() {
        TLRPC.PhotoSize closestPhotoSizeWithSize;
        if (this.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
            return FileLoader.getAttachFileName(getDocument());
        }
        if (!(this.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto)) {
            return this.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage ? FileLoader.getAttachFileName(this.messageOwner.media.webpage.document) : "";
        }
        ArrayList<TLRPC.PhotoSize> arrayList = this.messageOwner.media.photo.sizes;
        if (arrayList.size() <= 0 || (closestPhotoSizeWithSize = FileLoader.getClosestPhotoSizeWithSize(arrayList, AndroidUtilities.getPhotoSize())) == null) {
            return "";
        }
        return FileLoader.getAttachFileName(closestPhotoSizeWithSize);
    }

    public int getFileType() {
        if (isVideo()) {
            return 2;
        }
        if (isVoice()) {
            return 1;
        }
        if (this.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
            return 3;
        }
        return this.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto ? 0 : 4;
    }

    private static boolean containsUrls(CharSequence charSequence) {
        if (charSequence != null && charSequence.length() >= 2 && charSequence.length() <= 20480) {
            int length = charSequence.length();
            int i = 0;
            int i2 = 0;
            int i3 = 0;
            int i4 = 0;
            char c = 0;
            while (i < length) {
                char charAt = charSequence.charAt(i);
                if (charAt >= '0' && charAt <= '9') {
                    i2++;
                    if (i2 >= 6) {
                        return true;
                    }
                    i3 = 0;
                    i4 = 0;
                } else if (charAt == ' ' || i2 <= 0) {
                    i2 = 0;
                }
                if ((charAt != '@' && charAt != '#' && charAt != '/' && charAt != '$') || i != 0) {
                    if (i != 0) {
                        int i5 = i - 1;
                        if (charSequence.charAt(i5) != ' ') {
                            if (charSequence.charAt(i5) == '\n') {
                            }
                        }
                    }
                    if (charAt != ':') {
                        if (charAt != '/') {
                            if (charAt == '.') {
                                if (i4 == 0 && c != ' ') {
                                    i4++;
                                }
                            } else if (charAt != ' ' && c == '.' && i4 == 1) {
                                return true;
                            }
                            i4 = 0;
                        } else if (i3 == 2) {
                            return true;
                        } else {
                            if (i3 == 1) {
                                i3++;
                            }
                        }
                        i++;
                        c = charAt;
                    } else if (i3 == 0) {
                        i3 = 1;
                        i++;
                        c = charAt;
                    }
                    i3 = 0;
                    i++;
                    c = charAt;
                }
                return true;
            }
        }
        return false;
    }

    /* JADX WARNING: Removed duplicated region for block: B:31:0x00a5  */
    /* JADX WARNING: Removed duplicated region for block: B:44:? A[RETURN, SYNTHETIC] */
    public void generateLinkDescription() {
        int i;
        if (this.linkDescription == null) {
            if ((this.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) && (this.messageOwner.media.webpage instanceof TLRPC.TL_webPage) && this.messageOwner.media.webpage.description != null) {
                this.linkDescription = Spannable.Factory.getInstance().newSpannable(this.messageOwner.media.webpage.description);
                String str = this.messageOwner.media.webpage.site_name;
                if (str != null) {
                    str = str.toLowerCase();
                }
                if ("instagram".equals(str)) {
                    i = 1;
                } else if ("twitter".equals(str)) {
                    i = 2;
                }
                if (TextUtils.isEmpty(this.linkDescription)) {
                    if (containsUrls(this.linkDescription)) {
                        try {
                            Linkify.addLinks((Spannable) this.linkDescription, 1);
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                    }
                    CharSequence replaceEmoji = Emoji.replaceEmoji(this.linkDescription, Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20.0f), false);
                    this.linkDescription = replaceEmoji;
                    if (i != 0) {
                        if (!(replaceEmoji instanceof Spannable)) {
                            this.linkDescription = new SpannableStringBuilder(this.linkDescription);
                        }
                        addUrlsByPattern(isOutOwner(), this.linkDescription, false, i, 0);
                        return;
                    }
                    return;
                }
                return;
            } else if ((this.messageOwner.media instanceof TLRPC.TL_messageMediaGame) && this.messageOwner.media.game.description != null) {
                this.linkDescription = Spannable.Factory.getInstance().newSpannable(this.messageOwner.media.game.description);
            } else if ((this.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) && this.messageOwner.media.description != null) {
                this.linkDescription = Spannable.Factory.getInstance().newSpannable(this.messageOwner.media.description);
            }
            i = 0;
            if (TextUtils.isEmpty(this.linkDescription)) {
            }
        }
    }

    public void generateCaption() {
        boolean z;
        if (this.caption == null && !isRoundVideo() && !isMediaEmpty() && !(this.messageOwner.media instanceof TLRPC.TL_messageMediaGame) && !TextUtils.isEmpty(this.messageOwner.message)) {
            CharSequence replaceEmoji = Emoji.replaceEmoji(this.messageOwner.message, Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20.0f), false);
            this.caption = replaceEmoji;
            if (replaceEmoji != null) {
                this.caption = updateMetionText(replaceEmoji, this.messageOwner.entities);
            }
            if (this.messageOwner.send_state != 0) {
                int i = 0;
                while (true) {
                    if (i >= this.messageOwner.entities.size()) {
                        z = false;
                        break;
                    } else if (!(this.messageOwner.entities.get(i) instanceof TLRPC.TL_inputMessageEntityMentionName)) {
                        z = true;
                        break;
                    } else {
                        i++;
                    }
                }
            } else {
                z = !this.messageOwner.entities.isEmpty();
            }
            boolean z2 = !z && (this.eventId != 0 || (this.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto_old) || (this.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto_layer68) || (this.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto_layer74) || (this.messageOwner.media instanceof TLRPC.TL_messageMediaDocument_old) || (this.messageOwner.media instanceof TLRPC.TL_messageMediaDocument_layer68) || (this.messageOwner.media instanceof TLRPC.TL_messageMediaDocument_layer74) || ((isOut() && this.messageOwner.send_state != 0) || this.messageOwner.id < 0));
            if (z2) {
                if (containsUrls(this.caption)) {
                    try {
                        Linkify.addLinks((Spannable) this.caption, 5);
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                }
                addUrlsByPattern(isOutOwner(), this.caption, true, 0, 0);
            }
            addEntitiesToText(this.caption, z2);
            if (isVideo()) {
                addUrlsByPattern(isOutOwner(), this.caption, true, 3, getDuration());
            }
        }
    }

    private static void addUrlsByPattern(boolean z, CharSequence charSequence, boolean z2, int i, int i2) {
        Matcher matcher;
        int i3 = 3;
        if (i == 3) {
            try {
                if (videoTimeUrlPattern == null) {
                    videoTimeUrlPattern = Pattern.compile("\\b(?:(\\d{1,2}):)?(\\d{1,3}):([0-5][0-9])\\b");
                }
                matcher = videoTimeUrlPattern.matcher(charSequence);
            } catch (Exception e) {
                FileLog.e(e);
                return;
            }
        } else if (i == 1) {
            if (instagramUrlPattern == null) {
                instagramUrlPattern = Pattern.compile("(^|\\s|\\()@[a-zA-Z\\d_.]{1,32}|(^|\\s|\\()#[\\w.]+");
            }
            matcher = instagramUrlPattern.matcher(charSequence);
        } else {
            if (urlPattern == null) {
                urlPattern = Pattern.compile("");
            }
            matcher = urlPattern.matcher(charSequence);
        }
        Spannable spannable = (Spannable) charSequence;
        while (matcher.find()) {
            int start = matcher.start();
            int end = matcher.end();
            Object obj = null;
            if (i == i3) {
                URLSpan[] uRLSpanArr = (URLSpan[]) spannable.getSpans(start, end, URLSpan.class);
                if (uRLSpanArr == null || uRLSpanArr.length <= 0) {
                    matcher.groupCount();
                    int start2 = matcher.start(1);
                    int end2 = matcher.end(1);
                    int start3 = matcher.start(2);
                    int end3 = matcher.end(2);
                    int start4 = matcher.start(i3);
                    int end4 = matcher.end(i3);
                    int intValue = Utilities.parseInt(charSequence.subSequence(start3, end3)).intValue();
                    int intValue2 = Utilities.parseInt(charSequence.subSequence(start4, end4)).intValue();
                    int intValue3 = (start2 < 0 || end2 < 0) ? -1 : Utilities.parseInt(charSequence.subSequence(start2, end2)).intValue();
                    int i4 = intValue2 + (intValue * 60);
                    if (intValue3 > 0) {
                        i4 += intValue3 * 60 * 60;
                    }
                    if (i4 <= i2) {
                        obj = new URLSpanNoUnderline("video?" + i4);
                    }
                }
            } else {
                char charAt = charSequence.charAt(start);
                if (i != 0) {
                    if (!(charAt == '@' || charAt == '#')) {
                        start++;
                    }
                    charAt = charSequence.charAt(start);
                    if (!(charAt == '@' || charAt == '#')) {
                    }
                } else if (!(charAt == '@' || charAt == '#' || charAt == '/' || charAt == '$')) {
                    start++;
                }
                if (i == 1) {
                    if (charAt == '@') {
                        obj = new URLSpanNoUnderline("https://instagram.com/" + charSequence.subSequence(start + 1, end).toString());
                    } else if (charAt == '#') {
                        obj = new URLSpanNoUnderline("https://www.instagram.com/explore/tags/" + charSequence.subSequence(start + 1, end).toString());
                    }
                } else if (i == 2) {
                    if (charAt == '@') {
                        obj = new URLSpanNoUnderline("https://twitter.com/" + charSequence.subSequence(start + 1, end).toString());
                    } else if (charAt == '#') {
                        obj = new URLSpanNoUnderline("https://twitter.com/hashtag/" + charSequence.subSequence(start + 1, end).toString());
                    }
                } else if (charSequence.charAt(start) != '/') {
                    obj = new URLSpanNoUnderline(charSequence.subSequence(start, end).toString());
                } else if (z2) {
                    obj = new URLSpanBotCommand(charSequence.subSequence(start, end).toString(), z ? 1 : 0);
                }
            }
            if (obj != null) {
                spannable.setSpan(obj, start, end, 0);
            }
            i3 = 3;
        }
    }

    public static int[] getWebDocumentWidthAndHeight(TLRPC.WebDocument webDocument) {
        if (webDocument == null) {
            return null;
        }
        int size = webDocument.attributes.size();
        for (int i = 0; i < size; i++) {
            TLRPC.DocumentAttribute documentAttribute = webDocument.attributes.get(i);
            if (documentAttribute instanceof TLRPC.TL_documentAttributeImageSize) {
                return new int[]{documentAttribute.w, documentAttribute.h};
            } else if (documentAttribute instanceof TLRPC.TL_documentAttributeVideo) {
                return new int[]{documentAttribute.w, documentAttribute.h};
            }
        }
        return null;
    }

    public static int getWebDocumentDuration(TLRPC.WebDocument webDocument) {
        if (webDocument == null) {
            return 0;
        }
        int size = webDocument.attributes.size();
        for (int i = 0; i < size; i++) {
            TLRPC.DocumentAttribute documentAttribute = webDocument.attributes.get(i);
            if (documentAttribute instanceof TLRPC.TL_documentAttributeVideo) {
                return documentAttribute.duration;
            }
            if (documentAttribute instanceof TLRPC.TL_documentAttributeAudio) {
                return documentAttribute.duration;
            }
        }
        return 0;
    }

    public static int[] getInlineResultWidthAndHeight(TLRPC.BotInlineResult botInlineResult) {
        int[] webDocumentWidthAndHeight = getWebDocumentWidthAndHeight(botInlineResult.content);
        if (webDocumentWidthAndHeight != null) {
            return webDocumentWidthAndHeight;
        }
        int[] webDocumentWidthAndHeight2 = getWebDocumentWidthAndHeight(botInlineResult.thumb);
        if (webDocumentWidthAndHeight2 == null) {
            return new int[]{0, 0};
        }
        return webDocumentWidthAndHeight2;
    }

    public static int getInlineResultDuration(TLRPC.BotInlineResult botInlineResult) {
        int webDocumentDuration = getWebDocumentDuration(botInlineResult.content);
        return webDocumentDuration == 0 ? getWebDocumentDuration(botInlineResult.thumb) : webDocumentDuration;
    }

    public boolean hasValidGroupId() {
        ArrayList<TLRPC.PhotoSize> arrayList;
        return (getGroupId() == 0 || (arrayList = this.photoThumbs) == null || arrayList.isEmpty()) ? false : true;
    }

    public long getGroupIdForUse() {
        long j = this.localSentGroupId;
        return j != 0 ? j : this.messageOwner.grouped_id;
    }

    public long getGroupId() {
        long j = this.localGroupId;
        return j != 0 ? j : getGroupIdForUse();
    }

    public static void addLinks(boolean z, CharSequence charSequence) {
        addLinks(z, charSequence, true);
    }

    public static void addLinks(boolean z, CharSequence charSequence, boolean z2) {
        if ((charSequence instanceof Spannable) && containsUrls(charSequence)) {
            if (charSequence.length() < 1000) {
                try {
                    Linkify.addLinks((Spannable) charSequence, 5);
                } catch (Exception e) {
                    FileLog.e(e);
                }
            } else {
                try {
                    Linkify.addLinks((Spannable) charSequence, 1);
                } catch (Exception e2) {
                    FileLog.e(e2);
                }
            }
            addUrlsByPattern(z, charSequence, z2, 0, 0);
        }
    }

    public void resetPlayingProgress() {
        this.audioProgress = 0.0f;
        this.audioProgressSec = 0;
        this.bufferedProgress = 0.0f;
    }

    private boolean addEntitiesToText(CharSequence charSequence, boolean z) {
        return addEntitiesToText(charSequence, false, z);
    }

    public boolean addEntitiesToText(CharSequence charSequence, boolean z, boolean z2) {
        if (!this.isRestrictedMessage) {
            return addEntitiesToText(charSequence, this.entitiesCopy, isOutOwner(), this.type, true, z, z2);
        }
        ArrayList arrayList = new ArrayList();
        TLRPC.TL_messageEntityItalic tL_messageEntityItalic = new TLRPC.TL_messageEntityItalic();
        tL_messageEntityItalic.offset = 0;
        tL_messageEntityItalic.length = charSequence.length();
        arrayList.add(tL_messageEntityItalic);
        return addEntitiesToText(charSequence, arrayList, isOutOwner(), this.type, true, z, z2);
    }

    /* JADX WARNING: Removed duplicated region for block: B:112:0x016e  */
    /* JADX WARNING: Removed duplicated region for block: B:137:0x021b  */
    /* JADX WARNING: Removed duplicated region for block: B:192:0x0220 A[SYNTHETIC] */
    public static boolean addEntitiesToText(CharSequence charSequence, ArrayList<TLRPC.MessageEntity> arrayList, boolean z, int i, boolean z2, boolean z3, boolean z4) {
        int size;
        int i2;
        if (!(charSequence instanceof Spannable)) {
            return false;
        }
        Spannable spannable = (Spannable) charSequence;
        URLSpan[] uRLSpanArr = (URLSpan[]) spannable.getSpans(0, charSequence.length(), URLSpan.class);
        boolean z5 = uRLSpanArr != null && uRLSpanArr.length > 0;
        if (arrayList.isEmpty()) {
            return z5;
        }
        byte b = z3 ? 2 : z ? (byte) 1 : 0;
        ArrayList arrayList2 = new ArrayList();
        ArrayList arrayList3 = new ArrayList(arrayList);
        Collections.sort(arrayList3, $$Lambda$MessageObject$dudtksQJp6BqH6_Qpe2ND6HzeG8.INSTANCE);
        int size2 = arrayList3.size();
        for (int i3 = 0; i3 < size2; i3++) {
            TLRPC.MessageEntity messageEntity = (TLRPC.MessageEntity) arrayList3.get(i3);
            if (messageEntity.length > 0 && messageEntity.offset >= 0 && messageEntity.offset < charSequence.length()) {
                if (messageEntity.offset + messageEntity.length > charSequence.length()) {
                    messageEntity.length = charSequence.length() - messageEntity.offset;
                }
                if ((!z4 || (messageEntity instanceof TLRPC.TL_messageEntityBold) || (messageEntity instanceof TLRPC.TL_messageEntityItalic) || (messageEntity instanceof TLRPC.TL_messageEntityStrike) || (messageEntity instanceof TLRPC.TL_messageEntityUnderline) || (messageEntity instanceof TLRPC.TL_messageEntityBlockquote) || (messageEntity instanceof TLRPC.TL_messageEntityCode) || (messageEntity instanceof TLRPC.TL_messageEntityPre) || (messageEntity instanceof TLRPC.TL_messageEntityMentionName) || (messageEntity instanceof TLRPC.TL_inputMessageEntityMentionName) || (messageEntity instanceof TLRPC.TL_messageEntityTextUrl)) && uRLSpanArr != null && uRLSpanArr.length > 0) {
                    for (int i4 = 0; i4 < uRLSpanArr.length; i4++) {
                        if (uRLSpanArr[i4] != null) {
                            int spanStart = spannable.getSpanStart(uRLSpanArr[i4]);
                            int spanEnd = spannable.getSpanEnd(uRLSpanArr[i4]);
                            if ((messageEntity.offset <= spanStart && messageEntity.offset + messageEntity.length >= spanStart) || (messageEntity.offset <= spanEnd && messageEntity.offset + messageEntity.length >= spanEnd)) {
                                spannable.removeSpan(uRLSpanArr[i4]);
                                uRLSpanArr[i4] = null;
                            }
                        }
                    }
                }
                TextStyleSpan.TextStyleRun textStyleRun = new TextStyleSpan.TextStyleRun();
                textStyleRun.start = messageEntity.offset;
                textStyleRun.end = textStyleRun.start + messageEntity.length;
                if (messageEntity instanceof TLRPC.TL_messageEntityStrike) {
                    textStyleRun.flags = 8;
                } else if (messageEntity instanceof TLRPC.TL_messageEntityUnderline) {
                    textStyleRun.flags = 16;
                } else if (messageEntity instanceof TLRPC.TL_messageEntityBlockquote) {
                    textStyleRun.flags = 32;
                } else if (messageEntity instanceof TLRPC.TL_messageEntityBold) {
                    textStyleRun.flags = 1;
                } else {
                    if (messageEntity instanceof TLRPC.TL_messageEntityItalic) {
                        textStyleRun.flags = 2;
                    } else if ((messageEntity instanceof TLRPC.TL_messageEntityCode) || (messageEntity instanceof TLRPC.TL_messageEntityPre)) {
                        textStyleRun.flags = 4;
                    } else if (messageEntity instanceof TLRPC.TL_messageEntityMentionName) {
                        if (z2) {
                            textStyleRun.flags = 64;
                            textStyleRun.urlEntity = messageEntity;
                        }
                    } else if (messageEntity instanceof TLRPC.TL_inputMessageEntityMentionName) {
                        if (z2) {
                            textStyleRun.flags = 64;
                            textStyleRun.urlEntity = messageEntity;
                        }
                    } else if ((!z4 || (messageEntity instanceof TLRPC.TL_messageEntityTextUrl)) && (((!(messageEntity instanceof TLRPC.TL_messageEntityUrl) && !(messageEntity instanceof TLRPC.TL_messageEntityTextUrl)) || !Browser.isPassportUrl(messageEntity.url)) && (!(messageEntity instanceof TLRPC.TL_messageEntityMention) || z2))) {
                        textStyleRun.flags = 128;
                        textStyleRun.urlEntity = messageEntity;
                    }
                    size = arrayList2.size();
                    i2 = 0;
                    while (i2 < size) {
                        TextStyleSpan.TextStyleRun textStyleRun2 = (TextStyleSpan.TextStyleRun) arrayList2.get(i2);
                        if (textStyleRun.start > textStyleRun2.start) {
                            if (textStyleRun.start < textStyleRun2.end) {
                                if (textStyleRun.end < textStyleRun2.end) {
                                    TextStyleSpan.TextStyleRun textStyleRun3 = new TextStyleSpan.TextStyleRun(textStyleRun);
                                    textStyleRun3.merge(textStyleRun2);
                                    int i5 = i2 + 1;
                                    arrayList2.add(i5, textStyleRun3);
                                    TextStyleSpan.TextStyleRun textStyleRun4 = new TextStyleSpan.TextStyleRun(textStyleRun2);
                                    textStyleRun4.start = textStyleRun.end;
                                    i2 = i5 + 1;
                                    size = size + 1 + 1;
                                    arrayList2.add(i2, textStyleRun4);
                                } else if (textStyleRun.end >= textStyleRun2.end) {
                                    TextStyleSpan.TextStyleRun textStyleRun5 = new TextStyleSpan.TextStyleRun(textStyleRun);
                                    textStyleRun5.merge(textStyleRun2);
                                    textStyleRun5.end = textStyleRun2.end;
                                    i2++;
                                    size++;
                                    arrayList2.add(i2, textStyleRun5);
                                }
                                int i6 = textStyleRun.start;
                                textStyleRun.start = textStyleRun2.end;
                                textStyleRun2.end = i6;
                            }
                        } else if (textStyleRun2.start < textStyleRun.end) {
                            int i7 = textStyleRun2.start;
                            if (textStyleRun.end == textStyleRun2.end) {
                                textStyleRun2.merge(textStyleRun);
                            } else if (textStyleRun.end < textStyleRun2.end) {
                                TextStyleSpan.TextStyleRun textStyleRun6 = new TextStyleSpan.TextStyleRun(textStyleRun2);
                                textStyleRun6.merge(textStyleRun);
                                textStyleRun6.end = textStyleRun.end;
                                i2++;
                                size++;
                                arrayList2.add(i2, textStyleRun6);
                                textStyleRun2.start = textStyleRun.end;
                            } else {
                                TextStyleSpan.TextStyleRun textStyleRun7 = new TextStyleSpan.TextStyleRun(textStyleRun);
                                textStyleRun7.start = textStyleRun2.end;
                                i2++;
                                size++;
                                arrayList2.add(i2, textStyleRun7);
                                textStyleRun2.merge(textStyleRun);
                            }
                            textStyleRun.end = i7;
                        }
                        i2++;
                    }
                    if (textStyleRun.start >= textStyleRun.end) {
                        arrayList2.add(textStyleRun);
                    }
                }
                size = arrayList2.size();
                i2 = 0;
                while (i2 < size) {
                }
                if (textStyleRun.start >= textStyleRun.end) {
                }
            }
        }
        int size3 = arrayList2.size();
        for (int i8 = 0; i8 < size3; i8++) {
            TextStyleSpan.TextStyleRun textStyleRun8 = (TextStyleSpan.TextStyleRun) arrayList2.get(i8);
            String substring = textStyleRun8.urlEntity != null ? TextUtils.substring(charSequence, textStyleRun8.urlEntity.offset, textStyleRun8.urlEntity.offset + textStyleRun8.urlEntity.length) : null;
            if (textStyleRun8.urlEntity instanceof TLRPC.TL_messageEntityBotCommand) {
                spannable.setSpan(new URLSpanBotCommand(substring, b, textStyleRun8), textStyleRun8.start, textStyleRun8.end, 33);
            } else if ((textStyleRun8.urlEntity instanceof TLRPC.TL_messageEntityHashtag) || (textStyleRun8.urlEntity instanceof TLRPC.TL_messageEntityMention) || (textStyleRun8.urlEntity instanceof TLRPC.TL_messageEntityCashtag)) {
                spannable.setSpan(new URLSpanNoUnderline(substring, textStyleRun8), textStyleRun8.start, textStyleRun8.end, 33);
            } else if (textStyleRun8.urlEntity instanceof TLRPC.TL_messageEntityEmail) {
                spannable.setSpan(new URLSpanReplacement("mailto:" + substring, textStyleRun8), textStyleRun8.start, textStyleRun8.end, 33);
            } else {
                if (textStyleRun8.urlEntity instanceof TLRPC.TL_messageEntityUrl) {
                    if (substring.toLowerCase().startsWith("http") || substring.toLowerCase().startsWith("hchat://")) {
                        spannable.setSpan(new URLSpanBrowser(substring, textStyleRun8), textStyleRun8.start, textStyleRun8.end, 33);
                    } else {
                        spannable.setSpan(new URLSpanBrowser("http://" + substring, textStyleRun8), textStyleRun8.start, textStyleRun8.end, 33);
                    }
                } else if (textStyleRun8.urlEntity instanceof TLRPC.TL_messageEntityPhone) {
                    String stripExceptNumbers = PhoneFormat.stripExceptNumbers(substring);
                    if (substring.startsWith(Marker.ANY_NON_NULL_MARKER)) {
                        stripExceptNumbers = Marker.ANY_NON_NULL_MARKER + stripExceptNumbers;
                    }
                    spannable.setSpan(new URLSpanBrowser("tel:" + stripExceptNumbers, textStyleRun8), textStyleRun8.start, textStyleRun8.end, 33);
                } else if (textStyleRun8.urlEntity instanceof TLRPC.TL_messageEntityTextUrl) {
                    spannable.setSpan(new URLSpanReplacement(textStyleRun8.urlEntity.url, textStyleRun8), textStyleRun8.start, textStyleRun8.end, 33);
                } else if (textStyleRun8.urlEntity instanceof TLRPC.TL_messageEntityMentionName) {
                    spannable.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_messageEntityMentionName) textStyleRun8.urlEntity).user_id, b, textStyleRun8), textStyleRun8.start, textStyleRun8.end, 33);
                } else if (textStyleRun8.urlEntity instanceof TLRPC.TL_inputMessageEntityMentionName) {
                    spannable.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_inputMessageEntityMentionName) textStyleRun8.urlEntity).user_id.user_id, b, textStyleRun8), textStyleRun8.start, textStyleRun8.end, 33);
                } else {
                    if ((textStyleRun8.flags & 4) != 0) {
                        spannable.setSpan(new URLSpanMono(spannable, textStyleRun8.start, textStyleRun8.end, b, textStyleRun8), textStyleRun8.start, textStyleRun8.end, 33);
                    } else {
                        spannable.setSpan(new TextStyleSpan(textStyleRun8), textStyleRun8.start, textStyleRun8.end, 33);
                    }
                }
                z5 = true;
            }
        }
        return z5;
    }

    static /* synthetic */ int lambda$addEntitiesToText$2(TLRPC.MessageEntity messageEntity, TLRPC.MessageEntity messageEntity2) {
        if (messageEntity.offset > messageEntity2.offset) {
            return 1;
        }
        return messageEntity.offset < messageEntity2.offset ? -1 : 0;
    }

    public boolean needDrawShareButton() {
        int i;
        TLRPC.Chat chat;
        if (this.scheduled || this.eventId != 0) {
            return false;
        }
        if (this.messageOwner.fwd_from != null && !isOutOwner() && this.messageOwner.fwd_from.saved_from_peer != null && getDialogId() == ((long) UserConfig.getInstance(this.currentAccount).getClientUserId())) {
            return true;
        }
        int i2 = this.type;
        if (!(i2 == 13 || i2 == 15)) {
            if (this.messageOwner.fwd_from != null && this.messageOwner.fwd_from.channel_id != 0 && !isOutOwner()) {
                return true;
            }
            if (isFromUser()) {
                if ((this.messageOwner.media instanceof TLRPC.TL_messageMediaEmpty) || this.messageOwner.media == null || ((this.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) && !(this.messageOwner.media.webpage instanceof TLRPC.TL_webPage))) {
                    return false;
                }
                TLRPC.User user = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(this.messageOwner.from_id));
                if (user != null && user.bot) {
                    return true;
                }
                if (!isOut()) {
                    if ((this.messageOwner.media instanceof TLRPC.TL_messageMediaGame) || (this.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice)) {
                        return true;
                    }
                    if (!isMegagroup() || (chat = MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(this.messageOwner.to_id.channel_id))) == null || chat.username == null || chat.username.length() <= 0 || (this.messageOwner.media instanceof TLRPC.TL_messageMediaContact) || (this.messageOwner.media instanceof TLRPC.TL_messageMediaGeo)) {
                        return false;
                    }
                    return true;
                }
            } else if ((this.messageOwner.from_id < 0 || this.messageOwner.post) && this.messageOwner.to_id.channel_id != 0 && ((this.messageOwner.via_bot_id == 0 && this.messageOwner.reply_to_msg_id == 0) || !((i = this.type) == 13 || i == 15))) {
                return true;
            }
        }
        return false;
    }

    public boolean isYouTubeVideo() {
        return (this.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) && this.messageOwner.media.webpage != null && !TextUtils.isEmpty(this.messageOwner.media.webpage.embed_url) && "YouTube".equals(this.messageOwner.media.webpage.site_name);
    }

    public int getMaxMessageTextWidth() {
        int dp;
        if (!AndroidUtilities.isTablet() || this.eventId == 0) {
            this.generatedWithMinSize = AndroidUtilities.isTablet() ? AndroidUtilities.getMinTabletSide() : AndroidUtilities.displaySize.x;
        } else {
            this.generatedWithMinSize = AndroidUtilities.dp(530.0f);
        }
        this.generatedWithDensity = AndroidUtilities.density;
        int i = 0;
        if ((this.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) && this.messageOwner.media.webpage != null && "app_background".equals(this.messageOwner.media.webpage.type)) {
            try {
                Uri parse = Uri.parse(this.messageOwner.media.webpage.url);
                if (parse.getQueryParameter("bg_color") != null) {
                    dp = AndroidUtilities.dp(220.0f);
                } else if (parse.getLastPathSegment().length() == 6) {
                    dp = AndroidUtilities.dp(200.0f);
                }
                i = dp;
            } catch (Exception unused) {
            }
        } else if (isAndroidTheme()) {
            i = AndroidUtilities.dp(200.0f);
        }
        if (i != 0) {
            return i;
        }
        int dp2 = this.generatedWithMinSize - AndroidUtilities.dp(147.0f);
        if (needDrawShareButton() && !isOutOwner()) {
            dp2 -= AndroidUtilities.dp(10.0f);
        }
        return this.messageOwner.media instanceof TLRPC.TL_messageMediaGame ? dp2 - AndroidUtilities.dp(10.0f) : dp2;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:35:0x007a, code lost:
        if (r29.messageOwner.send_state == 0) goto L_0x007c;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:39:0x0088, code lost:
        if ((r29.messageOwner.media instanceof im.guobwnxjuc.tgnet.TLRPC.TL_messageMediaUnsupported) == false) goto L_0x008c;
     */
    /* JADX WARNING: Removed duplicated region for block: B:127:0x02f9 A[SYNTHETIC, Splitter:B:127:0x02f9] */
    /* JADX WARNING: Removed duplicated region for block: B:132:0x031c  */
    /* JADX WARNING: Removed duplicated region for block: B:137:0x033f  */
    /* JADX WARNING: Removed duplicated region for block: B:160:0x037f  */
    /* JADX WARNING: Removed duplicated region for block: B:163:0x0384  */
    /* JADX WARNING: Removed duplicated region for block: B:166:0x0390  */
    /* JADX WARNING: Removed duplicated region for block: B:202:0x0445  */
    /* JADX WARNING: Removed duplicated region for block: B:43:0x008f  */
    /* JADX WARNING: Removed duplicated region for block: B:44:0x0099  */
    /* JADX WARNING: Removed duplicated region for block: B:66:0x00ff  */
    /* JADX WARNING: Removed duplicated region for block: B:67:0x0102  */
    /* JADX WARNING: Removed duplicated region for block: B:72:0x010b A[Catch:{ Exception -> 0x04ce }] */
    /* JADX WARNING: Removed duplicated region for block: B:73:0x012e A[Catch:{ Exception -> 0x04ce }] */
    /* JADX WARNING: Removed duplicated region for block: B:76:0x0154 A[Catch:{ Exception -> 0x04ce }] */
    /* JADX WARNING: Removed duplicated region for block: B:83:0x01a3  */
    /* JADX WARNING: Removed duplicated region for block: B:88:0x01c5  */
    /* JADX WARNING: Removed duplicated region for block: B:89:0x01c7  */
    /* JADX WARNING: Removed duplicated region for block: B:92:0x01db  */
    public void generateLayout(TLRPC.User user) {
        boolean z;
        StaticLayout staticLayout;
        TextPaint textPaint;
        StaticLayout staticLayout2;
        int i;
        TextPaint textPaint2;
        StaticLayout staticLayout3;
        int i2;
        int i3;
        int i4;
        StaticLayout staticLayout4;
        boolean z2;
        TextPaint textPaint3;
        int i5;
        int i6;
        int i7;
        int i8;
        int i9;
        int i10;
        StaticLayout staticLayout5;
        int i11;
        TextLayoutBlock textLayoutBlock;
        float f;
        float f2;
        int ceil;
        int i12;
        int i13;
        int i14;
        float f3;
        float f4;
        int i15;
        int i16;
        float f5;
        Exception e;
        int i17;
        Exception e2;
        int i18;
        MessageObject messageObject;
        int i19 = this.type;
        if ((i19 == 0 || i19 == 2 || TextUtils.isEmpty(this.messageOwner.trans)) && this.messageOwner.to_id != null && !TextUtils.isEmpty(this.messageText)) {
            generateLinkDescription();
            this.textLayoutBlocks = new ArrayList<>();
            int i20 = 0;
            this.textWidth = 0;
            int i21 = 1;
            if (!(this.messageOwner.send_state != 0 ? false : !this.messageOwner.entities.isEmpty())) {
                if (this.eventId == 0) {
                    TLRPC.Message message = this.messageOwner;
                    if (!(message instanceof TLRPC.TL_message_old)) {
                        if (!(message instanceof TLRPC.TL_message_old2)) {
                            if (!(message instanceof TLRPC.TL_message_old3)) {
                                if (!(message instanceof TLRPC.TL_message_old4)) {
                                    if (!(message instanceof TLRPC.TL_messageForwarded_old)) {
                                        if (!(message instanceof TLRPC.TL_messageForwarded_old2)) {
                                            if (!(message instanceof TLRPC.TL_message_secret)) {
                                                if (!(message.media instanceof TLRPC.TL_messageMediaInvoice)) {
                                                    if (isOut()) {
                                                    }
                                                    if (this.messageOwner.id >= 0) {
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                z = true;
                if (!z) {
                    addLinks(isOutOwner(), this.messageText);
                } else {
                    CharSequence charSequence = this.messageText;
                    if ((charSequence instanceof Spannable) && charSequence.length() < 1000) {
                        try {
                            Linkify.addLinks((Spannable) this.messageText, 4);
                        } catch (Throwable th) {
                            FileLog.e(th);
                        }
                    }
                }
                if (!isYouTubeVideo() || ((messageObject = this.replyMessageObject) != null && messageObject.isYouTubeVideo())) {
                    addUrlsByPattern(isOutOwner(), this.messageText, false, 3, Integer.MAX_VALUE);
                } else {
                    MessageObject messageObject2 = this.replyMessageObject;
                    if (messageObject2 != null && messageObject2.isVideo()) {
                        addUrlsByPattern(isOutOwner(), this.messageText, false, 3, this.replyMessageObject.getDuration());
                    }
                }
                boolean addEntitiesToText = addEntitiesToText(this.messageText, z);
                int maxMessageTextWidth = getMaxMessageTextWidth();
                staticLayout = null;
                if (!(this.messageOwner.media instanceof TLRPC.TL_messageMediaGame)) {
                    textPaint = Theme.chat_msgGameTextPaint;
                } else {
                    textPaint = Theme.chat_msgTextPaint;
                }
                if (Build.VERSION.SDK_INT < 24) {
                    textPaint2 = textPaint;
                    i = 24;
                    staticLayout2 = StaticLayout.Builder.obtain(this.messageText, 0, this.messageText.length(), textPaint, maxMessageTextWidth).setBreakStrategy(1).setHyphenationFrequency(0).setAlignment(Layout.Alignment.ALIGN_NORMAL).build();
                } else {
                    i = 24;
                    textPaint2 = textPaint;
                    staticLayout2 = new StaticLayout(this.messageText, textPaint, maxMessageTextWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
                }
                if (!TextUtils.isEmpty(this.messageOwner.trans)) {
                    if (Build.VERSION.SDK_INT >= i) {
                        staticLayout = StaticLayout.Builder.obtain(this.messageOwner.trans, 0, this.messageOwner.trans.length(), textPaint2, maxMessageTextWidth).setBreakStrategy(1).setHyphenationFrequency(0).setAlignment(Layout.Alignment.ALIGN_NORMAL).build();
                    } else {
                        staticLayout3 = staticLayout2;
                        staticLayout = new StaticLayout(this.messageOwner.trans, textPaint2, maxMessageTextWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
                        this.textHeight = staticLayout3.getHeight();
                        this.linesCount = staticLayout3.getLineCount();
                        if (staticLayout != null) {
                            this.transHeight = staticLayout.getHeight();
                            int lineCount = staticLayout.getLineCount();
                            for (int i22 = 0; i22 < lineCount; i22++) {
                                this.transWidth = (int) Math.max((float) this.transWidth, staticLayout.getLineMax(i22));
                            }
                        }
                        if (Build.VERSION.SDK_INT >= i) {
                            i2 = 1;
                        } else {
                            i2 = (int) Math.ceil((double) (((float) this.linesCount) / 10.0f));
                        }
                        float f6 = 0.0f;
                        int i23 = 0;
                        i3 = 0;
                        float f7 = 0.0f;
                        while (i3 < i2) {
                            if (Build.VERSION.SDK_INT >= i) {
                                i4 = this.linesCount;
                            } else {
                                i4 = Math.min(10, this.linesCount - i23);
                            }
                            TextLayoutBlock textLayoutBlock2 = new TextLayoutBlock();
                            if (i2 == i21) {
                                textLayoutBlock2.textLayout = staticLayout3;
                                textLayoutBlock2.textYOffset = f6;
                                textLayoutBlock2.charactersOffset = i20;
                                int i24 = this.emojiOnlyCount;
                                if (i24 != 0) {
                                    if (i24 == i21) {
                                        this.textHeight -= AndroidUtilities.dp(5.3f);
                                        textLayoutBlock2.textYOffset -= (float) AndroidUtilities.dp(5.3f);
                                    } else if (i24 == 2) {
                                        this.textHeight -= AndroidUtilities.dp(4.5f);
                                        textLayoutBlock2.textYOffset -= (float) AndroidUtilities.dp(4.5f);
                                    } else if (i24 == 3) {
                                        this.textHeight -= AndroidUtilities.dp(4.2f);
                                        textLayoutBlock2.textYOffset -= (float) AndroidUtilities.dp(4.2f);
                                    }
                                }
                                textLayoutBlock2.height = this.textHeight;
                                textPaint3 = textPaint2;
                                staticLayout5 = staticLayout3;
                                textLayoutBlock = textLayoutBlock2;
                                i11 = i23;
                                i6 = i3;
                                i7 = i2;
                                i9 = maxMessageTextWidth;
                                i10 = i4;
                            } else {
                                int lineStart = staticLayout3.getLineStart(i23);
                                int lineEnd = staticLayout3.getLineEnd((i23 + i4) - i21);
                                if (lineEnd < lineStart) {
                                    textPaint3 = textPaint2;
                                    z2 = addEntitiesToText;
                                    staticLayout4 = staticLayout3;
                                    i17 = i23;
                                    i6 = i3;
                                    i7 = i2;
                                    i5 = maxMessageTextWidth;
                                } else {
                                    textLayoutBlock2.charactersOffset = lineStart;
                                    textLayoutBlock2.charactersEnd = lineEnd;
                                    if (addEntitiesToText) {
                                        try {
                                            if (Build.VERSION.SDK_INT >= i) {
                                                textLayoutBlock2.textLayout = StaticLayout.Builder.obtain(this.messageText, lineStart, lineEnd, textPaint2, maxMessageTextWidth + AndroidUtilities.dp(2.0f)).setBreakStrategy(i21).setHyphenationFrequency(i20).setAlignment(Layout.Alignment.ALIGN_NORMAL).build();
                                                textPaint3 = textPaint2;
                                                staticLayout5 = staticLayout3;
                                                textLayoutBlock = textLayoutBlock2;
                                                i11 = i23;
                                                i18 = i3;
                                                i7 = i2;
                                                i9 = maxMessageTextWidth;
                                                try {
                                                    textLayoutBlock.textYOffset = (float) staticLayout5.getLineTop(i11);
                                                    i6 = i18;
                                                    if (i6 != 0) {
                                                        try {
                                                            textLayoutBlock.height = (int) (textLayoutBlock.textYOffset - f7);
                                                        } catch (Exception e3) {
                                                            e2 = e3;
                                                            i17 = i11;
                                                            z2 = addEntitiesToText;
                                                            staticLayout4 = staticLayout5;
                                                            i5 = i9;
                                                            FileLog.e(e2);
                                                            i8 = i17;
                                                            i3 = i6 + 1;
                                                            i23 = i8;
                                                            i2 = i7;
                                                            maxMessageTextWidth = i5;
                                                            textPaint2 = textPaint3;
                                                            addEntitiesToText = z2;
                                                            staticLayout3 = staticLayout4;
                                                            i20 = 0;
                                                            i21 = 1;
                                                            i = 24;
                                                            f6 = 0.0f;
                                                        }
                                                    }
                                                    textLayoutBlock.height = Math.max(textLayoutBlock.height, textLayoutBlock.textLayout.getLineBottom(textLayoutBlock.textLayout.getLineCount() - 1));
                                                    float f8 = textLayoutBlock.textYOffset;
                                                    if (i6 != i7 - 1) {
                                                        i10 = Math.max(i4, textLayoutBlock.textLayout.getLineCount());
                                                        try {
                                                            this.textHeight = Math.max(this.textHeight, (int) (textLayoutBlock.textYOffset + ((float) textLayoutBlock.textLayout.getHeight())));
                                                        } catch (Exception e4) {
                                                            FileLog.e(e4);
                                                        }
                                                    } else {
                                                        i10 = i4;
                                                    }
                                                    f7 = f8;
                                                } catch (Exception e5) {
                                                    e2 = e5;
                                                    i17 = i11;
                                                    z2 = addEntitiesToText;
                                                    staticLayout4 = staticLayout5;
                                                    i6 = i18;
                                                    i5 = i9;
                                                    FileLog.e(e2);
                                                    i8 = i17;
                                                    i3 = i6 + 1;
                                                    i23 = i8;
                                                    i2 = i7;
                                                    maxMessageTextWidth = i5;
                                                    textPaint2 = textPaint3;
                                                    addEntitiesToText = z2;
                                                    staticLayout3 = staticLayout4;
                                                    i20 = 0;
                                                    i21 = 1;
                                                    i = 24;
                                                    f6 = 0.0f;
                                                }
                                            }
                                        } catch (Exception e6) {
                                            e2 = e6;
                                            textPaint3 = textPaint2;
                                            z2 = addEntitiesToText;
                                            staticLayout4 = staticLayout3;
                                            i17 = i23;
                                            i6 = i3;
                                            i7 = i2;
                                            i5 = maxMessageTextWidth;
                                            FileLog.e(e2);
                                            i8 = i17;
                                            i3 = i6 + 1;
                                            i23 = i8;
                                            i2 = i7;
                                            maxMessageTextWidth = i5;
                                            textPaint2 = textPaint3;
                                            addEntitiesToText = z2;
                                            staticLayout3 = staticLayout4;
                                            i20 = 0;
                                            i21 = 1;
                                            i = 24;
                                            f6 = 0.0f;
                                        }
                                    }
                                    textLayoutBlock = textLayoutBlock2;
                                    i11 = i23;
                                    i18 = i3;
                                    staticLayout4 = staticLayout3;
                                    textPaint3 = textPaint2;
                                    i7 = i2;
                                    i9 = maxMessageTextWidth;
                                    try {
                                        textLayoutBlock.textLayout = new StaticLayout(this.messageText, lineStart, lineEnd, textPaint2, maxMessageTextWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
                                        staticLayout5 = staticLayout4;
                                        textLayoutBlock.textYOffset = (float) staticLayout5.getLineTop(i11);
                                        i6 = i18;
                                        if (i6 != 0) {
                                        }
                                        textLayoutBlock.height = Math.max(textLayoutBlock.height, textLayoutBlock.textLayout.getLineBottom(textLayoutBlock.textLayout.getLineCount() - 1));
                                        float f82 = textLayoutBlock.textYOffset;
                                        if (i6 != i7 - 1) {
                                        }
                                        f7 = f82;
                                    } catch (Exception e7) {
                                        e2 = e7;
                                        i17 = i11;
                                        z2 = addEntitiesToText;
                                        i6 = i18;
                                        i5 = i9;
                                        FileLog.e(e2);
                                        i8 = i17;
                                        i3 = i6 + 1;
                                        i23 = i8;
                                        i2 = i7;
                                        maxMessageTextWidth = i5;
                                        textPaint2 = textPaint3;
                                        addEntitiesToText = z2;
                                        staticLayout3 = staticLayout4;
                                        i20 = 0;
                                        i21 = 1;
                                        i = 24;
                                        f6 = 0.0f;
                                    }
                                }
                                i8 = i17;
                                i3 = i6 + 1;
                                i23 = i8;
                                i2 = i7;
                                maxMessageTextWidth = i5;
                                textPaint2 = textPaint3;
                                addEntitiesToText = z2;
                                staticLayout3 = staticLayout4;
                                i20 = 0;
                                i21 = 1;
                                i = 24;
                                f6 = 0.0f;
                            }
                            this.textLayoutBlocks.add(textLayoutBlock);
                            try {
                                f = textLayoutBlock.textLayout.getLineLeft(i10 - 1);
                                f5 = 0.0f;
                                if (i6 == 0 && f >= 0.0f) {
                                    try {
                                        this.textXOffset = f;
                                    } catch (Exception e8) {
                                        e = e8;
                                    }
                                }
                            } catch (Exception e9) {
                                e = e9;
                                f5 = 0.0f;
                                if (i6 == 0) {
                                    this.textXOffset = f5;
                                }
                                FileLog.e(e);
                                f = 0.0f;
                                f2 = textLayoutBlock.textLayout.getLineWidth(i10 - 1);
                                ceil = (int) Math.ceil((double) f2);
                                i5 = i9;
                                if (ceil > i5 + 80) {
                                }
                                i12 = i7 - 1;
                                if (i6 == i12) {
                                }
                                int ceil2 = (int) Math.ceil((double) (f2 + f));
                                if (i10 <= 1) {
                                }
                                i8 = i14 + i13;
                                i3 = i6 + 1;
                                i23 = i8;
                                i2 = i7;
                                maxMessageTextWidth = i5;
                                textPaint2 = textPaint3;
                                addEntitiesToText = z2;
                                staticLayout3 = staticLayout4;
                                i20 = 0;
                                i21 = 1;
                                i = 24;
                                f6 = 0.0f;
                            }
                            try {
                                f2 = textLayoutBlock.textLayout.getLineWidth(i10 - 1);
                            } catch (Exception e10) {
                                FileLog.e(e10);
                                f2 = 0.0f;
                            }
                            ceil = (int) Math.ceil((double) f2);
                            i5 = i9;
                            if (ceil > i5 + 80) {
                                ceil = i5;
                            }
                            i12 = i7 - 1;
                            if (i6 == i12) {
                                this.lastLineWidth = ceil;
                            }
                            int ceil22 = (int) Math.ceil((double) (f2 + f));
                            if (i10 <= 1) {
                                z2 = addEntitiesToText;
                                int i25 = ceil22;
                                int i26 = 0;
                                float f9 = 0.0f;
                                float f10 = 0.0f;
                                boolean z3 = false;
                                while (i26 < i10) {
                                    try {
                                        f3 = textLayoutBlock.textLayout.getLineWidth(i26);
                                    } catch (Exception e11) {
                                        FileLog.e(e11);
                                        f3 = 0.0f;
                                    }
                                    if (f3 > ((float) (i5 + 20))) {
                                        f3 = (float) i5;
                                    }
                                    try {
                                        f4 = textLayoutBlock.textLayout.getLineLeft(i26);
                                    } catch (Exception e12) {
                                        FileLog.e(e12);
                                        f4 = 0.0f;
                                    }
                                    if (f4 > 0.0f) {
                                        i16 = i11;
                                        this.textXOffset = Math.min(this.textXOffset, f4);
                                        i15 = i10;
                                        textLayoutBlock.directionFlags = (byte) (textLayoutBlock.directionFlags | 1);
                                        this.hasRtl = true;
                                    } else {
                                        i16 = i11;
                                        i15 = i10;
                                        textLayoutBlock.directionFlags = (byte) (textLayoutBlock.directionFlags | 2);
                                    }
                                    if (!z3 && f4 == 0.0f) {
                                        try {
                                            if (textLayoutBlock.textLayout.getParagraphDirection(i26) != 1) {
                                            }
                                        } catch (Exception unused) {
                                        }
                                        z3 = true;
                                    }
                                    float max = Math.max(f9, f3);
                                    float f11 = f4 + f3;
                                    float max2 = Math.max(f10, f11);
                                    ceil = Math.max(ceil, (int) Math.ceil((double) f3));
                                    i25 = Math.max(i25, (int) Math.ceil((double) f11));
                                    i26++;
                                    f9 = max;
                                    f10 = max2;
                                    i11 = i16;
                                    i10 = i15;
                                    staticLayout5 = staticLayout5;
                                }
                                i14 = i11;
                                staticLayout4 = staticLayout5;
                                i13 = i10;
                                if (!z3) {
                                    if (i6 == i12) {
                                        this.lastLineWidth = ceil;
                                    }
                                    f10 = f9;
                                } else if (i6 == i12) {
                                    this.lastLineWidth = ceil22;
                                }
                                this.textWidth = Math.max(this.textWidth, (int) Math.ceil((double) f10));
                            } else {
                                i14 = i11;
                                z2 = addEntitiesToText;
                                staticLayout4 = staticLayout5;
                                i13 = i10;
                                if (f > 0.0f) {
                                    float min = Math.min(this.textXOffset, f);
                                    this.textXOffset = min;
                                    if (min == 0.0f) {
                                        ceil = (int) (((float) ceil) + f);
                                    }
                                    this.hasRtl = i7 != 1;
                                    textLayoutBlock.directionFlags = (byte) (textLayoutBlock.directionFlags | 1);
                                } else {
                                    textLayoutBlock.directionFlags = (byte) (textLayoutBlock.directionFlags | 2);
                                }
                                this.textWidth = Math.max(this.textWidth, Math.min(i5, ceil));
                            }
                            i8 = i14 + i13;
                            i3 = i6 + 1;
                            i23 = i8;
                            i2 = i7;
                            maxMessageTextWidth = i5;
                            textPaint2 = textPaint3;
                            addEntitiesToText = z2;
                            staticLayout3 = staticLayout4;
                            i20 = 0;
                            i21 = 1;
                            i = 24;
                            f6 = 0.0f;
                        }
                    }
                }
                staticLayout3 = staticLayout2;
                this.textHeight = staticLayout3.getHeight();
                this.linesCount = staticLayout3.getLineCount();
                if (staticLayout != null) {
                }
                if (Build.VERSION.SDK_INT >= i) {
                }
                float f62 = 0.0f;
                int i232 = 0;
                i3 = 0;
                float f72 = 0.0f;
                while (i3 < i2) {
                }
            }
            z = false;
            if (!z) {
            }
            if (!isYouTubeVideo()) {
            }
            addUrlsByPattern(isOutOwner(), this.messageText, false, 3, Integer.MAX_VALUE);
            boolean addEntitiesToText2 = addEntitiesToText(this.messageText, z);
            int maxMessageTextWidth2 = getMaxMessageTextWidth();
            staticLayout = null;
            if (!(this.messageOwner.media instanceof TLRPC.TL_messageMediaGame)) {
            }
            try {
                if (Build.VERSION.SDK_INT < 24) {
                }
                if (!TextUtils.isEmpty(this.messageOwner.trans)) {
                }
                staticLayout3 = staticLayout2;
                this.textHeight = staticLayout3.getHeight();
                this.linesCount = staticLayout3.getLineCount();
                if (staticLayout != null) {
                }
                if (Build.VERSION.SDK_INT >= i) {
                }
                float f622 = 0.0f;
                int i2322 = 0;
                i3 = 0;
                float f722 = 0.0f;
                while (i3 < i2) {
                }
            } catch (Exception e13) {
                FileLog.e(e13);
            }
        }
    }

    public boolean isOut() {
        return this.messageOwner.out;
    }

    public boolean isOutOwner() {
        if (!this.messageOwner.out || this.messageOwner.from_id <= 0 || this.messageOwner.post) {
            return false;
        }
        if (this.messageOwner.fwd_from == null) {
            return true;
        }
        int clientUserId = UserConfig.getInstance(this.currentAccount).getClientUserId();
        if (getDialogId() == ((long) clientUserId)) {
            if ((this.messageOwner.fwd_from.from_id != clientUserId || (this.messageOwner.fwd_from.saved_from_peer != null && this.messageOwner.fwd_from.saved_from_peer.user_id != clientUserId)) && (this.messageOwner.fwd_from.saved_from_peer == null || this.messageOwner.fwd_from.saved_from_peer.user_id != clientUserId)) {
                return false;
            }
            return true;
        } else if (this.messageOwner.fwd_from.saved_from_peer == null || this.messageOwner.fwd_from.saved_from_peer.user_id == clientUserId) {
            return true;
        } else {
            return false;
        }
    }

    public boolean needDrawAvatar() {
        return (!isFromUser() && this.eventId == 0 && (this.messageOwner.fwd_from == null || this.messageOwner.fwd_from.saved_from_peer == null)) ? false : true;
    }

    public boolean isNewSupport() {
        TLRPC.Message message = this.messageOwner;
        return (message == null || message.media == null || !(this.messageOwner.media instanceof TLRPCContacts.TL_messageMediaSysNotify)) ? false : true;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private boolean needDrawAvatarInternal() {
        return ((!isFromChat() || !isFromUser()) && this.eventId == 0 && (this.messageOwner.fwd_from == null || this.messageOwner.fwd_from.saved_from_peer == null)) ? false : true;
    }

    public boolean isFromChat() {
        TLRPC.Chat chat;
        if (getDialogId() == ((long) UserConfig.getInstance(this.currentAccount).clientUserId) || isMegagroup() || (this.messageOwner.to_id != null && this.messageOwner.to_id.chat_id != 0)) {
            return true;
        }
        if (this.messageOwner.to_id == null || this.messageOwner.to_id.channel_id == 0 || (chat = MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(this.messageOwner.to_id.channel_id))) == null || !chat.megagroup) {
            return false;
        }
        return true;
    }

    public boolean isFromUser() {
        return this.messageOwner.from_id > 0 && !this.messageOwner.post;
    }

    public boolean isForwardedChannelPost() {
        return (this.messageOwner.from_id > 0 || this.messageOwner.fwd_from == null || this.messageOwner.fwd_from.channel_post == 0) ? false : true;
    }

    public boolean isUnread() {
        return this.messageOwner.unread;
    }

    public boolean isContentUnread() {
        return this.messageOwner.media_unread;
    }

    public void setIsRead() {
        this.messageOwner.unread = false;
    }

    public int getUnradFlags() {
        return getUnreadFlags(this.messageOwner);
    }

    public static int getUnreadFlags(TLRPC.Message message) {
        int i = !message.unread ? 1 : 0;
        return !message.media_unread ? i | 2 : i;
    }

    public void setContentIsRead() {
        this.messageOwner.media_unread = false;
    }

    public int getId() {
        return this.messageOwner.id;
    }

    public String getTranslate() {
        return this.messageOwner.trans;
    }

    public boolean isTranslating() {
        return this.messageOwner.istransing;
    }

    public int getRealId() {
        return this.messageOwner.realId != 0 ? this.messageOwner.realId : this.messageOwner.id;
    }

    public static int getMessageSize(TLRPC.Message message) {
        TLRPC.Document document;
        if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
            document = message.media.webpage.document;
        } else if (message.media instanceof TLRPC.TL_messageMediaGame) {
            document = message.media.game.document;
        } else {
            document = message.media != null ? message.media.document : null;
        }
        if (document != null) {
            return document.size;
        }
        return 0;
    }

    public int getSize() {
        return getMessageSize(this.messageOwner);
    }

    public long getIdWithChannel() {
        long j = (long) this.messageOwner.id;
        return (this.messageOwner.to_id == null || this.messageOwner.to_id.channel_id == 0) ? j : j | (((long) this.messageOwner.to_id.channel_id) << 32);
    }

    public int getChannelId() {
        if (this.messageOwner.to_id != null) {
            return this.messageOwner.to_id.channel_id;
        }
        return 0;
    }

    public static boolean shouldEncryptPhotoOrVideo(TLRPC.Message message) {
        if (message instanceof TLRPC.TL_message_secret) {
            if (((message.media instanceof TLRPC.TL_messageMediaPhoto) || isVideoMessage(message)) && message.ttl > 0 && message.ttl <= 60) {
                return true;
            }
            return false;
        } else if (((message.media instanceof TLRPC.TL_messageMediaPhoto) || (message.media instanceof TLRPC.TL_messageMediaDocument)) && message.media.ttl_seconds != 0) {
            return true;
        } else {
            return false;
        }
    }

    public boolean shouldEncryptPhotoOrVideo() {
        return shouldEncryptPhotoOrVideo(this.messageOwner);
    }

    public static boolean isSecretPhotoOrVideo(TLRPC.Message message) {
        if (message instanceof TLRPC.TL_message_secret) {
            if (((message.media instanceof TLRPC.TL_messageMediaPhoto) || isRoundVideoMessage(message) || isVideoMessage(message)) && message.ttl > 0 && message.ttl <= 60) {
                return true;
            }
            return false;
        } else if (!(message instanceof TLRPC.TL_message)) {
            return false;
        } else {
            if (((message.media instanceof TLRPC.TL_messageMediaPhoto) || (message.media instanceof TLRPC.TL_messageMediaDocument)) && message.media.ttl_seconds != 0) {
                return true;
            }
            return false;
        }
    }

    public static boolean isSecretMedia(TLRPC.Message message) {
        if (message instanceof TLRPC.TL_message_secret) {
            if (((message.media instanceof TLRPC.TL_messageMediaPhoto) || isRoundVideoMessage(message) || isVideoMessage(message)) && message.media.ttl_seconds != 0) {
                return true;
            }
            return false;
        } else if (!(message instanceof TLRPC.TL_message)) {
            return false;
        } else {
            if (((message.media instanceof TLRPC.TL_messageMediaPhoto) || (message.media instanceof TLRPC.TL_messageMediaDocument)) && message.media.ttl_seconds != 0) {
                return true;
            }
            return false;
        }
    }

    public boolean needDrawBluredPreview() {
        TLRPC.Message message = this.messageOwner;
        if (message instanceof TLRPC.TL_message_secret) {
            int max = Math.max(message.ttl, this.messageOwner.media.ttl_seconds);
            if (max <= 0 || (((!(this.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) && !isVideo() && !isGif()) || max > 60) && !isRoundVideo())) {
                return false;
            }
            return true;
        } else if (!(message instanceof TLRPC.TL_message)) {
            return false;
        } else {
            if (((message.media instanceof TLRPC.TL_messageMediaPhoto) || (this.messageOwner.media instanceof TLRPC.TL_messageMediaDocument)) && this.messageOwner.media.ttl_seconds != 0) {
                return true;
            }
            return false;
        }
    }

    public boolean isSecretMedia() {
        TLRPC.Message message = this.messageOwner;
        if (message instanceof TLRPC.TL_message_secret) {
            if ((((message.media instanceof TLRPC.TL_messageMediaPhoto) || isGif()) && this.messageOwner.ttl > 0 && this.messageOwner.ttl <= 60) || isVoice() || isRoundVideo() || isVideo()) {
                return true;
            }
            return false;
        } else if (!(message instanceof TLRPC.TL_message)) {
            return false;
        } else {
            if (((message.media instanceof TLRPC.TL_messageMediaPhoto) || (this.messageOwner.media instanceof TLRPC.TL_messageMediaDocument)) && this.messageOwner.media.ttl_seconds != 0) {
                return true;
            }
            return false;
        }
    }

    public static void setUnreadFlags(TLRPC.Message message, int i) {
        boolean z = false;
        message.unread = (i & 1) == 0;
        if ((i & 2) == 0) {
            z = true;
        }
        message.media_unread = z;
    }

    public static boolean isUnread(TLRPC.Message message) {
        return message.unread;
    }

    public static boolean isContentUnread(TLRPC.Message message) {
        return message.media_unread;
    }

    public boolean isMegagroup() {
        return isMegagroup(this.messageOwner);
    }

    public boolean isSavedFromMegagroup() {
        if (this.messageOwner.fwd_from == null || this.messageOwner.fwd_from.saved_from_peer == null || this.messageOwner.fwd_from.saved_from_peer.channel_id == 0) {
            return false;
        }
        return ChatObject.isMegagroup(MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(this.messageOwner.fwd_from.saved_from_peer.channel_id)));
    }

    public static boolean isMegagroup(TLRPC.Message message) {
        return (message.flags & Integer.MIN_VALUE) != 0;
    }

    public static boolean isOut(TLRPC.Message message) {
        return message.out;
    }

    public long getDialogId() {
        return getDialogId(this.messageOwner);
    }

    public boolean canStreamVideo() {
        TLRPC.Document document = getDocument();
        if (document != null && !(document instanceof TLRPC.TL_documentEncrypted)) {
            if (SharedConfig.streamAllVideo) {
                return true;
            }
            for (int i = 0; i < document.attributes.size(); i++) {
                TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i);
                if (documentAttribute instanceof TLRPC.TL_documentAttributeVideo) {
                    return documentAttribute.supports_streaming;
                }
                if ((documentAttribute instanceof TLRPC.TL_documentAttributeFilename) && document.mime_type.toLowerCase().startsWith("video/")) {
                    return true;
                }
            }
            if (!SharedConfig.streamMkv || !"video/x-matroska".equals(document.mime_type)) {
                return false;
            }
            return true;
        }
        return false;
    }

    public static long getDialogId(TLRPC.Message message) {
        if (message.dialog_id == 0 && message.to_id != null) {
            if (message.to_id.chat_id != 0) {
                message.dialog_id = (long) (-message.to_id.chat_id);
            } else if (message.to_id.channel_id != 0) {
                message.dialog_id = (long) (-message.to_id.channel_id);
            } else if (isOut(message)) {
                message.dialog_id = (long) message.to_id.user_id;
            } else {
                message.dialog_id = (long) message.from_id;
            }
        }
        return message.dialog_id;
    }

    public boolean isSending() {
        return this.messageOwner.send_state == 1 && this.messageOwner.id < 0;
    }

    public boolean isEditing() {
        return this.messageOwner.send_state == 3 && this.messageOwner.id > 0;
    }

    public boolean isSendError() {
        return (this.messageOwner.send_state == 2 && this.messageOwner.id < 0) || (this.scheduled && this.messageOwner.id > 0 && this.messageOwner.date < ConnectionsManager.getInstance(this.currentAccount).getCurrentTime() + -60);
    }

    public boolean isSent() {
        return this.messageOwner.send_state == 0 || this.messageOwner.id > 0;
    }

    public int getSecretTimeLeft() {
        return this.messageOwner.destroyTime != 0 ? Math.max(0, this.messageOwner.destroyTime - ConnectionsManager.getInstance(this.currentAccount).getCurrentTime()) : this.messageOwner.ttl;
    }

    public String getSecretTimeString() {
        if (!isSecretMedia()) {
            return null;
        }
        int secretTimeLeft = getSecretTimeLeft();
        if (secretTimeLeft < 60) {
            return secretTimeLeft + "s";
        }
        return (secretTimeLeft / 60) + "m";
    }

    public String getDocumentName() {
        return FileLoader.getDocumentFileName(getDocument());
    }

    public static boolean isStickerDocument(TLRPC.Document document) {
        if (document != null) {
            for (int i = 0; i < document.attributes.size(); i++) {
                if (document.attributes.get(i) instanceof TLRPC.TL_documentAttributeSticker) {
                    if ("image/webp".equals(document.mime_type) || "application/x-tgsticker".equals(document.mime_type)) {
                        return true;
                    } else {
                        return false;
                    }
                }
            }
        }
        return false;
    }

    public static boolean isAnimatedStickerDocument(TLRPC.Document document) {
        return document != null && "application/x-tgsticker".equals(document.mime_type) && !document.thumbs.isEmpty();
    }

    public static boolean canAutoplayAnimatedSticker(TLRPC.Document document) {
        return isAnimatedStickerDocument(document) && SharedConfig.getDevicePerfomanceClass() != 0;
    }

    public static boolean isMaskDocument(TLRPC.Document document) {
        if (document != null) {
            for (int i = 0; i < document.attributes.size(); i++) {
                TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i);
                if ((documentAttribute instanceof TLRPC.TL_documentAttributeSticker) && documentAttribute.mask) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean isVoiceDocument(TLRPC.Document document) {
        if (document != null) {
            for (int i = 0; i < document.attributes.size(); i++) {
                TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i);
                if (documentAttribute instanceof TLRPC.TL_documentAttributeAudio) {
                    return documentAttribute.voice;
                }
            }
        }
        return false;
    }

    public static boolean isVoiceWebDocument(WebFile webFile) {
        return webFile != null && webFile.mime_type.equals("audio/ogg");
    }

    public static boolean isImageWebDocument(WebFile webFile) {
        return webFile != null && !isGifDocument(webFile) && webFile.mime_type.startsWith("image/");
    }

    public static boolean isVideoWebDocument(WebFile webFile) {
        return webFile != null && webFile.mime_type.startsWith("video/");
    }

    public static boolean isMusicDocument(TLRPC.Document document) {
        if (document != null) {
            for (int i = 0; i < document.attributes.size(); i++) {
                TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i);
                if (documentAttribute instanceof TLRPC.TL_documentAttributeAudio) {
                    return !documentAttribute.voice;
                }
            }
            if (!TextUtils.isEmpty(document.mime_type)) {
                String lowerCase = document.mime_type.toLowerCase();
                if (lowerCase.equals(MimeTypes.AUDIO_FLAC) || lowerCase.equals("audio/ogg") || lowerCase.equals(MimeTypes.AUDIO_OPUS) || lowerCase.equals("audio/x-opus+ogg") || (lowerCase.equals("application/octet-stream") && FileLoader.getDocumentFileName(document).endsWith(".opus"))) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean isVideoDocument(TLRPC.Document document) {
        if (document == null) {
            return false;
        }
        boolean z = false;
        int i = 0;
        int i2 = 0;
        boolean z2 = false;
        for (int i3 = 0; i3 < document.attributes.size(); i3++) {
            TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i3);
            if (documentAttribute instanceof TLRPC.TL_documentAttributeVideo) {
                if (documentAttribute.round_message) {
                    return false;
                }
                i = documentAttribute.w;
                i2 = documentAttribute.h;
                z2 = true;
            } else if (documentAttribute instanceof TLRPC.TL_documentAttributeAnimated) {
                z = true;
            }
        }
        if (z && (i > 1280 || i2 > 1280)) {
            z = false;
        }
        if (SharedConfig.streamMkv && !z2 && "video/x-matroska".equals(document.mime_type)) {
            z2 = true;
        }
        if (!z2 || z) {
            return false;
        }
        return true;
    }

    public TLRPC.Document getDocument() {
        TLRPC.Document document = this.emojiAnimatedSticker;
        if (document != null) {
            return document;
        }
        return getDocument(this.messageOwner);
    }

    public static TLRPC.Document getDocument(TLRPC.Message message) {
        if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
            return message.media.webpage.document;
        }
        if (message.media instanceof TLRPC.TL_messageMediaGame) {
            return message.media.game.document;
        }
        if (message.media != null) {
            return message.media.document;
        }
        return null;
    }

    public static TLRPC.Photo getPhoto(TLRPC.Message message) {
        if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
            return message.media.webpage.photo;
        }
        if (message.media != null) {
            return message.media.photo;
        }
        return null;
    }

    public static boolean isStickerMessage(TLRPC.Message message) {
        return message.media != null && isStickerDocument(message.media.document);
    }

    public static boolean isAnimatedStickerMessage(TLRPC.Message message) {
        return message.media != null && isAnimatedStickerDocument(message.media.document);
    }

    public static boolean isLocationMessage(TLRPC.Message message) {
        return (message.media instanceof TLRPC.TL_messageMediaGeo) || (message.media instanceof TLRPC.TL_messageMediaGeoLive) || (message.media instanceof TLRPC.TL_messageMediaVenue);
    }

    public static boolean isMaskMessage(TLRPC.Message message) {
        return message.media != null && isMaskDocument(message.media.document);
    }

    public static boolean isMusicMessage(TLRPC.Message message) {
        if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
            return isMusicDocument(message.media.webpage.document);
        }
        return message.media != null && isMusicDocument(message.media.document);
    }

    public static boolean isGifMessage(TLRPC.Message message) {
        if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
            return isGifDocument(message.media.webpage.document);
        }
        return message.media != null && isGifDocument(message.media.document);
    }

    public static boolean isRoundVideoMessage(TLRPC.Message message) {
        if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
            return isRoundVideoDocument(message.media.webpage.document);
        }
        return message.media != null && isRoundVideoDocument(message.media.document);
    }

    public static boolean isPhoto(TLRPC.Message message) {
        if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
            return (message.media.webpage.photo instanceof TLRPC.TL_photo) && !(message.media.webpage.document instanceof TLRPC.TL_document);
        }
        return message.media instanceof TLRPC.TL_messageMediaPhoto;
    }

    public static boolean isVoiceMessage(TLRPC.Message message) {
        if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
            return isVoiceDocument(message.media.webpage.document);
        }
        return message.media != null && isVoiceDocument(message.media.document);
    }

    public static boolean isNewGifMessage(TLRPC.Message message) {
        if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
            return isNewGifDocument(message.media.webpage.document);
        }
        return message.media != null && isNewGifDocument(message.media.document);
    }

    public static boolean isLiveLocationMessage(TLRPC.Message message) {
        return message.media instanceof TLRPC.TL_messageMediaGeoLive;
    }

    public static boolean isVideoMessage(TLRPC.Message message) {
        if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
            return isVideoDocument(message.media.webpage.document);
        }
        return message.media != null && isVideoDocument(message.media.document);
    }

    public static boolean isGameMessage(TLRPC.Message message) {
        return message.media instanceof TLRPC.TL_messageMediaGame;
    }

    public static boolean isInvoiceMessage(TLRPC.Message message) {
        return message.media instanceof TLRPC.TL_messageMediaInvoice;
    }

    public static TLRPC.InputStickerSet getInputStickerSet(TLRPC.Message message) {
        if (message.media == null || message.media.document == null) {
            return null;
        }
        return getInputStickerSet(message.media.document);
    }

    public static TLRPC.InputStickerSet getInputStickerSet(TLRPC.Document document) {
        if (document == null) {
            return null;
        }
        int size = document.attributes.size();
        for (int i = 0; i < size; i++) {
            TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i);
            if (documentAttribute instanceof TLRPC.TL_documentAttributeSticker) {
                if (documentAttribute.stickerset instanceof TLRPC.TL_inputStickerSetEmpty) {
                    return null;
                } else {
                    return documentAttribute.stickerset;
                }
            }
        }
        return null;
    }

    public static long getStickerSetId(TLRPC.Document document) {
        if (document == null) {
            return -1;
        }
        for (int i = 0; i < document.attributes.size(); i++) {
            TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i);
            if (documentAttribute instanceof TLRPC.TL_documentAttributeSticker) {
                if (documentAttribute.stickerset instanceof TLRPC.TL_inputStickerSetEmpty) {
                    return -1;
                } else {
                    return documentAttribute.stickerset.id;
                }
            }
        }
        return -1;
    }

    public String getStrickerChar() {
        TLRPC.Document document = getDocument();
        if (document == null) {
            return null;
        }
        Iterator<TLRPC.DocumentAttribute> it = document.attributes.iterator();
        while (it.hasNext()) {
            TLRPC.DocumentAttribute next = it.next();
            if (next instanceof TLRPC.TL_documentAttributeSticker) {
                return next.alt;
            }
        }
        return null;
    }

    public int getApproximateHeight() {
        int i;
        int i2;
        int i3;
        int i4;
        int i5 = this.type;
        int i6 = 0;
        if (i5 == 0) {
            int i7 = this.textHeight;
            if ((this.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) && (this.messageOwner.media.webpage instanceof TLRPC.TL_webPage)) {
                i6 = AndroidUtilities.dp(100.0f);
            }
            int i8 = i7 + i6;
            return isReply() ? i8 + AndroidUtilities.dp(42.0f) : i8;
        } else if (i5 == 2) {
            return AndroidUtilities.dp(72.0f);
        } else {
            if (i5 == 12) {
                return AndroidUtilities.dp(71.0f);
            }
            if (i5 == 9) {
                return AndroidUtilities.dp(100.0f);
            }
            if (i5 == 4) {
                return AndroidUtilities.dp(114.0f);
            }
            if (i5 == 14) {
                return AndroidUtilities.dp(82.0f);
            }
            if (i5 == 10) {
                return AndroidUtilities.dp(30.0f);
            }
            if (i5 == 11) {
                return AndroidUtilities.dp(50.0f);
            }
            if (i5 == 5) {
                return AndroidUtilities.roundMessageSize;
            }
            if (i5 == 13 || i5 == 15) {
                float f = ((float) AndroidUtilities.displaySize.y) * 0.4f;
                if (AndroidUtilities.isTablet()) {
                    i = AndroidUtilities.getMinTabletSide();
                } else {
                    i = AndroidUtilities.displaySize.x;
                }
                float f2 = ((float) i) * 0.5f;
                TLRPC.Document document = getDocument();
                int size = document.attributes.size();
                int i9 = 0;
                while (true) {
                    if (i9 >= size) {
                        i2 = 0;
                        break;
                    }
                    TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i9);
                    if (documentAttribute instanceof TLRPC.TL_documentAttributeImageSize) {
                        i6 = documentAttribute.w;
                        i2 = documentAttribute.h;
                        break;
                    }
                    i9++;
                }
                if (i6 == 0) {
                    i2 = (int) f;
                    i6 = AndroidUtilities.dp(100.0f) + i2;
                }
                float f3 = (float) i2;
                if (f3 > f) {
                    i6 = (int) (((float) i6) * (f / f3));
                    i2 = (int) f;
                }
                float f4 = (float) i6;
                if (f4 > f2) {
                    i2 = (int) (((float) i2) * (f2 / f4));
                }
                return i2 + AndroidUtilities.dp(14.0f);
            }
            if (AndroidUtilities.isTablet()) {
                i3 = AndroidUtilities.getMinTabletSide();
            } else {
                i3 = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
            }
            int i10 = (int) (((float) i3) * 0.7f);
            int dp = AndroidUtilities.dp(100.0f) + i10;
            if (i10 > AndroidUtilities.getPhotoSize()) {
                i10 = AndroidUtilities.getPhotoSize();
            }
            if (dp > AndroidUtilities.getPhotoSize()) {
                dp = AndroidUtilities.getPhotoSize();
            }
            TLRPC.PhotoSize closestPhotoSizeWithSize = FileLoader.getClosestPhotoSizeWithSize(this.photoThumbs, AndroidUtilities.getPhotoSize());
            if (closestPhotoSizeWithSize != null) {
                int i11 = (int) (((float) closestPhotoSizeWithSize.h) / (((float) closestPhotoSizeWithSize.w) / ((float) i10)));
                if (i11 == 0) {
                    i11 = AndroidUtilities.dp(100.0f);
                }
                if (i11 <= dp) {
                    dp = i11 < AndroidUtilities.dp(120.0f) ? AndroidUtilities.dp(120.0f) : i11;
                }
                if (needDrawBluredPreview()) {
                    if (AndroidUtilities.isTablet()) {
                        i4 = AndroidUtilities.getMinTabletSide();
                    } else {
                        i4 = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y);
                    }
                    dp = (int) (((float) i4) * 0.5f);
                }
            }
            return dp + AndroidUtilities.dp(14.0f);
        }
    }

    public String getStickerEmoji() {
        TLRPC.Document document = getDocument();
        if (document == null) {
            return null;
        }
        for (int i = 0; i < document.attributes.size(); i++) {
            TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i);
            if (documentAttribute instanceof TLRPC.TL_documentAttributeSticker) {
                if (documentAttribute.alt == null || documentAttribute.alt.length() <= 0) {
                    return null;
                } else {
                    return documentAttribute.alt;
                }
            }
        }
        return null;
    }

    public boolean isAnimatedEmoji() {
        return this.emojiAnimatedSticker != null;
    }

    public boolean isSticker() {
        int i = this.type;
        if (i != 1000) {
            return i == 13;
        }
        return isStickerDocument(getDocument());
    }

    public boolean isAnimatedSticker() {
        int i = this.type;
        if (i != 1000) {
            return i == 15;
        }
        return isAnimatedStickerDocument(getDocument());
    }

    public boolean isAnyKindOfSticker() {
        int i = this.type;
        return i == 13 || i == 15;
    }

    public boolean shouldDrawWithoutBackground() {
        int i = this.type;
        return i == 13 || i == 15 || i == 5;
    }

    public boolean isLocation() {
        return isLocationMessage(this.messageOwner);
    }

    public boolean isMask() {
        return isMaskMessage(this.messageOwner);
    }

    public boolean isMusic() {
        return isMusicMessage(this.messageOwner);
    }

    public boolean isVoice() {
        return isVoiceMessage(this.messageOwner);
    }

    public boolean isVideo() {
        return isVideoMessage(this.messageOwner);
    }

    public boolean isPhoto() {
        return isPhoto(this.messageOwner);
    }

    public boolean isLiveLocation() {
        return isLiveLocationMessage(this.messageOwner);
    }

    public boolean isGame() {
        return isGameMessage(this.messageOwner);
    }

    public boolean isInvoice() {
        return isInvoiceMessage(this.messageOwner);
    }

    public boolean isRoundVideo() {
        if (this.isRoundVideoCached == 0) {
            this.isRoundVideoCached = (this.type == 5 || isRoundVideoMessage(this.messageOwner)) ? 1 : 2;
        }
        if (this.isRoundVideoCached == 1) {
            return true;
        }
        return false;
    }

    public boolean hasPhotoStickers() {
        return (this.messageOwner.media == null || this.messageOwner.media.photo == null || !this.messageOwner.media.photo.has_stickers) ? false : true;
    }

    public boolean isGif() {
        return isGifMessage(this.messageOwner);
    }

    public boolean isWebpageDocument() {
        return (this.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) && this.messageOwner.media.webpage.document != null && !isGifDocument(this.messageOwner.media.webpage.document);
    }

    public boolean isWebpage() {
        return this.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage;
    }

    public boolean isNewGif() {
        return this.messageOwner.media != null && isNewGifDocument(this.messageOwner.media.document);
    }

    public boolean isAndroidTheme() {
        if (!(this.messageOwner.media == null || this.messageOwner.media.webpage == null)) {
            ArrayList<TLRPC.Document> arrayList = this.messageOwner.media.webpage.documents;
            int size = arrayList.size();
            for (int i = 0; i < size; i++) {
                if ("application/x-tgtheme-android".equals(arrayList.get(i).mime_type)) {
                    return true;
                }
            }
        }
        return false;
    }

    public String getMusicTitle() {
        return getMusicTitle(true);
    }

    public String getMusicTitle(boolean z) {
        TLRPC.Document document = getDocument();
        if (document != null) {
            for (int i = 0; i < document.attributes.size(); i++) {
                TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i);
                if (documentAttribute instanceof TLRPC.TL_documentAttributeAudio) {
                    if (!documentAttribute.voice) {
                        String str = documentAttribute.title;
                        if (!(str == null || str.length() == 0)) {
                            return str;
                        }
                        String documentFileName = FileLoader.getDocumentFileName(document);
                        return (!TextUtils.isEmpty(documentFileName) || !z) ? documentFileName : LocaleController.getString("AudioUnknownTitle", R.string.AudioUnknownTitle);
                    } else if (!z) {
                        return null;
                    } else {
                        return LocaleController.formatDateAudio((long) this.messageOwner.date);
                    }
                } else if ((documentAttribute instanceof TLRPC.TL_documentAttributeVideo) && documentAttribute.round_message) {
                    return LocaleController.formatDateAudio((long) this.messageOwner.date);
                }
            }
            String documentFileName2 = FileLoader.getDocumentFileName(document);
            if (!TextUtils.isEmpty(documentFileName2)) {
                return documentFileName2;
            }
        }
        return LocaleController.getString("AudioUnknownTitle", R.string.AudioUnknownTitle);
    }

    public int getDuration() {
        TLRPC.Document document = getDocument();
        if (document == null) {
            return 0;
        }
        int i = this.audioPlayerDuration;
        if (i > 0) {
            return i;
        }
        for (int i2 = 0; i2 < document.attributes.size(); i2++) {
            TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i2);
            if (documentAttribute instanceof TLRPC.TL_documentAttributeAudio) {
                return documentAttribute.duration;
            }
            if (documentAttribute instanceof TLRPC.TL_documentAttributeVideo) {
                return documentAttribute.duration;
            }
        }
        return this.audioPlayerDuration;
    }

    public String getArtworkUrl(boolean z) {
        TLRPC.Document document = getDocument();
        if (document != null) {
            int size = document.attributes.size();
            for (int i = 0; i < size; i++) {
                TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i);
                if (documentAttribute instanceof TLRPC.TL_documentAttributeAudio) {
                    if (documentAttribute.voice) {
                        return null;
                    } else {
                        String str = documentAttribute.performer;
                        String str2 = documentAttribute.title;
                        if (!TextUtils.isEmpty(str)) {
                            int i2 = 0;
                            while (true) {
                                String[] strArr = excludeWords;
                                if (i2 >= strArr.length) {
                                    break;
                                }
                                str = str.replace(strArr[i2], " ");
                                i2++;
                            }
                        }
                        if (TextUtils.isEmpty(str) && TextUtils.isEmpty(str2)) {
                            return null;
                        }
                        try {
                            StringBuilder sb = new StringBuilder();
                            sb.append("athumb://itunes.apple.com/search?term=");
                            sb.append(URLEncoder.encode(str + " - " + str2, "UTF-8"));
                            sb.append("&entity=song&limit=4");
                            sb.append(z ? "&s=1" : "");
                            return sb.toString();
                        } catch (Exception unused) {
                        }
                    }
                }
            }
        }
        return null;
    }

    public String getMusicAuthor() {
        return getMusicAuthor(true);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:17:0x003d, code lost:
        if (r5.round_message != false) goto L_0x0026;
     */
    /* JADX WARNING: Removed duplicated region for block: B:19:0x0042  */
    /* JADX WARNING: Removed duplicated region for block: B:73:0x012b A[SYNTHETIC] */
    public String getMusicAuthor(boolean z) {
        TLRPC.Chat chat;
        TLRPC.User user;
        TLRPC.Document document = getDocument();
        if (document != null) {
            boolean z2 = false;
            for (int i = 0; i < document.attributes.size(); i++) {
                TLRPC.DocumentAttribute documentAttribute = document.attributes.get(i);
                if (!(documentAttribute instanceof TLRPC.TL_documentAttributeAudio)) {
                    if (documentAttribute instanceof TLRPC.TL_documentAttributeVideo) {
                    }
                    if (!z2) {
                        TLRPC.User user2 = null;
                        if (!z) {
                            return null;
                        }
                        if (isOutOwner() || (this.messageOwner.fwd_from != null && this.messageOwner.fwd_from.from_id == UserConfig.getInstance(this.currentAccount).getClientUserId())) {
                            return LocaleController.getString("FromYou", R.string.FromYou);
                        }
                        if (this.messageOwner.fwd_from == null || this.messageOwner.fwd_from.channel_id == 0) {
                            if (this.messageOwner.fwd_from != null && this.messageOwner.fwd_from.from_id != 0) {
                                user = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(this.messageOwner.fwd_from.from_id));
                            } else if (this.messageOwner.fwd_from != null && this.messageOwner.fwd_from.from_name != null) {
                                return this.messageOwner.fwd_from.from_name;
                            } else {
                                if (this.messageOwner.from_id < 0) {
                                    chat = MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(-this.messageOwner.from_id));
                                } else if (this.messageOwner.from_id != 0 || this.messageOwner.to_id.channel_id == 0) {
                                    user = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(this.messageOwner.from_id));
                                } else {
                                    chat = MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(this.messageOwner.to_id.channel_id));
                                }
                            }
                            chat = null;
                            user2 = user;
                        } else {
                            chat = MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(this.messageOwner.fwd_from.channel_id));
                        }
                        if (user2 != null) {
                            return UserObject.getName(user2);
                        }
                        if (chat != null) {
                            return chat.title;
                        }
                    }
                } else if (!documentAttribute.voice) {
                    String str = documentAttribute.performer;
                    return (!TextUtils.isEmpty(str) || !z) ? str : LocaleController.getString("AudioUnknownArtist", R.string.AudioUnknownArtist);
                }
                z2 = true;
                if (!z2) {
                }
            }
        }
        return LocaleController.getString("AudioUnknownArtist", R.string.AudioUnknownArtist);
    }

    public TLRPC.InputStickerSet getInputStickerSet() {
        return getInputStickerSet(this.messageOwner);
    }

    public boolean isForwarded() {
        return isForwardedMessage(this.messageOwner);
    }

    public boolean needDrawForwarded() {
        return ((this.messageOwner.flags & 4) == 0 || this.messageOwner.fwd_from == null || (this.messageOwner.fwd_from.saved_from_peer != null && this.messageOwner.fwd_from.saved_from_peer.channel_id == this.messageOwner.fwd_from.channel_id) || ((long) UserConfig.getInstance(this.currentAccount).getClientUserId()) == getDialogId()) ? false : true;
    }

    public static boolean isForwardedMessage(TLRPC.Message message) {
        return ((message.flags & 4) == 0 || message.fwd_from == null) ? false : true;
    }

    public boolean isReply() {
        MessageObject messageObject = this.replyMessageObject;
        return (messageObject == null || !(messageObject.messageOwner instanceof TLRPC.TL_messageEmpty)) && !((this.messageOwner.reply_to_msg_id == 0 && this.messageOwner.reply_to_random_id == 0) || (this.messageOwner.flags & 8) == 0);
    }

    public boolean isMediaEmpty() {
        return isMediaEmpty(this.messageOwner);
    }

    public boolean isMediaEmptyWebpage() {
        return isMediaEmptyWebpage(this.messageOwner);
    }

    public static boolean isMediaEmpty(TLRPC.Message message) {
        return message == null || message.media == null || (message.media instanceof TLRPC.TL_messageMediaEmpty) || (message.media instanceof TLRPC.TL_messageMediaWebPage);
    }

    public static boolean isMediaEmptyWebpage(TLRPC.Message message) {
        return message == null || message.media == null || (message.media instanceof TLRPC.TL_messageMediaEmpty);
    }

    public boolean canEditMessage(TLRPC.Chat chat) {
        return canEditMessage(this.currentAccount, this.messageOwner, chat, this.scheduled);
    }

    public boolean canEditMessageScheduleTime(TLRPC.Chat chat) {
        return canEditMessageScheduleTime(this.currentAccount, this.messageOwner, chat);
    }

    public boolean canForwardMessage() {
        int i;
        return !(this.messageOwner instanceof TLRPC.TL_message_secret) && !needDrawBluredPreview() && !isLiveLocation() && (i = this.type) != 16 && i != 101 && i != 102;
    }

    public boolean canEditMedia() {
        if (isSecretMedia()) {
            return false;
        }
        if (this.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
            return true;
        }
        if (!(this.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) || isVoice() || isSticker() || isAnimatedSticker() || isRoundVideo()) {
            return false;
        }
        return true;
    }

    public boolean canEditMessageAnytime(TLRPC.Chat chat) {
        return canEditMessageAnytime(this.currentAccount, this.messageOwner, chat);
    }

    public static boolean canEditMessageAnytime(int i, TLRPC.Message message, TLRPC.Chat chat) {
        if (!(message == null || message.to_id == null || ((message.media != null && (isRoundVideoDocument(message.media.document) || isStickerDocument(message.media.document) || isAnimatedStickerDocument(message.media.document))) || ((message.action != null && !(message.action instanceof TLRPC.TL_messageActionEmpty)) || isForwardedMessage(message) || message.via_bot_id != 0 || message.id < 0)))) {
            if (message.from_id == message.to_id.user_id && message.from_id == UserConfig.getInstance(i).getClientUserId() && !isLiveLocationMessage(message)) {
                return true;
            }
            if (!(chat == null && message.to_id.channel_id != 0 && (chat = MessagesController.getInstance(UserConfig.selectedAccount).getChat(Integer.valueOf(message.to_id.channel_id))) == null) && message.out && chat != null && chat.megagroup && (chat.creator || (chat.admin_rights != null && chat.admin_rights.pin_messages))) {
                return true;
            }
        }
        return false;
    }

    public static boolean canEditMessageScheduleTime(int i, TLRPC.Message message, TLRPC.Chat chat) {
        if (chat == null && message.to_id.channel_id != 0 && (chat = MessagesController.getInstance(i).getChat(Integer.valueOf(message.to_id.channel_id))) == null) {
            return false;
        }
        if (!ChatObject.isChannel(chat) || chat.megagroup || chat.creator) {
            return true;
        }
        if (chat.admin_rights == null || (!chat.admin_rights.edit_messages && !message.out)) {
            return false;
        }
        return true;
    }

    public static boolean canEditMessage(int i, TLRPC.Message message, TLRPC.Chat chat, boolean z) {
        if (z && message.date < ConnectionsManager.getInstance(i).getCurrentTime() - 60) {
            return false;
        }
        if ((chat == null || (!chat.left && !chat.kicked)) && message != null && message.to_id != null && ((message.media == null || (!isRoundVideoDocument(message.media.document) && !isStickerDocument(message.media.document) && !isAnimatedStickerDocument(message.media.document) && !isLocationMessage(message))) && ((message.action == null || (message.action instanceof TLRPC.TL_messageActionEmpty)) && !isForwardedMessage(message) && message.via_bot_id == 0 && message.id >= 0))) {
            if (message.from_id == message.to_id.user_id && message.from_id == UserConfig.getInstance(i).getClientUserId() && !isLiveLocationMessage(message) && !(message.media instanceof TLRPC.TL_messageMediaContact)) {
                return true;
            }
            if (chat == null && message.to_id.channel_id != 0 && (chat = MessagesController.getInstance(i).getChat(Integer.valueOf(message.to_id.channel_id))) == null) {
                return false;
            }
            if (message.media != null && !(message.media instanceof TLRPC.TL_messageMediaEmpty) && !(message.media instanceof TLRPC.TL_messageMediaPhoto) && !(message.media instanceof TLRPC.TL_messageMediaDocument) && !(message.media instanceof TLRPC.TL_messageMediaWebPage)) {
                return false;
            }
            if (message.out && chat != null && chat.megagroup && (chat.creator || (chat.admin_rights != null && chat.admin_rights.pin_messages))) {
                return true;
            }
            if (!z && Math.abs(message.date - ConnectionsManager.getInstance(i).getCurrentTime()) > MessagesController.getInstance(i).maxEditTime) {
                return false;
            }
            if (message.to_id.channel_id == 0) {
                if (!message.out && message.from_id != UserConfig.getInstance(i).getClientUserId()) {
                    return false;
                }
                if ((message.media instanceof TLRPC.TL_messageMediaPhoto) || (((message.media instanceof TLRPC.TL_messageMediaDocument) && !isStickerMessage(message) && !isAnimatedStickerMessage(message)) || (message.media instanceof TLRPC.TL_messageMediaEmpty) || (message.media instanceof TLRPC.TL_messageMediaWebPage) || message.media == null)) {
                    return true;
                }
                return false;
            } else if (((!chat.megagroup || !message.out) && (chat.megagroup || ((!chat.creator && (chat.admin_rights == null || (!chat.admin_rights.edit_messages && (!message.out || !chat.admin_rights.post_messages)))) || !message.post))) || (!(message.media instanceof TLRPC.TL_messageMediaPhoto) && ((!(message.media instanceof TLRPC.TL_messageMediaDocument) || isStickerMessage(message) || isAnimatedStickerMessage(message)) && !(message.media instanceof TLRPC.TL_messageMediaEmpty) && !(message.media instanceof TLRPC.TL_messageMediaWebPage) && message.media != null))) {
                return false;
            } else {
                return true;
            }
        }
        return false;
    }

    public boolean canDeleteMessage(boolean z, TLRPC.Chat chat) {
        return this.eventId == 0 && canDeleteMessage(this.currentAccount, z, this.messageOwner, chat);
    }

    public static boolean canDeleteMessage(int i, boolean z, TLRPC.Message message, TLRPC.Chat chat) {
        if (message.id < 0) {
            return true;
        }
        if (chat == null && message.to_id.channel_id != 0) {
            chat = MessagesController.getInstance(i).getChat(Integer.valueOf(message.to_id.channel_id));
        }
        if (ChatObject.isChannel(chat)) {
            if (!z || chat.megagroup) {
                if (z) {
                    return true;
                }
                if (message.id != 1) {
                    if (chat.creator) {
                        return true;
                    }
                    if (chat.admin_rights != null) {
                        if (chat.admin_rights.delete_messages) {
                            return true;
                        }
                        if (message.out && (chat.megagroup || chat.admin_rights.post_messages)) {
                            return true;
                        }
                    }
                    if (!chat.megagroup || !message.out || message.from_id <= 0) {
                        return false;
                    }
                    return true;
                }
                return false;
            } else if (chat.creator) {
                return true;
            } else {
                if (chat.admin_rights == null || (!chat.admin_rights.delete_messages && !message.out)) {
                    return false;
                }
                return true;
            }
        } else if (z || isOut(message) || !ChatObject.isChannel(chat)) {
            return true;
        } else {
            return false;
        }
    }

    public String getForwardedName() {
        if (this.messageOwner.fwd_from == null) {
            return null;
        }
        if (this.messageOwner.fwd_from.channel_id != 0) {
            TLRPC.Chat chat = MessagesController.getInstance(this.currentAccount).getChat(Integer.valueOf(this.messageOwner.fwd_from.channel_id));
            if (chat != null) {
                return chat.title;
            }
            return null;
        } else if (this.messageOwner.fwd_from.from_id != 0) {
            TLRPC.User user = MessagesController.getInstance(this.currentAccount).getUser(Integer.valueOf(this.messageOwner.fwd_from.from_id));
            if (user != null) {
                return UserObject.getName(user);
            }
            return null;
        } else if (this.messageOwner.fwd_from.from_name != null) {
            return this.messageOwner.fwd_from.from_name;
        } else {
            return null;
        }
    }

    public int getFromId() {
        if (this.messageOwner.fwd_from == null || this.messageOwner.fwd_from.saved_from_peer == null) {
            if (this.messageOwner.from_id != 0) {
                return this.messageOwner.from_id;
            }
            if (this.messageOwner.post) {
                return this.messageOwner.to_id.channel_id;
            }
            return 0;
        } else if (this.messageOwner.fwd_from.saved_from_peer.user_id != 0) {
            if (this.messageOwner.fwd_from.from_id != 0) {
                return this.messageOwner.fwd_from.from_id;
            }
            return this.messageOwner.fwd_from.saved_from_peer.user_id;
        } else if (this.messageOwner.fwd_from.saved_from_peer.channel_id != 0) {
            if (isSavedFromMegagroup() && this.messageOwner.fwd_from.from_id != 0) {
                return this.messageOwner.fwd_from.from_id;
            }
            if (this.messageOwner.fwd_from.channel_id != 0) {
                return -this.messageOwner.fwd_from.channel_id;
            }
            return -this.messageOwner.fwd_from.saved_from_peer.channel_id;
        } else if (this.messageOwner.fwd_from.saved_from_peer.chat_id == 0) {
            return 0;
        } else {
            if (this.messageOwner.fwd_from.from_id != 0) {
                return this.messageOwner.fwd_from.from_id;
            }
            if (this.messageOwner.fwd_from.channel_id != 0) {
                return -this.messageOwner.fwd_from.channel_id;
            }
            return -this.messageOwner.fwd_from.saved_from_peer.chat_id;
        }
    }

    public boolean isWallpaper() {
        return (this.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) && this.messageOwner.media.webpage != null && "app_background".equals(this.messageOwner.media.webpage.type);
    }

    public int getMediaExistanceFlags() {
        int i = this.attachPathExists ? 1 : 0;
        return this.mediaExists ? i | 2 : i;
    }

    public void applyMediaExistanceFlags(int i) {
        if (i == -1) {
            checkMediaExistance();
            return;
        }
        boolean z = false;
        this.attachPathExists = (i & 1) != 0;
        if ((i & 2) != 0) {
            z = true;
        }
        this.mediaExists = z;
    }

    public void checkMediaExistance() {
        TLRPC.PhotoSize closestPhotoSizeWithSize;
        this.attachPathExists = false;
        this.mediaExists = false;
        int i = this.type;
        if (i == 1) {
            if (FileLoader.getClosestPhotoSizeWithSize(this.photoThumbs, AndroidUtilities.getPhotoSize()) != null) {
                File pathToMessage = FileLoader.getPathToMessage(this.messageOwner);
                if (needDrawBluredPreview()) {
                    this.mediaExists = new File(pathToMessage.getAbsolutePath() + ".enc").exists();
                }
                if (!this.mediaExists) {
                    this.mediaExists = pathToMessage.exists();
                }
            }
        } else if (i == 8 || i == 3 || i == 9 || i == 2 || i == 14 || i == 5) {
            if (this.messageOwner.attachPath != null && this.messageOwner.attachPath.length() > 0) {
                this.attachPathExists = new File(this.messageOwner.attachPath).exists();
            }
            if (!this.attachPathExists) {
                File pathToMessage2 = FileLoader.getPathToMessage(this.messageOwner);
                if (this.type == 3 && needDrawBluredPreview()) {
                    this.mediaExists = new File(pathToMessage2.getAbsolutePath() + ".enc").exists();
                }
                if (!this.mediaExists) {
                    this.mediaExists = pathToMessage2.exists();
                }
            }
        } else {
            TLRPC.Document document = getDocument();
            if (document != null) {
                if (isWallpaper()) {
                    this.mediaExists = FileLoader.getPathToAttach(document, true).exists();
                } else {
                    this.mediaExists = FileLoader.getPathToAttach(document).exists();
                }
            } else if (this.type == 0 && (closestPhotoSizeWithSize = FileLoader.getClosestPhotoSizeWithSize(this.photoThumbs, AndroidUtilities.getPhotoSize())) != null && closestPhotoSizeWithSize != null) {
                this.mediaExists = FileLoader.getPathToAttach(closestPhotoSizeWithSize, true).exists();
            }
        }
    }

    public boolean equals(MessageObject messageObject) {
        return getId() == messageObject.getId() && getDialogId() == messageObject.getDialogId();
    }
}