1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 04:22:05 +01:00

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.
This commit is contained in:
Florian Schmaus 2015-02-23 21:25:03 +01:00
parent 7e68bb7470
commit 9006ccf291

View file

@ -27,6 +27,7 @@ import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPConnectionRegistry; import org.jivesoftware.smack.XMPPConnectionRegistry;
import org.jivesoftware.smack.XMPPException.XMPPErrorException; import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.id.StanzaIdUtil;
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
import org.jivesoftware.smackx.vcardtemp.packet.VCard; import org.jivesoftware.smackx.vcardtemp.packet.VCard;
@ -91,7 +92,12 @@ public class VCardManager extends Manager {
* @throws NotConnectedException * @throws NotConnectedException
*/ */
public void saveVCard(VCard vcard) throws NoResponseException, XMPPErrorException, 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); 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(); connection().createPacketCollectorAndSend(vcard).nextResultOrThrow();
} }