From 9006ccf291ec6efd307f808f2fc9e136c0231136 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 23 Feb 2015 21:25:03 +0100 Subject: [PATCH] Fix VCardManager.saveVCard(VCard) In case the users tries to save a VCard he previously retrieved via loadVCard() this would previously fail, as the 'to' address is set to the clients full JID. --- .../org/jivesoftware/smackx/vcardtemp/VCardManager.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java index bc7bf47eb..3aea90308 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/vcardtemp/VCardManager.java @@ -27,6 +27,7 @@ import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnectionRegistry; import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.packet.IQ; +import org.jivesoftware.smack.packet.id.StanzaIdUtil; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.vcardtemp.packet.VCard; @@ -91,7 +92,12 @@ public class VCardManager extends Manager { * @throws NotConnectedException */ public void saveVCard(VCard vcard) throws NoResponseException, XMPPErrorException, NotConnectedException { + // XEP-54 § 3.2 "A user may publish or update his or her vCard by sending an IQ of type "set" with no 'to' address…" + vcard.setTo(null); vcard.setType(IQ.Type.set); + // Also make sure to generate a new stanza id (the given vcard could be a vcard result), in which case we don't + // want to use the same stanza id again (although it wouldn't break if we did) + vcard.setStanzaId(StanzaIdUtil.newStanzaId()); connection().createPacketCollectorAndSend(vcard).nextResultOrThrow(); }