From 4f902d8210d50a586c7ece1bb7da2ab26fd18da5 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 27 Jan 2014 20:40:42 +0100 Subject: conversation archiveable. new conversation will find or restart old conversations --- src/de/gultsch/chat/entities/Conversation.java | 27 ++++++++++++++++++++++++++ src/de/gultsch/chat/entities/Message.java | 11 ++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) (limited to 'src/de/gultsch/chat/entities') diff --git a/src/de/gultsch/chat/entities/Conversation.java b/src/de/gultsch/chat/entities/Conversation.java index 413e3d626..a00dd476a 100644 --- a/src/de/gultsch/chat/entities/Conversation.java +++ b/src/de/gultsch/chat/entities/Conversation.java @@ -53,8 +53,31 @@ public class Conversation extends AbstractEntity { public List getMessages() { if (messages == null) this.messages = new ArrayList(); //prevent null pointer + + //populate with Conversation (this) + + for(Message msg : messages) { + msg.setConversation(this); + } + return messages; } + + public String getLatestMessage() { + if ((this.messages == null)||(this.messages.size()==0)) { + return null; + } else { + return this.messages.get(this.messages.size() - 1).getBody(); + } + } + + public long getLatestMessageDate() { + if ((this.messages == null)||(this.messages.size()==0)) { + return this.getCreated(); + } else { + return this.messages.get(this.messages.size() - 1).getTimeSent(); + } + } public void setMessages(List msgs) { this.messages = msgs; @@ -112,4 +135,8 @@ public class Conversation extends AbstractEntity { cursor.getLong(cursor.getColumnIndex(CREATED)), cursor.getInt(cursor.getColumnIndex(STATUS))); } + + public void setStatus(int status) { + this.status = status; + } } diff --git a/src/de/gultsch/chat/entities/Message.java b/src/de/gultsch/chat/entities/Message.java index 26e646ff4..b52e44b4e 100644 --- a/src/de/gultsch/chat/entities/Message.java +++ b/src/de/gultsch/chat/entities/Message.java @@ -35,8 +35,9 @@ public class Message extends AbstractEntity { public Message(Conversation conversation, String body, int encryption) { this(java.util.UUID.randomUUID().toString(), conversation.getUuid(), - conversation.getContactJid(), body, 0, encryption, + conversation.getContactJid(), body, System.currentTimeMillis(), encryption, Message.STATUS_UNSEND); + this.conversation = conversation; } public Message(String uuid, String conversationUUid, String counterpart, @@ -66,6 +67,10 @@ public class Message extends AbstractEntity { public String getConversationUuid() { return conversationUuid; } + + public Conversation getConversation() { + return this.conversation; + } public String getCounterpart() { return counterpart; @@ -97,4 +102,8 @@ public class Message extends AbstractEntity { cursor.getInt(cursor.getColumnIndex(STATUS))); } + public void setConversation(Conversation conv) { + this.conversation = conv; + } + } -- cgit v1.2.3