void EntryBase::CheckVCardUpdate (const QXmppPresence& pres) { auto conn = Account_->GetClientConnection (); if (!conn->GetInfoReqPolicyManager ()->IsRequestAllowed (InfoRequest::VCard, this)) return; auto fetchVCard = [this, conn] () -> void { QPointer<EntryBase> ptr (this); conn->FetchVCard (GetJID (), [ptr] (const QXmppVCardIq& iq) { if (ptr) ptr->SetVCard (iq); }); }; const auto& vcardUpdate = pres.vCardUpdateType (); if (vcardUpdate == QXmppPresence::VCardUpdateNoPhoto) { if (!Avatar_.isNull ()) { Avatar_ = QImage (); emit avatarChanged (GetAvatar ()); } } else if (vcardUpdate == QXmppPresence::VCardUpdateValidPhoto) { if (pres.photoHash () != VCardPhotoHash_) fetchVCard (); } else if (pres.type () == QXmppPresence::Available && !HasBlindlyRequestedVCard_) { fetchVCard (); HasBlindlyRequestedVCard_ = true; } }
void TestPackets::testPresenceWithCapability() { const QByteArray xml( "<presence to=\"[email protected]/QXmpp\" from=\"[email protected]/QXmpp\">" "<show>away</show>" "<status>In a meeting</status>" "<priority>5</priority>" "<x xmlns=\"vcard-temp:x:update\">" "<photo>73b908bc</photo>" "</x>" "<c xmlns=\"http://jabber.org/protocol/caps\" hash=\"sha-1\" node=\"http://code.google.com/p/qxmpp\" ver=\"QgayPKawpkPSDYmwT/WM94uAlu0=\"/>" "</presence>"); QXmppPresence presence; parsePacket(presence, xml); QCOMPARE(presence.to(), QString("[email protected]/QXmpp")); QCOMPARE(presence.from(), QString("[email protected]/QXmpp")); QCOMPARE(presence.status().type(), QXmppPresence::Status::Away); QCOMPARE(presence.status().statusText(), QString("In a meeting")); QCOMPARE(presence.status().priority(), 5); QCOMPARE(presence.photoHash(), QByteArray::fromHex("73b908bc")); QCOMPARE(presence.vCardUpdateType(), QXmppPresence::VCardUpdateValidPhoto); QCOMPARE(presence.capabilityHash(), QString("sha-1")); QCOMPARE(presence.capabilityNode(), QString("http://code.google.com/p/qxmpp")); QCOMPARE(presence.capabilityVer(), QByteArray::fromBase64("QgayPKawpkPSDYmwT/WM94uAlu0=")); serializePacket(presence, xml); }
void EntryBase::CheckVCardUpdate (const QXmppPresence& pres) { auto conn = Account_->GetClientConnection (); if (!conn->GetInfoReqPolicyManager ()->IsRequestAllowed (InfoRequest::VCard, this)) return; const auto& vcardUpdate = pres.vCardUpdateType (); if (vcardUpdate == QXmppPresence::VCardUpdateNoPhoto) { if (!VCardPhotoHash_.isEmpty ()) { VCardPhotoHash_.clear (); WriteDownPhotoHash (); emit avatarChanged (this); } } else if (vcardUpdate == QXmppPresence::VCardUpdateValidPhoto) { if (pres.photoHash () != VCardPhotoHash_) { VCardPhotoHash_ = pres.photoHash (); WriteDownPhotoHash (); emit avatarChanged (this); } } }
void TestPackets::testPresence() { const QByteArray xml( "<presence to=\"[email protected]/QXmpp\" from=\"[email protected]/QXmpp\">" "<x xmlns=\"vcard-temp:x:update\"/></presence>"); QXmppPresence presence; parsePacket(presence, xml); QCOMPARE(presence.to(), QString("[email protected]/QXmpp")); QCOMPARE(presence.from(), QString("[email protected]/QXmpp")); QCOMPARE(presence.photoHash(), QByteArray("")); QCOMPARE(presence.vCardUpdateType(), QXmppPresence::VCardUpdateNotReady); serializePacket(presence, xml); }
void JabberContactAvatarService::presenceReceived(const QXmppPresence &presence) { auto jid = Jid::parse(presence.from()); auto contactId = ContactId{jid.bare().toUtf8()}; switch (presence.vCardUpdateType()) { case QXmppPresence::VCardUpdateNoPhoto: emit removed(contactId); break; case QXmppPresence::VCardUpdateValidPhoto: emit available({contactId, presence.photoHash()}); break; default: break; } }
void TestPackets::testPresenceFull() { const QByteArray xml( "<presence to=\"[email protected]/QXmpp\" from=\"[email protected]/QXmpp\">" "<show>away</show>" "<status>In a meeting</status>" "<priority>5</priority>" "</presence>"); QXmppPresence presence; parsePacket(presence, xml); QCOMPARE(presence.to(), QString("[email protected]/QXmpp")); QCOMPARE(presence.from(), QString("[email protected]/QXmpp")); QCOMPARE(presence.status().type(), QXmppPresence::Status::Away); QCOMPARE(presence.status().statusText(), QString("In a meeting")); QCOMPARE(presence.status().priority(), 5); QCOMPARE(presence.vCardUpdateType(), QXmppPresence::VCardUpdateNone); serializePacket(presence, xml); }
void TestPackets::testPresenceWithVCardUpdate() { const QByteArray xml( "<presence to=\"[email protected]/QXmpp\" from=\"[email protected]/QXmpp\">" "<show>away</show>" "<status>In a meeting</status>" "<priority>5</priority>" "<x xmlns=\"vcard-temp:x:update\">" "<photo>73b908bc</photo>" "</x>" "</presence>"); QXmppPresence presence; parsePacket(presence, xml); QCOMPARE(presence.to(), QString("[email protected]/QXmpp")); QCOMPARE(presence.from(), QString("[email protected]/QXmpp")); QCOMPARE(presence.status().type(), QXmppPresence::Status::Away); QCOMPARE(presence.status().statusText(), QString("In a meeting")); QCOMPARE(presence.status().priority(), 5); QCOMPARE(presence.photoHash(), QByteArray::fromHex("73b908bc")); QCOMPARE(presence.vCardUpdateType(), QXmppPresence::VCardUpdateValidPhoto); serializePacket(presence, xml); }