aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-07-01 08:35:00 +0200
committerChristian Schneppe <christian@pix-art.de>2019-07-01 08:35:00 +0200
commit66a57e01292d576dc7df6480ad8f3fa9090094d5 (patch)
treeb1a856154ee4857612c0747da1c2179bd87460ac /src/main/java
parent226d45a136d84ac8a95d25aa0c083c4fc471f1f4 (diff)
implement FCM push for group chats
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java1
-rw-r--r--src/main/java/de/pixart/messenger/generator/IqGenerator.java15
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java20
-rw-r--r--src/main/java/de/pixart/messenger/utils/Namespace.java1
4 files changed, 26 insertions, 11 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java
index b3e92fba2..d38a40888 100644
--- a/src/main/java/de/pixart/messenger/entities/Conversation.java
+++ b/src/main/java/de/pixart/messenger/entities/Conversation.java
@@ -57,6 +57,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
public static final String ATTRIBUTE_MUTED_TILL = "muted_till";
public static final String ATTRIBUTE_ALWAYS_NOTIFY = "always_notify";
+ public static final String ATTRIBUTE_PUSH_NODE = "push_node";
public static final String ATTRIBUTE_LAST_CLEAR_HISTORY = "last_clear_history";
static final String ATTRIBUTE_MUC_PASSWORD = "muc_password";
private static final String ATTRIBUTE_NEXT_MESSAGE = "next_message";
diff --git a/src/main/java/de/pixart/messenger/generator/IqGenerator.java b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
index feb1473db..ad977c7b4 100644
--- a/src/main/java/de/pixart/messenger/generator/IqGenerator.java
+++ b/src/main/java/de/pixart/messenger/generator/IqGenerator.java
@@ -433,14 +433,21 @@ public class IqGenerator extends AbstractGenerator {
}
public IqPacket pushTokenToAppServer(Jid appServer, String token, String deviceId) {
- IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
+ return pushTokenToAppServer(appServer, token, deviceId, null);
+ }
+
+ public IqPacket pushTokenToAppServer(Jid appServer, String token, String deviceId, Jid muc) {
+ final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
packet.setTo(appServer);
- Element command = packet.addChild("command", "http://jabber.org/protocol/commands");
+ final Element command = packet.addChild("command", Namespace.COMMANDS);
command.setAttribute("node", "register-push-fcm");
command.setAttribute("action", "execute");
- Data data = new Data();
+ final Data data = new Data();
data.put("token", token);
data.put("android-id", deviceId);
+ if (muc != null) {
+ data.put("muc", muc.toEscapedString());
+ }
data.submit();
command.addChild(data);
return packet;
@@ -464,7 +471,7 @@ public class IqGenerator extends AbstractGenerator {
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("jid", jid.toEscapedString());
disable.setAttribute("node", node);
return packet;
}
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index bad55aed9..9d9be2a5b 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -2854,31 +2854,35 @@ public class XmppConnectionService extends Service {
}
}
- private void enableMucPush(final Conversation conversation) {
+ private void enableDirectMucPush(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);
+ Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": enabled direct 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());
+ Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": unable to enable direct push for muc " + room + " " + response.getError());
}
});
+ }
+ private void enableMucPush(final Conversation conversation) {
+ enableDirectMucPush(conversation);
+ mPushManagementService.registerPushTokenOnServer(conversation);
}
- private void disableMucPush(final Conversation conversation) {
+ private void disableDirectMucPush(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);
+ Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": disabled direct 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());
+ Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": unable to disable direct push for muc " + room + " " + response.getError());
}
});
}
@@ -3064,7 +3068,8 @@ public class XmppConnectionService extends Service {
account.pendingConferenceLeaves.remove(conversation);
if (account.getStatus() == Account.State.ONLINE || now) {
if (conversation.getMucOptions().push()) {
- disableMucPush(conversation);
+ disableDirectMucPush(conversation);
+ mPushManagementService.disablePushOnServer(conversation);
}
sendPresencePacket(conversation.getAccount(), mPresenceGenerator.leave(conversation.getMucOptions()));
conversation.getMucOptions().setOffline();
@@ -4409,6 +4414,7 @@ public class XmppConnectionService extends Service {
for (Account account : getAccounts()) {
if (account.isOnlineAndConnected() && mPushManagementService.available(account)) {
mPushManagementService.registerPushTokenOnServer(account);
+ //TODO renew mucs
}
}
}
diff --git a/src/main/java/de/pixart/messenger/utils/Namespace.java b/src/main/java/de/pixart/messenger/utils/Namespace.java
index d46bb6d32..e9af9f4a4 100644
--- a/src/main/java/de/pixart/messenger/utils/Namespace.java
+++ b/src/main/java/de/pixart/messenger/utils/Namespace.java
@@ -29,4 +29,5 @@ public final class Namespace {
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";
+ public static final String COMMANDS = "http://jabber.org/protocol/commands";
}