aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/siacs/conversations/xmpp')
-rw-r--r--src/eu/siacs/conversations/xmpp/XmppConnection.java49
-rw-r--r--src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java9
2 files changed, 44 insertions, 14 deletions
diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java
index 1f0f23a23..dadd310aa 100644
--- a/src/eu/siacs/conversations/xmpp/XmppConnection.java
+++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java
@@ -15,6 +15,7 @@ import java.security.SecureRandom;
import java.security.cert.CertPathValidatorException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
@@ -66,6 +67,7 @@ public class XmppConnection implements Runnable {
private boolean shouldAuthenticate = true;
private Element streamFeatures;
private HashSet<String> discoFeatures = new HashSet<String>();
+ private List<String> discoItems = new ArrayList<String>();
private String streamId = null;
@@ -550,7 +552,8 @@ public class XmppConnection implements Runnable {
tagWriter.writeStanzaAsync(enable);
}
sendInitialPresence();
- sendServiceDiscovery();
+ sendServiceDiscoveryInfo();
+ sendServiceDiscoveryItems();
if (statusListener != null) {
statusListener.onStatusChanged(account);
}
@@ -558,32 +561,45 @@ public class XmppConnection implements Runnable {
});
}
- private void sendServiceDiscovery() {
+ private void sendServiceDiscoveryInfo() {
IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
- iq.setAttribute("to", account.getServer());
- Element query = new Element("query");
- query.setAttribute("xmlns", "http://jabber.org/protocol/disco#info");
- iq.addChild(query);
+ iq.setTo(account.getServer());
+ iq.query("http://jabber.org/protocol/disco#info");
this.sendIqPacket(iq, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket packet) {
- if (packet.hasChild("query")) {
- List<Element> elements = packet.findChild("query")
- .getChildren();
+ List<Element> elements = packet.query().getChildren();
for (int i = 0; i < elements.size(); ++i) {
if (elements.get(i).getName().equals("feature")) {
discoFeatures.add(elements.get(i).getAttribute(
"var"));
}
}
- }
if (discoFeatures.contains("urn:xmpp:carbons:2")) {
sendEnableCarbons();
}
}
});
}
+ private void sendServiceDiscoveryItems() {
+ IqPacket iq = new IqPacket(IqPacket.TYPE_GET);
+ iq.setTo(account.getServer());
+ iq.query("http://jabber.org/protocol/disco#items");
+ this.sendIqPacket(iq, new OnIqPacketReceived() {
+
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket packet) {
+ List<Element> elements = packet.query().getChildren();
+ for (int i = 0; i < elements.size(); ++i) {
+ if (elements.get(i).getName().equals("item")) {
+ discoItems.add(elements.get(i).getAttribute(
+ "jid"));
+ }
+ }
+ }
+ });
+ }
private void sendEnableCarbons() {
IqPacket iq = new IqPacket(IqPacket.TYPE_SET);
@@ -754,4 +770,17 @@ public class XmppConnection implements Runnable {
public int getSentStanzas() {
return this.stanzasSent;
}
+
+ public String getMucServer() {
+ for(int i = 0; i < discoItems.size(); ++i) {
+ if (discoItems.get(i).contains("conference.")) {
+ return discoItems.get(i);
+ } else if (discoItems.get(i).contains("conf.")) {
+ return discoItems.get(i);
+ } else if (discoItems.get(i).contains("muc.")) {
+ return discoItems.get(i);
+ }
+ }
+ return null;
+ }
}
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java
index f31a78e64..941bda4f8 100644
--- a/src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java
+++ b/src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java
@@ -5,7 +5,7 @@ import eu.siacs.conversations.xml.Element;
public class MessagePacket extends AbstractStanza {
public static final int TYPE_CHAT = 0;
public static final int TYPE_UNKNOWN = 1;
- public static final int TYPE_NO = 2;
+ public static final int TYPE_NORMAL = 2;
public static final int TYPE_GROUPCHAT = 3;
public static final int TYPE_ERROR = 4;
@@ -46,9 +46,10 @@ public class MessagePacket extends AbstractStanza {
public int getType() {
String type = getAttribute("type");
if (type==null) {
- return TYPE_NO;
- }
- if (type.equals("chat")) {
+ return TYPE_NORMAL;
+ } else if (type.equals("normal")) {
+ return TYPE_NORMAL;
+ } else if (type.equals("chat")) {
return TYPE_CHAT;
} else if (type.equals("groupchat")) {
return TYPE_GROUPCHAT;