Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to remove all messages from current chat #2175

Merged
merged 1 commit into from Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions res/menu/conversation_clear.xml
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:title="@string/menu_clear_chat"
android:id="@+id/menu_clear_chat"/>

</menu>
1 change: 1 addition & 0 deletions res/values/strings.xml
Expand Up @@ -192,6 +192,7 @@
<string name="menu_add_attachment">Add Attachment</string>
<string name="menu_leave_group">Leave Group</string>
<string name="menu_delete_chat">Delete Chat</string>
<string name="menu_clear_chat">Clear Chat</string>
<string name="ask_delete_named_chat">Are you sure you want to delete \"%1$s\"?</string>
<string name="menu_delete_messages">Delete Messages</string>
<string name="delete_contact">Delete Contact</string>
Expand Down
2 changes: 2 additions & 0 deletions src/org/thoughtcrime/securesms/ConversationActivity.java
Expand Up @@ -483,6 +483,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_archive_chat).setTitle(R.string.menu_unarchive_chat);
}

inflater.inflate(R.menu.conversation_clear, menu);
inflater.inflate(R.menu.conversation_delete, menu);

try {
Expand Down Expand Up @@ -533,6 +534,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.menu_add_attachment: handleAddAttachment(); return true;
case R.id.menu_leave: handleLeaveGroup(); return true;
case R.id.menu_archive_chat: handleArchiveChat(); return true;
case R.id.menu_clear_chat: fragment.handleClearChat(); return true;
case R.id.menu_delete_chat: handleDeleteChat(); return true;
case R.id.menu_mute_notifications: handleMuteNotifications(); return true;
case R.id.menu_show_map: handleShowMap(); return true;
Expand Down
4 changes: 4 additions & 0 deletions src/org/thoughtcrime/securesms/ConversationAdapter.java
Expand Up @@ -331,6 +331,10 @@ public Set<DcMsg> getSelectedItems() {
return Collections.unmodifiableSet(new HashSet<>(batchSelected));
}

public int[] getMessageIds() {
return dcMsgList;
}

public void pulseHighlightItem(int position) {
if (position>=0 && position < getItemCount()) {
positionToPulseHighlight = position;
Expand Down
4 changes: 4 additions & 0 deletions src/org/thoughtcrime/securesms/ConversationFragment.java
Expand Up @@ -357,6 +357,10 @@ static boolean canReplyToMsg(DcMsg dcMsg) {
return !dcMsg.isInfo() && dcMsg.getType() != DcMsg.DC_MSG_VIDEOCHAT_INVITATION;
}

public void handleClearChat() {
handleDeleteMessages((int) chatId, getListAdapter().getMessageIds());
}

private ConversationAdapter getListAdapter() {
return (ConversationAdapter) list.getAdapter();
}
Expand Down
10 changes: 6 additions & 4 deletions src/org/thoughtcrime/securesms/MessageSelectorFragment.java
Expand Up @@ -55,19 +55,21 @@ protected void handleDisplayDetails(DcMsg dcMsg) {
}

protected void handleDeleteMessages(int chatId, final Set<DcMsg> messageRecords) {
int messagesCount = messageRecords.size();
handleDeleteMessages(chatId, DcMsg.msgSetToIds(messageRecords));
}

protected void handleDeleteMessages(int chatId, final int[] messageIds) {
DcChat dcChat = DcHelper.getContext(getActivity()).getChat(chatId);

String text = getActivity().getResources().getQuantityString(
dcChat.isDeviceTalk()? R.plurals.ask_delete_messages_simple : R.plurals.ask_delete_messages,
messagesCount, messagesCount);
messageIds.length, messageIds.length);

new AlertDialog.Builder(getActivity())
.setMessage(text)
.setCancelable(true)
.setPositiveButton(R.string.delete, (dialog, which) -> {
int[] ids = DcMsg.msgSetToIds(messageRecords);
dcContext.deleteMsgs(ids);
dcContext.deleteMsgs(messageIds);
if (actionMode != null) actionMode.finish();
})
.setNegativeButton(android.R.string.cancel, null)
Expand Down