From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: alina sireneva <alina@tei.su>
Date: Mon, 18 May 2026 21:24:46 +0400
Subject: strip tracking parameters from urls

---
 .../telegram/messenger/browser/Browser.java   |  1 +
 .../ui/Components/EditTextCaption.java        | 24 ++++++++++++++++---
 .../java/org/telegram/ui/LaunchActivity.java  |  2 +-
 3 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java b/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java
index 0000000..0000000 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/browser/Browser.java
@@ -292,6 +292,7 @@ public class Browser {
         if (context == null || uri == null) {
             return;
         }
+        uri = desu.inugram.helpers.UrlCleanerHelper.clean(uri);
         final int currentAccount = UserConfig.selectedAccount;
         boolean[] forceBrowser = new boolean[]{false};
         boolean internalUri = isInternalUri(uri, forceBrowser);
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextCaption.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextCaption.java
index 0000000..0000000 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextCaption.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/EditTextCaption.java
@@ -329,6 +329,17 @@ public class EditTextCaption extends EditTextBoldCursor implements FloatingToolb
             protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                 super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64), MeasureSpec.EXACTLY));
             }
+
+            @Override
+            public boolean onTextContextMenuItem(int id) {
+                if (id == android.R.id.paste && desu.inugram.helpers.UrlCleanerHelper.handleContextMenuPaste(this)) return true;
+                return super.onTextContextMenuItem(id);
+            }
+
+            @Override
+            public android.view.inputmethod.InputConnection onCreateInputConnection(android.view.inputmethod.EditorInfo outAttrs) {
+                return desu.inugram.helpers.UrlCleanerHelper.wrapInputConnection(super.onCreateInputConnection(outAttrs));
+            }
         };
         final String def = "http://";
         editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
@@ -380,7 +391,7 @@ public class EditTextCaption extends EditTextBoldCursor implements FloatingToolb
                 FileLog.e(e);
             }
             if (text != null) {
-                editText.setText(text);
+                editText.setText(desu.inugram.helpers.UrlCleanerHelper.cleanUrlString(text));
                 editText.setSelection(0, editText.getText().length());
             }
             checkPaste.run();
@@ -405,7 +416,7 @@ public class EditTextCaption extends EditTextBoldCursor implements FloatingToolb
                 FileLog.e(e);
             }
             if (text != null) {
-                editText.setText(text);
+                editText.setText(desu.inugram.helpers.UrlCleanerHelper.cleanUrlString(text));
                 editText.setSelection(0, editText.getText().length());
             }
         }
@@ -445,7 +456,7 @@ public class EditTextCaption extends EditTextBoldCursor implements FloatingToolb
                 }
             }
             try {
-                final String url = editText.getText().toString().trim();
+                final String url = desu.inugram.helpers.UrlCleanerHelper.cleanUrlString(editText.getText().toString().trim()).toString();
                 editable.setSpan(new URLSpanReplacement(url), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
             } catch (Exception ignore) {}
             if (delegate != null) {
@@ -1000,6 +1011,7 @@ public class EditTextCaption extends EditTextBoldCursor implements FloatingToolb
                     String html = clipData.getItemAt(0).getHtmlText();
                     SpannableStringBuilder pasted = new SpannableStringBuilder(CopyUtilities.fromHTML(html));
                     Emoji.replaceEmoji(pasted, getPaint().getFontMetricsInt(), false, null);
+                    desu.inugram.helpers.UrlCleanerHelper.cleanSpannedUrls(pasted);
                     AnimatedEmojiSpan[] spans = pasted.getSpans(0, pasted.length(), AnimatedEmojiSpan.class);
                     if (spans != null) {
                         for (int k = 0; k < spans.length; ++k) {
@@ -1025,6 +1037,7 @@ public class EditTextCaption extends EditTextBoldCursor implements FloatingToolb
                     FileLog.e(e);
                 }
             }
+            if (desu.inugram.helpers.UrlCleanerHelper.handleContextMenuPaste(this)) return true;
         } else if (id == android.R.id.copy) {
             int start = Math.max(0, getSelectionStart());
             int end = Math.min(getText().length(), getSelectionEnd());
@@ -1057,4 +1070,9 @@ public class EditTextCaption extends EditTextBoldCursor implements FloatingToolb
         }
         return super.onTextContextMenuItem(id);
     }
+
+    @Override
+    public android.view.inputmethod.InputConnection onCreateInputConnection(android.view.inputmethod.EditorInfo outAttrs) {
+        return desu.inugram.helpers.UrlCleanerHelper.wrapInputConnection(super.onCreateInputConnection(outAttrs));
+    }
 }
diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java
index 0000000..0000000 100644
--- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java
+++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java
@@ -1697,7 +1697,7 @@ public class LaunchActivity extends BasePermissionsActivity implements INavigati
                             if ((text.startsWith("http://") || text.startsWith("https://")) && !TextUtils.isEmpty(subject)) {
                                 text = subject + "\n" + text;
                             }
-                            sendingText = text;
+                            sendingText = desu.inugram.helpers.UrlCleanerHelper.cleanText(text);
                         } else if (!TextUtils.isEmpty(subject)) {
                             sendingText = subject;
                         }
