support for delete bookmarks2
This commit is contained in:
parent
6923b2898c
commit
f1aa5f2cab
|
@ -19,6 +19,7 @@ import eu.siacs.conversations.entities.Account;
|
||||||
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.xml.Namespace;
|
import eu.siacs.conversations.xml.Namespace;
|
||||||
|
import eu.siacs.conversations.xmpp.XmppConnection;
|
||||||
import eu.siacs.conversations.xmpp.jingle.stanzas.Content;
|
import eu.siacs.conversations.xmpp.jingle.stanzas.Content;
|
||||||
|
|
||||||
public abstract class AbstractGenerator {
|
public abstract class AbstractGenerator {
|
||||||
|
@ -38,8 +39,6 @@ public abstract class AbstractGenerator {
|
||||||
"http://jabber.org/protocol/disco#info",
|
"http://jabber.org/protocol/disco#info",
|
||||||
"urn:xmpp:avatar:metadata+notify",
|
"urn:xmpp:avatar:metadata+notify",
|
||||||
Namespace.NICK+"+notify",
|
Namespace.NICK+"+notify",
|
||||||
//Namespace.BOOKMARKS+"+notify",
|
|
||||||
Namespace.BOOKMARK+"+notify",
|
|
||||||
"urn:xmpp:ping",
|
"urn:xmpp:ping",
|
||||||
"jabber:iq:version",
|
"jabber:iq:version",
|
||||||
"http://jabber.org/protocol/chatstates"
|
"http://jabber.org/protocol/chatstates"
|
||||||
|
@ -110,7 +109,8 @@ public abstract class AbstractGenerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getFeatures(Account account) {
|
public List<String> getFeatures(Account account) {
|
||||||
ArrayList<String> features = new ArrayList<>(Arrays.asList(FEATURES));
|
final XmppConnection connection = account.getXmppConnection();
|
||||||
|
final ArrayList<String> features = new ArrayList<>(Arrays.asList(FEATURES));
|
||||||
if (mXmppConnectionService.confirmMessages()) {
|
if (mXmppConnectionService.confirmMessages()) {
|
||||||
features.addAll(Arrays.asList(MESSAGE_CONFIRMATION_FEATURES));
|
features.addAll(Arrays.asList(MESSAGE_CONFIRMATION_FEATURES));
|
||||||
}
|
}
|
||||||
|
@ -126,6 +126,12 @@ public abstract class AbstractGenerator {
|
||||||
if (mXmppConnectionService.broadcastLastActivity()) {
|
if (mXmppConnectionService.broadcastLastActivity()) {
|
||||||
features.add(Namespace.IDLE);
|
features.add(Namespace.IDLE);
|
||||||
}
|
}
|
||||||
|
if (connection != null && connection.getFeatures().bookmarks2()) {
|
||||||
|
features.add(Namespace.BOOKMARK+"+notify");
|
||||||
|
} else {
|
||||||
|
features.add(Namespace.BOOKMARKS+"+notify");
|
||||||
|
}
|
||||||
|
|
||||||
Collections.sort(features);
|
Collections.sort(features);
|
||||||
return features;
|
return features;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,519 +38,528 @@ import rocks.xmpp.addr.Jid;
|
||||||
|
|
||||||
public class IqGenerator extends AbstractGenerator {
|
public class IqGenerator extends AbstractGenerator {
|
||||||
|
|
||||||
public IqGenerator(final XmppConnectionService service) {
|
public IqGenerator(final XmppConnectionService service) {
|
||||||
super(service);
|
super(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket discoResponse(final Account account, final IqPacket request) {
|
public IqPacket discoResponse(final Account account, final IqPacket request) {
|
||||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.RESULT);
|
final IqPacket packet = new IqPacket(IqPacket.TYPE.RESULT);
|
||||||
packet.setId(request.getId());
|
packet.setId(request.getId());
|
||||||
packet.setTo(request.getFrom());
|
packet.setTo(request.getFrom());
|
||||||
final Element query = packet.addChild("query", "http://jabber.org/protocol/disco#info");
|
final Element query = packet.addChild("query", "http://jabber.org/protocol/disco#info");
|
||||||
query.setAttribute("node", request.query().getAttribute("node"));
|
query.setAttribute("node", request.query().getAttribute("node"));
|
||||||
final Element identity = query.addChild("identity");
|
final Element identity = query.addChild("identity");
|
||||||
identity.setAttribute("category", "client");
|
identity.setAttribute("category", "client");
|
||||||
identity.setAttribute("type", getIdentityType());
|
identity.setAttribute("type", getIdentityType());
|
||||||
identity.setAttribute("name", getIdentityName());
|
identity.setAttribute("name", getIdentityName());
|
||||||
for (final String feature : getFeatures(account)) {
|
for (final String feature : getFeatures(account)) {
|
||||||
query.addChild("feature").setAttribute("var", feature);
|
query.addChild("feature").setAttribute("var", feature);
|
||||||
}
|
}
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket versionResponse(final IqPacket request) {
|
public IqPacket versionResponse(final IqPacket request) {
|
||||||
final IqPacket packet = request.generateResponse(IqPacket.TYPE.RESULT);
|
final IqPacket packet = request.generateResponse(IqPacket.TYPE.RESULT);
|
||||||
Element query = packet.query("jabber:iq:version");
|
Element query = packet.query("jabber:iq:version");
|
||||||
query.addChild("name").setContent(mXmppConnectionService.getString(R.string.app_name));
|
query.addChild("name").setContent(mXmppConnectionService.getString(R.string.app_name));
|
||||||
query.addChild("version").setContent(getIdentityVersion());
|
query.addChild("version").setContent(getIdentityVersion());
|
||||||
if ("chromium".equals(android.os.Build.BRAND)) {
|
if ("chromium".equals(android.os.Build.BRAND)) {
|
||||||
query.addChild("os").setContent("Chrome OS");
|
query.addChild("os").setContent("Chrome OS");
|
||||||
} else {
|
} else {
|
||||||
query.addChild("os").setContent("Android");
|
query.addChild("os").setContent("Android");
|
||||||
}
|
}
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket entityTimeResponse(IqPacket request) {
|
public IqPacket entityTimeResponse(IqPacket request) {
|
||||||
final IqPacket packet = request.generateResponse(IqPacket.TYPE.RESULT);
|
final IqPacket packet = request.generateResponse(IqPacket.TYPE.RESULT);
|
||||||
Element time = packet.addChild("time", "urn:xmpp:time");
|
Element time = packet.addChild("time", "urn:xmpp:time");
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
time.addChild("utc").setContent(getTimestamp(now));
|
time.addChild("utc").setContent(getTimestamp(now));
|
||||||
TimeZone ourTimezone = TimeZone.getDefault();
|
TimeZone ourTimezone = TimeZone.getDefault();
|
||||||
long offsetSeconds = ourTimezone.getOffset(now) / 1000;
|
long offsetSeconds = ourTimezone.getOffset(now) / 1000;
|
||||||
long offsetMinutes = Math.abs((offsetSeconds % 3600) / 60);
|
long offsetMinutes = Math.abs((offsetSeconds % 3600) / 60);
|
||||||
long offsetHours = offsetSeconds / 3600;
|
long offsetHours = offsetSeconds / 3600;
|
||||||
String hours;
|
String hours;
|
||||||
if (offsetHours < 0) {
|
if (offsetHours < 0) {
|
||||||
hours = String.format(Locale.US, "%03d", offsetHours);
|
hours = String.format(Locale.US, "%03d", offsetHours);
|
||||||
} else {
|
} else {
|
||||||
hours = String.format(Locale.US, "%02d", offsetHours);
|
hours = String.format(Locale.US, "%02d", offsetHours);
|
||||||
}
|
}
|
||||||
String minutes = String.format(Locale.US, "%02d", offsetMinutes);
|
String minutes = String.format(Locale.US, "%02d", offsetMinutes);
|
||||||
time.addChild("tzo").setContent(hours + ":" + minutes);
|
time.addChild("tzo").setContent(hours + ":" + minutes);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket purgeOfflineMessages() {
|
public IqPacket purgeOfflineMessages() {
|
||||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
packet.addChild("offline", Namespace.FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL).addChild("purge");
|
packet.addChild("offline", Namespace.FLEXIBLE_OFFLINE_MESSAGE_RETRIEVAL).addChild("purge");
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IqPacket publish(final String node, final Element item, final Bundle options) {
|
protected IqPacket publish(final String node, final Element item, final Bundle options) {
|
||||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB);
|
final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB);
|
||||||
final Element publish = pubsub.addChild("publish");
|
final Element publish = pubsub.addChild("publish");
|
||||||
publish.setAttribute("node", node);
|
publish.setAttribute("node", node);
|
||||||
publish.addChild(item);
|
publish.addChild(item);
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
final Element publishOptions = pubsub.addChild("publish-options");
|
final Element publishOptions = pubsub.addChild("publish-options");
|
||||||
publishOptions.addChild(Data.create(Namespace.PUBSUB_PUBLISH_OPTIONS, options));
|
publishOptions.addChild(Data.create(Namespace.PUBSUB_PUBLISH_OPTIONS, options));
|
||||||
}
|
}
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IqPacket publish(final String node, final Element item) {
|
protected IqPacket publish(final String node, final Element item) {
|
||||||
return publish(node, item, null);
|
return publish(node, item, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IqPacket retrieve(String node, Element item) {
|
private IqPacket retrieve(String node, Element item) {
|
||||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
final IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
||||||
final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB);
|
final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB);
|
||||||
final Element items = pubsub.addChild("items");
|
final Element items = pubsub.addChild("items");
|
||||||
items.setAttribute("node", node);
|
items.setAttribute("node", node);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
items.addChild(item);
|
items.addChild(item);
|
||||||
}
|
}
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket retrieveBookmarks() {
|
public IqPacket retrieveBookmarks() {
|
||||||
return retrieve(Namespace.BOOKMARK, null);
|
return retrieve(Namespace.BOOKMARK, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket publishNick(String nick) {
|
public IqPacket publishNick(String nick) {
|
||||||
final Element item = new Element("item");
|
final Element item = new Element("item");
|
||||||
item.addChild("nick", Namespace.NICK).setContent(nick);
|
item.addChild("nick", Namespace.NICK).setContent(nick);
|
||||||
return publish(Namespace.NICK, item);
|
return publish(Namespace.NICK, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket deleteNode(String node) {
|
public IqPacket deleteNode(String node) {
|
||||||
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB_OWNER);
|
final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB_OWNER);
|
||||||
pubsub.addChild("delete").setAttribute("node",node);
|
pubsub.addChild("delete").setAttribute("node", node);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket publishAvatar(Avatar avatar, Bundle options) {
|
public IqPacket deleteItem(final String node, final String id) {
|
||||||
final Element item = new Element("item");
|
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
item.setAttribute("id", avatar.sha1sum);
|
final Element pubsub = packet.addChild("pubsub", Namespace.PUBSUB);
|
||||||
final Element data = item.addChild("data", "urn:xmpp:avatar:data");
|
final Element retract = pubsub.addChild("retract");
|
||||||
data.setContent(avatar.image);
|
retract.setAttribute("node", node);
|
||||||
return publish("urn:xmpp:avatar:data", item, options);
|
retract.addChild("item").setAttribute("id", id);
|
||||||
}
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket publishElement(final String namespace, final Element element, final Bundle options) {
|
public IqPacket publishAvatar(Avatar avatar, Bundle options) {
|
||||||
return publishElement(namespace, element, "curent", options);
|
final Element item = new Element("item");
|
||||||
}
|
item.setAttribute("id", avatar.sha1sum);
|
||||||
|
final Element data = item.addChild("data", "urn:xmpp:avatar:data");
|
||||||
|
data.setContent(avatar.image);
|
||||||
|
return publish("urn:xmpp:avatar:data", item, options);
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket publishElement(final String namespace,final Element element, String id, final Bundle options) {
|
public IqPacket publishElement(final String namespace, final Element element, final Bundle options) {
|
||||||
final Element item = new Element("item");
|
return publishElement(namespace, element, "curent", options);
|
||||||
item.setAttribute("id",id);
|
}
|
||||||
item.addChild(element);
|
|
||||||
return publish(namespace, item, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IqPacket publishAvatarMetadata(final Avatar avatar, final Bundle options) {
|
public IqPacket publishElement(final String namespace, final Element element, String id, final Bundle options) {
|
||||||
final Element item = new Element("item");
|
final Element item = new Element("item");
|
||||||
item.setAttribute("id", avatar.sha1sum);
|
item.setAttribute("id", id);
|
||||||
final Element metadata = item
|
item.addChild(element);
|
||||||
.addChild("metadata", "urn:xmpp:avatar:metadata");
|
return publish(namespace, item, options);
|
||||||
final Element info = metadata.addChild("info");
|
}
|
||||||
info.setAttribute("bytes", avatar.size);
|
|
||||||
info.setAttribute("id", avatar.sha1sum);
|
|
||||||
info.setAttribute("height", avatar.height);
|
|
||||||
info.setAttribute("width", avatar.height);
|
|
||||||
info.setAttribute("type", avatar.type);
|
|
||||||
return publish("urn:xmpp:avatar:metadata", item, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IqPacket retrievePepAvatar(final Avatar avatar) {
|
public IqPacket publishAvatarMetadata(final Avatar avatar, final Bundle options) {
|
||||||
final Element item = new Element("item");
|
final Element item = new Element("item");
|
||||||
item.setAttribute("id", avatar.sha1sum);
|
item.setAttribute("id", avatar.sha1sum);
|
||||||
final IqPacket packet = retrieve("urn:xmpp:avatar:data", item);
|
final Element metadata = item
|
||||||
packet.setTo(avatar.owner);
|
.addChild("metadata", "urn:xmpp:avatar:metadata");
|
||||||
return packet;
|
final Element info = metadata.addChild("info");
|
||||||
}
|
info.setAttribute("bytes", avatar.size);
|
||||||
|
info.setAttribute("id", avatar.sha1sum);
|
||||||
|
info.setAttribute("height", avatar.height);
|
||||||
|
info.setAttribute("width", avatar.height);
|
||||||
|
info.setAttribute("type", avatar.type);
|
||||||
|
return publish("urn:xmpp:avatar:metadata", item, options);
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket retrieveVcardAvatar(final Avatar avatar) {
|
public IqPacket retrievePepAvatar(final Avatar avatar) {
|
||||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
final Element item = new Element("item");
|
||||||
packet.setTo(avatar.owner);
|
item.setAttribute("id", avatar.sha1sum);
|
||||||
packet.addChild("vCard", "vcard-temp");
|
final IqPacket packet = retrieve("urn:xmpp:avatar:data", item);
|
||||||
return packet;
|
packet.setTo(avatar.owner);
|
||||||
}
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket retrieveAvatarMetaData(final Jid to) {
|
public IqPacket retrieveVcardAvatar(final Avatar avatar) {
|
||||||
final IqPacket packet = retrieve("urn:xmpp:avatar:metadata", null);
|
final IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
||||||
if (to != null) {
|
packet.setTo(avatar.owner);
|
||||||
packet.setTo(to);
|
packet.addChild("vCard", "vcard-temp");
|
||||||
}
|
return packet;
|
||||||
return packet;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public IqPacket retrieveDeviceIds(final Jid to) {
|
public IqPacket retrieveAvatarMetaData(final Jid to) {
|
||||||
final IqPacket packet = retrieve(AxolotlService.PEP_DEVICE_LIST, null);
|
final IqPacket packet = retrieve("urn:xmpp:avatar:metadata", null);
|
||||||
if (to != null) {
|
if (to != null) {
|
||||||
packet.setTo(to);
|
packet.setTo(to);
|
||||||
}
|
}
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket retrieveBundlesForDevice(final Jid to, final int deviceid) {
|
public IqPacket retrieveDeviceIds(final Jid to) {
|
||||||
final IqPacket packet = retrieve(AxolotlService.PEP_BUNDLES + ":" + deviceid, null);
|
final IqPacket packet = retrieve(AxolotlService.PEP_DEVICE_LIST, null);
|
||||||
packet.setTo(to);
|
if (to != null) {
|
||||||
return packet;
|
packet.setTo(to);
|
||||||
}
|
}
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket retrieveVerificationForDevice(final Jid to, final int deviceid) {
|
public IqPacket retrieveBundlesForDevice(final Jid to, final int deviceid) {
|
||||||
final IqPacket packet = retrieve(AxolotlService.PEP_VERIFICATION + ":" + deviceid, null);
|
final IqPacket packet = retrieve(AxolotlService.PEP_BUNDLES + ":" + deviceid, null);
|
||||||
packet.setTo(to);
|
packet.setTo(to);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket publishDeviceIds(final Set<Integer> ids, final Bundle publishOptions) {
|
public IqPacket retrieveVerificationForDevice(final Jid to, final int deviceid) {
|
||||||
final Element item = new Element("item");
|
final IqPacket packet = retrieve(AxolotlService.PEP_VERIFICATION + ":" + deviceid, null);
|
||||||
item.setAttribute("id", "current");
|
packet.setTo(to);
|
||||||
final Element list = item.addChild("list", AxolotlService.PEP_PREFIX);
|
return packet;
|
||||||
for (Integer id : ids) {
|
}
|
||||||
final Element device = new Element("device");
|
|
||||||
device.setAttribute("id", id);
|
|
||||||
list.addChild(device);
|
|
||||||
}
|
|
||||||
return publish(AxolotlService.PEP_DEVICE_LIST, item, publishOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Element publishBookmarkItem(final Bookmark bookmark) {
|
public IqPacket publishDeviceIds(final Set<Integer> ids, final Bundle publishOptions) {
|
||||||
final String name = bookmark.getBookmarkName();
|
final Element item = new Element("item");
|
||||||
final String nick = bookmark.getNick();
|
item.setAttribute("id", "current");
|
||||||
final Element conference = new Element("conference", Namespace.BOOKMARK);
|
final Element list = item.addChild("list", AxolotlService.PEP_PREFIX);
|
||||||
if (name != null) {
|
for (Integer id : ids) {
|
||||||
conference.setAttribute("name", name);
|
final Element device = new Element("device");
|
||||||
}
|
device.setAttribute("id", id);
|
||||||
if (nick != null) {
|
list.addChild(device);
|
||||||
conference.addChild("nick").setContent(nick);
|
}
|
||||||
}
|
return publish(AxolotlService.PEP_DEVICE_LIST, item, publishOptions);
|
||||||
return conference;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public IqPacket publishBundles(final SignedPreKeyRecord signedPreKeyRecord, final IdentityKey identityKey,
|
public Element publishBookmarkItem(final Bookmark bookmark) {
|
||||||
final Set<PreKeyRecord> preKeyRecords, final int deviceId, Bundle publishOptions) {
|
final String name = bookmark.getBookmarkName();
|
||||||
final Element item = new Element("item");
|
final String nick = bookmark.getNick();
|
||||||
item.setAttribute("id", "current");
|
final Element conference = new Element("conference", Namespace.BOOKMARK);
|
||||||
final Element bundle = item.addChild("bundle", AxolotlService.PEP_PREFIX);
|
if (name != null) {
|
||||||
final Element signedPreKeyPublic = bundle.addChild("signedPreKeyPublic");
|
conference.setAttribute("name", name);
|
||||||
signedPreKeyPublic.setAttribute("signedPreKeyId", signedPreKeyRecord.getId());
|
}
|
||||||
ECPublicKey publicKey = signedPreKeyRecord.getKeyPair().getPublicKey();
|
if (nick != null) {
|
||||||
signedPreKeyPublic.setContent(Base64.encodeToString(publicKey.serialize(), Base64.DEFAULT));
|
conference.addChild("nick").setContent(nick);
|
||||||
final Element signedPreKeySignature = bundle.addChild("signedPreKeySignature");
|
}
|
||||||
signedPreKeySignature.setContent(Base64.encodeToString(signedPreKeyRecord.getSignature(), Base64.DEFAULT));
|
return conference;
|
||||||
final Element identityKeyElement = bundle.addChild("identityKey");
|
}
|
||||||
identityKeyElement.setContent(Base64.encodeToString(identityKey.serialize(), Base64.DEFAULT));
|
|
||||||
|
|
||||||
final Element prekeys = bundle.addChild("prekeys", AxolotlService.PEP_PREFIX);
|
public IqPacket publishBundles(final SignedPreKeyRecord signedPreKeyRecord, final IdentityKey identityKey,
|
||||||
for (PreKeyRecord preKeyRecord : preKeyRecords) {
|
final Set<PreKeyRecord> preKeyRecords, final int deviceId, Bundle publishOptions) {
|
||||||
final Element prekey = prekeys.addChild("preKeyPublic");
|
final Element item = new Element("item");
|
||||||
prekey.setAttribute("preKeyId", preKeyRecord.getId());
|
item.setAttribute("id", "current");
|
||||||
prekey.setContent(Base64.encodeToString(preKeyRecord.getKeyPair().getPublicKey().serialize(), Base64.DEFAULT));
|
final Element bundle = item.addChild("bundle", AxolotlService.PEP_PREFIX);
|
||||||
}
|
final Element signedPreKeyPublic = bundle.addChild("signedPreKeyPublic");
|
||||||
|
signedPreKeyPublic.setAttribute("signedPreKeyId", signedPreKeyRecord.getId());
|
||||||
|
ECPublicKey publicKey = signedPreKeyRecord.getKeyPair().getPublicKey();
|
||||||
|
signedPreKeyPublic.setContent(Base64.encodeToString(publicKey.serialize(), Base64.DEFAULT));
|
||||||
|
final Element signedPreKeySignature = bundle.addChild("signedPreKeySignature");
|
||||||
|
signedPreKeySignature.setContent(Base64.encodeToString(signedPreKeyRecord.getSignature(), Base64.DEFAULT));
|
||||||
|
final Element identityKeyElement = bundle.addChild("identityKey");
|
||||||
|
identityKeyElement.setContent(Base64.encodeToString(identityKey.serialize(), Base64.DEFAULT));
|
||||||
|
|
||||||
return publish(AxolotlService.PEP_BUNDLES + ":" + deviceId, item, publishOptions);
|
final Element prekeys = bundle.addChild("prekeys", AxolotlService.PEP_PREFIX);
|
||||||
}
|
for (PreKeyRecord preKeyRecord : preKeyRecords) {
|
||||||
|
final Element prekey = prekeys.addChild("preKeyPublic");
|
||||||
|
prekey.setAttribute("preKeyId", preKeyRecord.getId());
|
||||||
|
prekey.setContent(Base64.encodeToString(preKeyRecord.getKeyPair().getPublicKey().serialize(), Base64.DEFAULT));
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket publishVerification(byte[] signature, X509Certificate[] certificates, final int deviceId) {
|
return publish(AxolotlService.PEP_BUNDLES + ":" + deviceId, item, publishOptions);
|
||||||
final Element item = new Element("item");
|
}
|
||||||
item.setAttribute("id", "current");
|
|
||||||
final Element verification = item.addChild("verification", AxolotlService.PEP_PREFIX);
|
|
||||||
final Element chain = verification.addChild("chain");
|
|
||||||
for (int i = 0; i < certificates.length; ++i) {
|
|
||||||
try {
|
|
||||||
Element certificate = chain.addChild("certificate");
|
|
||||||
certificate.setContent(Base64.encodeToString(certificates[i].getEncoded(), Base64.DEFAULT));
|
|
||||||
certificate.setAttribute("index", i);
|
|
||||||
} catch (CertificateEncodingException e) {
|
|
||||||
Log.d(Config.LOGTAG, "could not encode certificate");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
verification.addChild("signature").setContent(Base64.encodeToString(signature, Base64.DEFAULT));
|
|
||||||
return publish(AxolotlService.PEP_VERIFICATION + ":" + deviceId, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IqPacket queryMessageArchiveManagement(final MessageArchiveService.Query mam) {
|
public IqPacket publishVerification(byte[] signature, X509Certificate[] certificates, final int deviceId) {
|
||||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
final Element item = new Element("item");
|
||||||
final Element query = packet.query(mam.version.namespace);
|
item.setAttribute("id", "current");
|
||||||
query.setAttribute("queryid", mam.getQueryId());
|
final Element verification = item.addChild("verification", AxolotlService.PEP_PREFIX);
|
||||||
final Data data = new Data();
|
final Element chain = verification.addChild("chain");
|
||||||
data.setFormType(mam.version.namespace);
|
for (int i = 0; i < certificates.length; ++i) {
|
||||||
if (mam.muc()) {
|
try {
|
||||||
packet.setTo(mam.getWith());
|
Element certificate = chain.addChild("certificate");
|
||||||
} else if (mam.getWith() != null) {
|
certificate.setContent(Base64.encodeToString(certificates[i].getEncoded(), Base64.DEFAULT));
|
||||||
data.put("with", mam.getWith().toString());
|
certificate.setAttribute("index", i);
|
||||||
}
|
} catch (CertificateEncodingException e) {
|
||||||
final long start = mam.getStart();
|
Log.d(Config.LOGTAG, "could not encode certificate");
|
||||||
final long end = mam.getEnd();
|
}
|
||||||
if (start != 0) {
|
}
|
||||||
data.put("start", getTimestamp(start));
|
verification.addChild("signature").setContent(Base64.encodeToString(signature, Base64.DEFAULT));
|
||||||
}
|
return publish(AxolotlService.PEP_VERIFICATION + ":" + deviceId, item);
|
||||||
if (end != 0) {
|
}
|
||||||
data.put("end", getTimestamp(end));
|
|
||||||
}
|
|
||||||
data.submit();
|
|
||||||
query.addChild(data);
|
|
||||||
Element set = query.addChild("set", "http://jabber.org/protocol/rsm");
|
|
||||||
if (mam.getPagingOrder() == MessageArchiveService.PagingOrder.REVERSE) {
|
|
||||||
set.addChild("before").setContent(mam.getReference());
|
|
||||||
} else if (mam.getReference() != null) {
|
|
||||||
set.addChild("after").setContent(mam.getReference());
|
|
||||||
}
|
|
||||||
set.addChild("max").setContent(String.valueOf(Config.PAGE_SIZE));
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IqPacket generateGetBlockList() {
|
public IqPacket queryMessageArchiveManagement(final MessageArchiveService.Query mam) {
|
||||||
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
|
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
iq.addChild("blocklist", Namespace.BLOCKING);
|
final Element query = packet.query(mam.version.namespace);
|
||||||
|
query.setAttribute("queryid", mam.getQueryId());
|
||||||
|
final Data data = new Data();
|
||||||
|
data.setFormType(mam.version.namespace);
|
||||||
|
if (mam.muc()) {
|
||||||
|
packet.setTo(mam.getWith());
|
||||||
|
} else if (mam.getWith() != null) {
|
||||||
|
data.put("with", mam.getWith().toString());
|
||||||
|
}
|
||||||
|
final long start = mam.getStart();
|
||||||
|
final long end = mam.getEnd();
|
||||||
|
if (start != 0) {
|
||||||
|
data.put("start", getTimestamp(start));
|
||||||
|
}
|
||||||
|
if (end != 0) {
|
||||||
|
data.put("end", getTimestamp(end));
|
||||||
|
}
|
||||||
|
data.submit();
|
||||||
|
query.addChild(data);
|
||||||
|
Element set = query.addChild("set", "http://jabber.org/protocol/rsm");
|
||||||
|
if (mam.getPagingOrder() == MessageArchiveService.PagingOrder.REVERSE) {
|
||||||
|
set.addChild("before").setContent(mam.getReference());
|
||||||
|
} else if (mam.getReference() != null) {
|
||||||
|
set.addChild("after").setContent(mam.getReference());
|
||||||
|
}
|
||||||
|
set.addChild("max").setContent(String.valueOf(Config.PAGE_SIZE));
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
return iq;
|
public IqPacket generateGetBlockList() {
|
||||||
}
|
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
|
||||||
|
iq.addChild("blocklist", Namespace.BLOCKING);
|
||||||
|
|
||||||
public IqPacket generateSetBlockRequest(final Jid jid, boolean reportSpam) {
|
return iq;
|
||||||
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
|
}
|
||||||
final Element block = iq.addChild("block", Namespace.BLOCKING);
|
|
||||||
final Element item = block.addChild("item").setAttribute("jid", jid.toEscapedString());
|
|
||||||
if (reportSpam) {
|
|
||||||
item.addChild("report", "urn:xmpp:reporting:0").addChild("spam");
|
|
||||||
}
|
|
||||||
Log.d(Config.LOGTAG, iq.toString());
|
|
||||||
return iq;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IqPacket generateSetUnblockRequest(final Jid jid) {
|
public IqPacket generateSetBlockRequest(final Jid jid, boolean reportSpam) {
|
||||||
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
|
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
|
||||||
final Element block = iq.addChild("unblock", Namespace.BLOCKING);
|
final Element block = iq.addChild("block", Namespace.BLOCKING);
|
||||||
block.addChild("item").setAttribute("jid", jid.toEscapedString());
|
final Element item = block.addChild("item").setAttribute("jid", jid.toEscapedString());
|
||||||
return iq;
|
if (reportSpam) {
|
||||||
}
|
item.addChild("report", "urn:xmpp:reporting:0").addChild("spam");
|
||||||
|
}
|
||||||
|
Log.d(Config.LOGTAG, iq.toString());
|
||||||
|
return iq;
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket generateSetPassword(final Account account, final String newPassword) {
|
public IqPacket generateSetUnblockRequest(final Jid jid) {
|
||||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
final IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
|
||||||
packet.setTo(Jid.of(account.getServer()));
|
final Element block = iq.addChild("unblock", Namespace.BLOCKING);
|
||||||
final Element query = packet.addChild("query", Namespace.REGISTER);
|
block.addChild("item").setAttribute("jid", jid.toEscapedString());
|
||||||
final Jid jid = account.getJid();
|
return iq;
|
||||||
query.addChild("username").setContent(jid.getLocal());
|
}
|
||||||
query.addChild("password").setContent(newPassword);
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IqPacket changeAffiliation(Conversation conference, Jid jid, String affiliation) {
|
public IqPacket generateSetPassword(final Account account, final String newPassword) {
|
||||||
List<Jid> jids = new ArrayList<>();
|
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
jids.add(jid);
|
packet.setTo(Jid.of(account.getServer()));
|
||||||
return changeAffiliation(conference, jids, affiliation);
|
final Element query = packet.addChild("query", Namespace.REGISTER);
|
||||||
}
|
final Jid jid = account.getJid();
|
||||||
|
query.addChild("username").setContent(jid.getLocal());
|
||||||
|
query.addChild("password").setContent(newPassword);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket changeAffiliation(Conversation conference, List<Jid> jids, String affiliation) {
|
public IqPacket changeAffiliation(Conversation conference, Jid jid, String affiliation) {
|
||||||
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
List<Jid> jids = new ArrayList<>();
|
||||||
packet.setTo(conference.getJid().asBareJid());
|
jids.add(jid);
|
||||||
packet.setFrom(conference.getAccount().getJid());
|
return changeAffiliation(conference, jids, affiliation);
|
||||||
Element query = packet.query("http://jabber.org/protocol/muc#admin");
|
}
|
||||||
for (Jid jid : jids) {
|
|
||||||
Element item = query.addChild("item");
|
|
||||||
item.setAttribute("jid", jid.toEscapedString());
|
|
||||||
item.setAttribute("affiliation", affiliation);
|
|
||||||
}
|
|
||||||
return packet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IqPacket changeRole(Conversation conference, String nick, String role) {
|
public IqPacket changeAffiliation(Conversation conference, List<Jid> jids, String affiliation) {
|
||||||
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
packet.setTo(conference.getJid().asBareJid());
|
packet.setTo(conference.getJid().asBareJid());
|
||||||
packet.setFrom(conference.getAccount().getJid());
|
packet.setFrom(conference.getAccount().getJid());
|
||||||
Element item = packet.query("http://jabber.org/protocol/muc#admin").addChild("item");
|
Element query = packet.query("http://jabber.org/protocol/muc#admin");
|
||||||
item.setAttribute("nick", nick);
|
for (Jid jid : jids) {
|
||||||
item.setAttribute("role", role);
|
Element item = query.addChild("item");
|
||||||
return packet;
|
item.setAttribute("jid", jid.toEscapedString());
|
||||||
}
|
item.setAttribute("affiliation", affiliation);
|
||||||
|
}
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file, String mime) {
|
public IqPacket changeRole(Conversation conference, String nick, String role) {
|
||||||
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
packet.setTo(host);
|
packet.setTo(conference.getJid().asBareJid());
|
||||||
Element request = packet.addChild("request", Namespace.HTTP_UPLOAD);
|
packet.setFrom(conference.getAccount().getJid());
|
||||||
request.setAttribute("filename", convertFilename(file.getName()));
|
Element item = packet.query("http://jabber.org/protocol/muc#admin").addChild("item");
|
||||||
request.setAttribute("size", file.getExpectedSize());
|
item.setAttribute("nick", nick);
|
||||||
request.setAttribute("content-type", mime);
|
item.setAttribute("role", role);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket requestHttpUploadLegacySlot(Jid host, DownloadableFile file, String mime) {
|
public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file, String mime) {
|
||||||
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
||||||
packet.setTo(host);
|
packet.setTo(host);
|
||||||
Element request = packet.addChild("request", Namespace.HTTP_UPLOAD_LEGACY);
|
Element request = packet.addChild("request", Namespace.HTTP_UPLOAD);
|
||||||
request.addChild("filename").setContent(convertFilename(file.getName()));
|
request.setAttribute("filename", convertFilename(file.getName()));
|
||||||
request.addChild("size").setContent(String.valueOf(file.getExpectedSize()));
|
request.setAttribute("size", file.getExpectedSize());
|
||||||
request.addChild("content-type").setContent(mime);
|
request.setAttribute("content-type", mime);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IqPacket requestP1S3Slot(Jid host, String md5) {
|
public IqPacket requestHttpUploadLegacySlot(Jid host, DownloadableFile file, String mime) {
|
||||||
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
||||||
packet.setTo(host);
|
packet.setTo(host);
|
||||||
packet.query(Namespace.P1_S3_FILE_TRANSFER).setAttribute("md5", md5);
|
Element request = packet.addChild("request", Namespace.HTTP_UPLOAD_LEGACY);
|
||||||
return packet;
|
request.addChild("filename").setContent(convertFilename(file.getName()));
|
||||||
}
|
request.addChild("size").setContent(String.valueOf(file.getExpectedSize()));
|
||||||
|
request.addChild("content-type").setContent(mime);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket requestP1S3Url(Jid host, String fileId) {
|
public IqPacket requestP1S3Slot(Jid host, String md5) {
|
||||||
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
packet.setTo(host);
|
packet.setTo(host);
|
||||||
packet.query(Namespace.P1_S3_FILE_TRANSFER).setAttribute("fileid", fileId);
|
packet.query(Namespace.P1_S3_FILE_TRANSFER).setAttribute("md5", md5);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String convertFilename(String name) {
|
public IqPacket requestP1S3Url(Jid host, String fileId) {
|
||||||
int pos = name.indexOf('.');
|
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
||||||
if (pos != -1) {
|
packet.setTo(host);
|
||||||
try {
|
packet.query(Namespace.P1_S3_FILE_TRANSFER).setAttribute("fileid", fileId);
|
||||||
UUID uuid = UUID.fromString(name.substring(0, pos));
|
return packet;
|
||||||
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
|
}
|
||||||
bb.putLong(uuid.getMostSignificantBits());
|
|
||||||
bb.putLong(uuid.getLeastSignificantBits());
|
|
||||||
return Base64.encodeToString(bb.array(), Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP) + name.substring(pos, name.length());
|
|
||||||
} catch (Exception e) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IqPacket generateCreateAccountWithCaptcha(Account account, String id, Data data) {
|
private static String convertFilename(String name) {
|
||||||
final IqPacket register = new IqPacket(IqPacket.TYPE.SET);
|
int pos = name.indexOf('.');
|
||||||
register.setFrom(account.getJid().asBareJid());
|
if (pos != -1) {
|
||||||
register.setTo(Jid.of(account.getServer()));
|
try {
|
||||||
register.setId(id);
|
UUID uuid = UUID.fromString(name.substring(0, pos));
|
||||||
Element query = register.query(Namespace.REGISTER);
|
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
|
||||||
if (data != null) {
|
bb.putLong(uuid.getMostSignificantBits());
|
||||||
query.addChild(data);
|
bb.putLong(uuid.getLeastSignificantBits());
|
||||||
}
|
return Base64.encodeToString(bb.array(), Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP) + name.substring(pos, name.length());
|
||||||
return register;
|
} catch (Exception e) {
|
||||||
}
|
return name;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket pushTokenToAppServer(Jid appServer, String token, String deviceId) {
|
public IqPacket generateCreateAccountWithCaptcha(Account account, String id, Data data) {
|
||||||
return pushTokenToAppServer(appServer, token, deviceId, null);
|
final IqPacket register = new IqPacket(IqPacket.TYPE.SET);
|
||||||
}
|
register.setFrom(account.getJid().asBareJid());
|
||||||
|
register.setTo(Jid.of(account.getServer()));
|
||||||
|
register.setId(id);
|
||||||
|
Element query = register.query(Namespace.REGISTER);
|
||||||
|
if (data != null) {
|
||||||
|
query.addChild(data);
|
||||||
|
}
|
||||||
|
return register;
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket pushTokenToAppServer(Jid appServer, String token, String deviceId, Jid muc) {
|
public IqPacket pushTokenToAppServer(Jid appServer, String token, String deviceId) {
|
||||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
return pushTokenToAppServer(appServer, token, deviceId, null);
|
||||||
packet.setTo(appServer);
|
}
|
||||||
final Element command = packet.addChild("command", Namespace.COMMANDS);
|
|
||||||
command.setAttribute("node", "register-push-fcm");
|
|
||||||
command.setAttribute("action", "execute");
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IqPacket unregisterChannelOnAppServer(Jid appServer, String deviceId, String channel) {
|
public IqPacket pushTokenToAppServer(Jid appServer, String token, String deviceId, Jid muc) {
|
||||||
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
packet.setTo(appServer);
|
packet.setTo(appServer);
|
||||||
final Element command = packet.addChild("command", Namespace.COMMANDS);
|
final Element command = packet.addChild("command", Namespace.COMMANDS);
|
||||||
command.setAttribute("node", "unregister-push-fcm");
|
command.setAttribute("node", "register-push-fcm");
|
||||||
command.setAttribute("action", "execute");
|
command.setAttribute("action", "execute");
|
||||||
final Data data = new Data();
|
final Data data = new Data();
|
||||||
data.put("channel", channel);
|
data.put("token", token);
|
||||||
data.put("android-id", deviceId);
|
data.put("android-id", deviceId);
|
||||||
data.submit();
|
if (muc != null) {
|
||||||
command.addChild(data);
|
data.put("muc", muc.toEscapedString());
|
||||||
return packet;
|
}
|
||||||
}
|
data.submit();
|
||||||
|
command.addChild(data);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket enablePush(final Jid jid, final String node, final String secret) {
|
public IqPacket unregisterChannelOnAppServer(Jid appServer, String deviceId, String channel) {
|
||||||
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
final IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
Element enable = packet.addChild("enable", Namespace.PUSH);
|
packet.setTo(appServer);
|
||||||
enable.setAttribute("jid", jid.toString());
|
final Element command = packet.addChild("command", Namespace.COMMANDS);
|
||||||
enable.setAttribute("node", node);
|
command.setAttribute("node", "unregister-push-fcm");
|
||||||
if (secret != null) {
|
command.setAttribute("action", "execute");
|
||||||
Data data = new Data();
|
final Data data = new Data();
|
||||||
data.setFormType(Namespace.PUBSUB_PUBLISH_OPTIONS);
|
data.put("channel", channel);
|
||||||
data.put("secret", secret);
|
data.put("android-id", deviceId);
|
||||||
data.submit();
|
data.submit();
|
||||||
enable.addChild(data);
|
command.addChild(data);
|
||||||
}
|
return packet;
|
||||||
return packet;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public IqPacket disablePush(final Jid jid, final String node) {
|
public IqPacket enablePush(final Jid jid, final String node, final String secret) {
|
||||||
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
Element disable = packet.addChild("disable", Namespace.PUSH);
|
Element enable = packet.addChild("enable", Namespace.PUSH);
|
||||||
disable.setAttribute("jid", jid.toEscapedString());
|
enable.setAttribute("jid", jid.toString());
|
||||||
disable.setAttribute("node", node);
|
enable.setAttribute("node", node);
|
||||||
return packet;
|
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 queryAffiliation(Conversation conversation, String affiliation) {
|
public IqPacket disablePush(final Jid jid, final String node) {
|
||||||
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
|
||||||
packet.setTo(conversation.getJid().asBareJid());
|
Element disable = packet.addChild("disable", Namespace.PUSH);
|
||||||
packet.query("http://jabber.org/protocol/muc#admin").addChild("item").setAttribute("affiliation", affiliation);
|
disable.setAttribute("jid", jid.toEscapedString());
|
||||||
return packet;
|
disable.setAttribute("node", node);
|
||||||
}
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
public static Bundle defaultGroupChatConfiguration() {
|
public IqPacket queryAffiliation(Conversation conversation, String affiliation) {
|
||||||
Bundle options = new Bundle();
|
IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
|
||||||
options.putString("muc#roomconfig_persistentroom", "1");
|
packet.setTo(conversation.getJid().asBareJid());
|
||||||
options.putString("muc#roomconfig_membersonly", "1");
|
packet.query("http://jabber.org/protocol/muc#admin").addChild("item").setAttribute("affiliation", affiliation);
|
||||||
options.putString("muc#roomconfig_publicroom", "0");
|
return packet;
|
||||||
options.putString("muc#roomconfig_whois", "anyone");
|
}
|
||||||
options.putString("muc#roomconfig_changesubject", "0");
|
|
||||||
options.putString("muc#roomconfig_allowinvites", "0");
|
|
||||||
options.putString("muc#roomconfig_enablearchiving", "1"); //prosody
|
|
||||||
options.putString("mam", "1"); //ejabberd community
|
|
||||||
options.putString("muc#roomconfig_mam","1"); //ejabberd saas
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Bundle defaultChannelConfiguration() {
|
public static Bundle defaultGroupChatConfiguration() {
|
||||||
Bundle options = new Bundle();
|
Bundle options = new Bundle();
|
||||||
options.putString("muc#roomconfig_persistentroom", "1");
|
options.putString("muc#roomconfig_persistentroom", "1");
|
||||||
options.putString("muc#roomconfig_membersonly", "0");
|
options.putString("muc#roomconfig_membersonly", "1");
|
||||||
options.putString("muc#roomconfig_publicroom", "1");
|
options.putString("muc#roomconfig_publicroom", "0");
|
||||||
options.putString("muc#roomconfig_whois", "moderators");
|
options.putString("muc#roomconfig_whois", "anyone");
|
||||||
options.putString("muc#roomconfig_changesubject", "0");
|
options.putString("muc#roomconfig_changesubject", "0");
|
||||||
options.putString("muc#roomconfig_enablearchiving", "1"); //prosody
|
options.putString("muc#roomconfig_allowinvites", "0");
|
||||||
options.putString("mam", "1"); //ejabberd community
|
options.putString("muc#roomconfig_enablearchiving", "1"); //prosody
|
||||||
options.putString("muc#roomconfig_mam","1"); //ejabberd saas
|
options.putString("mam", "1"); //ejabberd community
|
||||||
return options;
|
options.putString("muc#roomconfig_mam", "1"); //ejabberd saas
|
||||||
}
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket requestPubsubConfiguration(Jid jid, String node) {
|
public static Bundle defaultChannelConfiguration() {
|
||||||
return pubsubConfiguration(jid, node, null);
|
Bundle options = new Bundle();
|
||||||
}
|
options.putString("muc#roomconfig_persistentroom", "1");
|
||||||
|
options.putString("muc#roomconfig_membersonly", "0");
|
||||||
|
options.putString("muc#roomconfig_publicroom", "1");
|
||||||
|
options.putString("muc#roomconfig_whois", "moderators");
|
||||||
|
options.putString("muc#roomconfig_changesubject", "0");
|
||||||
|
options.putString("muc#roomconfig_enablearchiving", "1"); //prosody
|
||||||
|
options.putString("mam", "1"); //ejabberd community
|
||||||
|
options.putString("muc#roomconfig_mam", "1"); //ejabberd saas
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
public IqPacket publishPubsubConfiguration(Jid jid, String node, Data data) {
|
public IqPacket requestPubsubConfiguration(Jid jid, String node) {
|
||||||
return pubsubConfiguration(jid, node, data);
|
return pubsubConfiguration(jid, node, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IqPacket pubsubConfiguration(Jid jid, String node, Data data) {
|
public IqPacket publishPubsubConfiguration(Jid jid, String node, Data data) {
|
||||||
IqPacket packet = new IqPacket(data == null ? IqPacket.TYPE.GET : IqPacket.TYPE.SET);
|
return pubsubConfiguration(jid, node, data);
|
||||||
packet.setTo(jid);
|
}
|
||||||
Element pubsub = packet.addChild("pubsub", "http://jabber.org/protocol/pubsub#owner");
|
|
||||||
Element configure = pubsub.addChild("configure").setAttribute("node", node);
|
private IqPacket pubsubConfiguration(Jid jid, String node, Data data) {
|
||||||
if (data != null) {
|
IqPacket packet = new IqPacket(data == null ? IqPacket.TYPE.GET : IqPacket.TYPE.SET);
|
||||||
configure.addChild(data);
|
packet.setTo(jid);
|
||||||
}
|
Element pubsub = packet.addChild("pubsub", "http://jabber.org/protocol/pubsub#owner");
|
||||||
return packet;
|
Element configure = pubsub.addChild("configure").setAttribute("node", node);
|
||||||
}
|
if (data != null) {
|
||||||
|
configure.addChild(data);
|
||||||
|
}
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -314,11 +314,13 @@ public class XmppConnectionService extends Service {
|
||||||
mQuickConversationsService.considerSyncBackground(false);
|
mQuickConversationsService.considerSyncBackground(false);
|
||||||
fetchRosterFromServer(account);
|
fetchRosterFromServer(account);
|
||||||
|
|
||||||
fetchBookmarks2(account);
|
final XmppConnection connection = account.getXmppConnection();
|
||||||
|
|
||||||
/*if (!account.getXmppConnection().getFeatures().bookmarksConversion()) {
|
if (connection.getFeatures().bookmarks2()) {
|
||||||
|
fetchBookmarks2(account);
|
||||||
|
} else if (!account.getXmppConnection().getFeatures().bookmarksConversion()) {
|
||||||
fetchBookmarks(account);
|
fetchBookmarks(account);
|
||||||
}*/
|
}
|
||||||
final boolean flexible = account.getXmppConnection().getFeatures().flexibleOfflineMessageRetrieval();
|
final boolean flexible = account.getXmppConnection().getFeatures().flexibleOfflineMessageRetrieval();
|
||||||
final boolean catchup = getMessageArchiveService().inCatchup(account);
|
final boolean catchup = getMessageArchiveService().inCatchup(account);
|
||||||
if (flexible && catchup && account.getXmppConnection().isMamPreferenceAlways()) {
|
if (flexible && catchup && account.getXmppConnection().isMamPreferenceAlways()) {
|
||||||
|
@ -1579,8 +1581,6 @@ public class XmppConnectionService extends Service {
|
||||||
if (response.getType() == IqPacket.TYPE.RESULT) {
|
if (response.getType() == IqPacket.TYPE.RESULT) {
|
||||||
final Element pubsub = response.findChild("pubsub", Namespace.PUBSUB);
|
final Element pubsub = response.findChild("pubsub", Namespace.PUBSUB);
|
||||||
final Collection<Bookmark> bookmarks = Bookmark.parseFromPubsub(pubsub, account);
|
final Collection<Bookmark> bookmarks = Bookmark.parseFromPubsub(pubsub, account);
|
||||||
Log.d(Config.LOGTAG,"bookmarks2 "+pubsub);
|
|
||||||
Log.d(Config.LOGTAG,"bookmarks2"+ bookmarks);
|
|
||||||
processBookmarksInitial(account, bookmarks, true);
|
processBookmarksInitial(account, bookmarks, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1621,13 +1621,32 @@ public class XmppConnectionService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createBookmark(final Account account, final Bookmark bookmark) {
|
public void createBookmark(final Account account, final Bookmark bookmark) {
|
||||||
final Element item = mIqGenerator.publishBookmarkItem(bookmark);
|
final XmppConnection connection = account.getXmppConnection();
|
||||||
pushNodeAndEnforcePublishOptions(account, Namespace.BOOKMARK, item, bookmark.getJid().asBareJid().toEscapedString(), PublishOptions.persistentWhitelistAccessMaxItems());
|
if (connection.getFeatures().bookmarks2()) {
|
||||||
|
final Element item = mIqGenerator.publishBookmarkItem(bookmark);
|
||||||
|
pushNodeAndEnforcePublishOptions(account, Namespace.BOOKMARK, item, bookmark.getJid().asBareJid().toEscapedString(), PublishOptions.persistentWhitelistAccessMaxItems());
|
||||||
|
} else if (connection.getFeatures().bookmarksConversion()) {
|
||||||
|
pushBookmarksPep(account);
|
||||||
|
} else {
|
||||||
|
pushBookmarksPrivateXml(account);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteBookmark(final Account account, final Bookmark bookmark) {
|
public void deleteBookmark(final Account account, final Bookmark bookmark) {
|
||||||
final XmppConnection connection = account.getXmppConnection();
|
final XmppConnection connection = account.getXmppConnection();
|
||||||
|
if (connection.getFeatures().bookmarksConversion()) {
|
||||||
|
IqPacket request = mIqGenerator.deleteItem(Namespace.BOOKMARK, bookmark.getJid().asBareJid().toEscapedString());
|
||||||
|
sendIqPacket(account, request, new OnIqPacketReceived() {
|
||||||
|
@Override
|
||||||
|
public void onIqPacketReceived(Account account, IqPacket packet) {
|
||||||
|
Log.d(Config.LOGTAG,packet.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (connection.getFeatures().bookmarksConversion()) {
|
||||||
|
pushBookmarksPep(account);
|
||||||
|
} else {
|
||||||
|
pushBookmarksPrivateXml(account);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pushBookmarksPrivateXml(Account account) {
|
private void pushBookmarksPrivateXml(Account account) {
|
||||||
|
|
|
@ -1878,5 +1878,9 @@ public class XmppConnection implements Runnable {
|
||||||
public boolean stanzaIds() {
|
public boolean stanzaIds() {
|
||||||
return hasDiscoFeature(account.getJid().asBareJid(), Namespace.STANZA_IDS);
|
return hasDiscoFeature(account.getJid().asBareJid(), Namespace.STANZA_IDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean bookmarks2() {
|
||||||
|
return true; //hasDiscoFeature(account.getJid().asBareJid(), Namespace.BOOKMARK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue