diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-07-09 22:58:50 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-07-09 22:58:50 +0200 |
commit | 4f612fc9bc50e8665c11cab59f502ace854a4a9f (patch) | |
tree | 04d83e80e610cba6ffb55da8ad2b1fe7b2d44c91 /src | |
parent | 0a979ca94cbfdb81196e22aebe376afa35ed09b5 (diff) |
integrated locally message deletion from #208
thanks @acw81
Diffstat (limited to '')
6 files changed, 42 insertions, 0 deletions
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 @@ -26,6 +26,10 @@ android:title="@string/correct_message" android:visible="false" /> <item + android:id="@+id/delete_message" + android:title="@string/delete_message" + android:visible="false" /> + <item android:id="@+id/copy_url" android:title="@string/copy_original_url" android:visible="false" /> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index a04d2c9ee..d48801c54 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -803,4 +803,5 @@ <string name="create_dialog_group_chat_name">Group chat name</string> <string name="everyone_has_read_up_to_this_point">Everyone has read up to this point</string> <string name="conference_resource_constraint">Resource constraint</string> + <string name="delete_message">Delete message</string> </resources> |