From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: alina sireneva <alina@tei.su>
Date: Sun, 12 Apr 2026 21:03:46 +0300
Subject: replacements for web previews + menu option to refetch web preview in message input

---
 .../java/org/telegram/ui/ChatActivity.java    | 41 ++++++++++++++++++-
 .../ui/Components/ChatActivityEnterView.java  | 21 +++++++++-
 2 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
index 0000000..0000000 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java
@@ -14026,7 +14026,11 @@ public class ChatActivity extends BaseFragment implements
     }
 
     public void searchLinks(final CharSequence charSequence, final boolean force) {
-        if (currentEncryptedChat != null && getMessagesController().secretWebpagePreview == 0 || editingMessageObject != null && (!editingMessageObject.isWebpage() || editingMessageObject.messageOwner.media.webpage instanceof TLRPC.TL_webPagePending)) {
+        searchLinks(charSequence, force, false);
+    }
+
+    public void searchLinks(final CharSequence charSequence, final boolean force, final boolean inu_force) {
+        if (currentEncryptedChat != null && getMessagesController().secretWebpagePreview == 0 || !inu_force && editingMessageObject != null && (!editingMessageObject.isWebpage() || editingMessageObject.messageOwner.media.webpage instanceof TLRPC.TL_webPagePending)) {
             return;
         }
         if (currentChat != null && !ChatObject.canSendEmbed(currentChat)) {
@@ -14041,6 +14045,12 @@ public class ChatActivity extends BaseFragment implements
             return;
         }
         checkEditLinkRemoved(charSequence);
+        if (force && foundWebPage != null && !(foundWebPage instanceof TLRPC.TL_webPagePending) && desu.inugram.helpers.chat.WebPreviewHelper.allUrlsPresent(foundUrls, charSequence)) {
+            if (messagePreviewParams != null) {
+                messagePreviewParams.updateLink(currentAccount, foundWebPage, chatActivityEnterView.getFieldText(), replyingMessageObject == threadMessageObject ? null : replyingMessageObject, replyingQuote, editingMessageObject);
+            }
+            return;
+        }
         if (force && foundWebPage != null && !(foundWebPage instanceof TLRPC.TL_webPagePending)) {
             if (foundWebPage.url != null) {
                 int index = TextUtils.indexOf(charSequence, foundWebPage.url);
@@ -14169,6 +14179,7 @@ public class ChatActivity extends BaseFragment implements
             } else {
                 req.message = textToCheck.toString();
             }
+            req.message = desu.inugram.helpers.chat.WebPreviewHelper.applyReplacements(req.message);
             if (foundWebPage != null && req.message.equals(foundWebPage.displayedText)) {
                 return;
             }
@@ -14214,6 +14225,34 @@ public class ChatActivity extends BaseFragment implements
 
     private HashMap<String, TLRPC.WebPage> lastLinkPreviewResults;
 
+    public void inu_refetchWebPreview() {
+        if (chatActivityEnterView == null) return;
+        CharSequence text = chatActivityEnterView.getFieldText();
+        if (TextUtils.isEmpty(text)) return;
+        foundWebPage = null;
+        foundUrls = null;
+        if (lastLinkPreviewResults != null) {
+            lastLinkPreviewResults.clear();
+        }
+        chatActivityEnterView.setWebPage(null, true);
+        if (editingMessageObject != null && editingMessageObject.messageOwner != null && editingMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage) {
+            editingMessageObject.messageOwner.media.manual = false;
+        }
+        String firstUrl = null;
+        try {
+            Matcher m = AndroidUtilities.WEB_URL.matcher(text);
+            if (m.find()) firstUrl = text.subSequence(m.start(), m.end()).toString();
+        } catch (Exception ignore) {}
+        if (firstUrl != null) {
+            TLRPC.TL_webPagePending pending = new TLRPC.TL_webPagePending();
+            pending.url = firstUrl;
+            pending.display_url = firstUrl;
+            pendingLinkSearchString = firstUrl;
+            showFieldPanelForWebPage(true, pending, false);
+        }
+        searchLinks(text, true, true);
+    }
+
     private void requestLinkPreviewCached(TL_account.getWebPagePreview req, Utilities.Callback2<Boolean, TLRPC.WebPage> done) {
         if (lastLinkPreviewResults == null) {
             lastLinkPreviewResults = new HashMap<>();
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java
index 0000000..0000000 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java
@@ -5088,6 +5088,24 @@ public class ChatActivityEnterView extends FrameLayout implements
                 }
             });
         }
+        if (containsSendMessage && parentFragment != null && messageEditText != null) {
+            CharSequence inu_text = messageEditText.getText();
+            boolean inu_hasUrl = false;
+            try {
+                inu_hasUrl = inu_text != null && AndroidUtilities.WEB_URL.matcher(inu_text).find();
+            } catch (Exception ignore) {}
+            if (inu_hasUrl) {
+                options.add(R.drawable.msg_retry, getString(R.string.InuRefetchWebPreview), () -> {
+                    if (messageSendPreview != null) {
+                        messageSendPreview.dismiss(false);
+                        messageSendPreview = null;
+                    }
+                    if (parentFragment != null) {
+                        parentFragment.inu_refetchWebPreview();
+                    }
+                });
+            }
+        }
         options.setupSelectors();
         if (sendWhenOnlineButton != null) {
             TLRPC.User user = parentFragment == null ? null : parentFragment.getCurrentUser();
@@ -9896,6 +9914,7 @@ public class ChatActivityEnterView extends FrameLayout implements
             }
 
             doneButton.setOnLongClickListener(v -> {
+                if (ChatHelper.maybeHandleEditDoneLongTap(parentFragment, v, messageEditText, messageObject, groupedMessages)) return true;
                 if (messageObject.isMediaEmpty()) return false;
                 if (messageEditText == null || TextUtils.isEmpty(messageEditText.getTextToUse())) return false;
                 if (groupedMessages != null && (!groupedMessages.hasCaption || groupedMessages.isDocuments)) return false;
@@ -9989,7 +10008,7 @@ public class ChatActivityEnterView extends FrameLayout implements
                 draftMessage = messageEditText != null && messageEditText.length() > 0 ? messageEditText.getText() : null;
                 draftSearchWebpage = messageWebPageSearch;
             }
-            messageWebPageSearch = !(editingMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && editingMessageObject.messageOwner.media.manual) && (editingMessageObject.type == MessageObject.TYPE_TEXT || editingMessageObject.type == MessageObject.TYPE_EMOJIS);
+            messageWebPageSearch = !(editingMessageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && editingMessageObject.messageOwner.media.manual) && (editingMessageObject.type == MessageObject.TYPE_TEXT || editingMessageObject.type == MessageObject.TYPE_EMOJIS) && editingMessageObject.isWebpage();
             if (!keyboardVisible) {
                 final CharSequence textToSetWithKeyboardFinal = textToSetWithKeyboard;
                 AndroidUtilities.runOnUIThread(setTextFieldRunnable = () -> {
