forked from blue/squawk
muc participant avatars
This commit is contained in:
parent
efc90e18c3
commit
55703c2007
15 changed files with 506 additions and 221 deletions
|
@ -349,13 +349,15 @@ void Core::Account::addedAccount(const QString& jid)
|
|||
{"state", state}
|
||||
});
|
||||
|
||||
if (contact->hasAvatar()) {
|
||||
if (!contact->isAvatarAutoGenerated()) {
|
||||
Archive::AvatarInfo info;
|
||||
bool hasAvatar = contact->readAvatarInfo(info);
|
||||
if (hasAvatar) {
|
||||
if (info.autogenerated) {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::valid));
|
||||
} else {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::autocreated));
|
||||
}
|
||||
cData.insert("avatarPath", contact->avatarPath());
|
||||
cData.insert("avatarPath", contact->avatarPath() + "." + info.type);
|
||||
} else {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::empty));
|
||||
cData.insert("avatarPath", "");
|
||||
|
@ -382,6 +384,7 @@ void Core::Account::handleNewRosterItem(Core::RosterItem* contact)
|
|||
QObject::connect(contact, &RosterItem::historyResponse, this, &Account::onContactHistoryResponse);
|
||||
QObject::connect(contact, &RosterItem::nameChanged, this, &Account::onContactNameChanged);
|
||||
QObject::connect(contact, &RosterItem::avatarChanged, this, &Account::onContactAvatarChanged);
|
||||
QObject::connect(contact, &RosterItem::requestVCard, this, &Account::requestVCard);
|
||||
}
|
||||
|
||||
void Core::Account::handleNewContact(Core::Contact* contact)
|
||||
|
@ -440,42 +443,9 @@ void Core::Account::onPresenceReceived(const QXmppPresence& p_presence)
|
|||
}
|
||||
} else {
|
||||
if (pendingVCardRequests.find(jid) == pendingVCardRequests.end()) {
|
||||
RosterItem* item = 0;
|
||||
std::map<QString, Contact*>::const_iterator itr = contacts.find(jid);
|
||||
if (itr != contacts.end()) {
|
||||
item = itr->second;
|
||||
} else {
|
||||
std::map<QString, Conference*>::const_iterator citr = conferences.find(jid);
|
||||
if (citr != conferences.end()) {
|
||||
item = citr->second;
|
||||
}
|
||||
}
|
||||
|
||||
if (item != 0) {
|
||||
switch (p_presence.vCardUpdateType()) {
|
||||
case QXmppPresence::VCardUpdateNone: //this presence has nothing to do with photo
|
||||
break;
|
||||
case QXmppPresence::VCardUpdateNotReady: //let's say the photo didn't change here
|
||||
break;
|
||||
case QXmppPresence::VCardUpdateNoPhoto: //there is no photo, need to drop if any
|
||||
if (!item->hasAvatar() || (item->hasAvatar() && !item->isAvatarAutoGenerated())) {
|
||||
item->setAutoGeneratedAvatar();
|
||||
}
|
||||
break;
|
||||
case QXmppPresence::VCardUpdateValidPhoto: //there is a photo, need to load
|
||||
if (item->hasAvatar()) {
|
||||
if (item->isAvatarAutoGenerated()) {
|
||||
requestVCard(jid);
|
||||
} else {
|
||||
if (item->avatarHash() != p_presence.photoHash()) {
|
||||
requestVCard(jid);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
requestVCard(jid);
|
||||
}
|
||||
break;
|
||||
}
|
||||
itr->second->handlePresence(p_presence);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1333,13 +1303,15 @@ void Core::Account::addNewRoom(const QString& jid, const QString& nick, const QS
|
|||
{"name", conf->getName()}
|
||||
};
|
||||
|
||||
if (conf->hasAvatar()) {
|
||||
if (!conf->isAvatarAutoGenerated()) {
|
||||
Archive::AvatarInfo info;
|
||||
bool hasAvatar = conf->readAvatarInfo(info);
|
||||
if (hasAvatar) {
|
||||
if (info.autogenerated) {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::valid));
|
||||
} else {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::autocreated));
|
||||
}
|
||||
cData.insert("avatarPath", conf->avatarPath());
|
||||
cData.insert("avatarPath", conf->avatarPath() + "." + info.type);
|
||||
} else {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::empty));
|
||||
cData.insert("avatarPath", "");
|
||||
|
@ -1406,8 +1378,14 @@ void Core::Account::renameContactRequest(const QString& jid, const QString& newN
|
|||
|
||||
void Core::Account::onVCardReceived(const QXmppVCardIq& card)
|
||||
{
|
||||
QString jid = card.from();
|
||||
pendingVCardRequests.erase(jid);
|
||||
QString id = card.from();
|
||||
QStringList comps = id.split("/");
|
||||
QString jid = comps.front();
|
||||
QString resource("");
|
||||
if (comps.size() > 1) {
|
||||
resource = comps.back();
|
||||
}
|
||||
pendingVCardRequests.erase(id);
|
||||
RosterItem* item = 0;
|
||||
|
||||
std::map<QString, Contact*>::const_iterator contItr = contacts.find(jid);
|
||||
|
@ -1427,35 +1405,8 @@ void Core::Account::onVCardReceived(const QXmppVCardIq& card)
|
|||
item = contItr->second;
|
||||
}
|
||||
|
||||
QByteArray ava = card.photo();
|
||||
Shared::VCard vCard = item->handleResponseVCard(card, resource);
|
||||
|
||||
if (ava.size() > 0) {
|
||||
item->setAvatar(ava);
|
||||
} else {
|
||||
if (!item->hasAvatar() || !item->isAvatarAutoGenerated()) {
|
||||
item->setAutoGeneratedAvatar();
|
||||
}
|
||||
}
|
||||
|
||||
Shared::VCard vCard;
|
||||
initializeVCard(vCard, card);
|
||||
|
||||
if (item->hasAvatar()) {
|
||||
if (!item->isAvatarAutoGenerated()) {
|
||||
vCard.setAvatarType(Shared::Avatar::valid);
|
||||
} else {
|
||||
vCard.setAvatarType(Shared::Avatar::autocreated);
|
||||
}
|
||||
vCard.setAvatarPath(item->avatarPath());
|
||||
} else {
|
||||
vCard.setAvatarType(Shared::Avatar::empty);
|
||||
}
|
||||
|
||||
QMap<QString, QVariant> cd = {
|
||||
{"avatarState", static_cast<quint8>(vCard.getAvatarType())},
|
||||
{"avatarPath", vCard.getAvatarPath()}
|
||||
};
|
||||
emit changeContact(jid, cd);
|
||||
emit receivedVCard(jid, vCard);
|
||||
}
|
||||
|
||||
|
@ -1577,6 +1528,7 @@ void Core::Account::onContactAvatarChanged(Shared::Avatar type, const QString& p
|
|||
void Core::Account::requestVCard(const QString& jid)
|
||||
{
|
||||
if (pendingVCardRequests.find(jid) == pendingVCardRequests.end()) {
|
||||
qDebug() << "requesting vCard" << jid;
|
||||
if (jid == getLogin() + "@" + getServer()) {
|
||||
if (!ownVCardRequestInProgress) {
|
||||
vm->requestClientVCard();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue