use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatMessageCell method setMessageObjectInternal.
private void setMessageObjectInternal(MessageObject messageObject) {
if (((messageObject.messageOwner.flags & TLRPC.MESSAGE_FLAG_HAS_VIEWS) != 0 || messageObject.messageOwner.replies != null) && !currentMessageObject.scheduled && !currentMessageObject.isSponsored()) {
if (!currentMessageObject.viewsReloaded) {
MessagesController.getInstance(currentAccount).addToViewsQueue(currentMessageObject);
currentMessageObject.viewsReloaded = true;
}
}
updateCurrentUserAndChat();
if (isAvatarVisible) {
if (messageObject.customAvatarDrawable != null) {
avatarImage.setImageBitmap(messageObject.customAvatarDrawable);
} else if (currentUser != null) {
if (currentUser.photo != null) {
currentPhoto = currentUser.photo.photo_small;
} else {
currentPhoto = null;
}
avatarDrawable.setInfo(currentUser);
avatarImage.setForUserOrChat(currentUser, avatarDrawable);
} else if (currentChat != null) {
if (currentChat.photo != null) {
currentPhoto = currentChat.photo.photo_small;
} else {
currentPhoto = null;
}
avatarDrawable.setInfo(currentChat);
avatarImage.setForUserOrChat(currentChat, avatarDrawable);
} else if (messageObject != null && messageObject.isSponsored()) {
if (messageObject.sponsoredChatInvite != null && messageObject.sponsoredChatInvite.chat != null) {
avatarDrawable.setInfo(messageObject.sponsoredChatInvite.chat);
avatarImage.setForUserOrChat(messageObject.sponsoredChatInvite.chat, avatarDrawable);
} else {
avatarDrawable.setInfo(messageObject.sponsoredChatInvite);
TLRPC.Photo photo = messageObject.sponsoredChatInvite.photo;
if (photo != null) {
avatarImage.setImage(ImageLocation.getForPhoto(photo.sizes.get(0), photo), "50_50", avatarDrawable, null, null, 0);
}
}
} else {
currentPhoto = null;
avatarDrawable.setInfo(messageObject.getFromChatId(), null, null);
avatarImage.setImage(null, null, avatarDrawable, null, null, 0);
}
} else {
currentPhoto = null;
}
measureTime(messageObject);
namesOffset = 0;
String viaUsername = null;
CharSequence viaString = null;
if (messageObject.messageOwner.via_bot_id != 0) {
TLRPC.User botUser = MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.via_bot_id);
if (botUser != null && !TextUtils.isEmpty(botUser.username)) {
viaUsername = "@" + botUser.username;
viaString = AndroidUtilities.replaceTags(String.format(" %s <b>%s</b>", LocaleController.getString("ViaBot", R.string.ViaBot), viaUsername));
viaWidth = (int) Math.ceil(Theme.chat_replyNamePaint.measureText(viaString, 0, viaString.length()));
currentViaBotUser = botUser;
}
} else if (!TextUtils.isEmpty(messageObject.messageOwner.via_bot_name)) {
viaUsername = "@" + messageObject.messageOwner.via_bot_name;
viaString = AndroidUtilities.replaceTags(String.format(" %s <b>%s</b>", LocaleController.getString("ViaBot", R.string.ViaBot), viaUsername));
viaWidth = (int) Math.ceil(Theme.chat_replyNamePaint.measureText(viaString, 0, viaString.length()));
}
boolean needAuthorName = isNeedAuthorName();
boolean viaBot = (messageObject.messageOwner.fwd_from == null || messageObject.type == 14) && viaUsername != null;
if (!hasPsaHint && (needAuthorName || viaBot)) {
drawNameLayout = true;
nameWidth = getMaxNameWidth();
if (nameWidth < 0) {
nameWidth = AndroidUtilities.dp(100);
}
int adminWidth;
String adminString;
String adminLabel;
if (isMegagroup && currentChat != null && messageObject.messageOwner.post_author != null && currentChat.id == -currentMessageObject.getFromChatId()) {
adminString = messageObject.messageOwner.post_author.replace("\n", "");
adminWidth = (int) Math.ceil(Theme.chat_adminPaint.measureText(adminString));
nameWidth -= adminWidth;
} else if (isMegagroup && currentChat != null && currentMessageObject.isForwardedChannelPost()) {
adminString = LocaleController.getString("DiscussChannel", R.string.DiscussChannel);
adminWidth = (int) Math.ceil(Theme.chat_adminPaint.measureText(adminString));
// TODO
nameWidth -= adminWidth;
} else if (currentUser != null && !currentMessageObject.isOutOwner() && !currentMessageObject.isAnyKindOfSticker() && currentMessageObject.type != 5 && delegate != null && (adminLabel = delegate.getAdminRank(currentUser.id)) != null) {
if (adminLabel.length() == 0) {
adminLabel = LocaleController.getString("ChatAdmin", R.string.ChatAdmin);
}
adminString = adminLabel;
adminWidth = (int) Math.ceil(Theme.chat_adminPaint.measureText(adminString));
nameWidth -= adminWidth;
} else {
adminString = null;
adminWidth = 0;
}
if (messageObject.customName != null) {
currentNameString = messageObject.customName;
} else if (needAuthorName) {
currentNameString = getAuthorName();
} else {
currentNameString = "";
}
CharSequence nameStringFinal = TextUtils.ellipsize(currentNameString.replace('\n', ' ').replace('\u200F', ' '), Theme.chat_namePaint, nameWidth - (viaBot ? viaWidth : 0), TextUtils.TruncateAt.END);
if (viaBot) {
viaNameWidth = (int) Math.ceil(Theme.chat_namePaint.measureText(nameStringFinal, 0, nameStringFinal.length()));
if (viaNameWidth != 0) {
viaNameWidth += AndroidUtilities.dp(4);
}
int color;
if (currentMessageObject.shouldDrawWithoutBackground()) {
color = getThemedColor(Theme.key_chat_stickerViaBotNameText);
} else {
color = getThemedColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outViaBotNameText : Theme.key_chat_inViaBotNameText);
}
String viaBotString = LocaleController.getString("ViaBot", R.string.ViaBot);
if (currentNameString.length() > 0) {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(String.format("%s %s %s", nameStringFinal, viaBotString, viaUsername));
stringBuilder.setSpan(viaSpan1 = new TypefaceSpan(Typeface.DEFAULT, 0, color), nameStringFinal.length() + 1, nameStringFinal.length() + 1 + viaBotString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(viaSpan2 = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"), 0, color), nameStringFinal.length() + 2 + viaBotString.length(), stringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
nameStringFinal = stringBuilder;
} else {
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(String.format("%s %s", viaBotString, viaUsername));
stringBuilder.setSpan(viaSpan1 = new TypefaceSpan(Typeface.DEFAULT, 0, color), 0, viaBotString.length() + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
stringBuilder.setSpan(viaSpan2 = new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf"), 0, color), 1 + viaBotString.length(), stringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
nameStringFinal = stringBuilder;
}
nameStringFinal = TextUtils.ellipsize(nameStringFinal, Theme.chat_namePaint, nameWidth, TextUtils.TruncateAt.END);
}
try {
nameLayout = new StaticLayout(nameStringFinal, Theme.chat_namePaint, nameWidth + AndroidUtilities.dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (nameLayout.getLineCount() > 0) {
nameWidth = (int) Math.ceil(nameLayout.getLineWidth(0));
if (!messageObject.isAnyKindOfSticker()) {
namesOffset += AndroidUtilities.dp(19);
}
nameOffsetX = nameLayout.getLineLeft(0);
} else {
nameWidth = 0;
}
if (adminString != null) {
adminLayout = new StaticLayout(adminString, Theme.chat_adminPaint, adminWidth + AndroidUtilities.dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
nameWidth += adminLayout.getLineWidth(0) + AndroidUtilities.dp(8);
} else {
adminLayout = null;
}
} catch (Exception e) {
FileLog.e(e);
}
if (currentNameString.length() == 0) {
currentNameString = null;
}
} else {
currentNameString = null;
nameLayout = null;
nameWidth = 0;
}
currentForwardUser = null;
currentForwardNameString = null;
currentForwardChannel = null;
currentForwardName = null;
forwardedNameLayout[0] = null;
forwardedNameLayout[1] = null;
replyPanelIsForward = false;
forwardedNameWidth = 0;
if (messageObject.isForwarded()) {
if (messageObject.messageOwner.fwd_from.from_id instanceof TLRPC.TL_peerChannel) {
currentForwardChannel = MessagesController.getInstance(currentAccount).getChat(messageObject.messageOwner.fwd_from.from_id.channel_id);
} else if (messageObject.messageOwner.fwd_from.from_id instanceof TLRPC.TL_peerChat) {
currentForwardChannel = MessagesController.getInstance(currentAccount).getChat(messageObject.messageOwner.fwd_from.from_id.chat_id);
} else if (messageObject.messageOwner.fwd_from.from_id instanceof TLRPC.TL_peerUser) {
currentForwardUser = MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.fwd_from.from_id.user_id);
}
}
if (drawForwardedName && messageObject.needDrawForwarded() && (currentPosition == null || currentPosition.minY == 0)) {
if (messageObject.messageOwner.fwd_from.from_name != null) {
currentForwardName = messageObject.messageOwner.fwd_from.from_name;
}
if (currentForwardUser != null || currentForwardChannel != null || currentForwardName != null) {
if (currentForwardChannel != null) {
if (currentForwardUser != null) {
currentForwardNameString = String.format("%s (%s)", currentForwardChannel.title, UserObject.getUserName(currentForwardUser));
} else if (!TextUtils.isEmpty(messageObject.messageOwner.fwd_from.post_author)) {
currentForwardNameString = String.format("%s (%s)", currentForwardChannel.title, messageObject.messageOwner.fwd_from.post_author);
} else {
currentForwardNameString = currentForwardChannel.title;
}
} else if (currentForwardUser != null) {
currentForwardNameString = UserObject.getUserName(currentForwardUser);
} else {
currentForwardNameString = currentForwardName;
}
forwardedNameWidth = getMaxNameWidth();
String forwardedString = getForwardedMessageText(messageObject);
if (hasPsaHint) {
forwardedNameWidth -= AndroidUtilities.dp(36);
}
String from = LocaleController.getString("From", R.string.From);
String fromFormattedString = LocaleController.getString("FromFormatted", R.string.FromFormatted);
int idx = fromFormattedString.indexOf("%1$s");
int fromWidth = (int) Math.ceil(Theme.chat_forwardNamePaint.measureText(from + " "));
CharSequence name = TextUtils.ellipsize(currentForwardNameString.replace('\n', ' '), Theme.chat_replyNamePaint, forwardedNameWidth - fromWidth - viaWidth, TextUtils.TruncateAt.END);
String fromString;
try {
fromString = String.format(fromFormattedString, name);
} catch (Exception e) {
fromString = name.toString();
}
CharSequence lastLine;
SpannableStringBuilder stringBuilder;
if (viaString != null) {
stringBuilder = new SpannableStringBuilder(String.format("%s %s %s", fromString, LocaleController.getString("ViaBot", R.string.ViaBot), viaUsername));
viaNameWidth = (int) Math.ceil(Theme.chat_forwardNamePaint.measureText(fromString));
stringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), stringBuilder.length() - viaUsername.length() - 1, stringBuilder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
stringBuilder = new SpannableStringBuilder(String.format(fromFormattedString, name));
}
forwardNameCenterX = fromWidth + (int) Math.ceil(Theme.chat_forwardNamePaint.measureText(name, 0, name.length())) / 2;
if (idx >= 0 && (currentForwardName == null || messageObject.messageOwner.fwd_from.from_id != null)) {
stringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), idx, idx + name.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
lastLine = stringBuilder;
lastLine = TextUtils.ellipsize(lastLine, Theme.chat_forwardNamePaint, forwardedNameWidth, TextUtils.TruncateAt.END);
try {
forwardedNameLayout[1] = new StaticLayout(lastLine, Theme.chat_forwardNamePaint, forwardedNameWidth + AndroidUtilities.dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
lastLine = TextUtils.ellipsize(AndroidUtilities.replaceTags(forwardedString), Theme.chat_forwardNamePaint, forwardedNameWidth, TextUtils.TruncateAt.END);
forwardedNameLayout[0] = new StaticLayout(lastLine, Theme.chat_forwardNamePaint, forwardedNameWidth + AndroidUtilities.dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
forwardedNameWidth = Math.max((int) Math.ceil(forwardedNameLayout[0].getLineWidth(0)), (int) Math.ceil(forwardedNameLayout[1].getLineWidth(0)));
if (hasPsaHint) {
forwardedNameWidth += AndroidUtilities.dp(36);
}
forwardNameOffsetX[0] = forwardedNameLayout[0].getLineLeft(0);
forwardNameOffsetX[1] = forwardedNameLayout[1].getLineLeft(0);
if (messageObject.type != 5 && !messageObject.isAnyKindOfSticker()) {
namesOffset += AndroidUtilities.dp(36);
}
} catch (Exception e) {
FileLog.e(e);
}
}
}
if ((!isThreadChat || messageObject.getReplyTopMsgId() != 0) && messageObject.hasValidReplyMessageObject() || messageObject.messageOwner.fwd_from != null && messageObject.isDice()) {
if (currentPosition == null || currentPosition.minY == 0) {
if (!messageObject.isAnyKindOfSticker() && messageObject.type != 5) {
namesOffset += AndroidUtilities.dp(42);
if (messageObject.type != 0) {
namesOffset += AndroidUtilities.dp(5);
}
}
int maxWidth = getMaxNameWidth();
if (!messageObject.shouldDrawWithoutBackground()) {
maxWidth -= AndroidUtilities.dp(10);
} else if (messageObject.type == MessageObject.TYPE_ROUND_VIDEO) {
maxWidth += AndroidUtilities.dp(13);
}
CharSequence stringFinalText = null;
String name = null;
if ((!isThreadChat || messageObject.getReplyTopMsgId() != 0) && messageObject.hasValidReplyMessageObject()) {
lastReplyMessage = messageObject.replyMessageObject.messageOwner;
int cacheType = 1;
int size = 0;
TLObject photoObject;
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.replyMessageObject.photoThumbs2, 320);
TLRPC.PhotoSize thumbPhotoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.replyMessageObject.photoThumbs2, 40);
photoObject = messageObject.replyMessageObject.photoThumbsObject2;
if (photoSize == null) {
if (messageObject.replyMessageObject.mediaExists) {
photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.replyMessageObject.photoThumbs, AndroidUtilities.getPhotoSize());
if (photoSize != null) {
size = photoSize.size;
}
cacheType = 0;
} else {
photoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.replyMessageObject.photoThumbs, 320);
}
thumbPhotoSize = FileLoader.getClosestPhotoSizeWithSize(messageObject.replyMessageObject.photoThumbs, 40);
photoObject = messageObject.replyMessageObject.photoThumbsObject;
}
if (thumbPhotoSize == photoSize) {
thumbPhotoSize = null;
}
if (photoSize == null || messageObject.replyMessageObject.isAnyKindOfSticker() || messageObject.isAnyKindOfSticker() && !AndroidUtilities.isTablet() || messageObject.replyMessageObject.isSecretMedia() || messageObject.replyMessageObject.isWebpageDocument()) {
replyImageReceiver.setImageBitmap((Drawable) null);
needReplyImage = false;
} else {
if (messageObject.replyMessageObject.isRoundVideo()) {
replyImageReceiver.setRoundRadius(AndroidUtilities.dp(22));
} else {
replyImageReceiver.setRoundRadius(AndroidUtilities.dp(2));
}
currentReplyPhoto = photoSize;
replyImageReceiver.setImage(ImageLocation.getForObject(photoSize, photoObject), "50_50", ImageLocation.getForObject(thumbPhotoSize, photoObject), "50_50_b", size, null, messageObject.replyMessageObject, cacheType);
needReplyImage = true;
maxWidth -= AndroidUtilities.dp(44);
}
if (messageObject.customReplyName != null) {
name = messageObject.customReplyName;
} else {
long fromId = messageObject.replyMessageObject.getFromChatId();
if (fromId > 0) {
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(fromId);
if (user != null) {
name = UserObject.getUserName(user);
}
} else if (fromId < 0) {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-fromId);
if (chat != null) {
name = chat.title;
}
} else {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(messageObject.replyMessageObject.messageOwner.peer_id.channel_id);
if (chat != null) {
name = chat.title;
}
}
}
if (name == null) {
name = LocaleController.getString("Loading", R.string.Loading);
}
if (messageObject.replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
stringFinalText = Emoji.replaceEmoji(messageObject.replyMessageObject.messageOwner.media.game.title, Theme.chat_replyTextPaint.getFontMetricsInt(), AndroidUtilities.dp(14), false);
stringFinalText = TextUtils.ellipsize(stringFinalText, Theme.chat_replyTextPaint, maxWidth, TextUtils.TruncateAt.END);
} else if (messageObject.replyMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice) {
stringFinalText = Emoji.replaceEmoji(messageObject.replyMessageObject.messageOwner.media.title, Theme.chat_replyTextPaint.getFontMetricsInt(), AndroidUtilities.dp(14), false);
stringFinalText = TextUtils.ellipsize(stringFinalText, Theme.chat_replyTextPaint, maxWidth, TextUtils.TruncateAt.END);
} else if (!TextUtils.isEmpty(messageObject.replyMessageObject.caption)) {
String mess = messageObject.replyMessageObject.caption.toString();
if (mess.length() > 150) {
mess = mess.substring(0, 150);
}
mess = mess.replace('\n', ' ');
stringFinalText = Emoji.replaceEmoji(mess, Theme.chat_replyTextPaint.getFontMetricsInt(), AndroidUtilities.dp(14), false);
stringFinalText = TextUtils.ellipsize(stringFinalText, Theme.chat_replyTextPaint, maxWidth, TextUtils.TruncateAt.END);
if (stringFinalText instanceof Spannable) {
MediaDataController.addTextStyleRuns(messageObject.replyMessageObject.messageOwner.entities, messageObject.replyMessageObject.caption, (Spannable) stringFinalText);
}
} else if (messageObject.replyMessageObject.messageText != null && messageObject.replyMessageObject.messageText.length() > 0) {
String mess = messageObject.replyMessageObject.messageText.toString();
if (mess.length() > 150) {
mess = mess.substring(0, 150);
}
mess = mess.replace('\n', ' ');
stringFinalText = Emoji.replaceEmoji(mess, Theme.chat_replyTextPaint.getFontMetricsInt(), AndroidUtilities.dp(14), false);
stringFinalText = TextUtils.ellipsize(stringFinalText, Theme.chat_replyTextPaint, maxWidth, TextUtils.TruncateAt.END);
if (stringFinalText instanceof Spannable) {
MediaDataController.addTextStyleRuns(messageObject.replyMessageObject, (Spannable) stringFinalText);
}
}
} else {
replyImageReceiver.setImageBitmap((Drawable) null);
needReplyImage = false;
replyPanelIsForward = true;
if (messageObject.messageOwner.fwd_from.from_id instanceof TLRPC.TL_peerChannel) {
currentForwardChannel = MessagesController.getInstance(currentAccount).getChat(messageObject.messageOwner.fwd_from.from_id.channel_id);
} else if (messageObject.messageOwner.fwd_from.from_id instanceof TLRPC.TL_peerChat) {
currentForwardChannel = MessagesController.getInstance(currentAccount).getChat(messageObject.messageOwner.fwd_from.from_id.chat_id);
} else if (messageObject.messageOwner.fwd_from.from_id instanceof TLRPC.TL_peerUser) {
currentForwardUser = MessagesController.getInstance(currentAccount).getUser(messageObject.messageOwner.fwd_from.from_id.user_id);
}
if (messageObject.messageOwner.fwd_from.from_name != null) {
currentForwardName = messageObject.messageOwner.fwd_from.from_name;
}
if (currentForwardUser != null || currentForwardChannel != null || currentForwardName != null) {
if (currentForwardChannel != null) {
if (currentForwardUser != null) {
currentForwardNameString = String.format("%s (%s)", currentForwardChannel.title, UserObject.getUserName(currentForwardUser));
} else {
currentForwardNameString = currentForwardChannel.title;
}
} else if (currentForwardUser != null) {
currentForwardNameString = UserObject.getUserName(currentForwardUser);
} else {
currentForwardNameString = currentForwardName;
}
name = getForwardedMessageText(messageObject);
String from = LocaleController.getString("From", R.string.From);
String fromFormattedString = LocaleController.getString("FromFormatted", R.string.FromFormatted);
int idx = fromFormattedString.indexOf("%1$s");
int fromWidth = (int) Math.ceil(Theme.chat_replyNamePaint.measureText(from + " "));
CharSequence n = TextUtils.ellipsize(currentForwardNameString == null ? "" : currentForwardNameString.replace('\n', ' '), Theme.chat_replyNamePaint, maxWidth - fromWidth, TextUtils.TruncateAt.END);
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(String.format(fromFormattedString, n));
if (idx >= 0 && (currentForwardName == null || messageObject.messageOwner.fwd_from.from_id != null)) {
stringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), idx, idx + n.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
stringFinalText = TextUtils.ellipsize(stringBuilder, Theme.chat_replyTextPaint, maxWidth, TextUtils.TruncateAt.END);
forwardNameCenterX = fromWidth + (int) Math.ceil(Theme.chat_replyNamePaint.measureText(n, 0, n.length())) / 2;
}
}
CharSequence stringFinalName = name == null ? "" : TextUtils.ellipsize(name.replace('\n', ' '), Theme.chat_replyNamePaint, maxWidth, TextUtils.TruncateAt.END);
try {
replyNameWidth = AndroidUtilities.dp(4 + (needReplyImage ? 44 : 0));
if (stringFinalName != null) {
replyNameLayout = new StaticLayout(stringFinalName, Theme.chat_replyNamePaint, maxWidth + AndroidUtilities.dp(6), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (replyNameLayout.getLineCount() > 0) {
replyNameWidth += (int) Math.ceil(replyNameLayout.getLineWidth(0)) + AndroidUtilities.dp(8);
replyNameOffset = (int) replyNameLayout.getLineLeft(0);
}
}
} catch (Exception e) {
FileLog.e(e);
}
try {
replyTextWidth = AndroidUtilities.dp(4 + (needReplyImage ? 44 : 0));
if (stringFinalText != null) {
SpannableStringBuilder sb = new SpannableStringBuilder(stringFinalText);
for (TextStyleSpan span : sb.getSpans(0, sb.length(), TextStyleSpan.class)) {
if ((span.getTextStyleRun().flags & TextStyleSpan.FLAG_STYLE_MONO) != 0) {
sb.removeSpan(span);
}
}
replyTextLayout = new StaticLayout(sb, Theme.chat_replyTextPaint, maxWidth + AndroidUtilities.dp(10), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (replyTextLayout.getLineCount() > 0) {
replyTextWidth += (int) Math.ceil(replyTextLayout.getLineWidth(0)) + AndroidUtilities.dp(8);
replyTextOffset = (int) replyTextLayout.getLineLeft(0);
}
replySpoilers.clear();
if (getMessageObject().replyMessageObject != null && !getMessageObject().replyMessageObject.isSpoilersRevealed)
SpoilerEffect.addSpoilers(this, replyTextLayout, replySpoilersPool, replySpoilers);
}
} catch (Exception e) {
FileLog.e(e);
}
}
} else if (!isThreadChat && messageObject.getReplyMsgId() != 0) {
if (!(messageObject.replyMessageObject != null && messageObject.replyMessageObject.messageOwner instanceof TLRPC.TL_messageEmpty)) {
if (!messageObject.isAnyKindOfSticker() && messageObject.type != 5) {
namesOffset += AndroidUtilities.dp(42);
if (messageObject.type != 0) {
namesOffset += AndroidUtilities.dp(5);
}
}
needReplyImage = false;
int maxWidth = getMaxNameWidth();
if (!messageObject.shouldDrawWithoutBackground()) {
maxWidth -= AndroidUtilities.dp(10);
} else if (messageObject.type == MessageObject.TYPE_ROUND_VIDEO) {
maxWidth += AndroidUtilities.dp(13);
}
replyNameLayout = new StaticLayout(LocaleController.getString("Loading", R.string.Loading), Theme.chat_replyNamePaint, maxWidth + AndroidUtilities.dp(6), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (replyNameLayout.getLineCount() > 0) {
replyNameWidth += (int) Math.ceil(replyNameLayout.getLineWidth(0)) + AndroidUtilities.dp(8);
replyNameOffset = (int) replyNameLayout.getLineLeft(0);
}
}
}
requestLayout();
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method deleteParticipantFromChat.
public void deleteParticipantFromChat(long chatId, TLRPC.User user, TLRPC.Chat chat, TLRPC.ChatFull info, boolean forceDelete, boolean revoke) {
if (user == null && chat == null) {
return;
}
TLRPC.InputPeer inputPeer;
if (user != null) {
inputPeer = getInputPeer(user);
} else {
inputPeer = getInputPeer(chat);
}
TLObject request;
TLRPC.Chat ownerChat = getChat(chatId);
boolean isChannel = ChatObject.isChannel(ownerChat);
if (isChannel) {
if (UserObject.isUserSelf(user)) {
if (ownerChat.creator && forceDelete) {
TLRPC.TL_channels_deleteChannel req = new TLRPC.TL_channels_deleteChannel();
req.channel = getInputChannel(ownerChat);
request = req;
} else {
TLRPC.TL_channels_leaveChannel req = new TLRPC.TL_channels_leaveChannel();
req.channel = getInputChannel(ownerChat);
request = req;
}
} else {
TLRPC.TL_channels_editBanned req = new TLRPC.TL_channels_editBanned();
req.channel = getInputChannel(ownerChat);
req.participant = inputPeer;
req.banned_rights = new TLRPC.TL_chatBannedRights();
req.banned_rights.view_messages = true;
req.banned_rights.send_media = true;
req.banned_rights.send_messages = true;
req.banned_rights.send_stickers = true;
req.banned_rights.send_gifs = true;
req.banned_rights.send_games = true;
req.banned_rights.send_inline = true;
req.banned_rights.embed_links = true;
req.banned_rights.pin_messages = true;
req.banned_rights.send_polls = true;
req.banned_rights.invite_users = true;
req.banned_rights.change_info = true;
request = req;
}
} else {
if (forceDelete) {
TLRPC.TL_messages_deleteChat req = new TLRPC.TL_messages_deleteChat();
req.chat_id = chatId;
getConnectionsManager().sendRequest(req, (response, error) -> {
});
return;
}
TLRPC.TL_messages_deleteChatUser req = new TLRPC.TL_messages_deleteChatUser();
req.chat_id = chatId;
req.user_id = getInputUser(user);
req.revoke_history = true;
request = req;
}
if (UserObject.isUserSelf(user)) {
deleteDialog(-chatId, 0, revoke);
}
getConnectionsManager().sendRequest(request, (response, error) -> {
if (error != null) {
return;
}
TLRPC.Updates updates = (TLRPC.Updates) response;
processUpdates(updates, false);
if (isChannel && !UserObject.isUserSelf(user)) {
AndroidUtilities.runOnUIThread(() -> loadFullChat(chatId, 0, true), 1000);
}
}, ConnectionsManager.RequestFlagInvokeAfter);
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method changeChatAvatar.
public void changeChatAvatar(long chatId, TLRPC.TL_inputChatPhoto oldPhoto, TLRPC.InputFile inputPhoto, TLRPC.InputFile inputVideo, double videoStartTimestamp, String videoPath, TLRPC.FileLocation smallSize, TLRPC.FileLocation bigSize, Runnable callback) {
TLObject request;
TLRPC.InputChatPhoto inputChatPhoto;
if (oldPhoto != null) {
inputChatPhoto = oldPhoto;
} else if (inputPhoto != null || inputVideo != null) {
TLRPC.TL_inputChatUploadedPhoto uploadedPhoto = new TLRPC.TL_inputChatUploadedPhoto();
if (inputPhoto != null) {
uploadedPhoto.file = inputPhoto;
uploadedPhoto.flags |= 1;
}
if (inputVideo != null) {
uploadedPhoto.video = inputVideo;
uploadedPhoto.flags |= 2;
uploadedPhoto.video_start_ts = videoStartTimestamp;
uploadedPhoto.flags |= 4;
}
inputChatPhoto = uploadedPhoto;
} else {
inputChatPhoto = new TLRPC.TL_inputChatPhotoEmpty();
}
if (ChatObject.isChannel(chatId, currentAccount)) {
TLRPC.TL_channels_editPhoto req = new TLRPC.TL_channels_editPhoto();
req.channel = getInputChannel(chatId);
req.photo = inputChatPhoto;
request = req;
} else {
TLRPC.TL_messages_editChatPhoto req = new TLRPC.TL_messages_editChatPhoto();
req.chat_id = chatId;
req.photo = inputChatPhoto;
request = req;
}
getConnectionsManager().sendRequest(request, (response, error) -> {
if (error != null) {
return;
}
TLRPC.Updates updates = (TLRPC.Updates) response;
if (oldPhoto == null) {
TLRPC.Photo photo = null;
for (int a = 0, N = updates.updates.size(); a < N; a++) {
TLRPC.Update update = updates.updates.get(a);
if (update instanceof TLRPC.TL_updateNewChannelMessage) {
TLRPC.Message message = ((TLRPC.TL_updateNewChannelMessage) update).message;
if (message.action instanceof TLRPC.TL_messageActionChatEditPhoto && message.action.photo instanceof TLRPC.TL_photo) {
photo = message.action.photo;
break;
}
} else if (update instanceof TLRPC.TL_updateNewMessage) {
TLRPC.Message message = ((TLRPC.TL_updateNewMessage) update).message;
if (message.action instanceof TLRPC.TL_messageActionChatEditPhoto && message.action.photo instanceof TLRPC.TL_photo) {
photo = message.action.photo;
break;
}
}
}
if (photo != null) {
TLRPC.PhotoSize small = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 150);
TLRPC.VideoSize videoSize = photo.video_sizes.isEmpty() ? null : photo.video_sizes.get(0);
if (small != null && smallSize != null) {
File destFile = FileLoader.getPathToAttach(small, true);
File src = FileLoader.getPathToAttach(smallSize, true);
src.renameTo(destFile);
String oldKey = smallSize.volume_id + "_" + smallSize.local_id + "@50_50";
String newKey = small.location.volume_id + "_" + small.location.local_id + "@50_50";
ImageLoader.getInstance().replaceImageInCache(oldKey, newKey, ImageLocation.getForPhoto(small, photo), true);
}
TLRPC.PhotoSize big = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 800);
if (big != null && bigSize != null) {
File destFile = FileLoader.getPathToAttach(big, true);
File src = FileLoader.getPathToAttach(bigSize, true);
src.renameTo(destFile);
}
if (videoSize != null && videoPath != null) {
File destFile = FileLoader.getPathToAttach(videoSize, "mp4", true);
File src = new File(videoPath);
src.renameTo(destFile);
}
}
}
processUpdates(updates, false);
AndroidUtilities.runOnUIThread(() -> {
if (callback != null) {
callback.run();
}
getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_AVATAR);
});
}, ConnectionsManager.RequestFlagInvokeAfter);
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method loadFullChat.
public void loadFullChat(long chatId, int classGuid, boolean force) {
boolean loaded = loadedFullChats.contains(chatId);
if (loadingFullChats.contains(chatId) || !force && loaded) {
return;
}
loadingFullChats.add(chatId);
TLObject request;
long dialogId = -chatId;
TLRPC.Chat chat = getChat(chatId);
if (ChatObject.isChannel(chat)) {
TLRPC.TL_channels_getFullChannel req = new TLRPC.TL_channels_getFullChannel();
req.channel = getInputChannel(chat);
request = req;
loadChannelAdmins(chatId, !loaded);
} else {
TLRPC.TL_messages_getFullChat req = new TLRPC.TL_messages_getFullChat();
req.chat_id = chatId;
request = req;
if (dialogs_read_inbox_max.get(dialogId) == null || dialogs_read_outbox_max.get(dialogId) == null) {
reloadDialogsReadValue(null, dialogId);
}
}
int reqId = getConnectionsManager().sendRequest(request, (response, error) -> {
if (error == null) {
TLRPC.TL_messages_chatFull res = (TLRPC.TL_messages_chatFull) response;
getMessagesStorage().putUsersAndChats(res.users, res.chats, true, true);
getMessagesStorage().updateChatInfo(res.full_chat, false);
if (ChatObject.isChannel(chat)) {
Integer value = dialogs_read_inbox_max.get(dialogId);
if (value == null) {
value = getMessagesStorage().getDialogReadMax(false, dialogId);
}
dialogs_read_inbox_max.put(dialogId, Math.max(res.full_chat.read_inbox_max_id, value));
if (res.full_chat.read_inbox_max_id > value) {
ArrayList<TLRPC.Update> arrayList = new ArrayList<>();
TLRPC.TL_updateReadChannelInbox update = new TLRPC.TL_updateReadChannelInbox();
update.channel_id = chatId;
update.max_id = res.full_chat.read_inbox_max_id;
arrayList.add(update);
processUpdateArray(arrayList, null, null, false, 0);
}
value = dialogs_read_outbox_max.get(dialogId);
if (value == null) {
value = getMessagesStorage().getDialogReadMax(true, dialogId);
}
dialogs_read_outbox_max.put(dialogId, Math.max(res.full_chat.read_outbox_max_id, value));
if (res.full_chat.read_outbox_max_id > value) {
ArrayList<TLRPC.Update> arrayList = new ArrayList<>();
TLRPC.TL_updateReadChannelOutbox update = new TLRPC.TL_updateReadChannelOutbox();
update.channel_id = chatId;
update.max_id = res.full_chat.read_outbox_max_id;
arrayList.add(update);
processUpdateArray(arrayList, null, null, false, 0);
}
}
AndroidUtilities.runOnUIThread(() -> {
TLRPC.ChatFull old = fullChats.get(chatId);
if (old != null) {
res.full_chat.inviterId = old.inviterId;
}
fullChats.put(chatId, res.full_chat);
applyDialogNotificationsSettings(-chatId, res.full_chat.notify_settings);
for (int a = 0; a < res.full_chat.bot_info.size(); a++) {
TLRPC.BotInfo botInfo = res.full_chat.bot_info.get(a);
getMediaDataController().putBotInfo(-chatId, botInfo);
}
int index = blockePeers.indexOfKey(-chatId);
if (res.full_chat.blocked) {
if (index < 0) {
blockePeers.put(-chatId, 1);
getNotificationCenter().postNotificationName(NotificationCenter.blockedUsersDidLoad);
}
} else {
if (index >= 0) {
blockePeers.removeAt(index);
getNotificationCenter().postNotificationName(NotificationCenter.blockedUsersDidLoad);
}
}
exportedChats.put(chatId, res.full_chat.exported_invite);
loadingFullChats.remove(chatId);
loadedFullChats.add(chatId);
putUsers(res.users, false);
putChats(res.chats, false);
if (res.full_chat.stickerset != null) {
getMediaDataController().getGroupStickerSetById(res.full_chat.stickerset);
}
getNotificationCenter().postNotificationName(NotificationCenter.chatInfoDidLoad, res.full_chat, classGuid, false, true);
if ((res.full_chat.flags & 2048) != 0) {
TLRPC.Dialog dialog = dialogs_dict.get(-chatId);
if (dialog != null && dialog.folder_id != res.full_chat.folder_id) {
dialog.folder_id = res.full_chat.folder_id;
sortDialogs(null);
getNotificationCenter().postNotificationName(NotificationCenter.dialogsNeedReload);
}
}
});
} else {
AndroidUtilities.runOnUIThread(() -> {
checkChannelError(error.text, chatId);
loadingFullChats.remove(chatId);
});
}
});
if (classGuid != 0) {
getConnectionsManager().bindRequestToGuid(reqId, classGuid);
}
}
use of org.telegram.tgnet.TLObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class MessagesController method saveWallpaperToServer.
public void saveWallpaperToServer(File path, Theme.OverrideWallpaperInfo info, boolean install, long taskId) {
if (uploadingWallpaper != null) {
File finalPath = new File(ApplicationLoader.getFilesDirFixed(), info.originalFileName);
if (path != null && (path.getAbsolutePath().equals(uploadingWallpaper) || path.equals(finalPath))) {
uploadingWallpaperInfo = info;
return;
}
getFileLoader().cancelFileUpload(uploadingWallpaper, false);
uploadingWallpaper = null;
uploadingWallpaperInfo = null;
}
if (path != null) {
uploadingWallpaper = path.getAbsolutePath();
uploadingWallpaperInfo = info;
getFileLoader().uploadFile(uploadingWallpaper, false, true, ConnectionsManager.FileTypePhoto);
} else if (!info.isDefault() && !info.isColor() && info.wallpaperId > 0 && !info.isTheme()) {
TLRPC.InputWallPaper inputWallPaper;
if (info.wallpaperId > 0) {
TLRPC.TL_inputWallPaper inputWallPaperId = new TLRPC.TL_inputWallPaper();
inputWallPaperId.id = info.wallpaperId;
inputWallPaperId.access_hash = info.accessHash;
inputWallPaper = inputWallPaperId;
} else {
TLRPC.TL_inputWallPaperSlug inputWallPaperSlug = new TLRPC.TL_inputWallPaperSlug();
inputWallPaperSlug.slug = info.slug;
inputWallPaper = inputWallPaperSlug;
}
TLRPC.TL_wallPaperSettings settings = new TLRPC.TL_wallPaperSettings();
settings.blur = info.isBlurred;
settings.motion = info.isMotion;
if (info.color != 0) {
settings.background_color = info.color & 0x00ffffff;
settings.flags |= 1;
settings.intensity = (int) (info.intensity * 100);
settings.flags |= 8;
}
if (info.gradientColor1 != 0) {
settings.second_background_color = info.gradientColor1 & 0x00ffffff;
settings.rotation = AndroidUtilities.getWallpaperRotation(info.rotation, true);
settings.flags |= 16;
}
if (info.gradientColor2 != 0) {
settings.third_background_color = info.gradientColor2 & 0x00ffffff;
settings.flags |= 32;
}
if (info.gradientColor3 != 0) {
settings.fourth_background_color = info.gradientColor3 & 0x00ffffff;
settings.flags |= 64;
}
TLObject req;
if (install) {
TLRPC.TL_account_installWallPaper request = new TLRPC.TL_account_installWallPaper();
request.wallpaper = inputWallPaper;
request.settings = settings;
req = request;
} else {
TLRPC.TL_account_saveWallPaper request = new TLRPC.TL_account_saveWallPaper();
request.wallpaper = inputWallPaper;
request.settings = settings;
req = request;
}
long newTaskId;
if (taskId != 0) {
newTaskId = taskId;
} else {
NativeByteBuffer data = null;
try {
data = new NativeByteBuffer(1024);
data.writeInt32(21);
data.writeBool(info.isBlurred);
data.writeBool(info.isMotion);
data.writeInt32(info.color);
data.writeInt32(info.gradientColor1);
data.writeInt32(info.rotation);
data.writeDouble(info.intensity);
data.writeBool(install);
data.writeString(info.slug);
data.writeString(info.originalFileName);
data.limit(data.position());
} catch (Exception e) {
FileLog.e(e);
}
newTaskId = getMessagesStorage().createPendingTask(data);
}
getConnectionsManager().sendRequest(req, (response, error) -> getMessagesStorage().removePendingTask(newTaskId));
}
if ((info.isColor() || info.gradientColor2 != 0) && info.wallpaperId <= 0) {
TLRPC.WallPaper wallPaper;
if (info.isColor()) {
wallPaper = new TLRPC.TL_wallPaperNoFile();
} else {
wallPaper = new TLRPC.TL_wallPaper();
wallPaper.slug = info.slug;
wallPaper.document = new TLRPC.TL_documentEmpty();
}
if (info.wallpaperId == 0) {
wallPaper.id = Utilities.random.nextLong();
if (wallPaper.id > 0) {
wallPaper.id = -wallPaper.id;
}
} else {
wallPaper.id = info.wallpaperId;
}
wallPaper.dark = MotionBackgroundDrawable.isDark(info.color, info.gradientColor1, info.gradientColor2, info.gradientColor3);
wallPaper.flags |= 4;
wallPaper.settings = new TLRPC.TL_wallPaperSettings();
wallPaper.settings.blur = info.isBlurred;
wallPaper.settings.motion = info.isMotion;
if (info.color != 0) {
wallPaper.settings.background_color = info.color;
wallPaper.settings.flags |= 1;
wallPaper.settings.intensity = (int) (info.intensity * 100);
wallPaper.settings.flags |= 8;
}
if (info.gradientColor1 != 0) {
wallPaper.settings.second_background_color = info.gradientColor1;
wallPaper.settings.rotation = AndroidUtilities.getWallpaperRotation(info.rotation, true);
wallPaper.settings.flags |= 16;
}
if (info.gradientColor2 != 0) {
wallPaper.settings.third_background_color = info.gradientColor2;
wallPaper.settings.flags |= 32;
}
if (info.gradientColor3 != 0) {
wallPaper.settings.fourth_background_color = info.gradientColor3;
wallPaper.settings.flags |= 64;
}
ArrayList<TLRPC.WallPaper> arrayList = new ArrayList<>();
arrayList.add(wallPaper);
getMessagesStorage().putWallpapers(arrayList, -3);
getMessagesStorage().getWallpapers();
}
}
Aggregations