Skip to content

Commit c8cf341

Browse files
committed
Added option to delete all user messages in all forum topics at once.
1 parent 98e9748 commit c8cf341

3 files changed

Lines changed: 110 additions & 0 deletions

File tree

TMessagesProj/src/main/java/org/telegram/messenger/forkgram/Dialogs.kt

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,101 @@ public fun CreateDeleteAllUnpinnedMessagesAlert(
231231
}
232232
}
233233

234+
@JvmStatic
235+
public fun CreateDeleteAllYourMessagesInAllTopicsAlert(
236+
currentAccount: Int,
237+
dialogId: Long,
238+
context: Context) {
239+
240+
val create = { text: String, callback: () -> Unit ->
241+
val builder = AlertDialog.Builder(context);
242+
builder.setTitle(LocaleController.getString(
243+
"DeleteAllYourMessages",
244+
R.string.DeleteAllYourMessages));
245+
builder.setMessage(AndroidUtilities.replaceTags(text));
246+
247+
builder.setPositiveButton(
248+
LocaleController.getString("OK", R.string.OK),
249+
{ _: DialogInterface?, _: Int -> callback(); });
250+
builder.setNegativeButton(
251+
LocaleController.getString("Cancel", R.string.Cancel),
252+
null);
253+
val dialog = builder.show();
254+
val button = dialog.getButton(DialogInterface.BUTTON_POSITIVE) as TextView;
255+
button.setTextColor(Theme.getColor(Theme.key_text_RedBold));
256+
};
257+
258+
val messagesController = AccountInstance.getInstance(currentAccount).messagesController;
259+
val topicsController = messagesController.topicsController;
260+
val meId = UserConfig.getInstance(UserConfig.selectedAccount).clientUserId;
261+
val chatId = -dialogId;
262+
263+
val deleteFor = { to: Long, found: ArrayList<TLRPC.Message> ->
264+
val messages: java.util.ArrayList<Int> = ArrayList(found.map { it.id });
265+
AndroidUtilities.runOnUIThread {
266+
messagesController.deleteMessages(
267+
messages,
268+
null,
269+
null,
270+
to,
271+
0,
272+
true,
273+
0);
274+
};
275+
};
276+
277+
create(
278+
LocaleController.getString(
279+
"DeleteAllYourMessagesInfo",
280+
R.string.DeleteAllYourMessagesInfo) + "\n\n" +
281+
"This will delete your messages in ALL topics of this group."
282+
) {
283+
create(LocaleController.getString("ReallySure", R.string.ReallySure)) {
284+
val topics = topicsController.getTopics(chatId);
285+
val mePeer = messagesController.getInputPeer(meId);
286+
val dialogPeer = messagesController.getInputPeer(dialogId);
287+
288+
if (topics != null && topics.isNotEmpty()) {
289+
// Delete messages in each topic
290+
for (topic in topics) {
291+
// Use the main dialog peer but search within specific topic
292+
ForkApi.SearchAllMessages(
293+
currentAccount,
294+
dialogPeer,
295+
mePeer,
296+
{ found: ArrayList<TLRPC.Message> ->
297+
// Filter messages that belong to this topic
298+
val topicMessages = found.filter { message ->
299+
val topicId = if (message.reply_to != null && message.reply_to.reply_to_top_id != 0) {
300+
message.reply_to.reply_to_top_id
301+
} else if (message.reply_to != null && message.reply_to.reply_to_msg_id != 0) {
302+
message.reply_to.reply_to_msg_id
303+
} else {
304+
message.id
305+
}
306+
topicId == topic.id
307+
}
308+
if (topicMessages.isNotEmpty()) {
309+
deleteFor(dialogId, ArrayList(topicMessages))
310+
}
311+
},
312+
{}
313+
);
314+
}
315+
} else {
316+
// Fallback to main dialog if no topics
317+
ForkApi.SearchAllMessages(
318+
currentAccount,
319+
dialogPeer,
320+
mePeer,
321+
{ found: ArrayList<TLRPC.Message> -> deleteFor(dialogId, found); },
322+
{}
323+
);
324+
}
325+
}
326+
}
327+
}
328+
234329
@JvmStatic
235330
public fun CreateFieldAlert(
236331
context: Context,

TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,7 @@ public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolea
17581758
private final static int goToFirstMessage = 35;
17591759
private final static int deleteAllYourMessages = 36;
17601760
private final static int deleteAllUnpinnedMessages = 37;
1761+
private final static int deleteAllYourMessagesInAllTopics = 38;
17611762

17621763
private final static int attach_photo = 0;
17631764
private final static int attach_gallery = 1;
@@ -4190,6 +4191,11 @@ public void run(boolean revoke) {
41904191
currentAccount,
41914192
dialog_id,
41924193
getParentActivity());
4194+
} else if (id == deleteAllYourMessagesInAllTopics) {
4195+
org.telegram.messenger.forkgram.ForkDialogs.CreateDeleteAllYourMessagesInAllTopicsAlert(
4196+
currentAccount,
4197+
dialog_id,
4198+
getParentActivity());
41934199
} else if (id == deleteAllUnpinnedMessages) {
41944200
org.telegram.messenger.forkgram.ForkDialogs.CreateDeleteAllUnpinnedMessagesAlert(
41954201
currentAccount,
@@ -4530,6 +4536,14 @@ public void toggleMute() {
45304536
R.drawable.msg_delete,
45314537
LocaleController.getString("DeleteAllYourMessages", R.string.DeleteAllYourMessages),
45324538
themeDelegate);
4539+
// Add option to delete messages in all topics for forum groups
4540+
if (ChatObject.isForum(currentChat)) {
4541+
headerItem.addSubItem(
4542+
deleteAllYourMessagesInAllTopics,
4543+
R.drawable.msg_delete,
4544+
LocaleController.getString("DeleteAllYourMessagesInAllTopics", R.string.DeleteAllYourMessagesInAllTopics),
4545+
themeDelegate);
4546+
}
45334547
}
45344548
if (MessagesController.getGlobalMainSettings().getBoolean("addItemToDeleteAllUnpinnedMessages", false)
45354549
&& ((currentUser != null && currentEncryptedChat == null) || currentChat != null)) {

TMessagesProj/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9868,6 +9868,7 @@
98689868
<string name="ShowNotificationContentInfo">When app is locked. Can be cause of privacy leaks.</string>
98699869
<string name="DeleteAllYourMessages">Delete all your messages</string>
98709870
<string name="DeleteAllYourMessagesInfo">Are you sure you want **delete all your messages** from this chat?</string>
9871+
<string name="DeleteAllYourMessagesInAllTopics">Delete all your messages in all topics</string>
98719872
<string name="ReallySure">Are you **really sure**?</string>
98729873
<string name="DisableGlobalSearch">Disable Global Search</string>
98739874
<string name="DisableQuickReaction">Disable quick reaction</string>

0 commit comments

Comments
 (0)