aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/de/gultsch/chat/entities/Conversation.java2
-rw-r--r--src/de/gultsch/chat/entities/Message.java4
-rw-r--r--src/de/gultsch/chat/persistance/DatabaseBackend.java4
-rw-r--r--src/de/gultsch/chat/services/XmppConnectionService.java28
4 files changed, 31 insertions, 7 deletions
diff --git a/src/de/gultsch/chat/entities/Conversation.java b/src/de/gultsch/chat/entities/Conversation.java
index bddd1356..e0e5623c 100644
--- a/src/de/gultsch/chat/entities/Conversation.java
+++ b/src/de/gultsch/chat/entities/Conversation.java
@@ -73,7 +73,7 @@ public class Conversation extends AbstractEntity {
}
public boolean isRead() {
- if (this.messages == null) return true;
+ if ((this.messages == null)||(this.messages.size() == 0)) return true;
return this.messages.get(this.messages.size() - 1).isRead();
}
diff --git a/src/de/gultsch/chat/entities/Message.java b/src/de/gultsch/chat/entities/Message.java
index d53e93c1..a168c645 100644
--- a/src/de/gultsch/chat/entities/Message.java
+++ b/src/de/gultsch/chat/entities/Message.java
@@ -127,5 +127,9 @@ public class Message extends AbstractEntity {
public void markUnread() {
this.read = false;
}
+
+ public void setTime(long time) {
+ this.timeSent = time;
+ }
}
diff --git a/src/de/gultsch/chat/persistance/DatabaseBackend.java b/src/de/gultsch/chat/persistance/DatabaseBackend.java
index b3290ee0..f746f447 100644
--- a/src/de/gultsch/chat/persistance/DatabaseBackend.java
+++ b/src/de/gultsch/chat/persistance/DatabaseBackend.java
@@ -229,6 +229,10 @@ public class DatabaseBackend extends SQLiteOpenHelper {
}
}
}
+
+ public void mergeMessageIntoConversation(Message message) {
+ // select counterpart,body,(timeSent/1000)-180 as min,(timeSent/1000)+180 as max from messages where min<1392035670 and max>1392035670;
+ }
public List<Contact> getContacts(Account account) {
List<Contact> list = new ArrayList<Contact>();
diff --git a/src/de/gultsch/chat/services/XmppConnectionService.java b/src/de/gultsch/chat/services/XmppConnectionService.java
index 5a43f99f..a7125923 100644
--- a/src/de/gultsch/chat/services/XmppConnectionService.java
+++ b/src/de/gultsch/chat/services/XmppConnectionService.java
@@ -1,6 +1,9 @@
package de.gultsch.chat.services;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Date;
import java.util.Hashtable;
import java.util.List;
@@ -28,12 +31,8 @@ import de.gultsch.chat.xmpp.XmppConnection;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
-import android.content.CursorLoader;
import android.content.Intent;
-import android.content.Loader;
-import android.content.Loader.OnLoadCompleteListener;
import android.database.ContentObserver;
-import android.database.Cursor;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
@@ -115,8 +114,7 @@ public class XmppConnectionService extends Service {
String counterPart = null;
conversation = findOrCreateConversation(account, jid, muc);
if (muc) {
- if ((fromParts.length == 1) || (packet.hasChild("subject"))
- || (packet.hasChild("delay"))) {
+ if ((fromParts.length == 1) || (packet.hasChild("subject"))) {
return;
}
counterPart = fromParts[1];
@@ -129,6 +127,16 @@ public class XmppConnectionService extends Service {
}
Message message = new Message(conversation, counterPart, body,
Message.ENCRYPTION_NONE, status);
+ if (packet.hasChild("delay")) {
+ try {
+ String stamp = packet.findChild("delay").getAttribute("stamp");
+ stamp = stamp.replace("Z","+0000");
+ Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").parse(stamp);
+ message.setTime(date.getTime());
+ } catch (ParseException e) {
+ Log.d(LOGTAG,"error trying to parse date"+e.getMessage());
+ }
+ }
if(notify) {
message.markUnread();
}
@@ -550,7 +558,15 @@ public class XmppConnectionService extends Service {
packet.setAttribute("to", muc + "/" + account.getUsername());
Element x = new Element("x");
x.setAttribute("xmlns", "http://jabber.org/protocol/muc");
+ if (conversation.getMessages().size()!=0) {
+ Element history = new Element("history");
+ history.setAttribute("seconds",(System.currentTimeMillis() - conversation.getLatestMessageDate()) / 1000+"");
+ x.addChild(history);
+ } else {
+ Log.d(LOGTAG,"conversation had no prior messages"+conversation.getMessages().size());
+ }
packet.addChild(x);
+ Log.d(LOGTAG,packet.toString());
connections.get(conversation.getAccount()).sendPresencePacket(packet);
}