From b38fe1e8f0a9a1aa479b4a61f65f61ae78db6665 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sun, 11 Nov 2018 13:51:15 +0100 Subject: implement message deletion fixed #208 --- .../de/pixart/messenger/entities/Conversation.java | 14 ++++++++++ .../messenger/entities/IndividualMessage.java | 5 ++-- .../java/de/pixart/messenger/entities/Message.java | 12 +++++++- .../messenger/persistance/DatabaseBackend.java | 32 ++++++++++++---------- .../pixart/messenger/ui/ConversationFragment.java | 17 ++++++++---- 5 files changed, 56 insertions(+), 24 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 1e5224489..db6006ca3 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -222,6 +222,20 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } } + public void findDeletedMessages(final OnMessageFound onMessageFound) { + final ArrayList results = new ArrayList<>(); + synchronized (this.messages) { + for (final Message m : this.messages) { + if (m.isDeleted()) { + results.add(m); + } + } + } + for (Message result : results) { + onMessageFound.onMessageFound(result); + } + } + public Message findMessageWithFileAndUuid(final String uuid) { synchronized (this.messages) { for (final Message message : this.messages) { diff --git a/src/main/java/de/pixart/messenger/entities/IndividualMessage.java b/src/main/java/de/pixart/messenger/entities/IndividualMessage.java index f8d0b7938..2a7b4c8da 100644 --- a/src/main/java/de/pixart/messenger/entities/IndividualMessage.java +++ b/src/main/java/de/pixart/messenger/entities/IndividualMessage.java @@ -41,8 +41,8 @@ public class IndividualMessage extends Message { super(conversation); } - private IndividualMessage(Conversational conversation, String uuid, String conversationUUid, Jid counterpart, Jid trueCounterpart, String body, long timeSent, int encryption, int status, int type, boolean carbon, String remoteMsgId, String relativeFilePath, String serverMsgId, String fingerprint, boolean read, String edited, boolean oob, String errorMessage, Set readByMarkers, boolean markable) { - super(conversation, uuid, conversationUUid, counterpart, trueCounterpart, body, timeSent, encryption, status, type, carbon, remoteMsgId, relativeFilePath, serverMsgId, fingerprint, read, edited, oob, errorMessage, readByMarkers, markable); + private IndividualMessage(Conversational conversation, String uuid, String conversationUUid, Jid counterpart, Jid trueCounterpart, String body, long timeSent, int encryption, int status, int type, boolean carbon, String remoteMsgId, String relativeFilePath, String serverMsgId, String fingerprint, boolean read, boolean deleted, String edited, boolean oob, String errorMessage, Set readByMarkers, boolean markable) { + super(conversation, uuid, conversationUUid, counterpart, trueCounterpart, body, timeSent, encryption, status, type, carbon, remoteMsgId, relativeFilePath, serverMsgId, fingerprint, read, deleted, edited, oob, errorMessage, readByMarkers, markable); } public static Message createDateSeparator(Message message) { @@ -94,6 +94,7 @@ public class IndividualMessage extends Message { cursor.getString(cursor.getColumnIndex(SERVER_MSG_ID)), cursor.getString(cursor.getColumnIndex(FINGERPRINT)), cursor.getInt(cursor.getColumnIndex(READ)) > 0, + cursor.getInt(cursor.getColumnIndex(DELETED)) > 0, cursor.getString(cursor.getColumnIndex(EDITED)), cursor.getInt(cursor.getColumnIndex(OOB)) > 0, cursor.getString(cursor.getColumnIndex(ERROR_MESSAGE)), diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index 9a529877b..14d235553 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -68,6 +68,7 @@ public class Message extends AbstractEntity { public static final String RELATIVE_FILE_PATH = "relativeFilePath"; public static final String FINGERPRINT = "axolotl_fingerprint"; public static final String READ = "read"; + public static final String DELETED = "deleted"; public static final String ERROR_MESSAGE = "errorMsg"; public static final String READ_BY_MARKERS = "readByMarkers"; public static final String MARKABLE = "markable"; @@ -89,6 +90,7 @@ public class Message extends AbstractEntity { protected String edited = null; protected String relativeFilePath; protected boolean read = true; + protected boolean deleted = false; protected String remoteMsgId = null; protected String serverMsgId = null; private final Conversational conversation; @@ -131,6 +133,7 @@ public class Message extends AbstractEntity { null, null, true, + false, null, false, null, @@ -142,7 +145,7 @@ public class Message extends AbstractEntity { final Jid trueCounterpart, final String body, final long timeSent, final int encryption, final int status, final int type, final boolean carbon, final String remoteMsgId, final String relativeFilePath, - final String serverMsgId, final String fingerprint, final boolean read, + final String serverMsgId, final String fingerprint, final boolean read, final boolean deleted, final String edited, final boolean oob, final String errorMessage, final Set readByMarkers, final boolean markable) { this.conversation = conversation; @@ -161,6 +164,7 @@ public class Message extends AbstractEntity { this.serverMsgId = serverMsgId; this.axolotlFingerprint = fingerprint; this.read = read; + this.deleted = deleted; this.edited = edited; this.oob = oob; this.errorMessage = errorMessage; @@ -209,6 +213,7 @@ public class Message extends AbstractEntity { cursor.getString(cursor.getColumnIndex(SERVER_MSG_ID)), cursor.getString(cursor.getColumnIndex(FINGERPRINT)), cursor.getInt(cursor.getColumnIndex(READ)) > 0, + cursor.getInt(cursor.getColumnIndex(DELETED)) > 0, cursor.getString(cursor.getColumnIndex(EDITED)), cursor.getInt(cursor.getColumnIndex(OOB)) > 0, cursor.getString(cursor.getColumnIndex(ERROR_MESSAGE)), @@ -257,6 +262,7 @@ public class Message extends AbstractEntity { values.put(SERVER_MSG_ID, serverMsgId); values.put(FINGERPRINT, axolotlFingerprint); values.put(READ, read ? 1 : 0); + values.put(DELETED, deleted ? 1 : 0); values.put(EDITED, edited); values.put(OOB, oob ? 1 : 0); values.put(ERROR_MESSAGE, errorMessage); @@ -379,6 +385,10 @@ public class Message extends AbstractEntity { return this.read; } + public boolean isMessageDeleted() { + return this.deleted; + } + public void markRead() { this.read = true; } diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index dac626718..b4de5cd92 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -60,7 +60,7 @@ import rocks.xmpp.addr.Jid; public class DatabaseBackend extends SQLiteOpenHelper { public static final String DATABASE_NAME = "history"; - public static final int DATABASE_VERSION = 43; // = Conversations DATABASE_VERSION + 1 + public static final int DATABASE_VERSION = 44; // = Conversations DATABASE_VERSION + 2 private static DatabaseBackend instance = null; private static String CREATE_CONTATCS_STATEMENT = "create table " @@ -228,6 +228,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { + Message.CARBON + " INTEGER, " + Message.EDITED + " TEXT, " + Message.READ + " NUMBER DEFAULT 1, " + + Message.DELETED + " NUMBER DEFAULT 0, " + Message.OOB + " INTEGER, " + Message.ERROR_MESSAGE + " TEXT," + Message.READ_BY_MARKERS + " TEXT," @@ -527,9 +528,13 @@ public class DatabaseBackend extends SQLiteOpenHelper { db.execSQL(COPY_PREEXISTING_ENTRIES); } - if (oldVersion < 42 && newVersion >= 42) { + if (oldVersion < 43 && newVersion >= 43) { db.execSQL("DROP TRIGGER IF EXISTS after_message_delete"); } + + if (oldVersion < 44 && newVersion >= 44) { + db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.DELETED + " NUMBER DEFAULT 0"); + } } private void canonicalizeJids(SQLiteDatabase db) { @@ -716,21 +721,19 @@ public class DatabaseBackend extends SQLiteOpenHelper { return getMessages(conversations, limit, -1); } - public ArrayList getMessages(Conversation conversation, int limit, - long timestamp) { + public ArrayList getMessages(Conversation conversation, int limit, long timestamp) { ArrayList list = new ArrayList<>(); SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor; if (timestamp == -1) { - String[] selectionArgs = {conversation.getUuid()}; + String[] selectionArgs = {conversation.getUuid(), "1"}; cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION - + "=?", selectionArgs, null, null, Message.TIME_SENT + + "=? and " + Message.DELETED + " 0); - //temporarily hide single message deletion in chat view - deleteMessage.setVisible(false); - // deleteMessage.setVisible(true); String body = m.getMergedBody().toString(); if (ShareUtil.containsXmppUri(body)) { copyLink.setTitle(R.string.copy_jabber_id); @@ -1891,9 +1889,16 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke private void deleteMessage(Message message) { final Conversation conversation = (Conversation) message.getConversation(); - activity.xmppConnectionService.deleteMessage(conversation, message); - activity.onConversationsListItemUpdated(); - refresh(); + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setNegativeButton(R.string.cancel, null); + builder.setTitle(R.string.delete_message_dialog); + builder.setMessage(R.string.delete_message_dialog_msg); + builder.setPositiveButton(R.string.confirm, (dialog, which) -> { + activity.xmppConnectionService.deleteMessage(conversation, message); + activity.onConversationsListItemUpdated(); + refresh(); + }); + builder.create().show(); } private void deleteFile(final Message message) { -- cgit v1.2.3