From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: alina sireneva <alina@tei.su>
Date: Fri, 10 Apr 2026 05:17:27 +0300
Subject: remember all clicked replies when jumping back via the down button in chat

---
 .../java/org/telegram/ui/ChatActivity.java     | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

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
@@ -333,6 +333,7 @@ import java.io.FileWriter;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URLDecoder;
+import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -946,6 +947,7 @@ public class ChatActivity extends BaseFragment implements
     private boolean needSelectFromMessageId;
     private int returnToMessageId;
     private int returnToLoadIndex;
+    private final ArrayDeque<int[]> inu_replyStack = new ArrayDeque<>();
     private int createUnreadMessageAfterId;
     private boolean createUnreadMessageAfterIdLoading;
     private boolean loadingFromOldPosition;
@@ -10589,6 +10591,11 @@ public class ChatActivity extends BaseFragment implements
         final Runnable inCaseLoading = () -> {
             sideControlsButtonsLayout.setButtonLoading(ChatActivitySideControlsButtonsLayout.BUTTON_PAGE_DOWN, true, true);
         };
+        if (desu.inugram.InuConfig.CHAT_REMEMBER_ALL_REPLIES.getValue() && !inu_replyStack.isEmpty()) {
+            int[] top = inu_replyStack.pop();
+            scrollToMessageId(top[0], 0, true, top[1], true, 0, null, inCaseLoading);
+            return;
+        }
         if (createUnreadMessageAfterId != 0) {
             scrollToMessageId(createUnreadMessageAfterId, 0, false, returnToLoadIndex, true, 0, null, inCaseLoading);
         } else if (returnToMessageId > 0) {
@@ -16979,6 +16986,9 @@ public class ChatActivity extends BaseFragment implements
                 showFloatingTopicView(false);
             }
         }
+        if (desu.inugram.InuConfig.CHAT_REMEMBER_ALL_REPLIES.getValue() && fromMessageId != 0 && (inu_replyStack.isEmpty() || inu_replyStack.peek()[0] != fromMessageId)) {
+            inu_replyStack.push(new int[]{fromMessageId, loadIndex});
+        }
         returnToMessageId = fromMessageId;
         returnToLoadIndex = loadIndex;
         needSelectFromMessageId = select;
@@ -17016,6 +17026,7 @@ public class ChatActivity extends BaseFragment implements
         } else {
             returnToMessageId = 0;
             newUnreadMessageCount = 0;
+            inu_replyStack.clear();
         }
 
         sideControlsButtonsLayout.showButton(ChatActivitySideControlsButtonsLayout.BUTTON_PAGE_DOWN, show, animated);
@@ -46591,6 +46602,7 @@ public class ChatActivity extends BaseFragment implements
     }
 
     private void goToNextOrPrevSearchMessage(boolean searchUp) {
+        inu_replyStack.clear();
         if (chatMode == MODE_SEARCH) {
             HashtagSearchController.getInstance(currentAccount).jumpToMessage(classGuid, hashtagSearchSelectedIndex + (searchUp ? 1 : -1), searchType);
         } else {
@@ -46651,6 +46663,12 @@ public class ChatActivity extends BaseFragment implements
     }
 
     private boolean onSideControlButtonOnLongClick(int buttonId, View view) {
+        if (buttonId == ChatActivitySideControlsButtonsLayout.BUTTON_PAGE_DOWN && desu.inugram.InuConfig.CHAT_REMEMBER_ALL_REPLIES.getValue()) {
+            inu_replyStack.clear();
+            returnToMessageId = 0;
+            scrollToLastMessage(true, true, null);
+            return true;
+        }
         final Runnable onRead;
         final int type;
         if (buttonId == ChatActivitySideControlsButtonsLayout.BUTTON_MENTION) {
