mirror of
https://github.com/moparisthebest/Conversations
synced 2024-11-28 03:32:15 -05:00
code cleanup: made conversation property final in message object
This commit is contained in:
parent
f6c1af2b06
commit
a5e15d5a10
@ -472,7 +472,6 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
|
|||||||
return message;
|
return message;
|
||||||
} else {
|
} else {
|
||||||
Message message = this.messages.get(this.messages.size() - 1);
|
Message message = this.messages.get(this.messages.size() - 1);
|
||||||
message.setConversation(this);
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -939,14 +938,12 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void add(Message message) {
|
public void add(Message message) {
|
||||||
message.setConversation(this);
|
|
||||||
synchronized (this.messages) {
|
synchronized (this.messages) {
|
||||||
this.messages.add(message);
|
this.messages.add(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void prepend(Message message) {
|
public void prepend(Message message) {
|
||||||
message.setConversation(this);
|
|
||||||
synchronized (this.messages) {
|
synchronized (this.messages) {
|
||||||
this.messages.add(0,message);
|
this.messages.add(0,message);
|
||||||
}
|
}
|
||||||
|
@ -80,15 +80,15 @@ public class Message extends AbstractEntity {
|
|||||||
protected boolean read = true;
|
protected boolean read = true;
|
||||||
protected String remoteMsgId = null;
|
protected String remoteMsgId = null;
|
||||||
protected String serverMsgId = null;
|
protected String serverMsgId = null;
|
||||||
protected Conversation conversation = null;
|
private final Conversation conversation;
|
||||||
protected Transferable transferable = null;
|
protected Transferable transferable = null;
|
||||||
private Message mNextMessage = null;
|
private Message mNextMessage = null;
|
||||||
private Message mPreviousMessage = null;
|
private Message mPreviousMessage = null;
|
||||||
private String axolotlFingerprint = null;
|
private String axolotlFingerprint = null;
|
||||||
private String errorMessage = null;
|
private String errorMessage = null;
|
||||||
|
|
||||||
private Message() {
|
private Message(Conversation conversation) {
|
||||||
|
this.conversation = conversation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message(Conversation conversation, String body, int encryption) {
|
public Message(Conversation conversation, String body, int encryption) {
|
||||||
@ -96,7 +96,7 @@ public class Message extends AbstractEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Message(Conversation conversation, String body, int encryption, int status) {
|
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.getUuid(),
|
||||||
conversation.getJid() == null ? null : conversation.getJid().toBareJid(),
|
conversation.getJid() == null ? null : conversation.getJid().toBareJid(),
|
||||||
null,
|
null,
|
||||||
@ -114,15 +114,15 @@ public class Message extends AbstractEntity {
|
|||||||
null,
|
null,
|
||||||
false,
|
false,
|
||||||
null);
|
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 Jid trueCounterpart, final String body, final long timeSent,
|
||||||
final int encryption, final int status, final int type, final boolean carbon,
|
final int encryption, final int status, final int type, final boolean carbon,
|
||||||
final String remoteMsgId, final String relativeFilePath,
|
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 String edited, final boolean oob, final String errorMessage) {
|
final String edited, final boolean oob, final String errorMessage) {
|
||||||
|
this.conversation = conversation;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.conversationUuid = conversationUUid;
|
this.conversationUuid = conversationUUid;
|
||||||
this.counterpart = counterpart;
|
this.counterpart = counterpart;
|
||||||
@ -143,7 +143,7 @@ public class Message extends AbstractEntity {
|
|||||||
this.errorMessage = errorMessage;
|
this.errorMessage = errorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Message fromCursor(Cursor cursor) {
|
public static Message fromCursor(Cursor cursor, Conversation conversation) {
|
||||||
Jid jid;
|
Jid jid;
|
||||||
try {
|
try {
|
||||||
String value = cursor.getString(cursor.getColumnIndex(COUNTERPART));
|
String value = cursor.getString(cursor.getColumnIndex(COUNTERPART));
|
||||||
@ -168,7 +168,8 @@ public class Message extends AbstractEntity {
|
|||||||
} catch (InvalidJidException e) {
|
} catch (InvalidJidException e) {
|
||||||
trueCounterpart = null;
|
trueCounterpart = null;
|
||||||
}
|
}
|
||||||
return new Message(cursor.getString(cursor.getColumnIndex(UUID)),
|
return new Message(conversation,
|
||||||
|
cursor.getString(cursor.getColumnIndex(UUID)),
|
||||||
cursor.getString(cursor.getColumnIndex(CONVERSATION)),
|
cursor.getString(cursor.getColumnIndex(CONVERSATION)),
|
||||||
jid,
|
jid,
|
||||||
trueCounterpart,
|
trueCounterpart,
|
||||||
@ -189,17 +190,15 @@ public class Message extends AbstractEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Message createStatusMessage(Conversation conversation, String body) {
|
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.setType(Message.TYPE_STATUS);
|
||||||
message.setConversation(conversation);
|
|
||||||
message.setBody(body);
|
message.setBody(body);
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Message createLoadMoreMessage(Conversation conversation) {
|
public static Message createLoadMoreMessage(Conversation conversation) {
|
||||||
final Message message = new Message();
|
final Message message = new Message(conversation);
|
||||||
message.setType(Message.TYPE_STATUS);
|
message.setType(Message.TYPE_STATUS);
|
||||||
message.setConversation(conversation);
|
|
||||||
message.setBody("LOAD_MORE");
|
message.setBody("LOAD_MORE");
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
@ -244,10 +243,6 @@ public class Message extends AbstractEntity {
|
|||||||
return this.conversation;
|
return this.conversation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConversation(Conversation conv) {
|
|
||||||
this.conversation = conv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Jid getCounterpart() {
|
public Jid getCounterpart() {
|
||||||
return counterpart;
|
return counterpart;
|
||||||
}
|
}
|
||||||
|
@ -644,9 +644,8 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||||||
if (cursor.getCount() > 0) {
|
if (cursor.getCount() > 0) {
|
||||||
cursor.moveToLast();
|
cursor.moveToLast();
|
||||||
do {
|
do {
|
||||||
Message message = Message.fromCursor(cursor);
|
Message message = Message.fromCursor(cursor,conversation);
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
message.setConversation(conversation);
|
|
||||||
list.add(message);
|
list.add(message);
|
||||||
}
|
}
|
||||||
} while (cursor.moveToPrevious());
|
} while (cursor.moveToPrevious());
|
||||||
@ -677,7 +676,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Message next() {
|
public Message next() {
|
||||||
Message message = Message.fromCursor(cursor);
|
Message message = Message.fromCursor(cursor, conversation);
|
||||||
cursor.moveToNext();
|
cursor.moveToNext();
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,8 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
|||||||
|
|
||||||
private void sendMessage() {
|
private void sendMessage() {
|
||||||
final String body = mEditMessage.getText().toString();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
final Message message;
|
final Message message;
|
||||||
@ -397,7 +398,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
|
|||||||
message.setEdited(message.getUuid());
|
message.setEdited(message.getUuid());
|
||||||
message.setUuid(UUID.randomUUID().toString());
|
message.setUuid(UUID.randomUUID().toString());
|
||||||
}
|
}
|
||||||
switch (conversation.getNextEncryption()) {
|
switch (message.getConversation().getNextEncryption()) {
|
||||||
case Message.ENCRYPTION_OTR:
|
case Message.ENCRYPTION_OTR:
|
||||||
sendOtrMessage(message);
|
sendOtrMessage(message);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user