From 4f612fc9bc50e8665c11cab59f502ace854a4a9f Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Mon, 9 Jul 2018 22:58:50 +0200 Subject: integrated locally message deletion from #208 thanks @acw81 --- src/main/java/de/pixart/messenger/entities/Conversation.java | 4 ++++ .../de/pixart/messenger/persistance/DatabaseBackend.java | 11 +++++++++++ .../de/pixart/messenger/services/XmppConnectionService.java | 10 ++++++++++ .../java/de/pixart/messenger/ui/ConversationFragment.java | 12 ++++++++++++ src/main/res/menu/message_context.xml | 4 ++++ src/main/res/values/strings.xml | 1 + 6 files changed, 42 insertions(+) (limited to 'src') diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 18a20532a..fe89009d3 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -134,6 +134,10 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl this.messagesLeftOnServer = value; } + public void deleteMessage(Message message) { + this.messages.remove(message); + } + public Message getFirstUnreadMessage() { Message first = null; synchronized (this.messages) { diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 62b15c816..94710b86e 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -917,6 +917,17 @@ public class DatabaseBackend extends SQLiteOpenHelper { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": persisted roster in " + duration + "ms"); } + public void deleteMessageInConversation(Message message) { + long start = SystemClock.elapsedRealtime(); + final SQLiteDatabase db = this.getWritableDatabase(); + db.beginTransaction(); + String[] args = {message.getUuid()}; + db.delete("messages_index", "uuid =?", args); + db.setTransactionSuccessful(); + db.endTransaction(); + Log.d(Config.LOGTAG, "deleted single message in " + (SystemClock.elapsedRealtime() - start) + "ms"); + } + public void deleteMessagesInConversation(Conversation conversation) { long start = SystemClock.elapsedRealtime(); final SQLiteDatabase db = this.getWritableDatabase(); diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index e149821ec..f6fa55a3b 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -3959,6 +3959,16 @@ public class XmppConnectionService extends Service { updateConversationUi(); } + public void deleteMessage(final Conversation conversation, Message message) { + conversation.deleteMessage(message); + Runnable runnable = () -> { + databaseBackend.deleteMessageInConversation(message); + databaseBackend.updateConversation(conversation); + + }; + mDatabaseWriterExecutor.execute(runnable); + } + public void clearConversationHistory(final Conversation conversation) { final long clearDate; final String reference; diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index efb342f4d..f32aa26ed 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -1299,6 +1299,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke MenuItem quoteMessage = menu.findItem(R.id.quote_message); MenuItem retryDecryption = menu.findItem(R.id.retry_decryption); MenuItem correctMessage = menu.findItem(R.id.correct_message); + MenuItem deleteMessage = menu.findItem(R.id.delete_message); MenuItem shareWith = menu.findItem(R.id.share_with); MenuItem sendAgain = menu.findItem(R.id.send_again); MenuItem copyUrl = menu.findItem(R.id.copy_url); @@ -1309,6 +1310,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (!m.isFileOrImage() && !encrypted && !m.isGeoUri() && !m.treatAsDownloadable()) { copyMessage.setVisible(true); quoteMessage.setVisible(MessageUtils.prepareQuote(m).length() > 0); + deleteMessage.setVisible(true); String body = m.getMergedBody().toString(); if (ShareUtil.containsXmppUri(body)) { copyLink.setTitle(R.string.copy_jabber_id); @@ -1397,6 +1399,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke case R.id.retry_decryption: retryDecryption(selectedMessage); return true; + case R.id.delete_message: + deleteMessage(selectedMessage); + return true; case R.id.delete_file: deleteFile(selectedMessage); return true; @@ -1847,6 +1852,13 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke builder.create().show(); } + private void deleteMessage(Message message) { + final Conversation conversation = (Conversation) message.getConversation(); + activity.xmppConnectionService.deleteMessage(conversation, message); + activity.onConversationsListItemUpdated(); + refresh(); + } + private void deleteFile(Message message) { if (activity.xmppConnectionService.getFileBackend().deleteFile(message)) { message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED)); diff --git a/src/main/res/menu/message_context.xml b/src/main/res/menu/message_context.xml index 84ed0fb9f..4112dfb8c 100644 --- a/src/main/res/menu/message_context.xml +++ b/src/main/res/menu/message_context.xml @@ -25,6 +25,10 @@ android:id="@+id/correct_message" android:title="@string/correct_message" android:visible="false" /> + Group chat name Everyone has read up to this point Resource constraint + Delete message -- cgit v1.2.3