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 --- .../chat/services/XmppConnectionService.java | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/de/gultsch/chat/services') diff --git a/src/de/gultsch/chat/services/XmppConnectionService.java b/src/de/gultsch/chat/services/XmppConnectionService.java index 67e3901e7..20af97420 100644 --- a/src/de/gultsch/chat/services/XmppConnectionService.java +++ b/src/de/gultsch/chat/services/XmppConnectionService.java @@ -2,6 +2,8 @@ package de.gultsch.chat.services; import java.util.List; +import de.gultsch.chat.entities.Account; +import de.gultsch.chat.entities.Contact; import de.gultsch.chat.entities.Conversation; import de.gultsch.chat.entities.Message; import de.gultsch.chat.persistance.DatabaseBackend; @@ -35,15 +37,39 @@ public class XmppConnectionService extends Service { } public void sendMessage(Message message) { - Log.d(LOGTAG,"sending message"); + databaseBackend.createMessage(message); } public void addConversation(Conversation conversation) { - databaseBackend.addConversation(conversation); + databaseBackend.createConversation(conversation); } public List getConversations(int status) { return databaseBackend.getConversations(status); } + + public List getMessages(Conversation conversation) { + return databaseBackend.getMessages(conversation, 100); + } + public Conversation findOrCreateConversation(Account account, Contact contact) { + Conversation conversation = databaseBackend.findConversation(account, contact); + if (conversation!=null) { + Log.d("gultsch","found one. unarchive it"); + conversation.setStatus(Conversation.STATUS_AVAILABLE); + this.databaseBackend.updateConversation(conversation); + } else { + conversation = new Conversation(contact.getDisplayName(), contact.getProfilePhoto(), account, contact.getJid()); + this.databaseBackend.createConversation(conversation); + } + return conversation; + } + + public void updateConversation(Conversation conversation) { + this.databaseBackend.updateConversation(conversation); + } + + public int getConversationCount() { + return this.databaseBackend.getConversationCount(); + } } -- cgit v1.2.3