forked from blue/squawk
offline avatars in mucs
This commit is contained in:
parent
29c7d31c89
commit
21c7d65027
16 changed files with 225 additions and 45 deletions
|
@ -25,7 +25,8 @@ Core::Conference::Conference(const QString& p_jid, const QString& p_account, boo
|
|||
nick(p_nick),
|
||||
room(p_room),
|
||||
joined(false),
|
||||
autoJoin(p_autoJoin)
|
||||
autoJoin(p_autoJoin),
|
||||
exParticipants()
|
||||
{
|
||||
muc = true;
|
||||
name = p_name;
|
||||
|
@ -44,6 +45,8 @@ Core::Conference::Conference(const QString& p_jid, const QString& p_account, boo
|
|||
if (autoJoin) {
|
||||
room->join();
|
||||
}
|
||||
|
||||
archive->readAllResourcesAvatars(exParticipants);
|
||||
}
|
||||
|
||||
Core::Conference::~Conference()
|
||||
|
@ -140,8 +143,8 @@ void Core::Conference::onRoomParticipantAdded(const QString& p_name)
|
|||
resource = "";
|
||||
}
|
||||
|
||||
Archive::AvatarInfo info;
|
||||
bool hasAvatar = readAvatarInfo(info, resource);
|
||||
std::map<QString, Archive::AvatarInfo>::const_iterator itr = exParticipants.find(resource);
|
||||
bool hasAvatar = itr != exParticipants.end();
|
||||
|
||||
if (resource.size() > 0) {
|
||||
QDateTime lastInteraction = pres.lastUserInteraction();
|
||||
|
@ -158,12 +161,12 @@ void Core::Conference::onRoomParticipantAdded(const QString& p_name)
|
|||
};
|
||||
|
||||
if (hasAvatar) {
|
||||
if (info.autogenerated) {
|
||||
if (itr->second.autogenerated) {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::valid));
|
||||
} else {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::autocreated));
|
||||
}
|
||||
cData.insert("avatarPath", avatarPath(resource) + "." + info.type);
|
||||
cData.insert("avatarPath", avatarPath(resource) + "." + itr->second.type);
|
||||
} else {
|
||||
cData.insert("avatarState", static_cast<uint>(Shared::Avatar::empty));
|
||||
cData.insert("avatarPath", "");
|
||||
|
@ -179,14 +182,14 @@ void Core::Conference::onRoomParticipantAdded(const QString& p_name)
|
|||
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 || !info.autogenerated) {
|
||||
if (!hasAvatar || !itr->second.autogenerated) {
|
||||
setAutoGeneratedAvatar(resource);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case QXmppPresence::VCardUpdateValidPhoto:{ //there is a photo, need to load
|
||||
if (hasAvatar) {
|
||||
if (info.autogenerated || info.hash != pres.photoHash()) {
|
||||
if (itr->second.autogenerated || itr->second.hash != pres.photoHash()) {
|
||||
emit requestVCard(p_name);
|
||||
}
|
||||
} else {
|
||||
|
@ -285,30 +288,46 @@ void Core::Conference::handlePresence(const QXmppPresence& pres)
|
|||
|
||||
bool Core::Conference::setAutoGeneratedAvatar(const QString& resource)
|
||||
{
|
||||
bool result = RosterItem::setAutoGeneratedAvatar(resource);
|
||||
Archive::AvatarInfo newInfo;
|
||||
bool result = RosterItem::setAutoGeneratedAvatar(newInfo, resource);
|
||||
if (result && resource.size() != 0) {
|
||||
std::map<QString, Archive::AvatarInfo>::iterator itr = exParticipants.find(resource);
|
||||
if (itr == exParticipants.end()) {
|
||||
exParticipants.insert(std::make_pair(resource, newInfo));
|
||||
} else {
|
||||
itr->second = newInfo;
|
||||
}
|
||||
emit changeParticipant(resource, {
|
||||
{"avatarState", static_cast<uint>(Shared::Avatar::autocreated)},
|
||||
{"avatarPath", avatarPath(resource) + ".png"}
|
||||
{"avatarPath", avatarPath(resource) + "." + newInfo.type}
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool Core::Conference::setAvatar(const QByteArray& data, const QString& resource)
|
||||
bool Core::Conference::setAvatar(const QByteArray& data, Archive::AvatarInfo& info, const QString& resource)
|
||||
{
|
||||
bool result = RosterItem::setAvatar(data, resource);
|
||||
bool result = RosterItem::setAvatar(data, info, resource);
|
||||
if (result && resource.size() != 0) {
|
||||
if (data.size() > 0) {
|
||||
QMimeDatabase db;
|
||||
QMimeType type = db.mimeTypeForData(data);
|
||||
QString ext = type.preferredSuffix();
|
||||
std::map<QString, Archive::AvatarInfo>::iterator itr = exParticipants.find(resource);
|
||||
if (itr == exParticipants.end()) {
|
||||
exParticipants.insert(std::make_pair(resource, info));
|
||||
} else {
|
||||
itr->second = info;
|
||||
}
|
||||
|
||||
emit changeParticipant(resource, {
|
||||
{"avatarState", static_cast<uint>(Shared::Avatar::autocreated)},
|
||||
{"avatarPath", avatarPath(resource) + "." + ext}
|
||||
{"avatarPath", avatarPath(resource) + "." + info.type}
|
||||
});
|
||||
} else {
|
||||
std::map<QString, Archive::AvatarInfo>::iterator itr = exParticipants.find(resource);
|
||||
if (itr != exParticipants.end()) {
|
||||
exParticipants.erase(itr);
|
||||
}
|
||||
|
||||
emit changeParticipant(resource, {
|
||||
{"avatarState", static_cast<uint>(Shared::Avatar::empty)},
|
||||
{"avatarPath", ""}
|
||||
|
@ -333,3 +352,12 @@ Shared::VCard Core::Conference::handleResponseVCard(const QXmppVCardIq& card, co
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
QMap<QString, QVariant> Core::Conference::getAllAvatars() const
|
||||
{
|
||||
QMap<QString, QVariant> result;
|
||||
for (const std::pair<QString, Archive::AvatarInfo>& pair : exParticipants) {
|
||||
result.insert(pair.first, avatarPath(pair.first) + "." + pair.second.type);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue