Skip to content

Commit 0b0db6b

Browse files
committed
Added option to delete all user messages in all forum topics at once.
1 parent 7831949 commit 0b0db6b

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
@@ -1756,6 +1756,7 @@ public void sendButtonPressed(int index, VideoEditedInfo videoEditedInfo, boolea
17561756
private final static int goToFirstMessage = 35;
17571757
private final static int deleteAllYourMessages = 36;
17581758
private final static int deleteAllUnpinnedMessages = 37;
1759+
private final static int deleteAllYourMessagesInAllTopics = 38;
17591760

17601761
private final static int attach_photo = 0;
17611762
private final static int attach_gallery = 1;
@@ -4180,6 +4181,11 @@ public void run(boolean revoke) {
41804181
currentAccount,
41814182
dialog_id,
41824183
getParentActivity());
4184+
} else if (id == deleteAllYourMessagesInAllTopics) {
4185+
org.telegram.messenger.forkgram.ForkDialogs.CreateDeleteAllYourMessagesInAllTopicsAlert(
4186+
currentAccount,
4187+
dialog_id,
4188+
getParentActivity());
41834189
} else if (id == deleteAllUnpinnedMessages) {
41844190
org.telegram.messenger.forkgram.ForkDialogs.CreateDeleteAllUnpinnedMessagesAlert(
41854191
currentAccount,
@@ -4520,6 +4526,14 @@ public void toggleMute() {
45204526
R.drawable.msg_delete,
45214527
LocaleController.getString("DeleteAllYourMessages", R.string.DeleteAllYourMessages),
45224528
themeDelegate);
4529+
// Add option to delete messages in all topics for forum groups
4530+
if (ChatObject.isForum(currentChat)) {
4531+
headerItem.addSubItem(
4532+
deleteAllYourMessagesInAllTopics,
4533+
R.drawable.msg_delete,
4534+
LocaleController.getString("DeleteAllYourMessagesInAllTopics", R.string.DeleteAllYourMessagesInAllTopics),
4535+
themeDelegate);
4536+
}
45234537
}
45244538
if (MessagesController.getGlobalMainSettings().getBoolean("addItemToDeleteAllUnpinnedMessages", false)
45254539
&& ((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
@@ -9789,6 +9789,7 @@
97899789
<string name="ShowNotificationContentInfo">When app is locked. Can be cause of privacy leaks.</string>
97909790
<string name="DeleteAllYourMessages">Delete all your messages</string>
97919791
<string name="DeleteAllYourMessagesInfo">Are you sure you want **delete all your messages** from this chat?</string>
9792+
<string name="DeleteAllYourMessagesInAllTopics">Delete all your messages in all topics</string>
97929793
<string name="ReallySure">Are you **really sure**?</string>
97939794
<string name="DisableGlobalSearch">Disable Global Search</string>
97949795
<string name="DisableQuickReaction">Disable quick reaction</string>

0 commit comments

Comments
 (0)