2013-10-25 17:19:00 +02:00
|
|
|
/*
|
2015-10-29 18:10:07 +01:00
|
|
|
* This is the source code of Telegram for Android v. 3.x.x.
|
2013-10-25 17:19:00 +02:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2017-03-31 01:58:05 +02:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2017.
|
2013-10-25 17:19:00 +02:00
|
|
|
*/
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
package org.telegram.messenger;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-09-02 00:14:21 +02:00
|
|
|
import android.graphics.Typeface;
|
2017-07-08 18:32:04 +02:00
|
|
|
import android.os.Build;
|
2014-02-28 23:28:25 +01:00
|
|
|
import android.text.Layout;
|
|
|
|
import android.text.Spannable;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.text.SpannableString;
|
2014-10-15 20:43:52 +02:00
|
|
|
import android.text.SpannableStringBuilder;
|
|
|
|
import android.text.Spanned;
|
2014-02-28 23:28:25 +01:00
|
|
|
import android.text.StaticLayout;
|
|
|
|
import android.text.TextPaint;
|
2014-10-15 20:43:52 +02:00
|
|
|
import android.text.TextUtils;
|
2015-09-02 00:14:21 +02:00
|
|
|
import android.text.style.URLSpan;
|
2014-02-28 23:28:25 +01:00
|
|
|
import android.text.util.Linkify;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
2015-11-26 22:04:02 +01:00
|
|
|
import org.telegram.tgnet.TLObject;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2016-04-22 15:49:00 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
2015-09-02 00:14:21 +02:00
|
|
|
import org.telegram.ui.Components.TypefaceSpan;
|
2015-10-29 18:10:07 +01:00
|
|
|
import org.telegram.ui.Components.URLSpanBotCommand;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.URLSpanMono;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.ui.Components.URLSpanNoUnderline;
|
2015-05-21 23:27:27 +02:00
|
|
|
import org.telegram.ui.Components.URLSpanNoUnderlineBold;
|
2015-09-02 00:14:21 +02:00
|
|
|
import org.telegram.ui.Components.URLSpanReplacement;
|
2016-05-25 23:49:47 +02:00
|
|
|
import org.telegram.ui.Components.URLSpanUserMention;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
import java.io.File;
|
2013-10-25 17:19:00 +02:00
|
|
|
import java.util.AbstractMap;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.GregorianCalendar;
|
2017-07-08 18:32:04 +02:00
|
|
|
import java.util.HashMap;
|
2015-03-19 00:09:45 +01:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
public class MessageObject {
|
2014-08-22 16:24:33 +02:00
|
|
|
|
|
|
|
public static final int MESSAGE_SEND_STATE_SENDING = 1;
|
|
|
|
public static final int MESSAGE_SEND_STATE_SENT = 0;
|
|
|
|
public static final int MESSAGE_SEND_STATE_SEND_ERROR = 2;
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
public TLRPC.Message messageOwner;
|
|
|
|
public CharSequence messageText;
|
2015-04-09 20:00:14 +02:00
|
|
|
public CharSequence linkDescription;
|
2015-05-03 13:48:36 +02:00
|
|
|
public CharSequence caption;
|
2015-03-19 00:09:45 +01:00
|
|
|
public MessageObject replyMessageObject;
|
2016-04-22 15:49:00 +02:00
|
|
|
public int type = 1000;
|
2017-07-08 18:32:04 +02:00
|
|
|
private int isRoundVideoCached;
|
|
|
|
public long eventId;
|
2014-03-31 16:14:49 +02:00
|
|
|
public int contentType;
|
2013-10-25 17:19:00 +02:00
|
|
|
public String dateKey;
|
2015-02-26 02:32:51 +01:00
|
|
|
public String monthKey;
|
2015-05-21 23:27:27 +02:00
|
|
|
public boolean deleted;
|
2014-02-28 23:28:25 +01:00
|
|
|
public float audioProgress;
|
2017-07-08 18:32:04 +02:00
|
|
|
public float gifState;
|
2014-02-28 23:28:25 +01:00
|
|
|
public int audioProgressSec;
|
2017-03-31 01:58:05 +02:00
|
|
|
public boolean isDateObject;
|
2015-02-01 19:51:02 +01:00
|
|
|
public ArrayList<TLRPC.PhotoSize> photoThumbs;
|
2016-10-11 13:57:01 +02:00
|
|
|
public ArrayList<TLRPC.PhotoSize> photoThumbs2;
|
2015-05-21 23:27:27 +02:00
|
|
|
public VideoEditedInfo videoEditedInfo;
|
2015-09-24 22:52:02 +02:00
|
|
|
public boolean viewsReloaded;
|
2016-04-22 15:49:00 +02:00
|
|
|
public int wantedBotKeyboardWidth;
|
|
|
|
public boolean attachPathExists;
|
|
|
|
public boolean mediaExists;
|
2016-10-11 13:57:01 +02:00
|
|
|
public boolean resendAsIs;
|
2017-03-31 01:58:05 +02:00
|
|
|
public String customReplyName;
|
|
|
|
public boolean useCustomPhoto;
|
|
|
|
public StringBuilder botButtonsLayout;
|
2016-04-22 15:49:00 +02:00
|
|
|
|
|
|
|
public boolean forceUpdate;
|
2014-02-28 23:28:25 +01:00
|
|
|
|
|
|
|
public int lastLineWidth;
|
|
|
|
public int textWidth;
|
|
|
|
public int textHeight;
|
2017-03-31 01:58:05 +02:00
|
|
|
public boolean hasRtl;
|
|
|
|
public float textXOffset;
|
2014-02-28 23:28:25 +01:00
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
private boolean layoutCreated;
|
2016-10-11 13:57:01 +02:00
|
|
|
private int generatedWithMinSize;
|
2016-03-06 02:49:31 +01:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
public static Pattern urlPattern;
|
|
|
|
|
2014-02-28 23:28:25 +01:00
|
|
|
public static class TextLayoutBlock {
|
|
|
|
public StaticLayout textLayout;
|
2016-03-16 13:26:32 +01:00
|
|
|
public float textYOffset;
|
|
|
|
public int charactersOffset;
|
2017-03-31 01:58:05 +02:00
|
|
|
public int charactersEnd;
|
2016-03-16 13:26:32 +01:00
|
|
|
public int height;
|
2017-03-31 01:58:05 +02:00
|
|
|
public byte directionFlags;
|
|
|
|
|
|
|
|
public boolean isRtl() {
|
|
|
|
return (directionFlags & 1) != 0 && (directionFlags & 2) == 0;
|
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static final int LINES_PER_BLOCK = 10;
|
|
|
|
|
|
|
|
public ArrayList<TextLayoutBlock> textLayoutBlocks;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
public MessageObject(TLRPC.Message message, AbstractMap<Integer, TLRPC.User> users, boolean generateLayout) {
|
2015-11-26 22:04:02 +01:00
|
|
|
this(message, users, null, generateLayout);
|
|
|
|
}
|
|
|
|
|
|
|
|
public MessageObject(TLRPC.Message message, AbstractMap<Integer, TLRPC.User> users, AbstractMap<Integer, TLRPC.Chat> chats, boolean generateLayout) {
|
2017-07-08 18:32:04 +02:00
|
|
|
this(message, users, chats, generateLayout, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public MessageObject(TLRPC.Message message, AbstractMap<Integer, TLRPC.User> users, AbstractMap<Integer, TLRPC.Chat> chats, boolean generateLayout, long eid) {
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.createChatResources(null, true);
|
2014-05-17 01:05:49 +02:00
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
messageOwner = message;
|
2017-07-08 18:32:04 +02:00
|
|
|
eventId = eid;
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
if (message.replyMessage != null) {
|
2015-11-26 22:04:02 +01:00
|
|
|
replyMessageObject = new MessageObject(message.replyMessage, users, chats, false);
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
TLRPC.User fromUser = null;
|
2016-03-16 13:26:32 +01:00
|
|
|
if (message.from_id > 0) {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (users != null) {
|
|
|
|
fromUser = users.get(message.from_id);
|
|
|
|
}
|
|
|
|
if (fromUser == null) {
|
|
|
|
fromUser = MessagesController.getInstance().getUser(message.from_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 17:19:00 +02:00
|
|
|
if (message instanceof TLRPC.TL_messageService) {
|
|
|
|
if (message.action != null) {
|
|
|
|
if (message.action instanceof TLRPC.TL_messageActionChatCreate) {
|
2015-03-26 18:34:47 +01:00
|
|
|
if (isOut()) {
|
2014-03-22 23:31:55 +01:00
|
|
|
messageText = LocaleController.getString("ActionYouCreateGroup", R.string.ActionYouCreateGroup);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionCreateGroup", R.string.ActionCreateGroup), "un1", fromUser);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionChatDeleteUser) {
|
|
|
|
if (message.action.user_id == message.from_id) {
|
2015-03-26 18:34:47 +01:00
|
|
|
if (isOut()) {
|
2014-03-22 23:31:55 +01:00
|
|
|
messageText = LocaleController.getString("ActionYouLeftUser", R.string.ActionYouLeftUser);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionLeftUser", R.string.ActionLeftUser), "un1", fromUser);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2014-10-15 20:43:52 +02:00
|
|
|
TLRPC.User whoUser = null;
|
2014-08-22 16:24:33 +02:00
|
|
|
if (users != null) {
|
2014-10-15 20:43:52 +02:00
|
|
|
whoUser = users.get(message.action.user_id);
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
2014-10-15 20:43:52 +02:00
|
|
|
if (whoUser == null) {
|
|
|
|
whoUser = MessagesController.getInstance().getUser(message.action.user_id);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2016-03-16 13:26:32 +01:00
|
|
|
if (isOut()) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionYouKickUser", R.string.ActionYouKickUser), "un2", whoUser);
|
|
|
|
} else if (message.action.user_id == UserConfig.getClientUserId()) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionKickUserYou", R.string.ActionKickUserYou), "un1", fromUser);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionKickUser", R.string.ActionKickUser), "un2", whoUser);
|
|
|
|
messageText = replaceWithLink(messageText, "un1", fromUser);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionChatAddUser) {
|
2015-11-26 22:04:02 +01:00
|
|
|
int singleUserId = messageOwner.action.user_id;
|
|
|
|
if (singleUserId == 0 && messageOwner.action.users.size() == 1) {
|
|
|
|
singleUserId = messageOwner.action.users.get(0);
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
if (singleUserId != 0) {
|
|
|
|
TLRPC.User whoUser = null;
|
|
|
|
if (users != null) {
|
|
|
|
whoUser = users.get(singleUserId);
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
if (whoUser == null) {
|
|
|
|
whoUser = MessagesController.getInstance().getUser(singleUserId);
|
|
|
|
}
|
2016-03-16 13:26:32 +01:00
|
|
|
if (singleUserId == message.from_id) {
|
|
|
|
if (message.to_id.channel_id != 0 && !isMegagroup()) {
|
|
|
|
messageText = LocaleController.getString("ChannelJoined", R.string.ChannelJoined);
|
|
|
|
} else {
|
|
|
|
if (message.to_id.channel_id != 0 && isMegagroup()) {
|
|
|
|
if (singleUserId == UserConfig.getClientUserId()) {
|
|
|
|
messageText = LocaleController.getString("ChannelMegaJoined", R.string.ChannelMegaJoined);
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionAddUserSelfMega", R.string.ActionAddUserSelfMega), "un1", fromUser);
|
|
|
|
}
|
|
|
|
} else if (isOut()) {
|
|
|
|
messageText = LocaleController.getString("ActionAddUserSelfYou", R.string.ActionAddUserSelfYou);
|
2015-09-24 22:52:02 +02:00
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionAddUserSelf", R.string.ActionAddUserSelf), "un1", fromUser);
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
if (isOut()) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionYouAddUser", R.string.ActionYouAddUser), "un2", whoUser);
|
|
|
|
} else if (singleUserId == UserConfig.getClientUserId()) {
|
|
|
|
if (message.to_id.channel_id != 0) {
|
|
|
|
if (isMegagroup()) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("MegaAddedBy", R.string.MegaAddedBy), "un1", fromUser);
|
2015-11-26 22:04:02 +01:00
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ChannelAddedBy", R.string.ChannelAddedBy), "un1", fromUser);
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionAddUserYou", R.string.ActionAddUserYou), "un1", fromUser);
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionAddUser", R.string.ActionAddUser), "un2", whoUser);
|
|
|
|
messageText = replaceWithLink(messageText, "un1", fromUser);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isOut()) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionYouAddUser", R.string.ActionYouAddUser), "un2", message.action.users, users);
|
2015-09-24 22:52:02 +02:00
|
|
|
} else {
|
2015-11-26 22:04:02 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionAddUser", R.string.ActionAddUser), "un2", message.action.users, users);
|
|
|
|
messageText = replaceWithLink(messageText, "un1", fromUser);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionChatJoinedByLink) {
|
2016-03-16 13:26:32 +01:00
|
|
|
if (isOut()) {
|
|
|
|
messageText = LocaleController.getString("ActionInviteYou", R.string.ActionInviteYou);
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionInviteUser", R.string.ActionInviteUser), "un1", fromUser);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionChatEditPhoto) {
|
2015-11-26 22:04:02 +01:00
|
|
|
if (message.to_id.channel_id != 0 && !isMegagroup()) {
|
2015-09-24 22:52:02 +02:00
|
|
|
messageText = LocaleController.getString("ActionChannelChangedPhoto", R.string.ActionChannelChangedPhoto);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2015-09-24 22:52:02 +02:00
|
|
|
if (isOut()) {
|
|
|
|
messageText = LocaleController.getString("ActionYouChangedPhoto", R.string.ActionYouChangedPhoto);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionChangedPhoto", R.string.ActionChangedPhoto), "un1", fromUser);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionChatEditTitle) {
|
2015-11-26 22:04:02 +01:00
|
|
|
if (message.to_id.channel_id != 0 && !isMegagroup()) {
|
2015-09-24 22:52:02 +02:00
|
|
|
messageText = LocaleController.getString("ActionChannelChangedTitle", R.string.ActionChannelChangedTitle).replace("un2", message.action.title);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2015-09-24 22:52:02 +02:00
|
|
|
if (isOut()) {
|
|
|
|
messageText = LocaleController.getString("ActionYouChangedTitle", R.string.ActionYouChangedTitle).replace("un2", message.action.title);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionChangedTitle", R.string.ActionChangedTitle).replace("un2", message.action.title), "un1", fromUser);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionChatDeletePhoto) {
|
2015-11-26 22:04:02 +01:00
|
|
|
if (message.to_id.channel_id != 0 && !isMegagroup()) {
|
2015-09-24 22:52:02 +02:00
|
|
|
messageText = LocaleController.getString("ActionChannelRemovedPhoto", R.string.ActionChannelRemovedPhoto);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2015-09-24 22:52:02 +02:00
|
|
|
if (isOut()) {
|
|
|
|
messageText = LocaleController.getString("ActionYouRemovedPhoto", R.string.ActionYouRemovedPhoto);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionRemovedPhoto", R.string.ActionRemovedPhoto), "un1", fromUser);
|
2013-12-20 20:25:49 +01:00
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionTTLChange) {
|
|
|
|
if (message.action.ttl != 0) {
|
2015-03-26 18:34:47 +01:00
|
|
|
if (isOut()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, LocaleController.formatTTLString(message.action.ttl));
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
messageText = LocaleController.formatString("MessageLifetimeChanged", R.string.MessageLifetimeChanged, UserObject.getFirstName(fromUser), LocaleController.formatTTLString(message.action.ttl));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-03-26 18:34:47 +01:00
|
|
|
if (isOut()) {
|
2014-03-22 23:31:55 +01:00
|
|
|
messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = LocaleController.formatString("MessageLifetimeRemoved", R.string.MessageLifetimeRemoved, UserObject.getFirstName(fromUser));
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-20 20:25:49 +01:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
|
2015-11-26 22:04:02 +01:00
|
|
|
String date;
|
|
|
|
long time = ((long) message.date) * 1000;
|
|
|
|
if (LocaleController.getInstance().formatterDay != null && LocaleController.getInstance().formatterYear != null) {
|
|
|
|
date = LocaleController.formatString("formatDateAtTime", R.string.formatDateAtTime, LocaleController.getInstance().formatterYear.format(time), LocaleController.getInstance().formatterDay.format(time));
|
|
|
|
} else {
|
|
|
|
date = "" + message.date;
|
|
|
|
}
|
2014-09-14 01:40:36 +02:00
|
|
|
TLRPC.User to_user = UserConfig.getCurrentUser();
|
|
|
|
if (to_user == null) {
|
|
|
|
if (users != null) {
|
|
|
|
to_user = users.get(messageOwner.to_id.user_id);
|
|
|
|
}
|
|
|
|
if (to_user == null) {
|
|
|
|
to_user = MessagesController.getInstance().getUser(messageOwner.to_id.user_id);
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
String name = to_user != null ? UserObject.getFirstName(to_user) : "";
|
2014-09-14 01:40:36 +02:00
|
|
|
messageText = LocaleController.formatString("NotificationUnrecognizedDevice", R.string.NotificationUnrecognizedDevice, name, date, message.action.title, message.action.address);
|
2013-12-20 20:25:49 +01:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionUserJoined) {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = LocaleController.formatString("NotificationContactJoined", R.string.NotificationContactJoined, UserObject.getUserName(fromUser));
|
2013-12-20 20:25:49 +01:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = LocaleController.formatString("NotificationContactNewPhoto", R.string.NotificationContactNewPhoto, UserObject.getUserName(fromUser));
|
2014-10-22 22:01:07 +02:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageEncryptedAction) {
|
2014-04-04 19:58:33 +02:00
|
|
|
if (message.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages) {
|
2015-03-26 18:34:47 +01:00
|
|
|
if (isOut()) {
|
2014-04-04 19:58:33 +02:00
|
|
|
messageText = LocaleController.formatString("ActionTakeScreenshootYou", R.string.ActionTakeScreenshootYou);
|
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionTakeScreenshoot", R.string.ActionTakeScreenshoot), "un1", fromUser);
|
2014-04-04 19:58:33 +02:00
|
|
|
}
|
2014-10-22 22:01:07 +02:00
|
|
|
} else if (message.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
|
|
|
|
TLRPC.TL_decryptedMessageActionSetMessageTTL action = (TLRPC.TL_decryptedMessageActionSetMessageTTL) message.action.encryptedAction;
|
|
|
|
if (action.ttl_seconds != 0) {
|
2015-03-26 18:34:47 +01:00
|
|
|
if (isOut()) {
|
2017-03-31 01:58:05 +02:00
|
|
|
messageText = LocaleController.formatString("MessageLifetimeChangedOutgoing", R.string.MessageLifetimeChangedOutgoing, LocaleController.formatTTLString(action.ttl_seconds));
|
2014-10-22 22:01:07 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
messageText = LocaleController.formatString("MessageLifetimeChanged", R.string.MessageLifetimeChanged, UserObject.getFirstName(fromUser), LocaleController.formatTTLString(action.ttl_seconds));
|
2014-10-22 22:01:07 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-03-26 18:34:47 +01:00
|
|
|
if (isOut()) {
|
2014-10-22 22:01:07 +02:00
|
|
|
messageText = LocaleController.getString("MessageLifetimeYouRemoved", R.string.MessageLifetimeYouRemoved);
|
|
|
|
} else {
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = LocaleController.formatString("MessageLifetimeRemoved", R.string.MessageLifetimeRemoved, UserObject.getFirstName(fromUser));
|
2014-10-22 22:01:07 +02:00
|
|
|
}
|
|
|
|
}
|
2014-04-04 19:58:33 +02:00
|
|
|
}
|
2014-07-27 00:28:33 +02:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionCreatedBroadcastList) {
|
|
|
|
messageText = LocaleController.formatString("YouCreatedBroadcastList", R.string.YouCreatedBroadcastList);
|
2015-09-24 22:52:02 +02:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionChannelCreate) {
|
2015-11-26 22:04:02 +01:00
|
|
|
if (isMegagroup()) {
|
|
|
|
messageText = LocaleController.getString("ActionCreateMega", R.string.ActionCreateMega);
|
|
|
|
} else {
|
|
|
|
messageText = LocaleController.getString("ActionCreateChannel", R.string.ActionCreateChannel);
|
|
|
|
}
|
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionChatMigrateTo) {
|
|
|
|
messageText = LocaleController.getString("ActionMigrateFromGroup", R.string.ActionMigrateFromGroup);
|
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionChannelMigrateFrom) {
|
|
|
|
messageText = LocaleController.getString("ActionMigrateFromGroup", R.string.ActionMigrateFromGroup);
|
2016-03-16 13:26:32 +01:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionPinMessage) {
|
2017-03-31 01:58:05 +02:00
|
|
|
generatePinMessageText(fromUser, fromUser == null && chats != null ? chats.get(message.to_id.channel_id) : null);
|
2016-06-24 12:27:15 +02:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionHistoryClear) {
|
|
|
|
messageText = LocaleController.getString("HistoryCleared", R.string.HistoryCleared);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionGameScore) {
|
|
|
|
generateGameMessageText(fromUser);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionPhoneCall) {
|
|
|
|
TLRPC.TL_messageActionPhoneCall call = (TLRPC.TL_messageActionPhoneCall) messageOwner.action;
|
|
|
|
boolean isMissed = call.reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed;
|
|
|
|
if (messageOwner.from_id == UserConfig.getClientUserId()) {
|
|
|
|
if (isMissed) {
|
|
|
|
messageText = LocaleController.getString("CallMessageOutgoingMissed", R.string.CallMessageOutgoingMissed);
|
|
|
|
}else {
|
|
|
|
messageText = LocaleController.getString("CallMessageOutgoing", R.string.CallMessageOutgoing);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (isMissed) {
|
|
|
|
messageText = LocaleController.getString("CallMessageIncomingMissed", R.string.CallMessageIncomingMissed);
|
|
|
|
} else if(call.reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy) {
|
|
|
|
messageText = LocaleController.getString("CallMessageIncomingDeclined", R.string.CallMessageIncomingDeclined);
|
|
|
|
} else {
|
|
|
|
messageText = LocaleController.getString("CallMessageIncoming", R.string.CallMessageIncoming);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (call.duration > 0) {
|
|
|
|
String duration = LocaleController.formatCallDuration(call.duration);
|
|
|
|
messageText = LocaleController.formatString("CallMessageWithDuration", R.string.CallMessageWithDuration, messageText, duration);
|
|
|
|
String _messageText = messageText.toString();
|
|
|
|
int start = _messageText.indexOf(duration);
|
|
|
|
if (start != -1) {
|
|
|
|
SpannableString sp = new SpannableString(messageText);
|
|
|
|
int end = start + duration.length();
|
|
|
|
if (start > 0 && _messageText.charAt(start - 1) == '(') {
|
|
|
|
start--;
|
|
|
|
}
|
|
|
|
if (end < _messageText.length() && _messageText.charAt(end) == ')') {
|
|
|
|
end++;
|
|
|
|
}
|
|
|
|
sp.setSpan(new TypefaceSpan(Typeface.DEFAULT), start, end, 0);
|
|
|
|
messageText = sp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (message.action instanceof TLRPC.TL_messageActionPaymentSent) {
|
|
|
|
TLRPC.User user = null;
|
|
|
|
int uid = (int) getDialogId();
|
|
|
|
if (users != null) {
|
|
|
|
fromUser = users.get(uid);
|
|
|
|
}
|
|
|
|
if (fromUser == null) {
|
|
|
|
fromUser = MessagesController.getInstance().getUser(uid);
|
|
|
|
}
|
|
|
|
generatePaymentSentMessageText(user);
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (!isMediaEmpty()) {
|
2013-10-25 17:19:00 +02:00
|
|
|
if (message.media instanceof TLRPC.TL_messageMediaPhoto) {
|
2014-03-22 23:31:55 +01:00
|
|
|
messageText = LocaleController.getString("AttachPhoto", R.string.AttachPhoto);
|
2016-03-06 02:49:31 +01:00
|
|
|
} else if (isVideo()) {
|
2014-03-22 23:31:55 +01:00
|
|
|
messageText = LocaleController.getString("AttachVideo", R.string.AttachVideo);
|
2016-03-06 02:49:31 +01:00
|
|
|
} else if (isVoice()) {
|
|
|
|
messageText = LocaleController.getString("AttachAudio", R.string.AttachAudio);
|
2017-07-08 18:32:04 +02:00
|
|
|
} else if (isRoundVideo()) {
|
|
|
|
messageText = LocaleController.getString("AttachRound", R.string.AttachRound);
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (message.media instanceof TLRPC.TL_messageMediaGeo || message.media instanceof TLRPC.TL_messageMediaVenue) {
|
2014-03-22 23:31:55 +01:00
|
|
|
messageText = LocaleController.getString("AttachLocation", R.string.AttachLocation);
|
2013-10-25 17:19:00 +02:00
|
|
|
} else if (message.media instanceof TLRPC.TL_messageMediaContact) {
|
2014-03-22 23:31:55 +01:00
|
|
|
messageText = LocaleController.getString("AttachContact", R.string.AttachContact);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (message.media instanceof TLRPC.TL_messageMediaGame) {
|
|
|
|
messageText = message.message;
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (message.media instanceof TLRPC.TL_messageMediaInvoice) {
|
|
|
|
messageText = message.media.description;
|
2013-12-20 20:25:49 +01:00
|
|
|
} else if (message.media instanceof TLRPC.TL_messageMediaUnsupported) {
|
2016-01-09 18:40:23 +01:00
|
|
|
messageText = LocaleController.getString("UnsupportedMedia", R.string.UnsupportedMedia);
|
2013-12-26 12:43:37 +01:00
|
|
|
} else if (message.media instanceof TLRPC.TL_messageMediaDocument) {
|
2015-01-02 23:15:07 +01:00
|
|
|
if (isSticker()) {
|
2015-03-19 00:09:45 +01:00
|
|
|
String sch = getStrickerChar();
|
|
|
|
if (sch != null && sch.length() > 0) {
|
|
|
|
messageText = String.format("%s %s", sch, LocaleController.getString("AttachSticker", R.string.AttachSticker));
|
|
|
|
} else {
|
|
|
|
messageText = LocaleController.getString("AttachSticker", R.string.AttachSticker);
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
} else if (isMusic()) {
|
|
|
|
messageText = LocaleController.getString("AttachMusic", R.string.AttachMusic);
|
2016-01-11 18:19:48 +01:00
|
|
|
} else if (isGif()) {
|
|
|
|
messageText = LocaleController.getString("AttachGif", R.string.AttachGif);
|
2015-01-02 23:15:07 +01:00
|
|
|
} else {
|
2015-03-19 00:09:45 +01:00
|
|
|
String name = FileLoader.getDocumentFileName(message.media.document);
|
|
|
|
if (name != null && name.length() > 0) {
|
|
|
|
messageText = name;
|
|
|
|
} else {
|
|
|
|
messageText = LocaleController.getString("AttachDocument", R.string.AttachDocument);
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
messageText = message.message;
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
if (messageText == null) {
|
|
|
|
messageText = "";
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
setType();
|
|
|
|
measureInlineBotButtons();
|
2013-10-25 17:19:00 +02:00
|
|
|
|
|
|
|
Calendar rightNow = new GregorianCalendar();
|
2015-02-26 02:32:51 +01:00
|
|
|
rightNow.setTimeInMillis((long) (messageOwner.date) * 1000);
|
2013-10-25 17:19:00 +02:00
|
|
|
int dateDay = rightNow.get(Calendar.DAY_OF_YEAR);
|
|
|
|
int dateYear = rightNow.get(Calendar.YEAR);
|
|
|
|
int dateMonth = rightNow.get(Calendar.MONTH);
|
|
|
|
dateKey = String.format("%d_%02d_%02d", dateYear, dateMonth, dateDay);
|
2016-04-22 15:49:00 +02:00
|
|
|
monthKey = String.format("%d_%02d", dateYear, dateMonth);
|
2014-02-28 23:28:25 +01:00
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
if (messageOwner.message != null && messageOwner.id < 0 && messageOwner.message.length() > 6 && (isVideo() || isNewGif() || isRoundVideo())) {
|
2015-05-21 23:27:27 +02:00
|
|
|
videoEditedInfo = new VideoEditedInfo();
|
2016-06-24 12:27:15 +02:00
|
|
|
if (!videoEditedInfo.parseString(messageOwner.message)) {
|
|
|
|
videoEditedInfo = null;
|
2017-07-08 18:32:04 +02:00
|
|
|
} else {
|
|
|
|
videoEditedInfo.roundVideo = isRoundVideo();
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
generateCaption();
|
2015-02-01 19:51:02 +01:00
|
|
|
if (generateLayout) {
|
2016-10-11 13:57:01 +02:00
|
|
|
TextPaint paint;
|
|
|
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
2017-03-31 01:58:05 +02:00
|
|
|
paint = Theme.chat_msgGameTextPaint;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
paint = Theme.chat_msgTextPaint;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
int[] emojiOnly = MessagesController.getInstance().allowBigEmoji ? new int[1] : null;
|
|
|
|
messageText = Emoji.replaceEmoji(messageText, paint.getFontMetricsInt(), AndroidUtilities.dp(20), false, emojiOnly);
|
|
|
|
if (emojiOnly != null && emojiOnly[0] >= 1 && emojiOnly[0] <= 3) {
|
|
|
|
TextPaint emojiPaint;
|
|
|
|
int size;
|
|
|
|
switch (emojiOnly[0]) {
|
|
|
|
case 1:
|
2017-03-31 01:58:05 +02:00
|
|
|
emojiPaint = Theme.chat_msgTextPaintOneEmoji;
|
2016-10-11 13:57:01 +02:00
|
|
|
size = AndroidUtilities.dp(32);
|
|
|
|
break;
|
|
|
|
case 2:
|
2017-03-31 01:58:05 +02:00
|
|
|
emojiPaint = Theme.chat_msgTextPaintTwoEmoji;
|
2016-10-11 13:57:01 +02:00
|
|
|
size = AndroidUtilities.dp(28);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
default:
|
2017-03-31 01:58:05 +02:00
|
|
|
emojiPaint = Theme.chat_msgTextPaintThreeEmoji;
|
2016-10-11 13:57:01 +02:00
|
|
|
size = AndroidUtilities.dp(24);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Emoji.EmojiSpan[] spans = ((Spannable) messageText).getSpans(0, messageText.length(), Emoji.EmojiSpan.class);
|
|
|
|
if (spans != null && spans.length > 0) {
|
|
|
|
for (int a = 0; a < spans.length; a++) {
|
|
|
|
spans[a].replaceFontMetrics(emojiPaint.getFontMetricsInt(), size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
generateLayout(fromUser);
|
2014-11-21 20:36:21 +01:00
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
layoutCreated = generateLayout;
|
2015-02-01 19:51:02 +01:00
|
|
|
generateThumbs(false);
|
2016-04-22 15:49:00 +02:00
|
|
|
checkMediaExistance();
|
2014-10-15 20:43:52 +02:00
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public MessageObject(TLRPC.TL_channelAdminLogEvent event, ArrayList<MessageObject> messageObjects, HashMap<String, ArrayList<MessageObject>> messagesByDays, TLRPC.Chat chat, int[] mid) {
|
|
|
|
TLRPC.User fromUser = null;
|
|
|
|
if (event.user_id > 0) {
|
|
|
|
if (fromUser == null) {
|
|
|
|
fromUser = MessagesController.getInstance().getUser(event.user_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Calendar rightNow = new GregorianCalendar();
|
|
|
|
rightNow.setTimeInMillis((long) (event.date) * 1000);
|
|
|
|
int dateDay = rightNow.get(Calendar.DAY_OF_YEAR);
|
|
|
|
int dateYear = rightNow.get(Calendar.YEAR);
|
|
|
|
int dateMonth = rightNow.get(Calendar.MONTH);
|
|
|
|
dateKey = String.format("%d_%02d_%02d", dateYear, dateMonth, dateDay);
|
|
|
|
monthKey = String.format("%d_%02d", dateYear, dateMonth);
|
|
|
|
|
|
|
|
ArrayList<MessageObject> dayArray = messagesByDays.get(dateKey);
|
|
|
|
|
|
|
|
TLRPC.Peer to_id = new TLRPC.TL_peerChannel();
|
|
|
|
to_id.channel_id = chat.id;
|
|
|
|
|
|
|
|
if (dayArray == null) {
|
|
|
|
dayArray = new ArrayList<>();
|
|
|
|
messagesByDays.put(dateKey, dayArray);
|
|
|
|
TLRPC.Message dateMsg = new TLRPC.Message();
|
|
|
|
dateMsg.message = LocaleController.formatDateChat(event.date);
|
|
|
|
dateMsg.id = 0;
|
|
|
|
dateMsg.date = event.date;
|
|
|
|
MessageObject dateObj = new MessageObject(dateMsg, null, false);
|
|
|
|
dateObj.type = 10;
|
|
|
|
dateObj.contentType = 1;
|
|
|
|
dateObj.isDateObject = true;
|
|
|
|
messageObjects.add(dateObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
TLRPC.Message message = null;
|
|
|
|
if (event.action instanceof TLRPC.TL_channelAdminLogEventActionChangeTitle) {
|
|
|
|
String title = ((TLRPC.TL_channelAdminLogEventActionChangeTitle) event.action).new_value;
|
|
|
|
if (chat.megagroup) {
|
|
|
|
messageText = replaceWithLink(LocaleController.formatString("EventLogEditedGroupTitle", R.string.EventLogEditedGroupTitle, title), "un1", fromUser);
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.formatString("EventLogEditedChannelTitle", R.string.EventLogEditedChannelTitle, title), "un1", fromUser);
|
|
|
|
}
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionChangePhoto) {
|
|
|
|
messageOwner = new TLRPC.TL_messageService();
|
|
|
|
if (event.action.new_photo instanceof TLRPC.TL_chatPhotoEmpty) {
|
|
|
|
messageOwner.action = new TLRPC.TL_messageActionChatDeletePhoto();
|
|
|
|
if (chat.megagroup) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogRemovedWGroupPhoto", R.string.EventLogRemovedWGroupPhoto), "un1", fromUser);
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogRemovedChannelPhoto", R.string.EventLogRemovedChannelPhoto), "un1", fromUser);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
messageOwner.action = new TLRPC.TL_messageActionChatEditPhoto();
|
|
|
|
messageOwner.action.photo = new TLRPC.TL_photo();
|
|
|
|
TLRPC.TL_photoSize photoSize = new TLRPC.TL_photoSize();
|
|
|
|
photoSize.location = event.action.new_photo.photo_small;
|
|
|
|
photoSize.type = "s";
|
|
|
|
photoSize.w = photoSize.h = 80;
|
|
|
|
messageOwner.action.photo.sizes.add(photoSize);
|
|
|
|
photoSize = new TLRPC.TL_photoSize();
|
|
|
|
photoSize.location = event.action.new_photo.photo_big;
|
|
|
|
photoSize.type = "m";
|
|
|
|
photoSize.w = photoSize.h = 640;
|
|
|
|
messageOwner.action.photo.sizes.add(photoSize);
|
|
|
|
|
|
|
|
if (chat.megagroup) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogEditedGroupPhoto", R.string.EventLogEditedGroupPhoto), "un1", fromUser);
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogEditedChannelPhoto", R.string.EventLogEditedChannelPhoto), "un1", fromUser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionParticipantJoin) {
|
|
|
|
if (chat.megagroup) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogGroupJoined", R.string.EventLogGroupJoined), "un1", fromUser);
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogChannelJoined", R.string.EventLogChannelJoined), "un1", fromUser);
|
|
|
|
}
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionParticipantLeave) {
|
|
|
|
messageOwner = new TLRPC.TL_messageService();
|
|
|
|
messageOwner.action = new TLRPC.TL_messageActionChatDeleteUser();
|
|
|
|
messageOwner.action.user_id = event.user_id;
|
|
|
|
if (chat.megagroup) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogLeftGroup", R.string.EventLogLeftGroup), "un1", fromUser);
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogLeftChannel", R.string.EventLogLeftChannel), "un1", fromUser);
|
|
|
|
}
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionParticipantInvite) {
|
|
|
|
messageOwner = new TLRPC.TL_messageService();
|
|
|
|
messageOwner.action = new TLRPC.TL_messageActionChatAddUser();
|
|
|
|
TLRPC.User whoUser = MessagesController.getInstance().getUser(event.action.participant.user_id);
|
|
|
|
if (event.action.participant.user_id == messageOwner.from_id) {
|
|
|
|
if (chat.megagroup) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogGroupJoined", R.string.EventLogGroupJoined), "un1", fromUser);
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogChannelJoined", R.string.EventLogChannelJoined), "un1", fromUser);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogAdded", R.string.EventLogAdded), "un2", whoUser);
|
|
|
|
messageText = replaceWithLink(messageText, "un1", fromUser);
|
|
|
|
}
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionParticipantToggleAdmin) {
|
|
|
|
messageOwner = new TLRPC.TL_message();
|
|
|
|
|
|
|
|
TLRPC.User whoUser = MessagesController.getInstance().getUser(event.action.prev_participant.user_id);
|
|
|
|
String str = LocaleController.getString("EventLogPromoted", R.string.EventLogPromoted);
|
|
|
|
int offset = str.indexOf("%1$s");
|
|
|
|
StringBuilder rights = new StringBuilder(String.format(str, getUserName(whoUser, messageOwner.entities, offset)));
|
|
|
|
rights.append("\n");
|
|
|
|
|
|
|
|
TLRPC.TL_channelAdminRights o = event.action.prev_participant.admin_rights;
|
|
|
|
TLRPC.TL_channelAdminRights n = event.action.new_participant.admin_rights;
|
|
|
|
if (o == null) {
|
|
|
|
o = new TLRPC.TL_channelAdminRights();
|
|
|
|
}
|
|
|
|
if (n == null) {
|
|
|
|
n = new TLRPC.TL_channelAdminRights();
|
|
|
|
}
|
|
|
|
if (o.change_info != n.change_info) {
|
|
|
|
rights.append('\n').append(n.change_info ? '+' : '-').append(' ');
|
|
|
|
rights.append(chat.megagroup ? LocaleController.getString("EventLogPromotedChangeGroupInfo", R.string.EventLogPromotedChangeGroupInfo) : LocaleController.getString("EventLogPromotedChangeChannelInfo", R.string.EventLogPromotedChangeChannelInfo));
|
|
|
|
}
|
|
|
|
if (!chat.megagroup) {
|
|
|
|
if (o.post_messages != n.post_messages) {
|
|
|
|
rights.append('\n').append(n.post_messages ? '+' : '-').append(' ');
|
|
|
|
rights.append(LocaleController.getString("EventLogPromotedPostMessages", R.string.EventLogPromotedPostMessages));
|
|
|
|
}
|
|
|
|
if (o.edit_messages != n.edit_messages) {
|
|
|
|
rights.append('\n').append(n.edit_messages ? '+' : '-').append(' ');
|
|
|
|
rights.append(LocaleController.getString("EventLogPromotedEditMessages", R.string.EventLogPromotedEditMessages));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (o.delete_messages != n.delete_messages) {
|
|
|
|
rights.append('\n').append(n.delete_messages ? '+' : '-').append(' ');
|
|
|
|
rights.append(LocaleController.getString("EventLogPromotedDeleteMessages", R.string.EventLogPromotedDeleteMessages));
|
|
|
|
}
|
|
|
|
if (o.add_admins != n.add_admins) {
|
|
|
|
rights.append('\n').append(n.add_admins ? '+' : '-').append(' ');
|
|
|
|
rights.append(LocaleController.getString("EventLogPromotedAddAdmins", R.string.EventLogPromotedAddAdmins));
|
|
|
|
}
|
|
|
|
if (chat.megagroup) {
|
|
|
|
if (o.ban_users != n.ban_users) {
|
|
|
|
rights.append('\n').append(n.ban_users ? '+' : '-').append(' ');
|
|
|
|
rights.append(LocaleController.getString("EventLogPromotedBanUsers", R.string.EventLogPromotedBanUsers));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (o.invite_users != n.invite_users) {
|
|
|
|
rights.append('\n').append(n.invite_users ? '+' : '-').append(' ');
|
|
|
|
rights.append(LocaleController.getString("EventLogPromotedAddUsers", R.string.EventLogPromotedAddUsers));
|
|
|
|
}
|
|
|
|
if (chat.megagroup) {
|
|
|
|
if (o.pin_messages != n.pin_messages) {
|
|
|
|
rights.append('\n').append(n.pin_messages ? '+' : '-').append(' ');
|
|
|
|
rights.append(LocaleController.getString("EventLogPromotedPinMessages", R.string.EventLogPromotedPinMessages));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
messageText = rights.toString();
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionParticipantToggleBan) {
|
|
|
|
messageOwner = new TLRPC.TL_message();
|
|
|
|
TLRPC.User whoUser = MessagesController.getInstance().getUser(event.action.prev_participant.user_id);
|
|
|
|
TLRPC.TL_channelBannedRights o = event.action.prev_participant.banned_rights;
|
|
|
|
TLRPC.TL_channelBannedRights n = event.action.new_participant.banned_rights;
|
|
|
|
if (chat.megagroup && (n == null || !n.view_messages || n != null && o != null && n.until_date != o.until_date)) {
|
|
|
|
StringBuilder rights;
|
|
|
|
String bannedDuration;
|
|
|
|
if (n != null && !AndroidUtilities.isBannedForever(n.until_date)) {
|
|
|
|
bannedDuration = "";
|
|
|
|
int duration = n.until_date - event.date;
|
|
|
|
int days = duration / 60 / 60 / 24;
|
|
|
|
duration -= days * 60 * 60 * 24;
|
|
|
|
int hours = duration / 60 / 60;
|
|
|
|
duration -= hours * 60 * 60;
|
|
|
|
int minutes = duration / 60;
|
|
|
|
int count = 0;
|
|
|
|
for (int a = 0; a < 3; a++) {
|
|
|
|
String addStr = null;
|
|
|
|
if (a == 0) {
|
|
|
|
if (days != 0) {
|
|
|
|
addStr = LocaleController.formatPluralString("Days", days);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
} else if (a == 1) {
|
|
|
|
if (hours != 0) {
|
|
|
|
addStr = LocaleController.formatPluralString("Hours", hours);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (minutes != 0) {
|
|
|
|
addStr = LocaleController.formatPluralString("Minutes", minutes);
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (addStr != null) {
|
|
|
|
if (bannedDuration.length() > 0) {
|
|
|
|
bannedDuration += ", ";
|
|
|
|
}
|
|
|
|
bannedDuration += addStr;
|
|
|
|
}
|
|
|
|
if (count == 2) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bannedDuration = LocaleController.getString("UserRestrictionsUntilForever", R.string.UserRestrictionsUntilForever);
|
|
|
|
}
|
|
|
|
String str = LocaleController.getString("EventLogRestrictedUntil", R.string.EventLogRestrictedUntil);
|
|
|
|
int offset = str.indexOf("%1$s");
|
|
|
|
rights = new StringBuilder(String.format(str, getUserName(whoUser, messageOwner.entities, offset), bannedDuration));
|
|
|
|
boolean added = false;
|
|
|
|
if (o == null) {
|
|
|
|
o = new TLRPC.TL_channelBannedRights();
|
|
|
|
}
|
|
|
|
if (n == null) {
|
|
|
|
n = new TLRPC.TL_channelBannedRights();
|
|
|
|
}
|
|
|
|
if (o.view_messages != n.view_messages) {
|
|
|
|
if (!added) {
|
|
|
|
rights.append('\n');
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
rights.append('\n').append(!n.view_messages ? '+' : '-').append(' ');
|
|
|
|
rights.append(LocaleController.getString("EventLogRestrictedReadMessages", R.string.EventLogRestrictedReadMessages));
|
|
|
|
}
|
|
|
|
if (o.send_messages != n.send_messages) {
|
|
|
|
if (!added) {
|
|
|
|
rights.append('\n');
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
rights.append('\n').append(!n.send_messages ? '+' : '-').append(' ');
|
|
|
|
rights.append(LocaleController.getString("EventLogRestrictedSendMessages", R.string.EventLogRestrictedSendMessages));
|
|
|
|
}
|
|
|
|
if (o.send_stickers != n.send_stickers || o.send_inline != n.send_inline || o.send_gifs != n.send_gifs || o.send_games != n.send_games) {
|
|
|
|
if (!added) {
|
|
|
|
rights.append('\n');
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
rights.append('\n').append(!n.send_stickers ? '+' : '-').append(' ');
|
|
|
|
rights.append(LocaleController.getString("EventLogRestrictedSendStickers", R.string.EventLogRestrictedSendStickers));
|
|
|
|
}
|
|
|
|
if (o.send_media != n.send_media) {
|
|
|
|
if (!added) {
|
|
|
|
rights.append('\n');
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
rights.append('\n').append(!n.send_media ? '+' : '-').append(' ');
|
|
|
|
rights.append(LocaleController.getString("EventLogRestrictedSendMedia", R.string.EventLogRestrictedSendMedia));
|
|
|
|
}
|
|
|
|
if (o.embed_links != n.embed_links) {
|
|
|
|
if (!added) {
|
|
|
|
rights.append('\n');
|
|
|
|
}
|
|
|
|
rights.append('\n').append(!n.embed_links ? '+' : '-').append(' ');
|
|
|
|
rights.append(LocaleController.getString("EventLogRestrictedSendEmbed", R.string.EventLogRestrictedSendEmbed));
|
|
|
|
}
|
|
|
|
messageText = rights.toString();
|
|
|
|
} else {
|
|
|
|
String str;
|
|
|
|
if (n != null && (o == null || n.view_messages)) {
|
|
|
|
str = LocaleController.getString("EventLogChannelRestricted", R.string.EventLogChannelRestricted);
|
|
|
|
} else {
|
|
|
|
str = LocaleController.getString("EventLogChannelUnrestricted", R.string.EventLogChannelUnrestricted);
|
|
|
|
}
|
|
|
|
int offset = str.indexOf("%1$s");
|
|
|
|
messageText = String.format(str, getUserName(whoUser, messageOwner.entities, offset));
|
|
|
|
}
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionUpdatePinned) {
|
|
|
|
if (event.action.message instanceof TLRPC.TL_messageEmpty) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogUnpinnedMessages", R.string.EventLogUnpinnedMessages), "un1", fromUser);
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogPinnedMessages", R.string.EventLogPinnedMessages), "un1", fromUser);
|
|
|
|
}
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionToggleSignatures) {
|
|
|
|
if (((TLRPC.TL_channelAdminLogEventActionToggleSignatures) event.action).new_value) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogToggledSignaturesOn", R.string.EventLogToggledSignaturesOn), "un1", fromUser);
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogToggledSignaturesOff", R.string.EventLogToggledSignaturesOff), "un1", fromUser);
|
|
|
|
}
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionToggleInvites) {
|
|
|
|
if (((TLRPC.TL_channelAdminLogEventActionToggleInvites) event.action).new_value) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogToggledInvitesOn", R.string.EventLogToggledInvitesOn), "un1", fromUser);
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogToggledInvitesOff", R.string.EventLogToggledInvitesOff), "un1", fromUser);
|
|
|
|
}
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionDeleteMessage) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogDeletedMessages", R.string.EventLogDeletedMessages), "un1", fromUser);
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionChangeAbout) {
|
|
|
|
messageText = replaceWithLink(chat.megagroup ? LocaleController.getString("EventLogEditedGroupDescription", R.string.EventLogEditedGroupDescription) : LocaleController.getString("EventLogEditedChannelDescription", R.string.EventLogEditedChannelDescription), "un1", fromUser);
|
|
|
|
message = new TLRPC.TL_message();
|
|
|
|
message.out = false;
|
|
|
|
message.unread = false;
|
|
|
|
message.from_id = event.user_id;
|
|
|
|
message.to_id = to_id;
|
|
|
|
message.date = event.date;
|
|
|
|
message.message = ((TLRPC.TL_channelAdminLogEventActionChangeAbout) event.action).new_value;
|
|
|
|
if (!TextUtils.isEmpty(((TLRPC.TL_channelAdminLogEventActionChangeAbout) event.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) event.action).prev_value;
|
|
|
|
} else {
|
|
|
|
message.media = new TLRPC.TL_messageMediaEmpty();
|
|
|
|
}
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionChangeUsername) {
|
|
|
|
String newLink = ((TLRPC.TL_channelAdminLogEventActionChangeUsername) event.action).new_value;
|
|
|
|
if (!TextUtils.isEmpty(newLink)) {
|
|
|
|
messageText = replaceWithLink(chat.megagroup ? LocaleController.getString("EventLogChangedGroupLink", R.string.EventLogChangedGroupLink) : LocaleController.getString("EventLogChangedChannelLink", R.string.EventLogChangedChannelLink), "un1", fromUser);
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(chat.megagroup ? LocaleController.getString("EventLogRemovedGroupLink", R.string.EventLogRemovedGroupLink) : LocaleController.getString("EventLogRemovedChannelLink", R.string.EventLogRemovedChannelLink), "un1", fromUser);
|
|
|
|
}
|
|
|
|
message = new TLRPC.TL_message();
|
|
|
|
message.out = false;
|
|
|
|
message.unread = false;
|
|
|
|
message.from_id = event.user_id;
|
|
|
|
message.to_id = to_id;
|
|
|
|
message.date = event.date;
|
|
|
|
if (!TextUtils.isEmpty(newLink)) {
|
|
|
|
message.message = "https://" + MessagesController.getInstance().linkPrefix + "/" + newLink;
|
|
|
|
} else {
|
|
|
|
message.message = "";
|
|
|
|
}
|
|
|
|
TLRPC.TL_messageEntityUrl url = new TLRPC.TL_messageEntityUrl();
|
|
|
|
url.offset = 0;
|
|
|
|
url.length = message.message.length();
|
|
|
|
message.entities.add(url);
|
|
|
|
if (!TextUtils.isEmpty(((TLRPC.TL_channelAdminLogEventActionChangeUsername) event.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("EventLogPreviousLink", R.string.EventLogPreviousLink);
|
|
|
|
message.media.webpage.description = "https://" + MessagesController.getInstance().linkPrefix + "/" + ((TLRPC.TL_channelAdminLogEventActionChangeUsername) event.action).prev_value;
|
|
|
|
} else {
|
|
|
|
message.media = new TLRPC.TL_messageMediaEmpty();
|
|
|
|
}
|
|
|
|
} else if (event.action instanceof TLRPC.TL_channelAdminLogEventActionEditMessage) {
|
|
|
|
message = new TLRPC.TL_message();
|
|
|
|
message.out = false;
|
|
|
|
message.unread = false;
|
|
|
|
message.from_id = event.user_id;
|
|
|
|
message.to_id = to_id;
|
|
|
|
message.date = event.date;
|
|
|
|
TLRPC.Message newMessage = ((TLRPC.TL_channelAdminLogEventActionEditMessage) event.action).new_message;
|
|
|
|
TLRPC.Message oldMessage = ((TLRPC.TL_channelAdminLogEventActionEditMessage) event.action).prev_message;
|
|
|
|
if (newMessage.media != null && !(newMessage.media instanceof TLRPC.TL_messageMediaEmpty) && !(newMessage.media instanceof TLRPC.TL_messageMediaWebPage) && TextUtils.isEmpty(newMessage.message)) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogEditedCaption", R.string.EventLogEditedCaption), "un1", fromUser);
|
|
|
|
message.media = newMessage.media;
|
|
|
|
message.media.webpage = new TLRPC.TL_webPage();
|
|
|
|
message.media.webpage.site_name = LocaleController.getString("EventLogOriginalCaption", R.string.EventLogOriginalCaption);
|
|
|
|
if (TextUtils.isEmpty(oldMessage.media.caption)) {
|
|
|
|
message.media.webpage.description = LocaleController.getString("EventLogOriginalCaptionEmpty", R.string.EventLogOriginalCaptionEmpty);
|
|
|
|
} else {
|
|
|
|
message.media.webpage.description = oldMessage.media.caption;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("EventLogEditedMessages", R.string.EventLogEditedMessages), "un1", fromUser);
|
|
|
|
message.message = newMessage.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);
|
|
|
|
message.media.webpage.description = oldMessage.message;
|
|
|
|
}
|
|
|
|
message.reply_markup = newMessage.reply_markup;
|
|
|
|
message.media.webpage.flags = 10;
|
|
|
|
message.media.webpage.display_url = "";
|
|
|
|
message.media.webpage.url = "";
|
|
|
|
} else {
|
|
|
|
messageText = "unsupported " + event.action;
|
|
|
|
}
|
|
|
|
if (messageOwner == null) {
|
|
|
|
messageOwner = new TLRPC.TL_messageService();
|
|
|
|
}
|
|
|
|
messageOwner.message = messageText.toString();
|
|
|
|
messageOwner.from_id = event.user_id;
|
|
|
|
messageOwner.date = event.date;
|
|
|
|
messageOwner.id = mid[0]++;
|
|
|
|
eventId = event.id;
|
|
|
|
//messageOwner.out = event.user_id == UserConfig.getClientUserId();
|
|
|
|
messageOwner.out = false;
|
|
|
|
messageOwner.to_id = new TLRPC.TL_peerChannel();
|
|
|
|
messageOwner.to_id.channel_id = chat.id;
|
|
|
|
messageOwner.unread = false;
|
|
|
|
if (chat.megagroup) {
|
|
|
|
messageOwner.flags |= TLRPC.MESSAGE_FLAG_MEGAGROUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.action.message != null && !(event.action.message instanceof TLRPC.TL_messageEmpty)) {
|
|
|
|
message = event.action.message;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message != null) {
|
|
|
|
message.out = false;
|
|
|
|
message.id = mid[0]++;
|
|
|
|
message.reply_to_msg_id = 0;
|
|
|
|
message.flags = message.flags &~ TLRPC.MESSAGE_FLAG_EDITED;
|
|
|
|
if (chat.megagroup) {
|
|
|
|
message.flags |= TLRPC.MESSAGE_FLAG_MEGAGROUP;
|
|
|
|
}
|
|
|
|
MessageObject messageObject = new MessageObject(message, null, null, true, eventId);
|
|
|
|
messageObjects.add(messageObjects.size() - 1, messageObject);
|
|
|
|
}
|
|
|
|
messageObjects.add(messageObjects.size() - 1, this);
|
|
|
|
|
|
|
|
if (messageText == null) {
|
|
|
|
messageText = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
setType();
|
|
|
|
measureInlineBotButtons();
|
|
|
|
|
|
|
|
if (messageOwner.message != null && messageOwner.id < 0 && messageOwner.message.length() > 6 && (isVideo() || isNewGif() || isRoundVideo())) {
|
|
|
|
videoEditedInfo = new VideoEditedInfo();
|
|
|
|
if (!videoEditedInfo.parseString(messageOwner.message)) {
|
|
|
|
videoEditedInfo = null;
|
|
|
|
} else {
|
|
|
|
videoEditedInfo.roundVideo = isRoundVideo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
generateCaption();
|
|
|
|
|
|
|
|
TextPaint paint;
|
|
|
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
|
|
|
paint = Theme.chat_msgGameTextPaint;
|
|
|
|
} else {
|
|
|
|
paint = Theme.chat_msgTextPaint;
|
|
|
|
}
|
|
|
|
int[] emojiOnly = MessagesController.getInstance().allowBigEmoji ? new int[1] : null;
|
|
|
|
messageText = Emoji.replaceEmoji(messageText, paint.getFontMetricsInt(), AndroidUtilities.dp(20), false, emojiOnly);
|
|
|
|
if (emojiOnly != null && emojiOnly[0] >= 1 && emojiOnly[0] <= 3) {
|
|
|
|
TextPaint emojiPaint;
|
|
|
|
int size;
|
|
|
|
switch (emojiOnly[0]) {
|
|
|
|
case 1:
|
|
|
|
emojiPaint = Theme.chat_msgTextPaintOneEmoji;
|
|
|
|
size = AndroidUtilities.dp(32);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
emojiPaint = Theme.chat_msgTextPaintTwoEmoji;
|
|
|
|
size = AndroidUtilities.dp(28);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
emojiPaint = Theme.chat_msgTextPaintThreeEmoji;
|
|
|
|
size = AndroidUtilities.dp(24);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Emoji.EmojiSpan[] spans = ((Spannable) messageText).getSpans(0, messageText.length(), Emoji.EmojiSpan.class);
|
|
|
|
if (spans != null && spans.length > 0) {
|
|
|
|
for (int a = 0; a < spans.length; a++) {
|
|
|
|
spans[a].replaceFontMetrics(emojiPaint.getFontMetricsInt(), size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
generateLayout(fromUser);
|
|
|
|
layoutCreated = true;
|
|
|
|
generateThumbs(false);
|
|
|
|
checkMediaExistance();
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getUserName(TLRPC.User user, ArrayList<TLRPC.MessageEntity> entities, int offset) {
|
|
|
|
String name;
|
|
|
|
if (user == null) {
|
|
|
|
name = "";
|
|
|
|
} else {
|
|
|
|
name = ContactsController.formatName(user.first_name, user.last_name);
|
|
|
|
}
|
|
|
|
if (offset >= 0) {
|
|
|
|
TLRPC.TL_messageEntityMentionName entity = new TLRPC.TL_messageEntityMentionName();
|
|
|
|
entity.user_id = user.id;
|
|
|
|
entity.offset = offset;
|
|
|
|
entity.length = name.length();
|
|
|
|
entities.add(entity);
|
|
|
|
}
|
|
|
|
if (!TextUtils.isEmpty(user.username)) {
|
|
|
|
if (offset >= 0) {
|
|
|
|
TLRPC.TL_messageEntityMentionName entity = new TLRPC.TL_messageEntityMentionName();
|
|
|
|
entity.user_id = user.id;
|
|
|
|
entity.offset = offset + name.length() + 2;
|
|
|
|
entity.length = user.username.length() + 1;
|
|
|
|
entities.add(entity);
|
|
|
|
}
|
|
|
|
return String.format("%1$s (@%2$s)", name, user.username);
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void applyNewText() {
|
|
|
|
if (TextUtils.isEmpty(messageOwner.message)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TLRPC.User fromUser = null;
|
|
|
|
if (isFromUser()) {
|
|
|
|
fromUser = MessagesController.getInstance().getUser(messageOwner.from_id);
|
|
|
|
}
|
|
|
|
messageText = messageOwner.message;
|
|
|
|
TextPaint paint;
|
|
|
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
2017-03-31 01:58:05 +02:00
|
|
|
paint = Theme.chat_msgGameTextPaint;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
paint = Theme.chat_msgTextPaint;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
messageText = Emoji.replaceEmoji(messageText, paint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
|
|
|
generateLayout(fromUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void generateGameMessageText(TLRPC.User fromUser) {
|
|
|
|
if (fromUser == null) {
|
|
|
|
if (messageOwner.from_id > 0) {
|
|
|
|
fromUser = MessagesController.getInstance().getUser(messageOwner.from_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TLRPC.TL_game game = null;
|
|
|
|
if (replyMessageObject != null && replyMessageObject.messageOwner.media != null && replyMessageObject.messageOwner.media.game != null) {
|
|
|
|
game = replyMessageObject.messageOwner.media.game;
|
|
|
|
}
|
|
|
|
if (game == null) {
|
|
|
|
if (fromUser != null && fromUser.id == UserConfig.getClientUserId()) {
|
|
|
|
messageText = LocaleController.formatString("ActionYouScored", R.string.ActionYouScored, LocaleController.formatPluralString("Points", messageOwner.action.score));
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.formatString("ActionUserScored", R.string.ActionUserScored, LocaleController.formatPluralString("Points", messageOwner.action.score)), "un1", fromUser);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (fromUser != null && fromUser.id == UserConfig.getClientUserId()) {
|
|
|
|
messageText = LocaleController.formatString("ActionYouScoredInGame", R.string.ActionYouScoredInGame, LocaleController.formatPluralString("Points", messageOwner.action.score));
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.formatString("ActionUserScoredInGame", R.string.ActionUserScoredInGame, LocaleController.formatPluralString("Points", messageOwner.action.score)), "un1", fromUser);
|
|
|
|
}
|
|
|
|
messageText = replaceWithLink(messageText, "un2", game);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public void generatePaymentSentMessageText(TLRPC.User fromUser) {
|
|
|
|
if (fromUser == null) {
|
|
|
|
fromUser = MessagesController.getInstance().getUser((int) getDialogId());
|
|
|
|
}
|
|
|
|
String name;
|
|
|
|
if (fromUser != null) {
|
|
|
|
name = UserObject.getFirstName(fromUser);
|
|
|
|
} else {
|
|
|
|
name = "";
|
|
|
|
}
|
|
|
|
if (replyMessageObject != null && replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) {
|
|
|
|
messageText = LocaleController.formatString("PaymentSuccessfullyPaid", R.string.PaymentSuccessfullyPaid, LocaleController.getInstance().formatCurrencyString(messageOwner.action.total_amount, messageOwner.action.currency), name, replyMessageObject.messageOwner.media.title);
|
|
|
|
} else {
|
|
|
|
messageText = LocaleController.formatString("PaymentSuccessfullyPaidNoItem", R.string.PaymentSuccessfullyPaidNoItem, LocaleController.getInstance().formatCurrencyString(messageOwner.action.total_amount, messageOwner.action.currency), name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-16 13:26:32 +01:00
|
|
|
public void generatePinMessageText(TLRPC.User fromUser, TLRPC.Chat chat) {
|
|
|
|
if (fromUser == null && chat == null) {
|
|
|
|
if (messageOwner.from_id > 0) {
|
|
|
|
fromUser = MessagesController.getInstance().getUser(messageOwner.from_id);
|
|
|
|
}
|
|
|
|
if (fromUser == null) {
|
|
|
|
chat = MessagesController.getInstance().getChat(messageOwner.to_id.channel_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (replyMessageObject == null) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionPinnedNoText", R.string.ActionPinnedNoText), "un1", fromUser != null ? fromUser : chat);
|
|
|
|
} else {
|
|
|
|
if (replyMessageObject.isMusic()) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionPinnedMusic", R.string.ActionPinnedMusic), "un1", fromUser != null ? fromUser : chat);
|
|
|
|
} else if (replyMessageObject.isVideo()) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionPinnedVideo", R.string.ActionPinnedVideo), "un1", fromUser != null ? fromUser : chat);
|
|
|
|
} else if (replyMessageObject.isGif()) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionPinnedGif", R.string.ActionPinnedGif), "un1", fromUser != null ? fromUser : chat);
|
|
|
|
} else if (replyMessageObject.isVoice()) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionPinnedVoice", R.string.ActionPinnedVoice), "un1", fromUser != null ? fromUser : chat);
|
2017-07-08 18:32:04 +02:00
|
|
|
} else if (replyMessageObject.isRoundVideo()) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionPinnedRound", R.string.ActionPinnedRound), "un1", fromUser != null ? fromUser : chat);
|
2016-03-16 13:26:32 +01:00
|
|
|
} else if (replyMessageObject.isSticker()) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionPinnedSticker", R.string.ActionPinnedSticker), "un1", fromUser != null ? fromUser : chat);
|
|
|
|
} else if (replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionPinnedFile", R.string.ActionPinnedFile), "un1", fromUser != null ? fromUser : chat);
|
|
|
|
} else if (replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeo) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionPinnedGeo", R.string.ActionPinnedGeo), "un1", fromUser != null ? fromUser : chat);
|
|
|
|
} else if (replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionPinnedContact", R.string.ActionPinnedContact), "un1", fromUser != null ? fromUser : chat);
|
|
|
|
} else if (replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionPinnedPhoto", R.string.ActionPinnedPhoto), "un1", fromUser != null ? fromUser : chat);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
|
|
|
messageText = replaceWithLink(LocaleController.formatString("ActionPinnedGame", R.string.ActionPinnedGame, "\uD83C\uDFAE " + replyMessageObject.messageOwner.media.game.title), "un1", fromUser != null ? fromUser : chat);
|
2017-03-31 01:58:05 +02:00
|
|
|
messageText = Emoji.replaceEmoji(messageText, Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
2016-03-16 13:26:32 +01:00
|
|
|
} else if (replyMessageObject.messageText != null && replyMessageObject.messageText.length() > 0) {
|
|
|
|
CharSequence mess = replyMessageObject.messageText;
|
|
|
|
if (mess.length() > 20) {
|
|
|
|
mess = mess.subSequence(0, 20) + "...";
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
mess = Emoji.replaceEmoji(mess, Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
2016-03-16 13:26:32 +01:00
|
|
|
messageText = replaceWithLink(LocaleController.formatString("ActionPinnedText", R.string.ActionPinnedText, mess), "un1", fromUser != null ? fromUser : chat);
|
|
|
|
} else {
|
|
|
|
messageText = replaceWithLink(LocaleController.getString("ActionPinnedNoText", R.string.ActionPinnedNoText), "un1", fromUser != null ? fromUser : chat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void measureInlineBotButtons() {
|
2016-04-22 15:49:00 +02:00
|
|
|
wantedBotKeyboardWidth = 0;
|
|
|
|
if (!(messageOwner.reply_markup instanceof TLRPC.TL_replyInlineMarkup)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.createChatResources(null, true);
|
|
|
|
if (botButtonsLayout == null) {
|
|
|
|
botButtonsLayout = new StringBuilder();
|
|
|
|
} else {
|
|
|
|
botButtonsLayout.setLength(0);
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
for (int a = 0; a < messageOwner.reply_markup.rows.size(); a++) {
|
|
|
|
TLRPC.TL_keyboardButtonRow row = messageOwner.reply_markup.rows.get(a);
|
|
|
|
int maxButtonSize = 0;
|
|
|
|
int size = row.buttons.size();
|
|
|
|
for (int b = 0; b < size; b++) {
|
2017-03-31 01:58:05 +02:00
|
|
|
TLRPC.KeyboardButton button = row.buttons.get(b);
|
|
|
|
botButtonsLayout.append(a).append(b);
|
|
|
|
CharSequence text;
|
|
|
|
if (button instanceof TLRPC.TL_keyboardButtonBuy && (messageOwner.media.flags & 4) != 0) {
|
|
|
|
text = LocaleController.getString("PaymentReceipt", R.string.PaymentReceipt);
|
|
|
|
} else {
|
|
|
|
text = Emoji.replaceEmoji(button.text, Theme.chat_msgBotButtonPaint.getFontMetricsInt(), AndroidUtilities.dp(15), false);
|
|
|
|
}
|
|
|
|
StaticLayout staticLayout = new StaticLayout(text, Theme.chat_msgBotButtonPaint, AndroidUtilities.dp(2000), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
2016-04-22 15:49:00 +02:00
|
|
|
if (staticLayout.getLineCount() > 0) {
|
2017-07-08 18:32:04 +02:00
|
|
|
float width = staticLayout.getLineWidth(0);
|
|
|
|
float left = staticLayout.getLineLeft(0);
|
|
|
|
if (left < width) {
|
|
|
|
width -= left;
|
|
|
|
}
|
|
|
|
maxButtonSize = Math.max(maxButtonSize, (int) Math.ceil(width) + AndroidUtilities.dp(4));
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
wantedBotKeyboardWidth = Math.max(wantedBotKeyboardWidth, (maxButtonSize + AndroidUtilities.dp(12)) * size + AndroidUtilities.dp(5) * (size - 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setType() {
|
2016-05-25 23:49:47 +02:00
|
|
|
int oldType = type;
|
2016-04-22 15:49:00 +02:00
|
|
|
if (messageOwner instanceof TLRPC.TL_message || messageOwner instanceof TLRPC.TL_messageForwarded_old2) {
|
|
|
|
if (isMediaEmpty()) {
|
|
|
|
type = 0;
|
2017-07-08 18:32:04 +02:00
|
|
|
if (TextUtils.isEmpty(messageText) && eventId == 0) {
|
2016-04-22 15:49:00 +02:00
|
|
|
messageText = "Empty message";
|
|
|
|
}
|
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
|
|
|
type = 1;
|
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaGeo || messageOwner.media instanceof TLRPC.TL_messageMediaVenue) {
|
|
|
|
type = 4;
|
2017-07-08 18:32:04 +02:00
|
|
|
} else if (isRoundVideo()) {
|
|
|
|
type = 5;
|
2016-04-22 15:49:00 +02:00
|
|
|
} else if (isVideo()) {
|
|
|
|
type = 3;
|
|
|
|
} else if (isVoice()) {
|
|
|
|
type = 2;
|
|
|
|
} else if (isMusic()) {
|
|
|
|
type = 14;
|
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaContact) {
|
|
|
|
type = 12;
|
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaUnsupported) {
|
|
|
|
type = 0;
|
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (messageOwner.media.document != null && messageOwner.media.document.mime_type != null) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (isGifDocument(messageOwner.media.document)) {
|
|
|
|
type = 8;
|
|
|
|
} else if (messageOwner.media.document.mime_type.equals("image/webp") && isSticker()) {
|
|
|
|
type = 13;
|
|
|
|
} else {
|
|
|
|
type = 9;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
type = 9;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
|
|
|
type = 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) {
|
|
|
|
type = 0;
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
} else if (messageOwner instanceof TLRPC.TL_messageService) {
|
|
|
|
if (messageOwner.action instanceof TLRPC.TL_messageActionLoginUnknownLocation) {
|
|
|
|
type = 0;
|
|
|
|
} else if (messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto || messageOwner.action instanceof TLRPC.TL_messageActionUserUpdatedPhoto) {
|
|
|
|
contentType = 1;
|
|
|
|
type = 11;
|
|
|
|
} else if (messageOwner.action instanceof TLRPC.TL_messageEncryptedAction) {
|
|
|
|
if (messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionScreenshotMessages || messageOwner.action.encryptedAction instanceof TLRPC.TL_decryptedMessageActionSetMessageTTL) {
|
|
|
|
contentType = 1;
|
|
|
|
type = 10;
|
|
|
|
} else {
|
|
|
|
contentType = -1;
|
|
|
|
type = -1;
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
} else if (messageOwner.action instanceof TLRPC.TL_messageActionHistoryClear) {
|
|
|
|
contentType = -1;
|
|
|
|
type = -1;
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (messageOwner.action instanceof TLRPC.TL_messageActionPhoneCall) {
|
|
|
|
type = 16;
|
2016-04-22 15:49:00 +02:00
|
|
|
} else {
|
|
|
|
contentType = 1;
|
|
|
|
type = 10;
|
|
|
|
}
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
if (oldType != 1000 && oldType != type) {
|
|
|
|
generateThumbs(false);
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public boolean checkLayout() {
|
|
|
|
if (type != 0 || messageOwner.to_id == null || messageText == null || messageText.length() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (layoutCreated) {
|
|
|
|
int newMinSize = AndroidUtilities.isTablet() ? AndroidUtilities.getMinTabletSide() : AndroidUtilities.displaySize.x;
|
|
|
|
if (Math.abs(generatedWithMinSize - newMinSize) > AndroidUtilities.dp(52)) {
|
|
|
|
layoutCreated = false;
|
|
|
|
}
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
if (!layoutCreated) {
|
|
|
|
layoutCreated = true;
|
|
|
|
TLRPC.User fromUser = null;
|
|
|
|
if (isFromUser()) {
|
|
|
|
fromUser = MessagesController.getInstance().getUser(messageOwner.from_id);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
TextPaint paint;
|
|
|
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
2017-03-31 01:58:05 +02:00
|
|
|
paint = Theme.chat_msgGameTextPaint;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
paint = Theme.chat_msgTextPaint;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
messageText = Emoji.replaceEmoji(messageText, paint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
2016-03-06 02:49:31 +01:00
|
|
|
generateLayout(fromUser);
|
2016-10-11 13:57:01 +02:00
|
|
|
return true;
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
return false;
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public String getMimeType() {
|
|
|
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
return messageOwner.media.document.mime_type;
|
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) {
|
|
|
|
TLRPC.TL_webDocument photo = ((TLRPC.TL_messageMediaInvoice) messageOwner.media).photo;
|
|
|
|
if (photo != null) {
|
|
|
|
return photo.mime_type;
|
|
|
|
}
|
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
|
|
|
return "image/jpeg";
|
2017-07-08 18:32:04 +02:00
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
if (messageOwner.media.webpage.document != null) {
|
|
|
|
return messageOwner.media.document.mime_type;
|
|
|
|
} else if (messageOwner.media.webpage.photo != null) {
|
|
|
|
return "image/jpeg";
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
public static boolean isGifDocument(TLRPC.Document document) {
|
|
|
|
return document != null && document.thumb != null && document.mime_type != null && (document.mime_type.equals("image/gif") || isNewGifDocument(document));
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public static boolean isRoundVideoDocument(TLRPC.Document document) {
|
|
|
|
if (Build.VERSION.SDK_INT < 16) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (document != null && document.mime_type != null && document.mime_type.equals("video/mp4")) {
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
2017-07-08 18:32:04 +02:00
|
|
|
boolean round = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
for (int a = 0; a < document.attributes.size(); a++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
|
2017-07-08 18:32:04 +02:00
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
|
2017-03-31 01:58:05 +02:00
|
|
|
width = attribute.w;
|
|
|
|
height = attribute.w;
|
2017-07-08 18:32:04 +02:00
|
|
|
round = attribute.round_message;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
if (round && width <= 1280 && height <= 1280) {
|
2017-03-31 01:58:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
public static boolean isNewGifDocument(TLRPC.Document document) {
|
|
|
|
if (document != null && document.mime_type != null && document.mime_type.equals("video/mp4")) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
boolean animated = false;
|
2016-01-11 18:19:48 +01:00
|
|
|
for (int a = 0; a < document.attributes.size(); a++) {
|
2017-03-31 01:58:05 +02:00
|
|
|
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeAnimated) {
|
|
|
|
animated = true;
|
|
|
|
} else if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
|
|
|
|
width = attribute.w;
|
|
|
|
height = attribute.w;
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (animated && width <= 1280 && height <= 1280) {
|
|
|
|
return true;
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
public void generateThumbs(boolean update) {
|
2014-08-06 01:17:40 +02:00
|
|
|
if (messageOwner instanceof TLRPC.TL_messageService) {
|
|
|
|
if (messageOwner.action instanceof TLRPC.TL_messageActionChatEditPhoto) {
|
|
|
|
if (!update) {
|
2015-02-01 19:51:02 +01:00
|
|
|
photoThumbs = new ArrayList<>(messageOwner.action.photo.sizes);
|
2014-08-06 01:17:40 +02:00
|
|
|
} else if (photoThumbs != null && !photoThumbs.isEmpty()) {
|
2016-01-11 18:19:48 +01:00
|
|
|
for (int a = 0; a < photoThumbs.size(); a++) {
|
|
|
|
TLRPC.PhotoSize photoObject = photoThumbs.get(a);
|
|
|
|
for (int b = 0; b < messageOwner.action.photo.sizes.size(); b++) {
|
|
|
|
TLRPC.PhotoSize size = messageOwner.action.photo.sizes.get(b);
|
2014-08-06 01:17:40 +02:00
|
|
|
if (size instanceof TLRPC.TL_photoSizeEmpty) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
if (size.type.equals(photoObject.type)) {
|
|
|
|
photoObject.location = size.location;
|
2014-08-06 01:17:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (messageOwner.media != null && !(messageOwner.media instanceof TLRPC.TL_messageMediaEmpty)) {
|
|
|
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
2016-01-11 18:19:48 +01:00
|
|
|
if (!update || photoThumbs != null && photoThumbs.size() != messageOwner.media.photo.sizes.size()) {
|
2015-02-01 19:51:02 +01:00
|
|
|
photoThumbs = new ArrayList<>(messageOwner.media.photo.sizes);
|
2014-08-06 01:17:40 +02:00
|
|
|
} else if (photoThumbs != null && !photoThumbs.isEmpty()) {
|
2016-01-11 18:19:48 +01:00
|
|
|
for (int a = 0; a < photoThumbs.size(); a++) {
|
|
|
|
TLRPC.PhotoSize photoObject = photoThumbs.get(a);
|
|
|
|
for (int b = 0; b < messageOwner.media.photo.sizes.size(); b++) {
|
|
|
|
TLRPC.PhotoSize size = messageOwner.media.photo.sizes.get(b);
|
2014-08-06 01:17:40 +02:00
|
|
|
if (size instanceof TLRPC.TL_photoSizeEmpty) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
if (size.type.equals(photoObject.type)) {
|
|
|
|
photoObject.location = size.location;
|
2014-08-06 01:17:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
2014-08-06 01:17:40 +02:00
|
|
|
if (!(messageOwner.media.document.thumb instanceof TLRPC.TL_photoSizeEmpty)) {
|
|
|
|
if (!update) {
|
2015-01-02 23:15:07 +01:00
|
|
|
photoThumbs = new ArrayList<>();
|
2015-02-01 19:51:02 +01:00
|
|
|
photoThumbs.add(messageOwner.media.document.thumb);
|
2014-08-06 01:17:40 +02:00
|
|
|
} else if (photoThumbs != null && !photoThumbs.isEmpty() && messageOwner.media.document.thumb != null) {
|
2015-02-01 19:51:02 +01:00
|
|
|
TLRPC.PhotoSize photoObject = photoThumbs.get(0);
|
|
|
|
photoObject.location = messageOwner.media.document.thumb.location;
|
2016-04-22 15:49:00 +02:00
|
|
|
photoObject.w = messageOwner.media.document.thumb.w;
|
|
|
|
photoObject.h = messageOwner.media.document.thumb.h;
|
2014-08-06 01:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
|
|
|
if (messageOwner.media.game.document != null) {
|
|
|
|
if (!(messageOwner.media.game.document.thumb instanceof TLRPC.TL_photoSizeEmpty)) {
|
|
|
|
if (!update) {
|
|
|
|
photoThumbs = new ArrayList<>();
|
|
|
|
photoThumbs.add(messageOwner.media.game.document.thumb);
|
|
|
|
} else if (photoThumbs != null && !photoThumbs.isEmpty() && messageOwner.media.game.document.thumb != null) {
|
|
|
|
TLRPC.PhotoSize photoObject = photoThumbs.get(0);
|
|
|
|
photoObject.location = messageOwner.media.game.document.thumb.location;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (messageOwner.media.game.photo != null) {
|
|
|
|
if (!update || photoThumbs2 == null) {
|
|
|
|
photoThumbs2 = new ArrayList<>(messageOwner.media.game.photo.sizes);
|
|
|
|
} else if (!photoThumbs2.isEmpty()) {
|
|
|
|
for (int a = 0; a < photoThumbs2.size(); a++) {
|
|
|
|
TLRPC.PhotoSize photoObject = photoThumbs2.get(a);
|
|
|
|
for (int b = 0; b < messageOwner.media.game.photo.sizes.size(); b++) {
|
|
|
|
TLRPC.PhotoSize size = messageOwner.media.game.photo.sizes.get(b);
|
|
|
|
if (size instanceof TLRPC.TL_photoSizeEmpty) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (size.type.equals(photoObject.type)) {
|
|
|
|
photoObject.location = size.location;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (photoThumbs == null && photoThumbs2 != null) {
|
|
|
|
photoThumbs = photoThumbs2;
|
|
|
|
photoThumbs2 = null;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
if (messageOwner.media.webpage.photo != null) {
|
|
|
|
if (!update || photoThumbs == null) {
|
|
|
|
photoThumbs = new ArrayList<>(messageOwner.media.webpage.photo.sizes);
|
2015-05-21 23:27:27 +02:00
|
|
|
} else if (!photoThumbs.isEmpty()) {
|
2016-01-11 18:19:48 +01:00
|
|
|
for (int a = 0; a < photoThumbs.size(); a++) {
|
|
|
|
TLRPC.PhotoSize photoObject = photoThumbs.get(a);
|
|
|
|
for (int b = 0; b < messageOwner.media.webpage.photo.sizes.size(); b++) {
|
|
|
|
TLRPC.PhotoSize size = messageOwner.media.webpage.photo.sizes.get(b);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (size instanceof TLRPC.TL_photoSizeEmpty) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (size.type.equals(photoObject.type)) {
|
|
|
|
photoObject.location = size.location;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
} else if (messageOwner.media.webpage.document != null) {
|
|
|
|
if (!(messageOwner.media.webpage.document.thumb instanceof TLRPC.TL_photoSizeEmpty)) {
|
|
|
|
if (!update) {
|
|
|
|
photoThumbs = new ArrayList<>();
|
|
|
|
photoThumbs.add(messageOwner.media.webpage.document.thumb);
|
|
|
|
} else if (photoThumbs != null && !photoThumbs.isEmpty() && messageOwner.media.webpage.document.thumb != null) {
|
|
|
|
TLRPC.PhotoSize photoObject = photoThumbs.get(0);
|
|
|
|
photoObject.location = messageOwner.media.webpage.document.thumb.location;
|
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2014-08-06 01:17:40 +02:00
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|
2013-12-26 12:43:37 +01:00
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
public CharSequence replaceWithLink(CharSequence source, String param, ArrayList<Integer> uids, AbstractMap<Integer, TLRPC.User> usersDict) {
|
2015-02-01 19:51:02 +01:00
|
|
|
int start = TextUtils.indexOf(source, param);
|
2015-09-24 22:52:02 +02:00
|
|
|
if (start >= 0) {
|
2015-11-26 22:04:02 +01:00
|
|
|
SpannableStringBuilder names = new SpannableStringBuilder("");
|
|
|
|
for (int a = 0; a < uids.size(); a++) {
|
|
|
|
TLRPC.User user = null;
|
|
|
|
if (usersDict != null) {
|
|
|
|
user = usersDict.get(uids.get(a));
|
|
|
|
}
|
|
|
|
if (user == null) {
|
|
|
|
user = MessagesController.getInstance().getUser(uids.get(a));
|
|
|
|
}
|
|
|
|
if (user != null) {
|
|
|
|
String name = UserObject.getUserName(user);
|
|
|
|
start = names.length();
|
|
|
|
if (names.length() != 0) {
|
|
|
|
names.append(", ");
|
|
|
|
}
|
|
|
|
names.append(name);
|
|
|
|
names.setSpan(new URLSpanNoUnderlineBold("" + user.id), start, start + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TextUtils.replace(source, new String[]{param}, new CharSequence[]{names});
|
|
|
|
}
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CharSequence replaceWithLink(CharSequence source, String param, TLObject object) {
|
|
|
|
int start = TextUtils.indexOf(source, param);
|
|
|
|
if (start >= 0) {
|
|
|
|
String name;
|
2016-10-11 13:57:01 +02:00
|
|
|
String id;
|
2015-11-26 22:04:02 +01:00
|
|
|
if (object instanceof TLRPC.User) {
|
|
|
|
name = UserObject.getUserName((TLRPC.User) object);
|
2016-10-11 13:57:01 +02:00
|
|
|
id = "" + ((TLRPC.User) object).id;
|
2015-11-26 22:04:02 +01:00
|
|
|
} else if (object instanceof TLRPC.Chat) {
|
|
|
|
name = ((TLRPC.Chat) object).title;
|
2016-10-11 13:57:01 +02:00
|
|
|
id = "" + -((TLRPC.Chat) object).id;
|
|
|
|
} else if (object instanceof TLRPC.TL_game) {
|
|
|
|
TLRPC.TL_game game = (TLRPC.TL_game) object;
|
|
|
|
name = game.title;
|
|
|
|
id = "game";
|
2015-11-26 22:04:02 +01:00
|
|
|
} else {
|
|
|
|
name = "";
|
2016-10-11 13:57:01 +02:00
|
|
|
id = "0";
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
name = name.replace('\n', ' ');
|
2015-09-24 22:52:02 +02:00
|
|
|
SpannableStringBuilder builder = new SpannableStringBuilder(TextUtils.replace(source, new String[]{param}, new String[]{name}));
|
2015-11-26 22:04:02 +01:00
|
|
|
builder.setSpan(new URLSpanNoUnderlineBold("" + id), start, start + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
2015-09-24 22:52:02 +02:00
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
return source;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
public String getExtension() {
|
|
|
|
String fileName = getFileName();
|
2016-04-22 15:49:00 +02:00
|
|
|
int idx = fileName.lastIndexOf('.');
|
2015-10-29 18:10:07 +01:00
|
|
|
String ext = null;
|
|
|
|
if (idx != -1) {
|
|
|
|
ext = fileName.substring(idx + 1);
|
|
|
|
}
|
|
|
|
if (ext == null || ext.length() == 0) {
|
|
|
|
ext = messageOwner.media.document.mime_type;
|
|
|
|
}
|
|
|
|
if (ext == null) {
|
|
|
|
ext = "";
|
|
|
|
}
|
|
|
|
ext = ext.toUpperCase();
|
|
|
|
return ext;
|
|
|
|
}
|
|
|
|
|
2013-12-26 12:43:37 +01:00
|
|
|
public String getFileName() {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
2014-08-22 16:24:33 +02:00
|
|
|
return FileLoader.getAttachFileName(messageOwner.media.document);
|
2014-03-22 23:31:55 +01:00
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
|
|
|
ArrayList<TLRPC.PhotoSize> sizes = messageOwner.media.photo.sizes;
|
|
|
|
if (sizes.size() > 0) {
|
2014-10-01 21:55:24 +02:00
|
|
|
TLRPC.PhotoSize sizeFull = FileLoader.getClosestPhotoSizeWithSize(sizes, AndroidUtilities.getPhotoSize());
|
2014-03-22 23:31:55 +01:00
|
|
|
if (sizeFull != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
return FileLoader.getAttachFileName(sizeFull);
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
|
|
|
}
|
2016-03-16 13:26:32 +01:00
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
return FileLoader.getAttachFileName(messageOwner.media.webpage.document);
|
2013-12-26 12:43:37 +01:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
public int getFileType() {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (isVideo()) {
|
2015-02-01 19:51:02 +01:00
|
|
|
return FileLoader.MEDIA_DIR_VIDEO;
|
2016-03-06 02:49:31 +01:00
|
|
|
} else if (isVoice()) {
|
|
|
|
return FileLoader.MEDIA_DIR_AUDIO;
|
2015-02-01 19:51:02 +01:00
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
|
|
|
return FileLoader.MEDIA_DIR_DOCUMENT;
|
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto) {
|
|
|
|
return FileLoader.MEDIA_DIR_IMAGE;
|
|
|
|
}
|
|
|
|
return FileLoader.MEDIA_DIR_CACHE;
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
private static boolean containsUrls(CharSequence message) {
|
|
|
|
if (message == null || message.length() < 2 || message.length() > 1024 * 20) {
|
2014-12-01 18:56:31 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int length = message.length();
|
|
|
|
|
|
|
|
int digitsInRow = 0;
|
|
|
|
int schemeSequence = 0;
|
|
|
|
int dotSequence = 0;
|
|
|
|
|
|
|
|
char lastChar = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
char c = message.charAt(i);
|
|
|
|
|
|
|
|
if (c >= '0' && c <= '9') {
|
|
|
|
digitsInRow++;
|
|
|
|
if (digitsInRow >= 6) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
schemeSequence = 0;
|
|
|
|
dotSequence = 0;
|
2015-01-02 23:15:07 +01:00
|
|
|
} else if (!(c != ' ' && digitsInRow > 0)) {
|
|
|
|
digitsInRow = 0;
|
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
if ((c == '@' || c == '#' || c == '/') && i == 0 || i != 0 && (message.charAt(i - 1) == ' ' || message.charAt(i - 1) == '\n')) {
|
2015-03-19 00:09:45 +01:00
|
|
|
return true;
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
if (c == ':') {
|
2014-12-01 18:56:31 +01:00
|
|
|
if (schemeSequence == 0) {
|
|
|
|
schemeSequence = 1;
|
|
|
|
} else {
|
|
|
|
schemeSequence = 0;
|
|
|
|
}
|
|
|
|
} else if (c == '/') {
|
|
|
|
if (schemeSequence == 2) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (schemeSequence == 1) {
|
|
|
|
schemeSequence++;
|
|
|
|
} else {
|
|
|
|
schemeSequence = 0;
|
|
|
|
}
|
|
|
|
} else if (c == '.') {
|
|
|
|
if (dotSequence == 0 && lastChar != ' ') {
|
|
|
|
dotSequence++;
|
|
|
|
} else {
|
|
|
|
dotSequence = 0;
|
|
|
|
}
|
|
|
|
} else if (c != ' ' && lastChar == '.' && dotSequence == 1) {
|
|
|
|
return true;
|
2015-01-02 23:15:07 +01:00
|
|
|
} else {
|
|
|
|
dotSequence = 0;
|
2014-12-01 18:56:31 +01:00
|
|
|
}
|
|
|
|
lastChar = c;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
public void generateLinkDescription() {
|
|
|
|
if (linkDescription != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageOwner.media.webpage instanceof TLRPC.TL_webPage && messageOwner.media.webpage.description != null) {
|
|
|
|
linkDescription = Spannable.Factory.getInstance().newSpannable(messageOwner.media.webpage.description);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaGame && messageOwner.media.game.description != null) {
|
|
|
|
linkDescription = Spannable.Factory.getInstance().newSpannable(messageOwner.media.game.description);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaInvoice && messageOwner.media.description != null) {
|
|
|
|
linkDescription = Spannable.Factory.getInstance().newSpannable(messageOwner.media.description);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
if (linkDescription != null) {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (containsUrls(linkDescription)) {
|
2015-10-29 18:10:07 +01:00
|
|
|
try {
|
|
|
|
Linkify.addLinks((Spannable) linkDescription, Linkify.WEB_URLS);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
linkDescription = Emoji.replaceEmoji(linkDescription, Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public void generateCaption() {
|
|
|
|
if (caption != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (messageOwner.media != null && messageOwner.media.caption != null && messageOwner.media.caption.length() > 0) {
|
2017-03-31 01:58:05 +02:00
|
|
|
caption = Emoji.replaceEmoji(messageOwner.media.caption, Theme.chat_msgTextPaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
2015-05-03 13:48:36 +02:00
|
|
|
if (containsUrls(caption)) {
|
|
|
|
try {
|
2016-01-04 11:55:21 +01:00
|
|
|
Linkify.addLinks((Spannable) caption, Linkify.WEB_URLS | Linkify.PHONE_NUMBERS);
|
2015-05-03 13:48:36 +02:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
addUsernamesAndHashtags(isOutOwner(), caption, true);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private static void addUsernamesAndHashtags(boolean isOut, CharSequence charSequence, boolean botCommands) {
|
2015-05-03 13:48:36 +02:00
|
|
|
try {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (urlPattern == null) {
|
2016-03-06 02:49:31 +01:00
|
|
|
urlPattern = Pattern.compile("(^|\\s)/[a-zA-Z@\\d_]{1,255}|(^|\\s)@[a-zA-Z\\d_]{1,32}|(^|\\s)#[\\w\\.]+");
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
Matcher matcher = urlPattern.matcher(charSequence);
|
2015-05-03 13:48:36 +02:00
|
|
|
while (matcher.find()) {
|
|
|
|
int start = matcher.start();
|
|
|
|
int end = matcher.end();
|
2015-06-29 19:12:11 +02:00
|
|
|
if (charSequence.charAt(start) != '@' && charSequence.charAt(start) != '#' && charSequence.charAt(start) != '/') {
|
2015-05-03 13:48:36 +02:00
|
|
|
start++;
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
URLSpanNoUnderline url = null;
|
2015-10-29 18:10:07 +01:00
|
|
|
if (charSequence.charAt(start) == '/') {
|
2015-11-26 22:04:02 +01:00
|
|
|
if (botCommands) {
|
2017-03-31 01:58:05 +02:00
|
|
|
url = new URLSpanBotCommand(charSequence.subSequence(start, end).toString(), isOut);
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
} else {
|
|
|
|
url = new URLSpanNoUnderline(charSequence.subSequence(start, end).toString());
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
if (url != null) {
|
|
|
|
((Spannable) charSequence).setSpan(url, start, end, 0);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public static void addLinks(boolean isOut, CharSequence messageText) {
|
|
|
|
addLinks(isOut, messageText, true);
|
2015-11-26 22:04:02 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public static void addLinks(boolean isOut, CharSequence messageText, boolean botCommands) {
|
2015-01-02 23:15:07 +01:00
|
|
|
if (messageText instanceof Spannable && containsUrls(messageText)) {
|
2016-01-04 13:33:40 +01:00
|
|
|
if (messageText.length() < 200) {
|
2015-05-03 13:48:36 +02:00
|
|
|
try {
|
|
|
|
Linkify.addLinks((Spannable) messageText, Linkify.WEB_URLS | Linkify.PHONE_NUMBERS);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2014-12-01 18:56:31 +01:00
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
try {
|
|
|
|
Linkify.addLinks((Spannable) messageText, Linkify.WEB_URLS);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
addUsernamesAndHashtags(isOut, messageText, botCommands);
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void generateLayout(TLRPC.User fromUser) {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (type != 0 || messageOwner.to_id == null || messageText == null || messageText.length() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
generateLinkDescription();
|
|
|
|
textLayoutBlocks = new ArrayList<>();
|
2016-10-11 13:57:01 +02:00
|
|
|
textWidth = 0;
|
2015-06-29 19:12:11 +02:00
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
boolean hasEntities;
|
|
|
|
if (messageOwner.send_state != MESSAGE_SEND_STATE_SENT) {
|
|
|
|
hasEntities = false;
|
|
|
|
for (int a = 0; a < messageOwner.entities.size(); a++) {
|
|
|
|
if (!(messageOwner.entities.get(a) instanceof TLRPC.TL_inputMessageEntityMentionName)) {
|
|
|
|
hasEntities = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hasEntities = !messageOwner.entities.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean useManualParse = !hasEntities && (
|
2017-07-08 18:32:04 +02:00
|
|
|
eventId != 0 ||
|
2015-09-02 00:14:21 +02:00
|
|
|
messageOwner instanceof TLRPC.TL_message_old ||
|
|
|
|
messageOwner instanceof TLRPC.TL_message_old2 ||
|
|
|
|
messageOwner instanceof TLRPC.TL_message_old3 ||
|
|
|
|
messageOwner instanceof TLRPC.TL_message_old4 ||
|
|
|
|
messageOwner instanceof TLRPC.TL_messageForwarded_old ||
|
|
|
|
messageOwner instanceof TLRPC.TL_messageForwarded_old2 ||
|
|
|
|
messageOwner instanceof TLRPC.TL_message_secret ||
|
2017-03-31 01:58:05 +02:00
|
|
|
messageOwner.media instanceof TLRPC.TL_messageMediaInvoice ||
|
2016-01-11 18:19:48 +01:00
|
|
|
isOut() && messageOwner.send_state != MESSAGE_SEND_STATE_SENT ||
|
|
|
|
messageOwner.id < 0 || messageOwner.media instanceof TLRPC.TL_messageMediaUnsupported);
|
2015-09-02 00:14:21 +02:00
|
|
|
|
|
|
|
if (useManualParse) {
|
2017-03-31 01:58:05 +02:00
|
|
|
addLinks(isOutOwner(), messageText);
|
2015-09-24 22:52:02 +02:00
|
|
|
} else {
|
2016-01-11 18:19:48 +01:00
|
|
|
if (messageText instanceof Spannable && messageText.length() < 200) {
|
2015-09-24 22:52:02 +02:00
|
|
|
try {
|
|
|
|
Linkify.addLinks((Spannable) messageText, Linkify.PHONE_NUMBERS);
|
|
|
|
} catch (Throwable e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-02 00:14:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (messageText instanceof Spannable) {
|
|
|
|
Spannable spannable = (Spannable) messageText;
|
|
|
|
int count = messageOwner.entities.size();
|
2016-03-06 02:49:31 +01:00
|
|
|
URLSpan[] spans = spannable.getSpans(0, messageText.length(), URLSpan.class);
|
2015-09-02 00:14:21 +02:00
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
TLRPC.MessageEntity entity = messageOwner.entities.get(a);
|
|
|
|
if (entity.length <= 0 || entity.offset < 0 || entity.offset >= messageOwner.message.length()) {
|
|
|
|
continue;
|
|
|
|
} else if (entity.offset + entity.length > messageOwner.message.length()) {
|
|
|
|
entity.length = messageOwner.message.length() - entity.offset;
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
if (entity instanceof TLRPC.TL_messageEntityBold ||
|
|
|
|
entity instanceof TLRPC.TL_messageEntityItalic ||
|
|
|
|
entity instanceof TLRPC.TL_messageEntityCode ||
|
|
|
|
entity instanceof TLRPC.TL_messageEntityPre ||
|
|
|
|
entity instanceof TLRPC.TL_messageEntityMentionName ||
|
|
|
|
entity instanceof TLRPC.TL_inputMessageEntityMentionName) {
|
|
|
|
if (spans != null && spans.length > 0) {
|
|
|
|
for (int b = 0; b < spans.length; b++) {
|
|
|
|
if (spans[b] == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int start = spannable.getSpanStart(spans[b]);
|
|
|
|
int end = spannable.getSpanEnd(spans[b]);
|
|
|
|
if (entity.offset <= start && entity.offset + entity.length >= start || entity.offset <= end && entity.offset + entity.length >= end) {
|
|
|
|
spannable.removeSpan(spans[b]);
|
|
|
|
spans[b] = null;
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-09-02 00:14:21 +02:00
|
|
|
if (entity instanceof TLRPC.TL_messageEntityBold) {
|
|
|
|
spannable.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
} else if (entity instanceof TLRPC.TL_messageEntityItalic) {
|
|
|
|
spannable.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/ritalic.ttf")), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
2015-11-26 22:04:02 +01:00
|
|
|
} else if (entity instanceof TLRPC.TL_messageEntityCode || entity instanceof TLRPC.TL_messageEntityPre) {
|
2017-03-31 01:58:05 +02:00
|
|
|
spannable.setSpan(new URLSpanMono(spannable, entity.offset, entity.offset + entity.length, isOutOwner()), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
2016-05-25 23:49:47 +02:00
|
|
|
} else if (entity instanceof TLRPC.TL_messageEntityMentionName) {
|
2017-03-31 01:58:05 +02:00
|
|
|
spannable.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_messageEntityMentionName) entity).user_id, isOutOwner()), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
2016-05-25 23:49:47 +02:00
|
|
|
} else if (entity instanceof TLRPC.TL_inputMessageEntityMentionName) {
|
2017-03-31 01:58:05 +02:00
|
|
|
spannable.setSpan(new URLSpanUserMention("" + ((TLRPC.TL_inputMessageEntityMentionName) entity).user_id.user_id, isOutOwner()), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
2015-09-02 00:14:21 +02:00
|
|
|
} else if (!useManualParse) {
|
|
|
|
String url = messageOwner.message.substring(entity.offset, entity.offset + entity.length);
|
2015-10-29 18:10:07 +01:00
|
|
|
if (entity instanceof TLRPC.TL_messageEntityBotCommand) {
|
2017-03-31 01:58:05 +02:00
|
|
|
spannable.setSpan(new URLSpanBotCommand(url, isOutOwner()), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
2015-10-29 18:10:07 +01:00
|
|
|
} else if (entity instanceof TLRPC.TL_messageEntityHashtag || entity instanceof TLRPC.TL_messageEntityMention) {
|
2015-09-02 00:14:21 +02:00
|
|
|
spannable.setSpan(new URLSpanNoUnderline(url), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
} else if (entity instanceof TLRPC.TL_messageEntityEmail) {
|
|
|
|
spannable.setSpan(new URLSpanReplacement("mailto:" + url), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
} else if (entity instanceof TLRPC.TL_messageEntityUrl) {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (!url.toLowerCase().startsWith("http") && !url.toLowerCase().startsWith("tg://")) {
|
2015-09-02 00:14:21 +02:00
|
|
|
spannable.setSpan(new URLSpan("http://" + url), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
} else {
|
|
|
|
spannable.setSpan(new URLSpan(url), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
}
|
|
|
|
} else if (entity instanceof TLRPC.TL_messageEntityTextUrl) {
|
|
|
|
spannable.setSpan(new URLSpanReplacement(entity.url), entity.offset, entity.offset + entity.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
|
|
|
|
int maxWidth;
|
2017-07-08 18:32:04 +02:00
|
|
|
boolean needShare = eventId == 0 && messageOwner.from_id > 0 && (messageOwner.to_id.channel_id != 0 || messageOwner.to_id.chat_id != 0 || messageOwner.media instanceof TLRPC.TL_messageMediaGame || messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) && !isOut();
|
2016-10-11 13:57:01 +02:00
|
|
|
generatedWithMinSize = AndroidUtilities.isTablet() ? AndroidUtilities.getMinTabletSide() : AndroidUtilities.displaySize.x;
|
2017-07-08 18:32:04 +02:00
|
|
|
maxWidth = generatedWithMinSize - AndroidUtilities.dp(needShare || eventId != 0 ? 122 : 80);
|
2016-05-25 23:49:47 +02:00
|
|
|
if (fromUser != null && fromUser.bot || (isMegagroup() || messageOwner.fwd_from != null && messageOwner.fwd_from.channel_id != 0) && !isOut()) {
|
2016-03-06 02:49:31 +01:00
|
|
|
maxWidth -= AndroidUtilities.dp(20);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
|
|
|
maxWidth -= AndroidUtilities.dp(10);
|
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
StaticLayout textLayout;
|
2014-03-10 10:27:49 +01:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
TextPaint paint;
|
|
|
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
|
2017-03-31 01:58:05 +02:00
|
|
|
paint = Theme.chat_msgGameTextPaint;
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
paint = Theme.chat_msgTextPaint;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2014-03-10 10:27:49 +01:00
|
|
|
try {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
textLayout = StaticLayout.Builder.obtain(messageText, 0, messageText.length(), paint, maxWidth)
|
|
|
|
.setBreakStrategy(StaticLayout.BREAK_STRATEGY_HIGH_QUALITY)
|
|
|
|
.setHyphenationFrequency(StaticLayout.HYPHENATION_FREQUENCY_NONE)
|
|
|
|
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
|
|
|
|
.build();
|
|
|
|
} else {
|
|
|
|
textLayout = new StaticLayout(messageText, paint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
|
|
|
}
|
2014-03-10 10:27:49 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-03-10 10:27:49 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:28:25 +01:00
|
|
|
textHeight = textLayout.getHeight();
|
|
|
|
int linesCount = textLayout.getLineCount();
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
int blocksCount = (int) Math.ceil((float) linesCount / LINES_PER_BLOCK);
|
2014-02-28 23:28:25 +01:00
|
|
|
int linesOffset = 0;
|
2014-05-18 23:44:30 +02:00
|
|
|
float prevOffset = 0;
|
2014-02-28 23:28:25 +01:00
|
|
|
|
|
|
|
for (int a = 0; a < blocksCount; a++) {
|
|
|
|
int currentBlockLinesCount = Math.min(LINES_PER_BLOCK, linesCount - linesOffset);
|
|
|
|
TextLayoutBlock block = new TextLayoutBlock();
|
|
|
|
|
|
|
|
if (blocksCount == 1) {
|
|
|
|
block.textLayout = textLayout;
|
|
|
|
block.textYOffset = 0;
|
|
|
|
block.charactersOffset = 0;
|
2016-03-16 13:26:32 +01:00
|
|
|
block.height = textHeight;
|
2014-02-28 23:28:25 +01:00
|
|
|
} else {
|
|
|
|
int startCharacter = textLayout.getLineStart(linesOffset);
|
|
|
|
int endCharacter = textLayout.getLineEnd(linesOffset + currentBlockLinesCount - 1);
|
|
|
|
if (endCharacter < startCharacter) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
block.charactersOffset = startCharacter;
|
2017-03-31 01:58:05 +02:00
|
|
|
block.charactersEnd = endCharacter;
|
2014-03-10 10:27:49 +01:00
|
|
|
try {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
|
block.textLayout = StaticLayout.Builder.obtain(messageText, startCharacter, endCharacter, paint, maxWidth)
|
|
|
|
.setBreakStrategy(StaticLayout.BREAK_STRATEGY_HIGH_QUALITY)
|
|
|
|
.setHyphenationFrequency(StaticLayout.HYPHENATION_FREQUENCY_NONE)
|
|
|
|
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
|
|
|
|
.build();
|
|
|
|
} else {
|
|
|
|
block.textLayout = new StaticLayout(messageText, startCharacter, endCharacter, paint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
|
|
|
}
|
2014-03-10 10:27:49 +01:00
|
|
|
block.textYOffset = textLayout.getLineTop(linesOffset);
|
2014-09-24 04:17:27 +02:00
|
|
|
if (a != 0) {
|
2016-03-16 13:26:32 +01:00
|
|
|
block.height = (int) (block.textYOffset - prevOffset);
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
2016-03-16 13:26:32 +01:00
|
|
|
block.height = Math.max(block.height, block.textLayout.getLineBottom(block.textLayout.getLineCount() - 1));
|
2014-09-24 04:17:27 +02:00
|
|
|
prevOffset = block.textYOffset;
|
2014-03-10 10:27:49 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-03-10 10:27:49 +01:00
|
|
|
continue;
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (a == blocksCount - 1) {
|
|
|
|
currentBlockLinesCount = Math.max(currentBlockLinesCount, block.textLayout.getLineCount());
|
|
|
|
try {
|
|
|
|
textHeight = Math.max(textHeight, (int) (block.textYOffset + block.textLayout.getHeight()));
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-10-29 18:10:07 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
textLayoutBlocks.add(block);
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
float lastLeft;
|
2014-03-10 10:27:49 +01:00
|
|
|
try {
|
2017-03-31 01:58:05 +02:00
|
|
|
lastLeft = block.textLayout.getLineLeft(currentBlockLinesCount - 1);
|
|
|
|
if (a == 0) {
|
|
|
|
textXOffset = lastLeft;
|
|
|
|
}
|
2014-03-10 10:27:49 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
lastLeft = 0;
|
|
|
|
if (a == 0) {
|
|
|
|
textXOffset = 0;
|
|
|
|
}
|
|
|
|
FileLog.e(e);
|
2014-03-10 10:27:49 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
float lastLine;
|
2014-03-10 10:27:49 +01:00
|
|
|
try {
|
|
|
|
lastLine = block.textLayout.getLineWidth(currentBlockLinesCount - 1);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
lastLine = 0;
|
|
|
|
FileLog.e(e);
|
2014-03-10 10:27:49 +01:00
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
int linesMaxWidth = (int) Math.ceil(lastLine);
|
2014-02-28 23:28:25 +01:00
|
|
|
int lastLineWidthWithLeft;
|
|
|
|
int linesMaxWidthWithLeft;
|
|
|
|
|
|
|
|
if (a == blocksCount - 1) {
|
|
|
|
lastLineWidth = linesMaxWidth;
|
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
linesMaxWidthWithLeft = lastLineWidthWithLeft = (int) Math.ceil(lastLine + lastLeft);
|
2014-02-28 23:28:25 +01:00
|
|
|
|
|
|
|
if (currentBlockLinesCount > 1) {
|
2017-03-31 01:58:05 +02:00
|
|
|
boolean hasNonRTL = false;
|
2014-02-28 23:28:25 +01:00
|
|
|
float textRealMaxWidth = 0, textRealMaxWidthWithLeft = 0, lineWidth, lineLeft;
|
2015-10-29 18:10:07 +01:00
|
|
|
for (int n = 0; n < currentBlockLinesCount; n++) {
|
2014-02-28 23:28:25 +01:00
|
|
|
try {
|
|
|
|
lineWidth = block.textLayout.getLineWidth(n);
|
2014-03-10 10:27:49 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-03-10 10:27:49 +01:00
|
|
|
lineWidth = 0;
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
if (lineWidth > maxWidth + 20) {
|
2014-12-01 18:56:31 +01:00
|
|
|
lineWidth = maxWidth;
|
2014-07-11 23:47:50 +02:00
|
|
|
}
|
|
|
|
|
2014-03-10 10:27:49 +01:00
|
|
|
try {
|
2014-02-28 23:28:25 +01:00
|
|
|
lineLeft = block.textLayout.getLineLeft(n);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-03-10 10:27:49 +01:00
|
|
|
lineLeft = 0;
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
if (lineLeft > 0) {
|
|
|
|
textXOffset = Math.min(textXOffset, lineLeft);
|
|
|
|
block.directionFlags |= 1;
|
|
|
|
hasRtl = true;
|
|
|
|
} else {
|
|
|
|
block.directionFlags |= 2;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2014-03-10 10:27:49 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
try {
|
|
|
|
if (!hasNonRTL && lineLeft == 0 && block.textLayout.getParagraphDirection(n) == Layout.DIR_LEFT_TO_RIGHT) {
|
|
|
|
hasNonRTL = true;
|
|
|
|
}
|
|
|
|
} catch (Exception ignore) {
|
2014-02-28 23:28:25 +01:00
|
|
|
hasNonRTL = true;
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2014-02-28 23:28:25 +01:00
|
|
|
textRealMaxWidth = Math.max(textRealMaxWidth, lineWidth);
|
|
|
|
textRealMaxWidthWithLeft = Math.max(textRealMaxWidthWithLeft, lineWidth + lineLeft);
|
2015-02-26 02:32:51 +01:00
|
|
|
linesMaxWidth = Math.max(linesMaxWidth, (int) Math.ceil(lineWidth));
|
|
|
|
linesMaxWidthWithLeft = Math.max(linesMaxWidthWithLeft, (int) Math.ceil(lineWidth + lineLeft));
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
if (hasNonRTL) {
|
|
|
|
textRealMaxWidth = textRealMaxWidthWithLeft;
|
|
|
|
if (a == blocksCount - 1) {
|
|
|
|
lastLineWidth = lastLineWidthWithLeft;
|
|
|
|
}
|
|
|
|
} else if (a == blocksCount - 1) {
|
|
|
|
lastLineWidth = linesMaxWidth;
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
textWidth = Math.max(textWidth, (int) Math.ceil(textRealMaxWidth));
|
2014-02-28 23:28:25 +01:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
if (lastLeft > 0) {
|
|
|
|
textXOffset = Math.min(textXOffset, lastLeft);
|
|
|
|
hasRtl = blocksCount != 1;
|
|
|
|
block.directionFlags |= 1;
|
|
|
|
} else {
|
|
|
|
block.directionFlags |= 2;
|
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
textWidth = Math.max(textWidth, Math.min(maxWidth, linesMaxWidth));
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
linesOffset += currentBlockLinesCount;
|
|
|
|
}
|
|
|
|
}
|
2014-04-03 23:18:54 +02:00
|
|
|
|
|
|
|
public boolean isOut() {
|
2015-11-26 22:04:02 +01:00
|
|
|
return messageOwner.out;
|
2014-04-03 23:18:54 +02:00
|
|
|
}
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
public boolean isOutOwner() {
|
2016-03-06 02:49:31 +01:00
|
|
|
return messageOwner.out && messageOwner.from_id > 0 && !messageOwner.post;
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public boolean needDrawAvatar() {
|
|
|
|
return isFromUser() || eventId != 0;
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public boolean isFromUser() {
|
|
|
|
return messageOwner.from_id > 0 && !messageOwner.post;
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 17:55:05 +02:00
|
|
|
public boolean isUnread() {
|
2015-11-26 22:04:02 +01:00
|
|
|
return messageOwner.unread;
|
2014-10-09 17:55:05 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public boolean isContentUnread() {
|
2015-11-26 22:04:02 +01:00
|
|
|
return messageOwner.media_unread;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 17:55:05 +02:00
|
|
|
public void setIsRead() {
|
2015-11-26 22:04:02 +01:00
|
|
|
messageOwner.unread = false;
|
2014-10-09 17:55:05 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public int getUnradFlags() {
|
|
|
|
return getUnreadFlags(messageOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int getUnreadFlags(TLRPC.Message message) {
|
|
|
|
int flags = 0;
|
2015-11-26 22:04:02 +01:00
|
|
|
if (!message.unread) {
|
2015-05-03 13:48:36 +02:00
|
|
|
flags |= 1;
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
if (!message.media_unread) {
|
2015-05-03 13:48:36 +02:00
|
|
|
flags |= 2;
|
|
|
|
}
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setContentIsRead() {
|
2015-11-26 22:04:02 +01:00
|
|
|
messageOwner.media_unread = false;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public int getId() {
|
|
|
|
return messageOwner.id;
|
|
|
|
}
|
|
|
|
|
2014-10-21 22:35:16 +02:00
|
|
|
public boolean isSecretPhoto() {
|
2017-07-08 18:32:04 +02:00
|
|
|
return messageOwner instanceof TLRPC.TL_message_secret && (messageOwner.media instanceof TLRPC.TL_messageMediaPhoto || isRoundVideo()) && messageOwner.ttl > 0 && messageOwner.ttl <= 60;
|
2014-10-09 17:55:05 +02:00
|
|
|
}
|
|
|
|
|
2014-10-21 22:35:16 +02:00
|
|
|
public boolean isSecretMedia() {
|
|
|
|
return messageOwner instanceof TLRPC.TL_message_secret &&
|
2017-07-08 18:32:04 +02:00
|
|
|
((messageOwner.media instanceof TLRPC.TL_messageMediaPhoto || isRoundVideo()) && messageOwner.ttl > 0 && messageOwner.ttl <= 60 || isVoice() || isVideo());
|
2014-10-21 22:35:16 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public static void setUnreadFlags(TLRPC.Message message, int flag) {
|
2015-11-26 22:04:02 +01:00
|
|
|
message.unread = (flag & 1) == 0;
|
|
|
|
message.media_unread = (flag & 2) == 0;
|
2014-10-09 17:55:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isUnread(TLRPC.Message message) {
|
2015-11-26 22:04:02 +01:00
|
|
|
return message.unread;
|
2014-10-09 17:55:05 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public static boolean isContentUnread(TLRPC.Message message) {
|
2015-11-26 22:04:02 +01:00
|
|
|
return message.media_unread;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
public boolean isMegagroup() {
|
|
|
|
return isMegagroup(messageOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isMegagroup(TLRPC.Message message) {
|
|
|
|
return (message.flags & TLRPC.MESSAGE_FLAG_MEGAGROUP) != 0;
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
|
|
|
|
2014-10-09 17:55:05 +02:00
|
|
|
public static boolean isOut(TLRPC.Message message) {
|
2015-11-26 22:04:02 +01:00
|
|
|
return message.out;
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
public long getDialogId() {
|
2015-11-26 22:04:02 +01:00
|
|
|
return getDialogId(messageOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static long getDialogId(TLRPC.Message message) {
|
|
|
|
if (message.dialog_id == 0 && message.to_id != null) {
|
|
|
|
if (message.to_id.chat_id != 0) {
|
|
|
|
if (message.to_id.chat_id < 0) {
|
|
|
|
message.dialog_id = AndroidUtilities.makeBroadcastId(message.to_id.chat_id);
|
2015-09-24 22:52:02 +02:00
|
|
|
} else {
|
2015-11-26 22:04:02 +01:00
|
|
|
message.dialog_id = -message.to_id.chat_id;
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
} else if (message.to_id.channel_id != 0) {
|
|
|
|
message.dialog_id = -message.to_id.channel_id;
|
|
|
|
} else if (isOut(message)) {
|
|
|
|
message.dialog_id = message.to_id.user_id;
|
2014-07-03 00:39:05 +02:00
|
|
|
} else {
|
2015-11-26 22:04:02 +01:00
|
|
|
message.dialog_id = message.from_id;
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
return message.dialog_id;
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
2014-09-28 15:37:26 +02:00
|
|
|
|
|
|
|
public boolean isSending() {
|
2015-04-09 20:00:14 +02:00
|
|
|
return messageOwner.send_state == MESSAGE_SEND_STATE_SENDING && messageOwner.id < 0;
|
2014-09-28 15:37:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSendError() {
|
2015-06-29 19:12:11 +02:00
|
|
|
return messageOwner.send_state == MESSAGE_SEND_STATE_SEND_ERROR && messageOwner.id < 0;
|
2014-09-28 15:37:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSent() {
|
2015-04-09 20:00:14 +02:00
|
|
|
return messageOwner.send_state == MESSAGE_SEND_STATE_SENT || messageOwner.id > 0;
|
2014-09-28 15:37:26 +02:00
|
|
|
}
|
2014-10-09 17:55:05 +02:00
|
|
|
|
|
|
|
public String getSecretTimeString() {
|
|
|
|
if (!isSecretMedia()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
int secondsLeft = messageOwner.ttl;
|
|
|
|
if (messageOwner.destroyTime != 0) {
|
|
|
|
secondsLeft = Math.max(0, messageOwner.destroyTime - ConnectionsManager.getInstance().getCurrentTime());
|
|
|
|
}
|
|
|
|
String str;
|
|
|
|
if (secondsLeft < 60) {
|
|
|
|
str = secondsLeft + "s";
|
|
|
|
} else {
|
2014-10-10 19:16:39 +02:00
|
|
|
str = secondsLeft / 60 + "m";
|
2014-10-09 17:55:05 +02:00
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
public String getDocumentName() {
|
2017-03-31 01:58:05 +02:00
|
|
|
TLRPC.Document document;
|
|
|
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaDocument) {
|
2015-01-02 23:15:07 +01:00
|
|
|
return FileLoader.getDocumentFileName(messageOwner.media.document);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
return FileLoader.getDocumentFileName(messageOwner.media.webpage.document);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public static boolean isStickerDocument(TLRPC.Document document) {
|
|
|
|
if (document != null) {
|
|
|
|
for (int a = 0; a < document.attributes.size(); a++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
|
2015-01-02 23:15:07 +01:00
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public static boolean isMaskDocument(TLRPC.Document document) {
|
|
|
|
if (document != null) {
|
|
|
|
for (int a = 0; a < document.attributes.size(); a++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeSticker && attribute.mask) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public static boolean isVoiceDocument(TLRPC.Document document) {
|
|
|
|
if (document != null) {
|
|
|
|
for (int a = 0; a < document.attributes.size(); a++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
|
|
|
|
return attribute.voice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public static boolean isVoiceWebDocument(TLRPC.TL_webDocument webDocument) {
|
|
|
|
return webDocument != null && webDocument.mime_type.equals("audio/ogg");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isImageWebDocument(TLRPC.TL_webDocument webDocument) {
|
|
|
|
return webDocument != null && webDocument.mime_type.startsWith("image/");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isVideoWebDocument(TLRPC.TL_webDocument webDocument) {
|
|
|
|
return webDocument != null && webDocument.mime_type.startsWith("video/");
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
public static boolean isMusicDocument(TLRPC.Document document) {
|
|
|
|
if (document != null) {
|
|
|
|
for (int a = 0; a < document.attributes.size(); a++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
|
|
|
|
return !attribute.voice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public static boolean isVideoDocument(TLRPC.Document document) {
|
|
|
|
if (document != null) {
|
|
|
|
boolean isAnimated = false;
|
|
|
|
boolean isVideo = false;
|
2017-03-31 01:58:05 +02:00
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
2016-03-06 02:49:31 +01:00
|
|
|
for (int a = 0; a < document.attributes.size(); a++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 16 && attribute.round_message) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
isVideo = true;
|
2017-03-31 01:58:05 +02:00
|
|
|
width = attribute.w;
|
|
|
|
height = attribute.h;
|
2016-03-06 02:49:31 +01:00
|
|
|
} else if (attribute instanceof TLRPC.TL_documentAttributeAnimated) {
|
|
|
|
isAnimated = true;
|
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (isAnimated && (width > 1280 || height > 1280)) {
|
|
|
|
isAnimated = false;
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
return isVideo && !isAnimated;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
public TLRPC.Document getDocument() {
|
|
|
|
if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
return messageOwner.media.webpage.document;
|
|
|
|
}
|
|
|
|
return messageOwner.media != null ? messageOwner.media.document : null;
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public static boolean isStickerMessage(TLRPC.Message message) {
|
|
|
|
return message.media != null && message.media.document != null && isStickerDocument(message.media.document);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public static boolean isMaskMessage(TLRPC.Message message) {
|
|
|
|
return message.media != null && message.media.document != null && isMaskDocument(message.media.document);
|
|
|
|
}
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
public static boolean isMusicMessage(TLRPC.Message message) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
return isMusicDocument(message.media.webpage.document);
|
2015-07-22 20:56:37 +02:00
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
return message.media != null && message.media.document != null && isMusicDocument(message.media.document);
|
2015-07-22 20:56:37 +02:00
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public static boolean isRoundVideoMessage(TLRPC.Message message) {
|
|
|
|
if (Build.VERSION.SDK_INT < 16) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
return isRoundVideoDocument(message.media.webpage.document);
|
|
|
|
}
|
|
|
|
return message.media != null && message.media.document != null && isRoundVideoDocument(message.media.document);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public static boolean isVoiceMessage(TLRPC.Message message) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
return isVoiceDocument(message.media.webpage.document);
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
return message.media != null && message.media.document != null && isVoiceDocument(message.media.document);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public static boolean isNewGifMessage(TLRPC.Message message) {
|
|
|
|
if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
return isNewGifDocument(message.media.webpage.document);
|
|
|
|
}
|
|
|
|
return message.media != null && message.media.document != null && isNewGifDocument(message.media.document);
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public static boolean isVideoMessage(TLRPC.Message message) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (message.media instanceof TLRPC.TL_messageMediaWebPage) {
|
|
|
|
return isVideoDocument(message.media.webpage.document);
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
return message.media != null && message.media.document != null && isVideoDocument(message.media.document);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public static boolean isGameMessage(TLRPC.Message message) {
|
|
|
|
return message.media instanceof TLRPC.TL_messageMediaGame;
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public static boolean isInvoiceMessage(TLRPC.Message message) {
|
|
|
|
return message.media instanceof TLRPC.TL_messageMediaInvoice;
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
public static TLRPC.InputStickerSet getInputStickerSet(TLRPC.Message message) {
|
|
|
|
if (message.media != null && message.media.document != null) {
|
|
|
|
for (TLRPC.DocumentAttribute attribute : message.media.document.attributes) {
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
|
|
|
|
if (attribute.stickerset instanceof TLRPC.TL_inputStickerSetEmpty) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return attribute.stickerset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public String getStrickerChar() {
|
|
|
|
if (messageOwner.media != null && messageOwner.media.document != null) {
|
|
|
|
for (TLRPC.DocumentAttribute attribute : messageOwner.media.document.attributes) {
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
|
|
|
|
return attribute.alt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getApproximateHeight() {
|
|
|
|
if (type == 0) {
|
2016-04-22 15:49:00 +02:00
|
|
|
int height = textHeight + (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageOwner.media.webpage instanceof TLRPC.TL_webPage ? AndroidUtilities.dp(100) : 0);
|
|
|
|
if (isReply()) {
|
|
|
|
height += AndroidUtilities.dp(42);
|
|
|
|
}
|
|
|
|
return height;
|
|
|
|
} else if (type == 2) {
|
|
|
|
return AndroidUtilities.dp(72);
|
|
|
|
} else if (type == 12) {
|
2015-03-19 00:09:45 +01:00
|
|
|
return AndroidUtilities.dp(71);
|
|
|
|
} else if (type == 9) {
|
|
|
|
return AndroidUtilities.dp(100);
|
|
|
|
} else if (type == 4) {
|
|
|
|
return AndroidUtilities.dp(114);
|
2015-07-22 20:56:37 +02:00
|
|
|
} else if (type == 14) {
|
2016-04-22 15:49:00 +02:00
|
|
|
return AndroidUtilities.dp(82);
|
|
|
|
} else if (type == 10) {
|
|
|
|
return AndroidUtilities.dp(30);
|
|
|
|
} else if (type == 11) {
|
|
|
|
return AndroidUtilities.dp(50);
|
2017-07-08 18:32:04 +02:00
|
|
|
} else if (type == 5) {
|
|
|
|
return AndroidUtilities.roundMessageSize;
|
2015-03-19 00:09:45 +01:00
|
|
|
} else if (type == 13) {
|
|
|
|
float maxHeight = AndroidUtilities.displaySize.y * 0.4f;
|
|
|
|
float maxWidth;
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
maxWidth = AndroidUtilities.getMinTabletSide() * 0.5f;
|
|
|
|
} else {
|
|
|
|
maxWidth = AndroidUtilities.displaySize.x * 0.5f;
|
|
|
|
}
|
|
|
|
int photoHeight = 0;
|
|
|
|
int photoWidth = 0;
|
|
|
|
for (TLRPC.DocumentAttribute attribute : messageOwner.media.document.attributes) {
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeImageSize) {
|
|
|
|
photoWidth = attribute.w;
|
|
|
|
photoHeight = attribute.h;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (photoWidth == 0) {
|
|
|
|
photoHeight = (int) maxHeight;
|
|
|
|
photoWidth = photoHeight + AndroidUtilities.dp(100);
|
|
|
|
}
|
|
|
|
if (photoHeight > maxHeight) {
|
|
|
|
photoWidth *= maxHeight / photoHeight;
|
|
|
|
photoHeight = (int)maxHeight;
|
|
|
|
}
|
|
|
|
if (photoWidth > maxWidth) {
|
|
|
|
photoHeight *= maxWidth / photoWidth;
|
|
|
|
}
|
|
|
|
return photoHeight + AndroidUtilities.dp(14);
|
|
|
|
} else {
|
2015-05-21 23:27:27 +02:00
|
|
|
int photoHeight;
|
|
|
|
int photoWidth;
|
2015-03-19 00:09:45 +01:00
|
|
|
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
photoWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f);
|
|
|
|
} else {
|
|
|
|
photoWidth = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f);
|
|
|
|
}
|
|
|
|
photoHeight = photoWidth + AndroidUtilities.dp(100);
|
|
|
|
if (photoWidth > AndroidUtilities.getPhotoSize()) {
|
|
|
|
photoWidth = AndroidUtilities.getPhotoSize();
|
|
|
|
}
|
|
|
|
if (photoHeight > AndroidUtilities.getPhotoSize()) {
|
|
|
|
photoHeight = AndroidUtilities.getPhotoSize();
|
|
|
|
}
|
|
|
|
TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(photoThumbs, AndroidUtilities.getPhotoSize());
|
|
|
|
|
|
|
|
if (currentPhotoObject != null) {
|
|
|
|
float scale = (float) currentPhotoObject.w / (float) photoWidth;
|
|
|
|
int h = (int) (currentPhotoObject.h / scale);
|
|
|
|
if (h == 0) {
|
|
|
|
h = AndroidUtilities.dp(100);
|
|
|
|
}
|
|
|
|
if (h > photoHeight) {
|
|
|
|
h = photoHeight;
|
|
|
|
} else if (h < AndroidUtilities.dp(120)) {
|
|
|
|
h = AndroidUtilities.dp(120);
|
|
|
|
}
|
|
|
|
if (isSecretPhoto()) {
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
2015-05-21 23:27:27 +02:00
|
|
|
h = (int) (AndroidUtilities.getMinTabletSide() * 0.5f);
|
2015-03-19 00:09:45 +01:00
|
|
|
} else {
|
2015-05-21 23:27:27 +02:00
|
|
|
h = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.5f);
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
photoHeight = h;
|
|
|
|
}
|
|
|
|
return photoHeight + AndroidUtilities.dp(14);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
public String getStickerEmoji() {
|
|
|
|
for (int a = 0; a < messageOwner.media.document.attributes.size(); a++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = messageOwner.media.document.attributes.get(a);
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeSticker) {
|
|
|
|
return attribute.alt != null && attribute.alt.length() > 0 ? attribute.alt : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
public boolean isSticker() {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (type != 1000) {
|
|
|
|
return type == 13;
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
return isStickerMessage(messageOwner);
|
|
|
|
}
|
2015-03-19 00:09:45 +01:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public boolean isMask() {
|
|
|
|
return isMaskMessage(messageOwner);
|
|
|
|
}
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
public boolean isMusic() {
|
|
|
|
return isMusicMessage(messageOwner);
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public boolean isVoice() {
|
|
|
|
return isVoiceMessage(messageOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isVideo() {
|
|
|
|
return isVideoMessage(messageOwner);
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public boolean isGame() {
|
|
|
|
return isGameMessage(messageOwner);
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public boolean isInvoice() {
|
|
|
|
return isInvoiceMessage(messageOwner);
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public boolean isRoundVideo() {
|
|
|
|
if (Build.VERSION.SDK_INT < 16) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isRoundVideoCached == 0) {
|
|
|
|
isRoundVideoCached = type == 5 || isRoundVideoMessage(messageOwner) ? 1 : 2;
|
|
|
|
}
|
|
|
|
return isRoundVideoCached == 1;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public boolean hasPhotoStickers() {
|
|
|
|
return messageOwner.media != null && messageOwner.media.photo != null && messageOwner.media.photo.has_stickers;
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
public boolean isGif() {
|
2016-03-16 13:26:32 +01:00
|
|
|
return messageOwner.media instanceof TLRPC.TL_messageMediaDocument && isGifDocument(messageOwner.media.document);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isWebpageDocument() {
|
|
|
|
return messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageOwner.media.webpage.document != null && !isGifDocument(messageOwner.media.webpage.document);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isNewGif() {
|
|
|
|
return messageOwner.media != null && isNewGifDocument(messageOwner.media.document);
|
|
|
|
}
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
public String getMusicTitle() {
|
2017-07-08 18:32:04 +02:00
|
|
|
return getMusicTitle(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getMusicTitle(boolean unknown) {
|
2016-04-22 15:49:00 +02:00
|
|
|
TLRPC.Document document;
|
|
|
|
if (type == 0) {
|
|
|
|
document = messageOwner.media.webpage.document;
|
|
|
|
} else {
|
|
|
|
document = messageOwner.media.document;
|
|
|
|
}
|
|
|
|
for (int a = 0; a < document.attributes.size(); a++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
|
2015-07-22 20:56:37 +02:00
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (attribute.voice) {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (!unknown) {
|
|
|
|
return null;
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
return LocaleController.formatDateAudio(messageOwner.date);
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
String title = attribute.title;
|
|
|
|
if (title == null || title.length() == 0) {
|
2016-04-22 15:49:00 +02:00
|
|
|
title = FileLoader.getDocumentFileName(document);
|
2017-07-08 18:32:04 +02:00
|
|
|
if (TextUtils.isEmpty(title) && unknown) {
|
2015-07-22 20:56:37 +02:00
|
|
|
title = LocaleController.getString("AudioUnknownTitle", R.string.AudioUnknownTitle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return title;
|
2017-07-08 18:32:04 +02:00
|
|
|
} else if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
|
|
|
|
if (attribute.round_message) {
|
|
|
|
return LocaleController.formatDateAudio(messageOwner.date);
|
|
|
|
}
|
2015-07-22 20:56:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
public int getDuration() {
|
|
|
|
TLRPC.Document document;
|
|
|
|
if (type == 0) {
|
|
|
|
document = messageOwner.media.webpage.document;
|
|
|
|
} else {
|
|
|
|
document = messageOwner.media.document;
|
|
|
|
}
|
|
|
|
for (int a = 0; a < document.attributes.size(); a++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
|
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
|
|
|
|
return attribute.duration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-22 20:56:37 +02:00
|
|
|
public String getMusicAuthor() {
|
2017-07-08 18:32:04 +02:00
|
|
|
return getMusicAuthor(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getMusicAuthor(boolean unknown) {
|
2016-04-22 15:49:00 +02:00
|
|
|
TLRPC.Document document;
|
|
|
|
if (type == 0) {
|
|
|
|
document = messageOwner.media.webpage.document;
|
|
|
|
} else {
|
|
|
|
document = messageOwner.media.document;
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
boolean isVoice = false;
|
2016-04-22 15:49:00 +02:00
|
|
|
for (int a = 0; a < document.attributes.size(); a++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
|
2015-07-22 20:56:37 +02:00
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (attribute.voice) {
|
2017-07-08 18:32:04 +02:00
|
|
|
isVoice = true;
|
|
|
|
} else {
|
|
|
|
String performer = attribute.performer;
|
|
|
|
if (TextUtils.isEmpty(performer) && unknown) {
|
|
|
|
performer = LocaleController.getString("AudioUnknownArtist", R.string.AudioUnknownArtist);
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
return performer;
|
|
|
|
}
|
|
|
|
} else if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
|
|
|
|
if (attribute.round_message) {
|
|
|
|
isVoice = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isVoice) {
|
|
|
|
if (!unknown) {
|
|
|
|
return null;
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
if (isOutOwner() || messageOwner.fwd_from != null && messageOwner.fwd_from.from_id == UserConfig.getClientUserId()) {
|
|
|
|
return LocaleController.getString("FromYou", R.string.FromYou);
|
|
|
|
}
|
|
|
|
TLRPC.User user = null;
|
|
|
|
TLRPC.Chat chat = null;
|
|
|
|
if (messageOwner.fwd_from != null && messageOwner.fwd_from.channel_id != 0) {
|
|
|
|
chat = MessagesController.getInstance().getChat(messageOwner.fwd_from.channel_id);
|
|
|
|
} else if (messageOwner.fwd_from != null && messageOwner.fwd_from.from_id != 0) {
|
|
|
|
user = MessagesController.getInstance().getUser(messageOwner.fwd_from.from_id);
|
|
|
|
} else if (messageOwner.from_id < 0) {
|
|
|
|
chat = MessagesController.getInstance().getChat(-messageOwner.from_id);
|
|
|
|
} else {
|
|
|
|
user = MessagesController.getInstance().getUser(messageOwner.from_id);
|
|
|
|
}
|
|
|
|
if (user != null) {
|
|
|
|
return UserObject.getUserName(user);
|
|
|
|
} else if (chat != null) {
|
|
|
|
return chat.title;
|
2015-07-22 20:56:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
public TLRPC.InputStickerSet getInputStickerSet() {
|
|
|
|
return getInputStickerSet(messageOwner);
|
|
|
|
}
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public boolean isForwarded() {
|
2016-03-06 02:49:31 +01:00
|
|
|
return isForwardedMessage(messageOwner);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isForwardedMessage(TLRPC.Message message) {
|
2017-07-08 18:32:04 +02:00
|
|
|
return (message.flags & TLRPC.MESSAGE_FLAG_FWD) != 0 && message.fwd_from != null;
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isReply() {
|
2016-03-06 02:49:31 +01:00
|
|
|
return !(replyMessageObject != null && replyMessageObject.messageOwner instanceof TLRPC.TL_messageEmpty) && (messageOwner.reply_to_msg_id != 0 || messageOwner.reply_to_random_id != 0) && (messageOwner.flags & TLRPC.MESSAGE_FLAG_REPLY) != 0;
|
2015-03-19 00:09:45 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
public boolean isMediaEmpty() {
|
|
|
|
return isMediaEmpty(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;
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public boolean canEditMessage(TLRPC.Chat chat) {
|
|
|
|
return canEditMessage(messageOwner, chat);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean canEditMessage(TLRPC.Message message, TLRPC.Chat chat) {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (message == null || message.to_id == null || message.media != null && isRoundVideoDocument(message.media.document) || message.action != null && !(message.action instanceof TLRPC.TL_messageActionEmpty) || isForwardedMessage(message) || message.via_bot_id != 0 || message.id < 0) {
|
2016-10-11 13:57:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (message.from_id == message.to_id.user_id && message.from_id == UserConfig.getClientUserId()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Math.abs(message.date - ConnectionsManager.getInstance().getCurrentTime()) > MessagesController.getInstance().maxEditTime) {
|
2016-03-06 02:49:31 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
if (message.to_id.channel_id == 0) {
|
2016-10-11 13:57:01 +02:00
|
|
|
return (message.out || message.from_id == UserConfig.getClientUserId()) && (message.media instanceof TLRPC.TL_messageMediaPhoto ||
|
2016-05-25 23:49:47 +02:00
|
|
|
message.media instanceof TLRPC.TL_messageMediaDocument && !isStickerMessage(message) ||
|
2016-04-22 15:49:00 +02:00
|
|
|
message.media instanceof TLRPC.TL_messageMediaEmpty ||
|
|
|
|
message.media instanceof TLRPC.TL_messageMediaWebPage ||
|
|
|
|
message.media == null);
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
if (chat == null && message.to_id.channel_id != 0) {
|
|
|
|
chat = MessagesController.getInstance().getChat(message.to_id.channel_id);
|
2016-04-22 15:49:00 +02:00
|
|
|
if (chat == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
if (chat.megagroup && message.out || !chat.megagroup && (chat.creator || chat.admin_rights != null && chat.admin_rights.edit_messages) && message.post) {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (message.media instanceof TLRPC.TL_messageMediaPhoto ||
|
2016-05-25 23:49:47 +02:00
|
|
|
message.media instanceof TLRPC.TL_messageMediaDocument && !isStickerMessage(message) ||
|
2016-03-06 02:49:31 +01:00
|
|
|
message.media instanceof TLRPC.TL_messageMediaEmpty ||
|
|
|
|
message.media instanceof TLRPC.TL_messageMediaWebPage ||
|
|
|
|
message.media == null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
public boolean canDeleteMessage(TLRPC.Chat chat) {
|
2017-07-08 18:32:04 +02:00
|
|
|
return eventId == 0 && canDeleteMessage(messageOwner, chat);
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean canDeleteMessage(TLRPC.Message message, TLRPC.Chat chat) {
|
2015-11-26 22:04:02 +01:00
|
|
|
if (message.id < 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
if (chat == null && message.to_id.channel_id != 0) {
|
|
|
|
chat = MessagesController.getInstance().getChat(message.to_id.channel_id);
|
|
|
|
}
|
|
|
|
if (ChatObject.isChannel(chat)) {
|
2017-07-08 18:32:04 +02:00
|
|
|
return message.id != 1 && (chat.creator || chat.admin_rights != null && chat.admin_rights.delete_messages || chat.megagroup && isOut(message) && message.from_id > 0);
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
|
|
|
return isOut(message) || !ChatObject.isChannel(chat);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getForwardedName() {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (messageOwner.fwd_from != null) {
|
|
|
|
if (messageOwner.fwd_from.channel_id != 0) {
|
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().getChat(messageOwner.fwd_from.channel_id);
|
|
|
|
if (chat != null) {
|
|
|
|
return chat.title;
|
|
|
|
}
|
|
|
|
} else if (messageOwner.fwd_from.from_id != 0) {
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(messageOwner.fwd_from.from_id);
|
|
|
|
if (user != null) {
|
|
|
|
return UserObject.getUserName(user);
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
|
|
|
|
public void checkMediaExistance() {
|
|
|
|
File cacheFile = null;
|
2016-04-25 21:26:41 +02:00
|
|
|
attachPathExists = false;
|
|
|
|
mediaExists = false;
|
2016-04-22 15:49:00 +02:00
|
|
|
if (type == 1) {
|
|
|
|
TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(photoThumbs, AndroidUtilities.getPhotoSize());
|
|
|
|
if (currentPhotoObject != null) {
|
|
|
|
mediaExists = FileLoader.getPathToMessage(messageOwner).exists();
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
} else if (type == 8 || type == 3 || type == 9 || type == 2 || type == 14 || type == 5) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (messageOwner.attachPath != null && messageOwner.attachPath.length() > 0) {
|
|
|
|
File f = new File(messageOwner.attachPath);
|
|
|
|
attachPathExists = f.exists();
|
|
|
|
}
|
|
|
|
if (!attachPathExists) {
|
|
|
|
mediaExists = FileLoader.getPathToMessage(messageOwner).exists();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TLRPC.Document document = getDocument();
|
|
|
|
if (document != null) {
|
|
|
|
mediaExists = FileLoader.getPathToAttach(document).exists();
|
|
|
|
} else if (type == 0) {
|
|
|
|
TLRPC.PhotoSize currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(photoThumbs, AndroidUtilities.getPhotoSize());
|
|
|
|
if (currentPhotoObject == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (currentPhotoObject != null) {
|
|
|
|
mediaExists = FileLoader.getPathToAttach(currentPhotoObject, true).exists();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-25 17:19:00 +02:00
|
|
|
}
|