summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rwxr-xr-xsrc/com/isode/stroke/avatars/VCardAvatarManager.java10
-rwxr-xr-xsrc/com/isode/stroke/avatars/VCardUpdateAvatarManager.java9
-rw-r--r--src/com/isode/stroke/elements/VCard.java17
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/VCardSerializer.java4
-rw-r--r--src/com/isode/stroke/vcards/VCardStorage.java14
5 files changed, 32 insertions, 22 deletions
diff --git a/src/com/isode/stroke/avatars/VCardAvatarManager.java b/src/com/isode/stroke/avatars/VCardAvatarManager.java
index 83c8c64..a924676 100755
--- a/src/com/isode/stroke/avatars/VCardAvatarManager.java
+++ b/src/com/isode/stroke/avatars/VCardAvatarManager.java
@@ -17,6 +17,7 @@ import com.isode.stroke.elements.VCard;
import com.isode.stroke.crypto.CryptoProvider;
import com.isode.stroke.stringcodecs.Hexify;
import com.isode.stroke.avatars.AvatarStorage;
+import com.isode.stroke.base.ByteArray;
import com.isode.stroke.muc.MUCRegistry;
import com.isode.stroke.vcards.VCardManager;
import com.isode.stroke.signals.Slot2;
@@ -62,16 +63,17 @@ public class VCardAvatarManager extends AvatarProvider {
String hash = vcardManager_.getPhotoHash(avatarJID);
if(hash.length() != 0) {
if (!avatarStorage_.hasAvatar(hash)) {
- VCard vCard = vcardManager_.getVCard(avatarJID);
- if (vCard != null) {
- String newHash = Hexify.hexify(crypto_.getSHA1Hash(vCard.getPhoto()));
+ final VCard vCard = vcardManager_.getVCard(avatarJID);
+ final ByteArray photo = vCard != null ? vCard.getPhoto() : null;
+ if (photo != null) {
+ String newHash = Hexify.hexify(crypto_.getSHA1Hash(photo));
if (!newHash.equals(hash)) {
// Shouldn't happen, but sometimes seem to. Might be fixed if we
// move to a safer backend.
logger_.warning("Inconsistent vCard photo hash cache");
hash = newHash;
}
- avatarStorage_.addAvatar(hash, vCard.getPhoto());
+ avatarStorage_.addAvatar(hash, photo);
}
else {
// Can happen if the cache is inconsistent.
diff --git a/src/com/isode/stroke/avatars/VCardUpdateAvatarManager.java b/src/com/isode/stroke/avatars/VCardUpdateAvatarManager.java
index 5328fb4..681e94b 100755
--- a/src/com/isode/stroke/avatars/VCardUpdateAvatarManager.java
+++ b/src/com/isode/stroke/avatars/VCardUpdateAvatarManager.java
@@ -24,12 +24,14 @@ import com.isode.stroke.client.StanzaChannel;
import com.isode.stroke.crypto.CryptoProvider;
import com.isode.stroke.stringcodecs.Hexify;
import com.isode.stroke.avatars.AvatarStorage;
+import com.isode.stroke.base.ByteArray;
import com.isode.stroke.muc.MUCRegistry;
import com.isode.stroke.vcards.VCardManager;
import com.isode.stroke.signals.Slot2;
import com.isode.stroke.signals.Slot1;
import java.util.logging.Logger;
+
import com.isode.stroke.signals.SignalConnection;
public class VCardUpdateAvatarManager extends AvatarProvider {
@@ -124,13 +126,14 @@ public class VCardUpdateAvatarManager extends AvatarProvider {
return;
}
- if (vCard.getPhoto().isEmpty()) {
+ final ByteArray photo = vCard.getPhoto();
+ if (photo == null) {
setAvatarHash(from, "");
}
else {
- String hash = Hexify.hexify(crypto_.getSHA1Hash(vCard.getPhoto()));
+ String hash = Hexify.hexify(crypto_.getSHA1Hash(photo));
if (!avatarStorage_.hasAvatar(hash)) {
- avatarStorage_.addAvatar(hash, vCard.getPhoto());
+ avatarStorage_.addAvatar(hash, photo);
}
setAvatarHash(from, hash);
}
diff --git a/src/com/isode/stroke/elements/VCard.java b/src/com/isode/stroke/elements/VCard.java
index 3bd4db2..3e64c7c 100644
--- a/src/com/isode/stroke/elements/VCard.java
+++ b/src/com/isode/stroke/elements/VCard.java
@@ -131,14 +131,17 @@ public class VCard extends Payload implements Serializable {
public void setNickname(final String nick) { nick_ = nick; }
public final String getNickname() { return nick_; }
- public void setPhoto(final ByteArray photo) { photo_ = photo; }
+ /**
+ * Set the photo, but store null if the photo is empty.
+ */
+ public void setPhoto(final ByteArray photo) { photo_ = photo != null && !photo.isEmpty() ? photo : null; }
+ /**
+ * Get the photo.
+ * Unlike Swiften, this will return null for empty photos,
+ * instead of an empty ByteArray.
+ */
public final ByteArray getPhoto() {
- if(this.photo_ != null) {
- return photo_;
- }
- else {
- return new ByteArray();
- }
+ return photo_;
}
public void setPhotoType(final String photoType) { photoType_ = photoType; }
diff --git a/src/com/isode/stroke/serializer/payloadserializers/VCardSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/VCardSerializer.java
index 9d460fa..9630d80 100644
--- a/src/com/isode/stroke/serializer/payloadserializers/VCardSerializer.java
+++ b/src/com/isode/stroke/serializer/payloadserializers/VCardSerializer.java
@@ -74,12 +74,12 @@ public class VCardSerializer extends GenericPayloadSerializer<VCard>{
if (vcard.getNickname() != null && !vcard.getNickname().isEmpty()) {
queryElement.addNode(new XMLElement("NICKNAME", "", vcard.getNickname()));
}
- if (vcard.getPhoto() != null && !vcard.getPhoto().isEmpty() || vcard.getPhotoType() != null && !vcard.getPhotoType().isEmpty()) {
+ if (vcard.getPhoto() != null || vcard.getPhotoType() != null && !vcard.getPhotoType().isEmpty()) {
XMLElement photoElement = new XMLElement("PHOTO");
if (vcard.getPhotoType() != null && !vcard.getPhotoType().isEmpty()) {
photoElement.addNode(new XMLElement("TYPE", "", vcard.getPhotoType()));
}
- if (vcard.getPhoto() != null && !vcard.getPhoto().isEmpty()) {
+ if (vcard.getPhoto() != null) {
photoElement.addNode(new XMLElement("BINVAL", "", Base64.encode(vcard.getPhoto())));
}
queryElement.addNode(photoElement);
diff --git a/src/com/isode/stroke/vcards/VCardStorage.java b/src/com/isode/stroke/vcards/VCardStorage.java
index cb732ea..5ac095c 100644
--- a/src/com/isode/stroke/vcards/VCardStorage.java
+++ b/src/com/isode/stroke/vcards/VCardStorage.java
@@ -4,6 +4,7 @@
*/
package com.isode.stroke.vcards;
+import com.isode.stroke.base.ByteArray;
import com.isode.stroke.crypto.CryptoProvider;
import com.isode.stroke.elements.VCard;
import com.isode.stroke.jid.JID;
@@ -24,12 +25,13 @@ public abstract class VCardStorage {
public void delete() {};
public String getPhotoHash(final JID jid) {
- VCard vCard = getVCard(jid);
- if (vCard != null && vCard.getPhoto().getSize() != 0) {
- return Hexify.hexify(crypto.getSHA1Hash(vCard.getPhoto()));
- }
- else {
- return "";
+ final VCard vCard = getVCard(jid);
+ if (vCard != null) {
+ final ByteArray photo = vCard.getPhoto();
+ if (photo != null) {
+ return Hexify.hexify(crypto.getSHA1Hash(photo));
+ }
}
+ return "";
}
}