From 64dd622d32147513968d5ab8e0d0d9c38294d27a Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 25 Nov 2017 20:55:43 +0100 Subject: [PATCH] make 'markable' attribute persistent --- .../eu/siacs/conversations/entities/Message.java | 16 +++++++++++----- .../persistance/DatabaseBackend.java | 9 +++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index fda02c316..9e8f2944b 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -72,6 +72,7 @@ public class Message extends AbstractEntity { public static final String READ = "read"; public static final String ERROR_MESSAGE = "errorMsg"; public static final String READ_BY_MARKERS = "readByMarkers"; + public static final String MARKABLE = "markable"; public static final String ME_COMMAND = "/me "; @@ -98,7 +99,7 @@ public class Message extends AbstractEntity { private Message mPreviousMessage = null; private String axolotlFingerprint = null; private String errorMessage = null; - protected Set readByMarkers = new HashSet<>(); + private Set readByMarkers = new HashSet<>(); private Boolean isGeoUri = null; private Boolean isEmojisOnly = null; @@ -133,7 +134,8 @@ public class Message extends AbstractEntity { null, false, null, - null); + null, + false); } private Message(final Conversation conversation, final String uuid, final String conversationUUid, final Jid counterpart, @@ -141,7 +143,8 @@ public class Message extends AbstractEntity { 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 edited, final boolean oob, final String errorMessage, final Set readByMarkers) { + final String edited, final boolean oob, final String errorMessage, final Set readByMarkers, + final boolean markable) { this.conversation = conversation; this.uuid = uuid; this.conversationUuid = conversationUUid; @@ -161,7 +164,8 @@ public class Message extends AbstractEntity { this.edited = edited; this.oob = oob; this.errorMessage = errorMessage; - this.readByMarkers = new HashSet<>(); + this.readByMarkers = readByMarkers == null ? new HashSet() : readByMarkers; + this.markable = markable; } public static Message fromCursor(Cursor cursor, Conversation conversation) { @@ -208,7 +212,8 @@ public class Message extends AbstractEntity { cursor.getString(cursor.getColumnIndex(EDITED)), cursor.getInt(cursor.getColumnIndex(OOB)) > 0, cursor.getString(cursor.getColumnIndex(ERROR_MESSAGE)), - ReadByMarker.fromJsonString(cursor.getString(cursor.getColumnIndex(READ_BY_MARKERS)))); + ReadByMarker.fromJsonString(cursor.getString(cursor.getColumnIndex(READ_BY_MARKERS))), + cursor.getInt(cursor.getColumnIndex(MARKABLE)) > 0); } public static Message createStatusMessage(Conversation conversation, String body) { @@ -264,6 +269,7 @@ public class Message extends AbstractEntity { values.put(OOB, oob ? 1 : 0); values.put(ERROR_MESSAGE,errorMessage); values.put(READ_BY_MARKERS,ReadByMarker.toJson(readByMarkers).toString()); + values.put(MARKABLE, markable ? 1 : 0); return values; } diff --git a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java index de8dbb0a5..d61c7f0b6 100644 --- a/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java +++ b/src/main/java/eu/siacs/conversations/persistance/DatabaseBackend.java @@ -60,7 +60,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { private static DatabaseBackend instance = null; private static final String DATABASE_NAME = "history"; - private static final int DATABASE_VERSION = 37; + private static final int DATABASE_VERSION = 38; private static String CREATE_CONTATCS_STATEMENT = "create table " + Contact.TABLENAME + "(" + Contact.ACCOUNT + " TEXT, " @@ -198,6 +198,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { + Message.OOB + " INTEGER, " + Message.ERROR_MESSAGE + " TEXT," + Message.READ_BY_MARKERS + " TEXT," + + Message.MARKABLE + " NUMBER DEFAULT 0," + Message.REMOTE_MSG_ID + " TEXT, FOREIGN KEY(" + Message.CONVERSATION + ") REFERENCES " + Conversation.TABLENAME + "(" + Conversation.UUID @@ -457,7 +458,11 @@ public class DatabaseBackend extends SQLiteOpenHelper { } if (oldVersion < 37 && newVersion >= 37) { - db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.READ_BY_MARKERS + " TEXTs"); + db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.READ_BY_MARKERS + " TEXT"); + } + + if (oldVersion < 38 && newVersion >= 38) { + db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.MARKABLE + " NUMBER DEFAULT 0"); } }