aboutsummaryrefslogtreecommitdiffstats
path: root/src/de/gultsch/chat/services
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-02 17:53:34 +0100
committerDaniel Gultsch <daniel.gultsch@rwth-aachen.de>2014-02-02 17:53:34 +0100
commit3d9294684c739cc54de8dfa08ad22097ca8a1811 (patch)
tree28f5bd5b6f5dfa7c955db5a0b8ac25fc8bcfd443 /src/de/gultsch/chat/services
parentbbdaf5b0bd7c42729aeba12f3b4ea4cabc794c4f (diff)
tls is no optional
Diffstat (limited to 'src/de/gultsch/chat/services')
-rw-r--r--src/de/gultsch/chat/services/XmppConnectionService.java90
1 files changed, 48 insertions, 42 deletions
diff --git a/src/de/gultsch/chat/services/XmppConnectionService.java b/src/de/gultsch/chat/services/XmppConnectionService.java
index 2fc3c937e..d7ee76eec 100644
--- a/src/de/gultsch/chat/services/XmppConnectionService.java
+++ b/src/de/gultsch/chat/services/XmppConnectionService.java
@@ -46,18 +46,19 @@ public class XmppConnectionService extends Service {
@Override
public void onMessagePacketReceived(Account account, MessagePacket packet) {
- String fullJid = packet.getFrom();
- String jid = fullJid.split("/")[0];
- String name = jid.split("@")[0];
- Log.d(LOGTAG,"message received for "+account.getJid()+" from "+jid);
- Log.d(LOGTAG,packet.toString());
- Contact contact = new Contact(account,name,jid,null); //dummy contact
- Conversation conversation = findOrCreateConversation(account, contact);
- Message message = new Message(conversation, fullJid, packet.getBody(), Message.ENCRYPTION_NONE, Message.STATUS_RECIEVED);
- conversation.getMessages().add(message);
- databaseBackend.createMessage(message);
- if (convChangedListener != null) {
- convChangedListener.onConversationListChanged();
+ if (packet.getType()==MessagePacket.TYPE_CHAT) {
+ Log.d(LOGTAG,account.getJid()+": message of type chat");
+ String fullJid = packet.getFrom();
+ String jid = fullJid.split("/")[0];
+ String name = jid.split("@")[0];
+ Contact contact = new Contact(account,name,jid,null); //dummy contact
+ Conversation conversation = findOrCreateConversation(account, contact);
+ Message message = new Message(conversation, fullJid, packet.getBody(), Message.ENCRYPTION_NONE, Message.STATUS_RECIEVED);
+ conversation.getMessages().add(message);
+ databaseBackend.createMessage(message);
+ if (convChangedListener != null) {
+ convChangedListener.onConversationListChanged();
+ }
}
}
};
@@ -117,36 +118,41 @@ public class XmppConnectionService extends Service {
}
public void getRoster(final Account account, final OnRosterFetchedListener listener) {
- IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET);
- Element query = new Element("query");
- query.setAttribute("xmlns", "jabber:iq:roster");
- query.setAttribute("ver", "");
- iqPacket.addChild(query);
- try {
- connections.get(account).sendIqPacket(iqPacket, new OnIqPacketReceived() {
-
- @Override
- public void onIqPacketReceived(Account account, IqPacket packet) {
- Element roster = packet.findChild("query");
- Log.d(LOGTAG,roster.toString());
- List<Contact> contacts = new ArrayList<Contact>();
- for(Element item : roster.getChildren()) {
- String name = item.getAttribute("name");
- String jid = item.getAttribute("jid");
- if (name==null) {
- name = jid.split("@")[0];
- }
- Contact contact = new Contact(account, name, jid, null);
- contacts.add(contact);
- }
- if (listener != null) {
- listener.onRosterFetched(contacts);
- }
- }
- });
- } catch (IOException e) {
- Log.d(LOGTAG,"io error during roster fetch");
- }
+ new Thread() {
+ @Override
+ public void run() {
+ IqPacket iqPacket = new IqPacket(IqPacket.TYPE_GET);
+ Element query = new Element("query");
+ query.setAttribute("xmlns", "jabber:iq:roster");
+ query.setAttribute("ver", "");
+ iqPacket.addChild(query);
+ try {
+ connections.get(account).sendIqPacket(iqPacket, new OnIqPacketReceived() {
+
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ Element roster = packet.findChild("query");
+ Log.d(LOGTAG,roster.toString());
+ List<Contact> contacts = new ArrayList<Contact>();
+ for(Element item : roster.getChildren()) {
+ String name = item.getAttribute("name");
+ String jid = item.getAttribute("jid");
+ if (name==null) {
+ name = jid.split("@")[0];
+ }
+ Contact contact = new Contact(account, name, jid, null);
+ contacts.add(contact);
+ }
+ if (listener != null) {
+ listener.onRosterFetched(contacts);
+ }
+ }
+ });
+ } catch (IOException e) {
+ Log.d(LOGTAG,"io error during roster fetch");
+ }
+ }
+ }.start();
}
public void addConversation(Conversation conversation) {