diff options
Diffstat (limited to '')
6 files changed, 59 insertions, 25 deletions
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<Message> 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<ReadByMarker> 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<ReadByMarker> 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<ReadByMarker> 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<Message> getMessages(Conversation conversation, int limit, - long timestamp) { + public ArrayList<Message> getMessages(Conversation conversation, int limit, long timestamp) { ArrayList<Message> 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 + "<?", selectionArgs, null, null, Message.TIME_SENT + " DESC", String.valueOf(limit)); } else { - String[] selectionArgs = {conversation.getUuid(), - Long.toString(timestamp)}; + String[] selectionArgs = {conversation.getUuid(), Long.toString(timestamp), "1"}; cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION - + "=? and " + Message.TIME_SENT + "<?", selectionArgs, + + "=? and " + Message.TIME_SENT + "<? and " + Message.DELETED + "<?", selectionArgs, null, null, Message.TIME_SENT + " DESC", String.valueOf(limit)); } @@ -738,7 +741,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { cursor.moveToLast(); do { Message message = Message.fromCursor(cursor, conversation); - if (message != null) { + if (message != null && !message.isMessageDeleted()) { list.add(message); } } while (cursor.moveToPrevious()); @@ -944,12 +947,11 @@ public class DatabaseBackend extends SQLiteOpenHelper { public void deleteMessageInConversation(Message message) { long start = SystemClock.elapsedRealtime(); final SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransaction(); + ContentValues values = new ContentValues(); + values.put(Message.DELETED, "1"); 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"); + int rows = db.update("messages", values, "uuid =?", args); + Log.d(Config.LOGTAG, "deleted " + rows + " message in " + (SystemClock.elapsedRealtime() - start) + "ms"); } public void deleteMessagesInConversation(Conversation conversation) { diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 45929344c..69aa51918 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -1334,12 +1334,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke MenuItem downloadFile = menu.findItem(R.id.download_file); MenuItem deleteFile = menu.findItem(R.id.delete_file); MenuItem showErrorMessage = menu.findItem(R.id.show_error_message); + deleteMessage.setVisible(true); if (!m.isFileOrImage() && !encrypted && !m.isGeoUri() && !m.treatAsDownloadable()) { copyMessage.setVisible(true); quoteMessage.setVisible(MessageUtils.prepareQuote(m).length() > 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) { diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 81be5072d..369395d30 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -831,11 +831,13 @@ <string name="action_delete">Delete</string> <string name="security_violation_not_attaching_file">File omitted due to security violation.</string> <string name="delete_file_dialog">Delete file</string> - <string name="delete_file_dialog_msg">Are you sure you want to delete this file?\n\n<b>Warning:</b> This will not delete copies of this file that are stored on other devices or servers. </string> + <string name="delete_file_dialog_msg">Are you sure you want to delete this file?\n\n<b>Warning:</b> This will not delete copies of this file that are stored on other devices or servers.</string> <string name="cancelled">cancelled</string> <string name="remote_server_timeout">Remote server timeout</string> <string name="already_drafting_message">You are already drafting a message.</string> <string name="bad_key_for_encryption">Bad key for encryption.</string> <string name="server_info_available_with">yes, %s</string> + <string name="delete_message_dialog">Delete message</string> + <string name="delete_message_dialog_msg">Are you sure you want to delete this message?\n\n<b>Warning:</b> This will not delete copies of this message that are stored on other devices or servers.</string> </resources> |