Now avatars are properly autogenerated, reduced vCard spam

This commit is contained in:
Blue 2024-01-31 20:22:49 -03:00
parent 93c5be412e
commit 0be2648849
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
9 changed files with 76 additions and 92 deletions

View file

@ -132,9 +132,8 @@ void Core::Conference::onRoomParticipantAdded(const QString& p_name) {
if (resource.size() > 0) {
QDateTime lastInteraction = pres.lastUserInteraction();
if (!lastInteraction.isValid()) {
if (!lastInteraction.isValid())
lastInteraction = QDateTime::currentDateTimeUtc();
}
QMap<QString, QVariant> cData = {
{"lastActivity", lastInteraction},
@ -153,29 +152,37 @@ void Core::Conference::onRoomParticipantAdded(const QString& p_name) {
careAboutAvatar(hasAvatar, itr->second, cData, resource, p_name);
emit addParticipant(resource, cData);
if (!hasAvatar) // because this way vCard is already requested, no need to handle possible avatar update
return;
}
handlePossibleAvatarUpdate(pres, resource, hasAvatar, itr->second);
}
void Core::Conference::handlePossibleAvatarUpdate (
const QXmppPresence& pres,
const QString& resource,
bool hasAvatar,
const Archive::AvatarInfo& info
) {
switch (pres.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 (!hasAvatar || !itr->second.autogenerated) {
case QXmppPresence::VCardUpdateNoPhoto: //there is no photo, need to drop if any
if (!hasAvatar || !info.autogenerated)
setAutoGeneratedAvatar(resource);
}
}
break;
case QXmppPresence::VCardUpdateValidPhoto:{ //there is a photo, need to load
if (hasAvatar) {
if (itr->second.autogenerated || itr->second.hash != pres.photoHash())
emit requestVCard(p_name);
break;
case QXmppPresence::VCardUpdateValidPhoto: //there is a photo, need to load
if (hasAvatar) {
if (info.autogenerated || info.hash != pres.photoHash())
emit requestVCard(pres.from());
} else {
emit requestVCard(p_name);
emit requestVCard(pres.from());
}
break;
}
}
}
@ -235,32 +242,10 @@ void Core::Conference::handlePresence(const QXmppPresence& pres) {
QString resource("");
if (comps.size() > 1)
resource = comps.back();
switch (pres.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
Archive::AvatarInfo info;
bool hasAvatar = readAvatarInfo(info, resource);
if (!hasAvatar || !info.autogenerated) {
setAutoGeneratedAvatar(resource);
}
}
break;
case QXmppPresence::VCardUpdateValidPhoto:{ //there is a photo, need to load
Archive::AvatarInfo info;
bool hasAvatar = readAvatarInfo(info, resource);
if (hasAvatar) {
if (info.autogenerated || info.hash != pres.photoHash())
emit requestVCard(id);
} else {
emit requestVCard(id);
}
break;
}
}
Archive::AvatarInfo info;
bool hasAvatar = readAvatarInfo(info, resource);
handlePossibleAvatarUpdate(pres, resource, hasAvatar, info);
}
bool Core::Conference::setAutoGeneratedAvatar(const QString& resource) {
@ -272,6 +257,7 @@ bool Core::Conference::setAutoGeneratedAvatar(const QString& resource) {
exParticipants.insert(std::make_pair(resource, newInfo));
else
itr->second = newInfo;
emit changeParticipant(resource, {
{"avatarState", static_cast<uint>(Shared::Avatar::autocreated)},
{"avatarPath", avatarPath(resource) + "." + newInfo.type}
@ -313,18 +299,18 @@ bool Core::Conference::setAvatar(const QByteArray& data, Archive::AvatarInfo& in
void Core::Conference::handleResponseVCard(const QXmppVCardIq& card, const QString &resource, Shared::VCard& out) {
RosterItem::handleResponseVCard(card, resource, out);
if (resource.size() > 0) {
if (resource.size() > 0)
emit changeParticipant(resource, {
{"avatarState", static_cast<uint>(out.getAvatarType())},
{"avatarPath", out.getAvatarPath()}
});
}
}
QMap<QString, QVariant> Core::Conference::getAllAvatars() const {
QMap<QString, QVariant> result;
for (const std::pair<const QString, Archive::AvatarInfo>& pair : exParticipants)
result.insert(pair.first, avatarPath(pair.first) + "." + pair.second.type);
return result;
}