Skip to content

Commit

Permalink
Allow publishing vcard4
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Jun 12, 2024
1 parent 5a54eba commit 94b7166
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/infodlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,8 @@ void InfoWidget::doRefresh()
flags |= VCardFactory::MucUser;
}
auto request = VCardFactory::instance()->getVCard(d->pa, d->jid, flags);
connect(request, &VCardRequest::finished, this, [this, request]() {
QObject::connect(request, &VCardRequest::finished, this, [this, request]() {
qDebug() << "VCardRequest::finished" << request->jid().full();
release();
if (request->success()) {
auto vcard = request->vcard();
Expand Down
8 changes: 5 additions & 3 deletions src/pepmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,11 @@ PEPGetTask::PEPGetTask(Task *parent, const QString &jid, const QString &node, co
items.setAttribute("node", node);
pubsub.appendChild(items);

QDomElement item = doc()->createElement("item");
item.setAttribute("id", itemID);
items.appendChild(item);
if (!itemID.isEmpty()) {
QDomElement item = doc()->createElement("item");
item.setAttribute("id", itemID);
items.appendChild(item);
}
}

void PEPGetTask::onGo() { send(iq_); }
Expand Down
39 changes: 24 additions & 15 deletions src/vcardfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ VCard4::VCard VCardFactory::vcard(const Jid &j, Flags flags)
*/
Task *VCardFactory::setVCard(PsiAccount *account, const VCard4::VCard &v, const Jid &targetJid, Flags flags)
{
if ((flags & MucRoom) || !account->client()->serverInfoManager()->server_features().hasVCard4()) {
if ((flags & MucRoom) || !account->client()->serverInfoManager()->hasPersistentStorage()) {
JT_VCard *jtVCard_ = new JT_VCard(account->client()->rootTask());
connect(jtVCard_, &JT_VCard::finished, this, [this, v, jtVCard_, flags]() {
if (jtVCard_->success()) {
Expand All @@ -248,7 +248,7 @@ Task *VCardFactory::setVCard(PsiAccount *account, const VCard4::VCard &v, const
}
QDomDocument *doc = account->client()->doc();
auto el = v.toXmlElement(*doc);
return account->pepManager()->publish(QLatin1String(PEP_VCARD4_NS), PubSubItem({}, el));
return account->pepManager()->publish(QLatin1String(PEP_VCARD4_NODE), PubSubItem({}, el));
}

/**
Expand Down Expand Up @@ -352,14 +352,24 @@ Task *VCardRequest::execute()
return nullptr;

bool doTemp = (d->flags & VCardFactory::MucRoom) || (d->flags & VCardFactory::MucUser);
if (!doTemp && (*paIt)->client()->capsManager()->disco(d->jid).features().hasVCard4()) {
auto client = (*paIt)->client();
auto cm = client->capsManager();

if (!doTemp) {
if (d->jid.compare((*paIt)->jid(), false)) {
doTemp = !client->serverInfoManager()->hasPersistentStorage();
} else {
doTemp = !cm->features(d->jid).hasVCard4();
}
}
if (!doTemp) {
auto task = (*paIt)->pepManager()->get(d->jid, PEP_VCARD4_NODE, {});
task->connect(task, &JT_VCard::finished, this, [this, task]() {
task->connect(task, &PEPGetTask::finished, this, [this, task]() {
if (task->success()) {
d->vcard = VCard4::VCard(task->items().value(0).payload());
} else if (!task->error().isCancel()
|| task->error().condition != XMPP::Stanza::Error::ErrorCond::ItemNotFound) {
// consider not founf vcard as not an error. maybe user removed their vcard intentionally
// consider not found vcard as not an error. maybe user removed their vcard intentionally
d->error.reset(new Stanza::Error(task->error()));
d->statusString = task->statusString();
}
Expand All @@ -374,7 +384,7 @@ Task *VCardRequest::execute()
d->vcard.fromVCardTemp(task->vcard());
} else if (!task->error().isCancel()
|| task->error().condition != XMPP::Stanza::Error::ErrorCond::ItemNotFound) {
// consider not founf vcard as not an error. maybe user removed their vcard intentionally
// consider not found vcard as not an error. maybe user removed their vcard intentionally
d->error.reset(new Stanza::Error(task->error()));
d->statusString = task->statusString();
}
Expand Down Expand Up @@ -413,17 +423,16 @@ VCardFactory::QueuedLoader::QueuedLoader(VCardFactory *vcf) : QObject(vcf), q(vc
return;
}
auto request = queue_.takeFirst();
auto task = request->execute();
if (task) {
connect(task, &JT_VCard::finished, this, [this, request]() {
connect(request, &VCardRequest::finished, this, [this, request]() {
#ifdef VCF_DEBUG
qDebug() << "received VCardRequest" << request->jid().full();
qDebug() << "received VCardRequest" << request->jid().full();
#endif
emit vcardReceived(request);
jid2req.remove(request->jid());
request->deleteLater();
});
} else {
emit vcardReceived(request);
jid2req.remove(request->jid());
request->deleteLater();
});
auto task = request->execute();
if (!task) {
jid2req.remove(request->jid());
request->deleteLater();
}
Expand Down

0 comments on commit 94b7166

Please sign in to comment.