From 25b4d5f3b4ba76575919c07878fe2cf2dccec32a Mon Sep 17 00:00:00 2001 From: Next Alone <12210746+NextAlone@users.noreply.github.com> Date: Sun, 26 Nov 2023 05:33:55 +0800 Subject: [PATCH] fix: entity lost in merge message Signed-off-by: Next Alone <12210746+NextAlone@users.noreply.github.com> --- .../java/org/telegram/ui/ChatActivity.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 88724e4642..65d14531ec 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -3197,7 +3197,8 @@ public void onItemClick(final int id) { StringBuilder str = new StringBuilder(); ArrayList toDeleteMessagesIds = new ArrayList<>(); MessageObject toEdit = null; - + ArrayList entities; + entities = new ArrayList<>(); for (int a = 1; a >= 0; a--) { ArrayList ids = new ArrayList<>(); for (int b = 0; b < selectedMessagesIds[a].size(); b++) { @@ -3216,7 +3217,21 @@ public void onItemClick(final int id) { continue; } if (str.length() != 0) { - str.append(" "); + str.append(" "); + } + if (messageObject.messageOwner.entities != null && !messageObject.messageOwner.entities.isEmpty()) { + for (TLRPC.MessageEntity entity : messageObject.messageOwner.entities) { + if (entity instanceof TLRPC.TL_messageEntityMentionName) { + TLRPC.TL_inputMessageEntityMentionName mention = new TLRPC.TL_inputMessageEntityMentionName(); + mention.length = entity.length; + mention.offset = str.length() + entity.offset; + mention.user_id = getMessagesController().getInputUser(((TLRPC.TL_messageEntityMentionName) entity).user_id); + entities.add(mention); + } else { + entity.offset += str.length(); + entities.add(entity); + } + } } str.append(messageObject.messageText); if (messageObject.getSenderId() == UserConfig.getInstance(currentAccount).getClientUserId()) { @@ -3231,11 +3246,13 @@ public void onItemClick(final int id) { if (str.length() != 0 && toEdit != null) { if (toEdit.canEditMessage(currentChat)) { toEdit.editingMessage = str; + toEdit.editingMessageEntities = entities; SendMessagesHelper.getInstance(currentAccount).editMessage(toEdit, null, null, null, null, null, false, toEdit.hasMediaSpoilers(), null); } else { MessageObject replyTo = toEdit.replyMessageObject; toDeleteMessagesIds.add(toEdit.getId()); - SendMessagesHelper.getInstance(currentAccount).sendMessage(SendMessagesHelper.SendMessageParams.of(str.toString(), dialog_id, replyTo, getThreadMessage(), null, false, null, null, null, true, 0, null, false)); + SendMessagesHelper.getInstance(currentAccount) + .sendMessage(SendMessagesHelper.SendMessageParams.of(str.toString(), dialog_id, replyTo, getThreadMessage(), null, false, entities, null, null, true, 0, null, false)); } MessagesController.getInstance(currentAccount).deleteMessages(toDeleteMessagesIds, null, null, dialog_id, true, false); }