aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/services
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-11-30 21:15:16 +0100
committerChristian Schneppe <christian@pix-art.de>2018-11-30 21:15:16 +0100
commit126b71398479c39c915d2205ec316703a9d2dfbb (patch)
tree4619a6e43be5a9a82db789ea8a3d509143f5356c /src/main/java/de/pixart/messenger/services
parentfaf18982c13bbc2f70d23bca13670d9b91617d76 (diff)
set access model to open when publishing avatar
Diffstat (limited to 'src/main/java/de/pixart/messenger/services')
-rw-r--r--src/main/java/de/pixart/messenger/services/XmppConnectionService.java83
1 files changed, 62 insertions, 21 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
index 708200355..c435c1f35 100644
--- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
+++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java
@@ -1671,9 +1671,7 @@ public class XmppConnectionService extends Service {
if (response.getType() == IqPacket.TYPE.RESULT) {
return;
}
- final Element error = response.getType() == IqPacket.TYPE.ERROR ? response.findChild("error") : null;
- final boolean preconditionNotMet = error != null && error.hasChild("precondition-not-met", Namespace.PUBSUB_ERROR);
- if (retry && preconditionNotMet) {
+ if (retry && PublishOptions.preconditionNotMet(response)) {
pushNodeConfiguration(account, node, options, new OnConfigurationPushed() {
@Override
public void onPushSucceeded() {
@@ -3290,30 +3288,36 @@ public class XmppConnectionService extends Service {
}
public void publishAvatar(Account account, final Avatar avatar, final OnAvatarPublication callback) {
- IqPacket packet = this.mIqGenerator.publishAvatar(avatar);
+ final Bundle options;
+ if (account.getXmppConnection().getFeatures().pepPublishOptions()) {
+ options = PublishOptions.openAccess();
+ } else {
+ options = null;
+ }
+ publishAvatar(account, avatar, options, true, callback);
+ }
+
+ public void publishAvatar(Account account, final Avatar avatar, final Bundle options, final boolean retry, final OnAvatarPublication callback) {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": publishing avatar. options=" + options);
+ IqPacket packet = this.mIqGenerator.publishAvatar(avatar, options);
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket result) {
if (result.getType() == IqPacket.TYPE.RESULT) {
- final IqPacket packet = XmppConnectionService.this.mIqGenerator.publishAvatarMetadata(avatar);
- sendIqPacket(account, packet, new OnIqPacketReceived() {
+ publishAvatarMetadata(account, avatar, options, true, callback);
+ } else if (retry && PublishOptions.preconditionNotMet(result)) {
+ pushNodeConfiguration(account, "urn:xmpp:avatar:data", options, new OnConfigurationPushed() {
@Override
- public void onIqPacketReceived(Account account, IqPacket result) {
- if (result.getType() == IqPacket.TYPE.RESULT) {
- if (account.setAvatar(avatar.getFilename())) {
- getAvatarService().clear(account);
- databaseBackend.updateAccount(account);
- }
- Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": published avatar " + (avatar.size / 1024) + "KiB");
- if (callback != null) {
- callback.onAvatarPublicationSucceeded();
- }
- } else {
- if (callback != null) {
- callback.onAvatarPublicationFailed(R.string.error_publish_avatar_server_reject);
- }
- }
+ public void onPushSucceeded() {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": changed node configuration for avatar node");
+ publishAvatar(account, avatar, options, false, callback);
+ }
+
+ @Override
+ public void onPushFailed() {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": unable to change node configuration for avatar node");
+ publishAvatar(account, avatar, null, false, callback);
}
});
} else {
@@ -3327,6 +3331,43 @@ public class XmppConnectionService extends Service {
});
}
+ public void publishAvatarMetadata(Account account, final Avatar avatar, final Bundle options, final boolean retry, final OnAvatarPublication callback) {
+ final IqPacket packet = XmppConnectionService.this.mIqGenerator.publishAvatarMetadata(avatar, options);
+ sendIqPacket(account, packet, new OnIqPacketReceived() {
+ @Override
+ public void onIqPacketReceived(Account account, IqPacket result) {
+ if (result.getType() == IqPacket.TYPE.RESULT) {
+ if (account.setAvatar(avatar.getFilename())) {
+ getAvatarService().clear(account);
+ databaseBackend.updateAccount(account);
+ }
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": published avatar " + (avatar.size / 1024) + "KiB");
+ if (callback != null) {
+ callback.onAvatarPublicationSucceeded();
+ }
+ } else if (retry && PublishOptions.preconditionNotMet(result)) {
+ pushNodeConfiguration(account, "urn:xmpp:avatar:metadata", options, new OnConfigurationPushed() {
+ @Override
+ public void onPushSucceeded() {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": changed node configuration for avatar meta data node");
+ publishAvatarMetadata(account, avatar, options, false, callback);
+ }
+
+ @Override
+ public void onPushFailed() {
+ Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": unable to change node configuration for avatar meta data node");
+ publishAvatarMetadata(account, avatar, null, false, callback);
+ }
+ });
+ } else {
+ if (callback != null) {
+ callback.onAvatarPublicationFailed(R.string.error_publish_avatar_server_reject);
+ }
+ }
+ }
+ });
+ }
+
public void republishAvatarIfNeeded(Account account) {
if (account.getAxolotlService().isPepBroken()) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": skipping republication of avatar because pep is broken");