aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/entities/MucOptions.java5
-rw-r--r--src/main/java/de/pixart/messenger/generator/IqGenerator.java24
-rw-r--r--src/main/java/de/pixart/messenger/parser/IqParser.java25
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java35
-rw-r--r--src/main/java/de/pixart/messenger/utils/Namespace.java1
-rw-r--r--src/main/java/de/pixart/messenger/xmpp/XmppConnection.java4
6 files changed, 84 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/MucOptions.java b/src/main/java/de/pixart/messenger/entities/MucOptions.java
index c3050f3fa..d1e30062a 100644
--- a/src/main/java/de/pixart/messenger/entities/MucOptions.java
+++ b/src/main/java/de/pixart/messenger/entities/MucOptions.java
@@ -17,6 +17,7 @@ import de.pixart.messenger.R;
import de.pixart.messenger.services.AvatarService;
import de.pixart.messenger.services.MessageArchiveService;
import de.pixart.messenger.utils.JidHelper;
+import de.pixart.messenger.utils.Namespace;
import de.pixart.messenger.utils.UIHelper;
import de.pixart.messenger.xmpp.chatstate.ChatState;
import de.pixart.messenger.xmpp.forms.Data;
@@ -114,6 +115,10 @@ public class MucOptions {
return MessageArchiveService.Version.has(getFeatures());
}
+ public boolean push() {
+ return getFeatures().contains(Namespace.PUSH);
+ }
+
public boolean updateConfiguration(ServiceDiscoveryResult serviceDiscoveryResult) {
this.serviceDiscoveryResult = serviceDiscoveryResult;
String name;
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
index 16e585a18..feb1473db 100644
--- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
@@ -446,16 +446,26 @@ public class IqGenerator extends AbstractGenerator {
return packet;
}
- public IqPacket enablePush(Jid jid, String node, String secret) {
+ public IqPacket enablePush(final Jid jid, final String node, final String secret) {
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
- Element enable = packet.addChild("enable", "urn:xmpp:push:0");
+ Element enable = packet.addChild("enable", Namespace.PUSH);
enable.setAttribute("jid", jid.toString());
enable.setAttribute("node", node);
- Data data = new Data();
- data.setFormType(Namespace.PUBSUB_PUBLISH_OPTIONS);
- data.put("secret", secret);
- data.submit();
- enable.addChild(data);
+ if (secret != null) {
+ Data data = new Data();
+ data.setFormType(Namespace.PUBSUB_PUBLISH_OPTIONS);
+ data.put("secret", secret);
+ data.submit();
+ enable.addChild(data);
+ }
+ return packet;
+ }
+
+ public IqPacket disablePush(final Jid jid, final String node) {
+ IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
+ Element disable = packet.addChild("disable", Namespace.PUSH);
+ disable.setAttribute("jid", jid.toString());
+ disable.setAttribute("node", node);
return packet;
}
diff --git a/src/main/java/de/pixart/messenger/parser/IqParser.java b/src/main/java/de/pixart/messenger/parser/IqParser.java
index 24e8aad98..c3bd85922 100644
--- a/src/main/java/de/pixart/messenger/parser/IqParser.java
+++ b/src/main/java/de/pixart/messenger/parser/IqParser.java
@@ -26,6 +26,7 @@ import de.pixart.messenger.Config;
import de.pixart.messenger.crypto.axolotl.AxolotlService;
import de.pixart.messenger.entities.Account;
import de.pixart.messenger.entities.Contact;
+import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.services.XmppConnectionService;
import de.pixart.messenger.utils.Namespace;
import de.pixart.messenger.xml.Element;
@@ -382,6 +383,29 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
response = mXmppConnectionService.getIqGenerator().entityTimeResponse(packet);
}
mXmppConnectionService.sendIqPacket(account, response, null);
+ } else if (packet.hasChild("pubsub", Namespace.PUBSUB) && packet.getType() == IqPacket.TYPE.SET) {
+ final Jid server = packet.getFrom();
+ final Element pubsub = packet.findChild("pubsub", Namespace.PUBSUB);
+ final Element publish = pubsub == null ? null : pubsub.findChild("publish");
+ final String node = publish == null ? null : publish.getAttribute("node");
+ final Element item = publish == null ? null : publish.findChild("item");
+ final Element notification = item == null ? null : item.findChild("notification", Namespace.PUSH);
+ if (notification != null && node != null && server != null) {
+ final Conversation conversation = mXmppConnectionService.findConversationByUuid(node);
+ if (conversation != null && conversation.getAccount() == account && conversation.getJid().getDomain().equals(server.getDomain())) {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received muc push event for " + conversation.getJid().asBareJid());
+ mXmppConnectionService.sendIqPacket(account, packet.generateResponse(IqPacket.TYPE.RESULT), null);
+ mXmppConnectionService.mucSelfPingAndRejoin(conversation);
+ } else {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": received push event for unknown conference from " + server);
+ final IqPacket response = packet.generateResponse(IqPacket.TYPE.ERROR);
+ final Element error = response.addChild("error");
+ error.setAttribute("type", "cancel");
+ error.addChild("item-not-found", "urn:ietf:params:xml:ns:xmpp-stanzas");
+ mXmppConnectionService.sendIqPacket(account, response, null);
+ }
+ }
+
} else {
if (packet.getType() == IqPacket.TYPE.GET || packet.getType() == IqPacket.TYPE.SET) {
final IqPacket response = packet.generateResponse(IqPacket.TYPE.ERROR);
@@ -392,5 +416,4 @@ public class IqParser extends AbstractParser implements OnIqPacketReceived {
}
}
}
-
}
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 8ce549e8c..b9945de0a 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -2803,6 +2803,9 @@ public class XmppConnectionService extends Service {
saveConversationAsBookmark(conversation, null);
}
}
+ if (mucOptions.push()) {
+ enableMucPush(conversation);
+ }
synchronized (account.inProgressConferenceJoins) {
account.inProgressConferenceJoins.remove(conversation);
sendUnsentMessages(conversation);
@@ -2845,6 +2848,35 @@ public class XmppConnectionService extends Service {
}
}
+ private void enableMucPush(final Conversation conversation) {
+ final Account account = conversation.getAccount();
+ final Jid room = conversation.getJid().asBareJid();
+ final IqPacket enable = mIqGenerator.enablePush(conversation.getAccount().getJid(), conversation.getUuid(), null);
+ enable.setTo(room);
+ sendIqPacket(account, enable, (a, response) -> {
+ if (response.getType() == IqPacket.TYPE.RESULT) {
+ Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": enabled push for muc " + room);
+ } else if (response.getType() == IqPacket.TYPE.ERROR) {
+ Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": unable to enable push for muc " + room + " " + response.getError());
+ }
+ });
+
+ }
+
+ private void disableMucPush(final Conversation conversation) {
+ final Account account = conversation.getAccount();
+ final Jid room = conversation.getJid().asBareJid();
+ final IqPacket disable = mIqGenerator.disablePush(conversation.getAccount().getJid(), conversation.getUuid());
+ disable.setTo(room);
+ sendIqPacket(account, disable, (a, response) -> {
+ if (response.getType() == IqPacket.TYPE.RESULT) {
+ Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": disabled push for muc " + room);
+ } else if (response.getType() == IqPacket.TYPE.ERROR) {
+ Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": unable to disable push for muc " + room + " " + response.getError());
+ }
+ });
+ }
+
private void fetchConferenceMembers(final Conversation conversation) {
final Account account = conversation.getAccount();
final AxolotlService axolotlService = account.getAxolotlService();
@@ -3025,6 +3057,9 @@ public class XmppConnectionService extends Service {
account.pendingConferenceJoins.remove(conversation);
account.pendingConferenceLeaves.remove(conversation);
if (account.getStatus() == Account.State.ONLINE || now) {
+ if (conversation.getMucOptions().push()) {
+ disableMucPush(conversation);
+ }
sendPresencePacket(conversation.getAccount(), mPresenceGenerator.leave(conversation.getMucOptions()));
conversation.getMucOptions().setOffline();
Bookmark bookmark = conversation.getBookmark();
diff --git a/src/main/java/de/pixart/messenger/utils/Namespace.java b/src/main/java/de/pixart/messenger/utils/Namespace.java
index a28adb20c..d46bb6d32 100644
--- a/src/main/java/de/pixart/messenger/utils/Namespace.java
+++ b/src/main/java/de/pixart/messenger/utils/Namespace.java
@@ -28,4 +28,5 @@ public final class Namespace {
public static final String JINGLE_TRANSPORTS_S5B = "urn:xmpp:jingle:transports:s5b:1";
public static final String JINGLE_TRANSPORTS_IBB = "urn:xmpp:jingle:transports:ibb:1";
public static final String PING = "urn:xmpp:ping";
+ public static final String PUSH = "urn:xmpp:push:0";
}
diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
index 28ea68d4e..9a72203b7 100644
--- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
+++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java
@@ -1907,8 +1907,8 @@ public class XmppConnection implements Runnable {
}
public boolean push() {
- return hasDiscoFeature(account.getJid().asBareJid(), "urn:xmpp:push:0")
- || hasDiscoFeature(Jid.of(account.getServer()), "urn:xmpp:push:0");
+ return hasDiscoFeature(account.getJid().asBareJid(), Namespace.PUSH)
+ || hasDiscoFeature(Jid.of(account.getServer()), Namespace.PUSH);
}
public boolean rosterVersioning() {