aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/entities
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-04-26 20:36:04 +0200
committerChristian Schneppe <christian@pix-art.de>2017-04-26 20:36:04 +0200
commitba792f819234736132ca1cee70ab26954a85572e (patch)
tree364151c40c52cbf434e8c2cba5a96bf6aa7ef4ce /src/main/java/de/pixart/messenger/entities
parentc106bb872eaa042effa0263eded078fd027ff862 (diff)
code cleanup: made conversation property final in message object
Diffstat (limited to 'src/main/java/de/pixart/messenger/entities')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java3
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java30
2 files changed, 12 insertions, 21 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;
}