send push enable to server. simplified logging
This commit is contained in:
parent
c7a14092a8
commit
6f9f871928
|
@ -15,6 +15,8 @@ import java.util.TimeZone;
|
||||||
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
|
||||||
import eu.siacs.conversations.services.XmppConnectionService;
|
import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.utils.PhoneHelper;
|
import eu.siacs.conversations.utils.PhoneHelper;
|
||||||
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
|
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
||||||
|
|
||||||
public abstract class AbstractGenerator {
|
public abstract class AbstractGenerator {
|
||||||
private final String[] FEATURES = {
|
private final String[] FEATURES = {
|
||||||
|
|
|
@ -25,6 +25,7 @@ import eu.siacs.conversations.services.XmppConnectionService;
|
||||||
import eu.siacs.conversations.utils.Xmlns;
|
import eu.siacs.conversations.utils.Xmlns;
|
||||||
import eu.siacs.conversations.xml.Element;
|
import eu.siacs.conversations.xml.Element;
|
||||||
import eu.siacs.conversations.xmpp.forms.Data;
|
import eu.siacs.conversations.xmpp.forms.Data;
|
||||||
|
import eu.siacs.conversations.xmpp.forms.Field;
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
import eu.siacs.conversations.xmpp.pep.Avatar;
|
import eu.siacs.conversations.xmpp.pep.Avatar;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
||||||
|
@ -321,4 +322,16 @@ public class IqGenerator extends AbstractGenerator {
|
||||||
command.addChild(data);
|
command.addChild(data);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IqPacket enablePush(Jid jid, String node, String secret) {
|
||||||
|
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
|
Element enable = packet.addChild("enable","urn:xmpp:push:0");
|
||||||
|
enable.setAttribute("jid",jid.toString());
|
||||||
|
enable.setAttribute("node", node);
|
||||||
|
Data data = new Data();
|
||||||
|
data.setFormType("http://jabber.org/protocol/pubsub#publish-options");
|
||||||
|
data.put("secret",secret);
|
||||||
|
enable.addChild(data);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,8 +80,13 @@ public class Data extends Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFormType() {
|
public String getFormType() {
|
||||||
Field typeFiled = this.getFieldByName("FORM_TYPE");
|
String type = getValue("FORM_TYPE");
|
||||||
return typeFiled == null ? "" : typeFiled.getValue();
|
return type == null ? "" : type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue(String name) {
|
||||||
|
Field field = this.getFieldByName(name);
|
||||||
|
return field == null ? null : field.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
|
|
|
@ -13,7 +13,9 @@ import java.io.IOException;
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
|
import eu.siacs.conversations.xml.Element;
|
||||||
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
|
import eu.siacs.conversations.xmpp.OnIqPacketReceived;
|
||||||
|
import eu.siacs.conversations.xmpp.forms.Data;
|
||||||
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
|
||||||
import eu.siacs.conversations.xmpp.jid.Jid;
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
||||||
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
import eu.siacs.conversations.xmpp.stanzas.IqPacket;
|
||||||
|
@ -39,7 +41,25 @@ public class PushManagementService {
|
||||||
mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {
|
mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {
|
||||||
@Override
|
@Override
|
||||||
public void onIqPacketReceived(Account account, IqPacket packet) {
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
||||||
Log.d(Config.LOGTAG, "push to app server result: " + packet.toString());
|
Element command = packet.findChild("command","http://jabber.org/protocol/commands");
|
||||||
|
if (packet.getType() == IqPacket.TYPE.RESULT && command != null) {
|
||||||
|
Element x = command.findChild("x","jabber:x:data");
|
||||||
|
if (x != null) {
|
||||||
|
Data data = Data.parse(x);
|
||||||
|
try {
|
||||||
|
String node = data.getValue("node");
|
||||||
|
String secret = data.getValue("secret");
|
||||||
|
Jid jid = Jid.fromString(data.getValue("jid"));
|
||||||
|
if (node != null && secret != null) {
|
||||||
|
enablePushOnServer(account, jid, node, secret);
|
||||||
|
}
|
||||||
|
} catch (InvalidJidException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": invalid response from app server");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (InvalidJidException ignored) {
|
} catch (InvalidJidException ignored) {
|
||||||
|
@ -49,6 +69,20 @@ public class PushManagementService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enablePushOnServer(final Account account, final Jid jid, final String node, final String secret) {
|
||||||
|
IqPacket enable = mXmppConnectionService.getIqGenerator().enablePush(jid, node, secret);
|
||||||
|
mXmppConnectionService.sendIqPacket(account, enable, new OnIqPacketReceived() {
|
||||||
|
@Override
|
||||||
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
||||||
|
if (packet.getType() == IqPacket.TYPE.RESULT) {
|
||||||
|
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": successfully enabled push on server");
|
||||||
|
} else if (packet.getType() == IqPacket.TYPE.ERROR) {
|
||||||
|
Log.d(Config.LOGTAG,account.getJid().toBareJid()+": enabling push on server failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void retrieveGcmInstanceToken(final OnGcmInstanceTokenRetrieved instanceTokenRetrieved) {
|
private void retrieveGcmInstanceToken(final OnGcmInstanceTokenRetrieved instanceTokenRetrieved) {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue