diff --git a/res/values/strings.xml b/res/values/strings.xml index 6ea733186..7faeeed99 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -276,4 +276,5 @@ Something went wrong while converting your picture Could not save avatar to disk (Or long press to bring back default) + Your server does not support the publication of avatars diff --git a/src/eu/siacs/conversations/ui/ManageAccountActivity.java b/src/eu/siacs/conversations/ui/ManageAccountActivity.java index 238cf0a49..19c9552a8 100644 --- a/src/eu/siacs/conversations/ui/ManageAccountActivity.java +++ b/src/eu/siacs/conversations/ui/ManageAccountActivity.java @@ -184,7 +184,7 @@ public class ManageAccountActivity extends XmppActivity { connection.setText(connectionAge + " " + getString(R.string.mins)); } - if (xmpp.hasFeatureStreamManagment()) { + if (xmpp.getFeatures().sm()) { if (sessionAgeHours >= 2) { session.setText(sessionAgeHours + " " + getString(R.string.hours)); @@ -197,12 +197,12 @@ public class ManageAccountActivity extends XmppActivity { stream.setText(getString(R.string.no)); session.setText(connection.getText()); } - if (xmpp.hasFeaturesCarbon()) { + if (xmpp.getFeatures().carbons()) { carbon.setText(getString(R.string.yes)); } else { carbon.setText(getString(R.string.no)); } - if (xmpp.hasFeatureRosterManagment()) { + if (xmpp.getFeatures().rosterVersioning()) { roster.setText(getString(R.string.yes)); } else { roster.setText(getString(R.string.no)); diff --git a/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java b/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java index e0e0826af..0661f1a9c 100644 --- a/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java +++ b/src/eu/siacs/conversations/ui/PublishProfilePictureActivity.java @@ -32,6 +32,8 @@ public class PublishProfilePictureActivity extends XmppActivity { private Uri defaultUri; private Account account; + + private boolean support = false; private UiCallback avatarPublication = new UiCallback() { @@ -148,6 +150,9 @@ public class PublishProfilePictureActivity extends XmppActivity { String jid = getIntent().getStringExtra("account"); if (jid != null) { this.account = xmppConnectionService.findAccountByJid(jid); + if (this.account.getXmppConnection() != null) { + this.support = this.account.getXmppConnection().getFeatures().pubsub(); + } if (this.avatarUri == null) { if (this.account.getAvatar() != null) { this.avatar.setImageBitmap(this.account.getImage( @@ -173,10 +178,16 @@ public class PublishProfilePictureActivity extends XmppActivity { Bitmap bm = xmppConnectionService.getFileBackend().cropCenterSquare( uri, 384); this.avatar.setImageBitmap(bm); - enablePublishButton(); - this.publishButton.setText(R.string.publish_avatar); - this.hintOrWarning.setText(R.string.publish_avatar_explanation); - this.hintOrWarning.setTextColor(getPrimaryTextColor()); + if (support) { + enablePublishButton(); + this.publishButton.setText(R.string.publish_avatar); + this.hintOrWarning.setText(R.string.publish_avatar_explanation); + this.hintOrWarning.setTextColor(getPrimaryTextColor()); + } else { + disablePublishButton(); + this.hintOrWarning.setTextColor(getWarningTextColor()); + this.hintOrWarning.setText(R.string.error_publish_avatar_no_server_support); + } if (this.defaultUri != null && uri.equals(this.defaultUri)) { this.secondaryHint.setVisibility(View.INVISIBLE); this.avatar.setOnLongClickListener(null); diff --git a/src/eu/siacs/conversations/xmpp/XmppConnection.java b/src/eu/siacs/conversations/xmpp/XmppConnection.java index 6d01825e0..b1f580d88 100644 --- a/src/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/eu/siacs/conversations/xmpp/XmppConnection.java @@ -64,6 +64,8 @@ public class XmppConnection implements Runnable { private Socket socket; private XmlReader tagReader; private TagWriter tagWriter; + + private Features features = new Features(this); private boolean shouldBind = true; private boolean shouldAuthenticate = true; @@ -662,7 +664,7 @@ public class XmppConnection implements Runnable { } private void enableAdvancedStreamFeatures() { - if (hasFeaturesCarbon()) { + if (getFeatures().carbons()) { sendEnableCarbons(); } } @@ -833,33 +835,6 @@ public class XmppConnection implements Runnable { } } - public boolean hasFeatureRosterManagment() { - if (this.streamFeatures == null) { - return false; - } else { - return this.streamFeatures.hasChild("ver"); - } - } - - public boolean hasFeatureStreamManagment() { - if (this.streamFeatures == null) { - return false; - } else { - return this.streamFeatures.hasChild("sm"); - } - } - - public boolean hasFeaturesCarbon() { - return hasDiscoFeature(account.getServer(), "urn:xmpp:carbons:2"); - } - - public boolean hasDiscoFeature(String server, String feature) { - if (!disco.containsKey(server)) { - return false; - } - return disco.get(server).contains(feature); - } - public List findDiscoItemsByFeature(String feature) { List items = new ArrayList(); for (Entry> cursor : disco.entrySet()) { @@ -903,4 +878,46 @@ public class XmppConnection implements Runnable { public int getAttempt() { return this.attempt; } + + public Features getFeatures() { + return this.features; + } + + public class Features { + XmppConnection connection; + public Features(XmppConnection connection) { + this.connection = connection; + } + + private boolean hasDiscoFeature(String server, String feature) { + if (!connection.disco.containsKey(server)) { + return false; + } + return connection.disco.get(server).contains(feature); + } + + public boolean carbons() { + return hasDiscoFeature(account.getServer(), "urn:xmpp:carbons:2"); + } + + public boolean sm() { + if (connection.streamFeatures == null) { + return false; + } else { + return connection.streamFeatures.hasChild("sm"); + } + } + + public boolean pubsub() { + return hasDiscoFeature(account.getServer(), "http://jabber.org/protocol/pubsub#publish"); + } + + public boolean rosterVersioning() { + if (connection.streamFeatures == null) { + return false; + } else { + return connection.streamFeatures.hasChild("ver"); + } + } + } }