mirror of
https://github.com/NekoX-Dev/NekoX.git
synced 2024-12-11 18:49:59 +01:00
Delete all from self
This commit is contained in:
parent
92c7d0a51b
commit
df1ec9d5c6
@ -147,6 +147,7 @@ import org.telegram.ui.Cells.StickerCell;
|
||||
import org.telegram.ui.Components.AlertsCreator;
|
||||
import org.telegram.ui.Components.AnimatedFileDrawable;
|
||||
import org.telegram.ui.Components.AnimationProperties;
|
||||
import org.telegram.ui.Components.AvatarDrawable;
|
||||
import org.telegram.ui.Components.BackupImageView;
|
||||
import org.telegram.ui.ActionBar.BaseFragment;
|
||||
import org.telegram.ui.Cells.BotHelpCell;
|
||||
@ -186,6 +187,7 @@ import org.telegram.ui.Components.URLSpanUserMention;
|
||||
import org.telegram.ui.Components.UndoView;
|
||||
import org.telegram.ui.Components.voip.VoIPHelper;
|
||||
|
||||
import tw.nekomimi.nekogram.MessageHelper;
|
||||
import tw.nekomimi.nekogram.NekoConfig;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
@ -684,6 +686,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
private final static int chat_enc_timer = 13;
|
||||
private final static int chat_menu_attach = 14;
|
||||
private final static int clear_history = 15;
|
||||
private final static int delete_history = 92;
|
||||
private final static int delete_chat = 16;
|
||||
private final static int share_contact = 17;
|
||||
private final static int mute = 18;
|
||||
@ -1228,6 +1231,43 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
return;
|
||||
}
|
||||
showDialog(AlertsCreator.createTTLAlert(getParentActivity(), currentEncryptedChat).create());
|
||||
} else if (id == delete_history) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
TextView messageTextView = new TextView(context);
|
||||
messageTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
|
||||
messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
|
||||
messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
|
||||
FrameLayout frameLayout = new FrameLayout(context);
|
||||
builder.setView(frameLayout);
|
||||
AvatarDrawable avatarDrawable = new AvatarDrawable();
|
||||
avatarDrawable.setTextSize(AndroidUtilities.dp(12));
|
||||
BackupImageView imageView = new BackupImageView(context);
|
||||
imageView.setRoundRadius(AndroidUtilities.dp(20));
|
||||
frameLayout.addView(imageView, LayoutHelper.createFrame(40, 40, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 22, 5, 22, 0));
|
||||
imageView.setImage(ImageLocation.getForChat(currentChat, false), "50_50", avatarDrawable, currentChat);
|
||||
TextView textView = new TextView(context);
|
||||
textView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuItem));
|
||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
|
||||
textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
||||
textView.setLines(1);
|
||||
textView.setMaxLines(1);
|
||||
textView.setSingleLine(true);
|
||||
textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
|
||||
textView.setEllipsize(TextUtils.TruncateAt.END);
|
||||
textView.setText(LocaleController.getString("DeleteAllFromSelf", R.string.DeleteAllFromSelf));
|
||||
frameLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, (LocaleController.isRTL ? 21 : 76), 11, (LocaleController.isRTL ? 76 : 21), 0));
|
||||
frameLayout.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 57, 24, 9));
|
||||
messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("DeleteAllFromSelfAlert", R.string.DeleteAllFromSelfAlert)));
|
||||
builder.setPositiveButton(LocaleController.getString("DeleteAll", R.string.DeleteAll), (dialogInterface, i) -> {
|
||||
MessageHelper.getInstance(currentAccount).deleteUserChannelHistoryWithSearch(dialog_id, UserConfig.getInstance(currentAccount).getCurrentUser());
|
||||
});
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
AlertDialog alertDialog = builder.create();
|
||||
showDialog(alertDialog);
|
||||
TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
|
||||
if (button != null) {
|
||||
button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
|
||||
}
|
||||
} else if (id == clear_history || id == delete_chat) {
|
||||
if (getParentActivity() == null) {
|
||||
return;
|
||||
@ -1577,18 +1617,12 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
if (searchItem != null) {
|
||||
headerItem.addSubItem(search, R.drawable.msg_search, LocaleController.getString("Search", R.string.Search));
|
||||
}
|
||||
if (currentChat != null && !currentChat.creator) {
|
||||
headerItem.addSubItem(report, R.drawable.msg_report, LocaleController.getString("ReportChat", R.string.ReportChat));
|
||||
}
|
||||
if (currentUser != null) {
|
||||
addContactItem = headerItem.addSubItem(share_contact, R.drawable.msg_addcontact, "");
|
||||
}
|
||||
if (currentEncryptedChat != null) {
|
||||
timeItem2 = headerItem.addSubItem(chat_enc_timer, R.drawable.msg_timer, LocaleController.getString("SetTimer", R.string.SetTimer));
|
||||
}
|
||||
if (!ChatObject.isChannel(currentChat) || currentChat != null && currentChat.megagroup && TextUtils.isEmpty(currentChat.username)) {
|
||||
headerItem.addSubItem(clear_history, R.drawable.msg_clear, LocaleController.getString("ClearHistory", R.string.ClearHistory));
|
||||
}
|
||||
|
||||
boolean allowShowPinned;
|
||||
if (currentChat != null) {
|
||||
@ -1607,6 +1641,17 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
|
||||
if (currentUser == null || !currentUser.self) {
|
||||
muteItem = headerItem.addSubItem(mute, R.drawable.msg_mute, null);
|
||||
}
|
||||
|
||||
if (currentChat != null && !currentChat.creator) {
|
||||
headerItem.addSubItem(report, R.drawable.msg_report, LocaleController.getString("ReportChat", R.string.ReportChat));
|
||||
}
|
||||
if (!ChatObject.isChannel(currentChat) || currentChat != null && currentChat.megagroup && TextUtils.isEmpty(currentChat.username)) {
|
||||
headerItem.addSubItem(clear_history, R.drawable.msg_clear, LocaleController.getString("ClearHistory", R.string.ClearHistory));
|
||||
}
|
||||
if (ChatObject.isChannel(currentChat) && currentChat.megagroup) {
|
||||
headerItem.addSubItem(delete_history, R.drawable.msg_delete, LocaleController.getString("DeleteAllFromSelf", R.string.DeleteAllFromSelf));
|
||||
}
|
||||
|
||||
if (ChatObject.isChannel(currentChat) && !currentChat.creator) {
|
||||
if (!ChatObject.isNotInChat(currentChat)) {
|
||||
if (currentChat.megagroup) {
|
||||
|
@ -13,10 +13,7 @@ public class MessageHelper {
|
||||
|
||||
private static volatile MessageHelper[] Instance = new MessageHelper[UserConfig.MAX_ACCOUNT_COUNT];
|
||||
private int currentAccount;
|
||||
private int reqId;
|
||||
private int mergeReqId;
|
||||
private int lastReqId;
|
||||
private int[] messagesSearchCount = new int[]{0, 0};
|
||||
|
||||
public MessageHelper(int num) {
|
||||
currentAccount = num;
|
||||
@ -35,98 +32,50 @@ public class MessageHelper {
|
||||
return localInstance;
|
||||
}
|
||||
|
||||
public void deleteUserChannelHistoryWithSearch(final long dialog_id, final TLRPC.User user, boolean scheduled) {
|
||||
deleteUserChannelHistoryWithSearch(dialog_id, user, scheduled, false);
|
||||
public void deleteUserChannelHistoryWithSearch(final long dialog_id, final TLRPC.User user) {
|
||||
deleteUserChannelHistoryWithSearch(dialog_id, user, 0);
|
||||
}
|
||||
|
||||
public void deleteUserChannelHistoryWithSearch(final long dialog_id, final TLRPC.User user, boolean scheduled, final boolean internal) {
|
||||
boolean firstQuery = !internal;
|
||||
if (reqId != 0) {
|
||||
ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true);
|
||||
reqId = 0;
|
||||
public void deleteUserChannelHistoryWithSearch(final long dialog_id, final TLRPC.User user, final int offset_id) {
|
||||
final TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
|
||||
req.peer = MessagesController.getInstance(currentAccount).getInputPeer((int) dialog_id);
|
||||
if (req.peer == null) {
|
||||
return;
|
||||
}
|
||||
if (mergeReqId != 0) {
|
||||
ConnectionsManager.getInstance(currentAccount).cancelRequest(mergeReqId, true);
|
||||
mergeReqId = 0;
|
||||
req.limit = 100;
|
||||
req.q = "";
|
||||
req.offset_id = offset_id;
|
||||
if (user != null) {
|
||||
req.from_id = MessagesController.getInstance(currentAccount).getInputUser(user);
|
||||
req.flags |= 1;
|
||||
}
|
||||
if (firstQuery) {
|
||||
TLRPC.InputPeer inputPeer = MessagesController.getInstance(currentAccount).getInputPeer((int) dialog_id);
|
||||
if (inputPeer == null) {
|
||||
return;
|
||||
}
|
||||
final TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
|
||||
req.peer = inputPeer;
|
||||
req.limit = 1;
|
||||
req.q = "";
|
||||
if (user != null) {
|
||||
req.from_id = MessagesController.getInstance(currentAccount).getInputUser(user);
|
||||
req.flags |= 1;
|
||||
}
|
||||
req.filter = new TLRPC.TL_inputMessagesFilterEmpty();
|
||||
mergeReqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
||||
mergeReqId = 0;
|
||||
req.filter = new TLRPC.TL_inputMessagesFilterEmpty();
|
||||
final int currentReqId = ++lastReqId;
|
||||
ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
||||
int lastMessageId = offset_id;
|
||||
if (currentReqId == lastReqId) {
|
||||
if (response != null) {
|
||||
TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
|
||||
messagesSearchCount[0] = res.count;
|
||||
FileLog.d("total " + messagesSearchCount[0]);
|
||||
deleteUserChannelHistoryWithSearch(dialog_id, user, scheduled, true);
|
||||
}
|
||||
}), ConnectionsManager.RequestFlagFailOnServerErrors);
|
||||
} else {
|
||||
final TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
|
||||
req.peer = MessagesController.getInstance(currentAccount).getInputPeer((int) dialog_id);
|
||||
if (req.peer == null) {
|
||||
return;
|
||||
}
|
||||
req.limit = 100;
|
||||
req.q = "";
|
||||
req.offset_id = 0;
|
||||
if (user != null) {
|
||||
req.from_id = MessagesController.getInstance(currentAccount).getInputUser(user);
|
||||
req.flags |= 1;
|
||||
}
|
||||
req.filter = new TLRPC.TL_inputMessagesFilterEmpty();
|
||||
final int currentReqId = ++lastReqId;
|
||||
reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
|
||||
if (currentReqId == lastReqId) {
|
||||
reqId = 0;
|
||||
if (response != null) {
|
||||
TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
|
||||
messagesSearchCount[1] = res.messages.size();
|
||||
for (int a = 0; a < res.messages.size(); a++) {
|
||||
TLRPC.Message message = res.messages.get(a);
|
||||
if (message instanceof TLRPC.TL_messageEmpty || message.action instanceof TLRPC.TL_messageActionHistoryClear || message instanceof TLRPC.TL_messageService) {
|
||||
res.messages.remove(a);
|
||||
a--;
|
||||
}
|
||||
}
|
||||
ArrayList<Integer> ids = new ArrayList<>();
|
||||
ArrayList<Long> random_ids = new ArrayList<>();
|
||||
int channelId = 0;
|
||||
for (int a = 0; a < res.messages.size(); a++) {
|
||||
TLRPC.Message message = res.messages.get(a);
|
||||
ids.add(message.id);
|
||||
if (message.random_id != 0) {
|
||||
random_ids.add(message.random_id);
|
||||
}
|
||||
channelId = message.to_id.channel_id;
|
||||
}
|
||||
MessagesController.getInstance(currentAccount).deleteMessages(ids, random_ids, null, dialog_id, channelId, true, scheduled);
|
||||
messagesSearchCount[0] = messagesSearchCount[0] - messagesSearchCount[1];
|
||||
FileLog.d("found " + messagesSearchCount[1]);
|
||||
FileLog.d("after " + messagesSearchCount[0]);
|
||||
if (messagesSearchCount[0] > 0) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
deleteUserChannelHistoryWithSearch(dialog_id, user, scheduled, true);
|
||||
}
|
||||
int size = res.messages.size();
|
||||
if (size == 0) {
|
||||
return;
|
||||
}
|
||||
ArrayList<Integer> ids = new ArrayList<>();
|
||||
ArrayList<Long> random_ids = new ArrayList<>();
|
||||
int channelId = 0;
|
||||
for (int a = 0; a < res.messages.size(); a++) {
|
||||
TLRPC.Message message = res.messages.get(a);
|
||||
ids.add(message.id);
|
||||
if (message.random_id != 0) {
|
||||
random_ids.add(message.random_id);
|
||||
}
|
||||
channelId = message.to_id.channel_id;
|
||||
lastMessageId = message.id;
|
||||
}
|
||||
MessagesController.getInstance(currentAccount).deleteMessages(ids, random_ids, null, dialog_id, channelId, true, false);
|
||||
deleteUserChannelHistoryWithSearch(dialog_id, user, lastMessageId);
|
||||
}
|
||||
}), ConnectionsManager.RequestFlagFailOnServerErrors);
|
||||
}
|
||||
}
|
||||
}), ConnectionsManager.RequestFlagFailOnServerErrors);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
<string name="HidePhone">あなたの携帯電話番号を隠す</string>
|
||||
<string name="MessageMenu">メッセージメニュー</string>
|
||||
<string name="Hide">隠す</string>
|
||||
<string name="DeleteAllFromSelf">送信したすべてのメッセージを削除する</string>
|
||||
<string name="DeleteAllFromSelf">自閉</string>
|
||||
<string name="DeleteAllFromSelfAlert">警告!これはこのチャットの **すべての人** が **あなたが送った全部のメッセージ** を削除します。</string>
|
||||
<string name="BotLogin">ボットログイン</string>
|
||||
<string name="InvalidAccessToken">無効なアクセストークン</string>
|
||||
<string name="IgnoreBlocked">ブロックした相手の発言を無視する</string>
|
||||
|
@ -5,7 +5,8 @@
|
||||
<string name="HidePhone">隐藏咱的手机号</string>
|
||||
<string name="MessageMenu">消息菜单</string>
|
||||
<string name="Hide">隐藏</string>
|
||||
<string name="DeleteAllFromSelf">删除全部自己的历史消息</string>
|
||||
<string name="DeleteAllFromSelf">自闭</string>
|
||||
<string name="DeleteAllFromSelfAlert">警告!这将为此会话中的 **所有人** 删除 **全部你发出的消息**。</string>
|
||||
<string name="BotLogin">机器人登录</string>
|
||||
<string name="InvalidAccessToken">无效的访问令牌</string>
|
||||
<string name="IgnoreBlocked">忽略渣滓们在群里说的话</string>
|
||||
|
@ -5,7 +5,8 @@
|
||||
<string name="HidePhone">隱藏您的手機號碼</string>
|
||||
<string name="MessageMenu">訊息菜單</string>
|
||||
<string name="Hide">隱藏</string>
|
||||
<string name="DeleteAllFromSelf">刪除所有您傳送的訊息</string>
|
||||
<string name="DeleteAllFromSelf">自閉</string>
|
||||
<string name="DeleteAllFromSelfAlert">警告!這將為此會話中的 **所有人** 刪除 **全部你發出的訊息**。</string>
|
||||
<string name="BotLogin">機器人登入</string>
|
||||
<string name="InvalidAccessToken">無效的訪問令牌</string>
|
||||
<string name="IgnoreBlocked">忽略被封鎖的使用者在群組內的發言</string>
|
||||
|
@ -6,6 +6,7 @@
|
||||
<string name="HidePhone">Hide my phone number</string>
|
||||
<string name="Hide">Hide</string>
|
||||
<string name="DeleteAllFromSelf">Delete all from yourself</string>
|
||||
<string name="DeleteAllFromSelfAlert">Warning! This will **delete all messages from you** in this chat for **all** participants.</string>
|
||||
<string name="BotLogin">Bot Login</string>
|
||||
<string name="InvalidAccessToken">Invalid access token</string>
|
||||
<string name="IgnoreBlocked">Ignore blocked users in group</string>
|
||||
|
Loading…
Reference in New Issue
Block a user