diff options
Diffstat (limited to 'src/main')
4 files changed, 17 insertions, 26 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 922ba614f..15dc844b1 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -486,7 +486,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl return message; } else { Message message = this.messages.get(this.messages.size() - 1); - message.setConversation(this); return message; } } @@ -974,14 +973,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public void add(Message message) { - message.setConversation(this); synchronized (this.messages) { this.messages.add(message); } } public void prepend(Message message) { - message.setConversation(this); synchronized (this.messages) { this.messages.add(0, message); } diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index 7aa8ca513..544640ab0 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -81,15 +81,15 @@ public class Message extends AbstractEntity { protected boolean read = true; protected String remoteMsgId = null; protected String serverMsgId = null; - protected Conversation conversation = null; + private final Conversation conversation; protected Transferable transferable = null; private Message mNextMessage = null; private Message mPreviousMessage = null; private String axolotlFingerprint = null; private String errorMessage = null; - private Message() { - + private Message(Conversation conversation) { + this.conversation = conversation; } public Message(Conversation conversation, String body, int encryption) { @@ -97,7 +97,7 @@ public class Message extends AbstractEntity { } public Message(Conversation conversation, String body, int encryption, int status) { - this(java.util.UUID.randomUUID().toString(), + this(conversation, java.util.UUID.randomUUID().toString(), conversation.getUuid(), conversation.getJid() == null ? null : conversation.getJid().toBareJid(), null, @@ -115,15 +115,15 @@ public class Message extends AbstractEntity { null, false, null); - this.conversation = conversation; } - private Message(final String uuid, final String conversationUUid, final Jid counterpart, + private Message(final Conversation conversation, final String uuid, final String conversationUUid, final Jid counterpart, 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 edited, final boolean oob, final String errorMessage) { + this.conversation = conversation; this.uuid = uuid; this.conversationUuid = conversationUUid; this.counterpart = counterpart; @@ -144,7 +144,7 @@ public class Message extends AbstractEntity { this.errorMessage = errorMessage; } - public static Message fromCursor(Cursor cursor) { + public static Message fromCursor(Cursor cursor, Conversation conversation) { Jid jid; try { String value = cursor.getString(cursor.getColumnIndex(COUNTERPART)); @@ -169,7 +169,8 @@ public class Message extends AbstractEntity { } catch (InvalidJidException e) { trueCounterpart = null; } - return new Message(cursor.getString(cursor.getColumnIndex(UUID)), + return new Message(conversation, + cursor.getString(cursor.getColumnIndex(UUID)), cursor.getString(cursor.getColumnIndex(CONVERSATION)), jid, trueCounterpart, @@ -190,25 +191,22 @@ public class Message extends AbstractEntity { } public static Message createDateMessage(Conversation conversation, String body) { - final Message message = new Message(); + final Message message = new Message(conversation); message.setType(Message.TYPE_STATUS); - message.setConversation(conversation); message.setBody(body); return message; } public static Message createStatusMessage(Conversation conversation, String body) { - final Message message = new Message(); + final Message message = new Message(conversation); message.setType(Message.TYPE_STATUS); - message.setConversation(conversation); message.setBody(body); return message; } public static Message createLoadMoreMessage(Conversation conversation) { - final Message message = new Message(); + final Message message = new Message(conversation); message.setType(Message.TYPE_STATUS); - message.setConversation(conversation); message.setBody("LOAD_MORE"); return message; } @@ -253,10 +251,6 @@ public class Message extends AbstractEntity { return this.conversation; } - public void setConversation(Conversation conv) { - this.conversation = conv; - } - public Jid getCounterpart() { return counterpart; } diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 1b7d09663..8f264639d 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -655,9 +655,8 @@ public class DatabaseBackend extends SQLiteOpenHelper { if (cursor.getCount() > 0) { cursor.moveToLast(); do { - Message message = Message.fromCursor(cursor); + Message message = Message.fromCursor(cursor, conversation); if (message != null) { - message.setConversation(conversation); list.add(message); } } while (cursor.moveToPrevious()); @@ -688,7 +687,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { @Override public Message next() { - Message message = Message.fromCursor(cursor); + Message message = Message.fromCursor(cursor, conversation); cursor.moveToNext(); return message; } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index c9fc7aeb2..e7526e315 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -400,7 +400,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa private void sendMessage() { final String body = mEditMessage.getText().toString(); - if (body.length() == 0 || this.conversation == null) { + final Conversation conversation = this.conversation; + if (body.length() == 0 || conversation == null) { return; } final Message message; @@ -418,7 +419,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa message.setEdited(message.getUuid()); message.setUuid(UUID.randomUUID().toString()); } - switch (conversation.getNextEncryption()) { + switch (message.getConversation().getNextEncryption()) { case Message.ENCRYPTION_OTR: sendOtrMessage(message); break; |