aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-07-09 22:58:50 +0200
committerChristian Schneppe <christian@pix-art.de>2018-07-09 22:58:50 +0200
commit4f612fc9bc50e8665c11cab59f502ace854a4a9f (patch)
tree04d83e80e610cba6ffb55da8ad2b1fe7b2d44c91 /src/main/java
parent0a979ca94cbfdb81196e22aebe376afa35ed09b5 (diff)
integrated locally message deletion from #208
thanks @acw81
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java4
-rw-r--r--src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java11
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java10
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java12
4 files changed, 37 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));