From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: alina sireneva <alina@tei.su>
Date: Thu, 23 Apr 2026 08:35:17 +0300
Subject: media type filter + "show only matches" in chat search

---
 .../messenger/MediaDataController.java        |  8 ++--
 .../java/org/telegram/ui/ChatActivity.java    | 43 +++++++++++++------
 2 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MediaDataController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MediaDataController.java
index 0000000..0000000 100644
--- a/TMessagesProj/src/main/java/org/telegram/messenger/MediaDataController.java
+++ b/TMessagesProj/src/main/java/org/telegram/messenger/MediaDataController.java
@@ -3954,7 +3954,7 @@ public class MediaDataController extends BaseController {
                     req.saved_reaction.add(reaction.toTLReaction());
                     req.flags |= 8;
                 }
-                req.filter = new TLRPC.TL_inputMessagesFilterEmpty();
+                req.filter = desu.inugram.helpers.search.SearchFilterHelper.filterForGuid(guid);
                 mergeReqId = getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                     if (lastMergeDialogId == mergeDialogId) {
                         mergeReqId = 0;
@@ -3989,7 +3989,7 @@ public class MediaDataController extends BaseController {
         lastSearchChat = chat;
         lastReplyMessageId = replyMessageId;
         lastReaction = reaction;
-        req.limit = 21;
+        req.limit = desu.inugram.helpers.search.SearchFilterHelper.isOnlyMatchesForGuid(guid) ? 100 : 21;
         req.q = query != null ? query : "";
         req.offset_id = max_id;
         if (user != null) {
@@ -4039,7 +4039,7 @@ public class MediaDataController extends BaseController {
             req.saved_reaction.add(reaction.toTLReaction());
             req.flags |= 8;
         }
-        req.filter = new TLRPC.TL_inputMessagesFilterEmpty();
+        req.filter = desu.inugram.helpers.search.SearchFilterHelper.filterForGuid(guid);
         lastSearchQuery = query;
         long queryWithDialogFinal = queryWithDialog;
         String finalQuery = query;
@@ -4114,7 +4114,7 @@ public class MediaDataController extends BaseController {
                                 searchMessagesInChat(lastSearchQuery, dialogId, mergeDialogId, guid, 0, replyMessageId, true, user, chat, jumpToMessage, lastReaction);
                             }
                         };
-                        if (isSaved) {
+                        if (isSaved || desu.inugram.helpers.search.SearchFilterHelper.isOnlyMatchesForGuid(guid)) {
                             loadReplyMessagesForMessages(messageObjects, dialogId, 0, lastReplyMessageId, done, guid, null);
                         } else {
                             done.run();
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
@@ -458,7 +458,7 @@ public class ChatActivity extends BaseFragment implements
     private ClippingImageView animatingImageView;
     private ThanosEffect chatListThanosEffect;
     private ChatListViewPaddingsAnimator chatListViewPaddingsAnimator;
-    private ChatListRecyclerView chatListView;
+    public ChatListRecyclerView chatListView;
     private ChatListItemAnimator chatListItemAnimator;
     private GridLayoutManagerFixed chatLayoutManager;
     private ChatActivityAdapter chatAdapter;
@@ -604,6 +604,7 @@ public class ChatActivity extends BaseFragment implements
     private FrameLayout searchContainer;
     private ImageView searchCalendarButton;
     private ImageView searchUserButton;
+    private desu.inugram.helpers.search.SearchFilterHelper inu_searchFilter;
     private AnimatedTextView searchCountText;
     private AnimatedTextView searchExpandList;
     private AnimatedTextView searchOtherButton;
@@ -625,8 +626,8 @@ public class ChatActivity extends BaseFragment implements
     private boolean scrollingChatListView;
     private boolean checkTextureViewPosition;
     private boolean searchingForUser;
-    private TLRPC.User searchingUserMessages;
-    private TLRPC.Chat searchingChatMessages;
+    public TLRPC.User searchingUserMessages;
+    public TLRPC.Chat searchingChatMessages;
     public static boolean scrolling;
     public ReactionsLayoutInBubble.VisibleReaction searchingReaction;
     public ReactionsLayoutInBubble.VisibleReaction getFilterTag() {
@@ -643,7 +644,7 @@ public class ChatActivity extends BaseFragment implements
     }
     private boolean searchingFiltered;
     private boolean searching;
-    private String searchingQuery;
+    public String searchingQuery;
     private String searchingHashtag;
     private int hashtagSearchSelectedIndex;
     private int searchLastCount;
@@ -9156,10 +9157,10 @@ public class ChatActivity extends BaseFragment implements
 
     }
 
-    private void setFilterMessages(boolean filter) {
+    public void setFilterMessages(boolean filter) {
         setFilterMessages(filter, false, true);
     }
-    private void setFilterMessages(boolean filter, boolean ignoreMessageNotFound, boolean animated) {
+    public void setFilterMessages(boolean filter, boolean ignoreMessageNotFound, boolean animated) {
         if (chatAdapter == null || chatAdapter.isFiltered == filter) return;
         chatAdapter.isFiltered = filter;
         createEmptyView(true);
@@ -9366,7 +9367,7 @@ public class ChatActivity extends BaseFragment implements
         hint2MessageObject.contentType = 1;
     }
 
-    private void updateFilteredMessages(boolean notify) {
+    public void updateFilteredMessages(boolean notify) {
         ArrayList<MessageObject> results = new ArrayList<>(MediaDataController.getInstance(currentAccount).getFoundMessageObjects());
         if (filteredMessagesDict == null) {
             filteredMessagesDict = new LongSparseArray<>();
@@ -9411,7 +9412,7 @@ public class ChatActivity extends BaseFragment implements
                 msg.stableId = lastStableId++;
             }
             msg.isOutOwnerCached = null;
-            if (msg.messageOwner != null) {
+            if (msg.messageOwner != null && dialog_id == getUserConfig().getClientUserId()) {
                 msg.messageOwner.out = true;
             }
             msg.isOutOwner();
@@ -10485,6 +10486,9 @@ public class ChatActivity extends BaseFragment implements
                     if (searchUserButton != null && searchUserButton.getVisibility() != GONE) {
                         leftMargin += 48;
                     }
+                    if (inu_searchFilter != null && inu_searchFilter.getButton().getVisibility() != GONE) {
+                        leftMargin += 48;
+                    }
                     ((MarginLayoutParams) child.getLayoutParams()).leftMargin = AndroidUtilities.dp(leftMargin);
                 }
                 super.measureChildWithMargins(child, parentWidthMeasureSpec, widthUsed, parentHeightMeasureSpec, heightUsed);
@@ -10551,6 +10555,7 @@ public class ChatActivity extends BaseFragment implements
                 }
                 searchCalendarButton.setVisibility(View.GONE);
                 searchUserButton.setVisibility(View.GONE);
+                if (inu_searchFilter != null) inu_searchFilter.setCompact(true);
                 searchingForUser = true;
                 searchingUserMessages = null;
                 searchingChatMessages = null;
@@ -10585,6 +10590,8 @@ public class ChatActivity extends BaseFragment implements
             });
             searchCalendarButton.setContentDescription(LocaleController.getString(R.string.JumpToDate));
         }
+
+        inu_searchFilter = new desu.inugram.helpers.search.SearchFilterHelper(this, searchContainer, searchUserButton != null ? 93.34f : 48f);
     }
 
     private void showSearchShowOther(boolean show) {
@@ -17047,7 +17054,7 @@ public class ChatActivity extends BaseFragment implements
         if (sideControlsButtonsLayout == null) {
             return;
         }
-        boolean show = !getMediaDataController().searchResultMessages.isEmpty() && searching && !searchingFiltered || chatMode == MODE_SEARCH && searchType == SEARCH_PUBLIC_POSTS && !messages.isEmpty();
+        boolean show = !getMediaDataController().searchResultMessages.isEmpty() && searching && !searchingFiltered && (inu_searchFilter == null || !inu_searchFilter.getOnlyMatches()) || chatMode == MODE_SEARCH && searchType == SEARCH_PUBLIC_POSTS && !messages.isEmpty();
 
         sideControlsButtonsLayout.showButton(ChatActivitySideControlsButtonsLayout.BUTTON_SEARCH_UP, show, animated);
         sideControlsButtonsLayout.showButton(ChatActivitySideControlsButtonsLayout.BUTTON_SEARCH_DOWN, show, animated);
@@ -23673,7 +23680,7 @@ public class ChatActivity extends BaseFragment implements
                 if (jumpToMessage) {
                     int messageId = (Integer) args[1];
                     long did = (Long) args[3];
-                    if (searchingReaction != null && searchingFiltered) {
+                    if ((searchingReaction != null && searchingFiltered) || (inu_searchFilter != null && inu_searchFilter.getOnlyMatches())) {
                         if (chatAdapter.isFiltered) {
                             updateFilteredMessages(true);
                         } else {
@@ -23692,7 +23699,7 @@ public class ChatActivity extends BaseFragment implements
                         updateVisibleRows();
                     }
                     onSearchLoadingUpdate(false);
-                } else if (searchingReaction != null) {
+                } else if (searchingReaction != null || (inu_searchFilter != null && inu_searchFilter.getOnlyMatches())) {
                     if (chatAdapter.isFiltered) {
                         updateFilteredMessages(true);
                     } else {
@@ -35262,6 +35269,7 @@ public class ChatActivity extends BaseFragment implements
             if (searchUserButton != null) {
                 searchUserButton.setVisibility(View.GONE);
             }
+            if (inu_searchFilter != null) inu_searchFilter.setCompact(true);
         }
         if (searchItem != null) {
             preventReopenSearchWithText = true;
@@ -35321,6 +35329,7 @@ public class ChatActivity extends BaseFragment implements
             if (searchUserButton != null) {
                 searchUserButton.setVisibility(View.GONE);
             }
+            if (inu_searchFilter != null) inu_searchFilter.setCompact(true);
         }
         if (searchItem != null) {
             preventReopenSearchWithText = true;
@@ -38493,6 +38502,11 @@ public class ChatActivity extends BaseFragment implements
             if (searchUserButton != null) {
                 searchUserButton.setVisibility(View.VISIBLE);
             }
+            if (inu_searchFilter != null) {
+                inu_searchFilter.reset();
+                inu_searchFilter.setCompact(false);
+                setFilterMessages(false, true, false);
+            }
             if (searchingForUser) {
                 mentionContainer.getAdapter().searchUsernameOrHashtag(null, 0, null, false, true);
                 searchingForUser = false;
@@ -38778,6 +38792,7 @@ public class ChatActivity extends BaseFragment implements
                 if (searchUserButton != null) {
                     searchUserButton.setVisibility(View.VISIBLE);
                 }
+                if (inu_searchFilter != null) inu_searchFilter.setCompact(false);
                 searchingUserMessages = null;
                 searchingChatMessages = null;
             }
@@ -40911,6 +40926,8 @@ public class ChatActivity extends BaseFragment implements
                 } else if (chatMode == MODE_PINNED || chatMode == MODE_SCHEDULED) {
                     chatActivityDelegate.openReplyMessage(id);
                     finishFragment();
+                } else if (inu_searchFilter != null && inu_searchFilter.getOnlyMatches()) {
+                    ChatHelper.openInNewChat(ChatActivity.this, dialog_id, id);
                 } else {
                     if (option_id != null) {
                         highlightPollOptionId = option_id;
@@ -44186,7 +44203,7 @@ public class ChatActivity extends BaseFragment implements
         int lastBottom;
     }
 
-    private class RecyclerListViewInternal extends RecyclerListView implements StoriesListPlaceProvider.ClippedView {
+    public class RecyclerListViewInternal extends RecyclerListView implements StoriesListPlaceProvider.ClippedView {
         public RecyclerListViewInternal(Context context, ThemeDelegate themeDelegate) {
             super(context, themeDelegate);
         }
@@ -47126,7 +47143,7 @@ public class ChatActivity extends BaseFragment implements
         );
     }
 
-    private abstract class ChatListRecyclerView extends RecyclerListViewInternal {
+    public abstract class ChatListRecyclerView extends RecyclerListViewInternal {
 
         public ChatListRecyclerView(Context context, ThemeDelegate themeDelegate) {
             super(context, themeDelegate);
