|
|
|
@ -33,13 +33,9 @@
@@ -33,13 +33,9 @@
|
|
|
|
|
* so we don't spam avatar transfers to a friend who already has it. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
QByteArray AvatarBroadcaster::avatarData; |
|
|
|
|
QMap<uint32_t, bool> AvatarBroadcaster::friendsSentTo; |
|
|
|
|
|
|
|
|
|
static QMetaObject::Connection autoBroadcastConn; |
|
|
|
|
static auto autoBroadcast = [](uint32_t friendId, Status::Status) { |
|
|
|
|
AvatarBroadcaster::sendAvatarTo(friendId); |
|
|
|
|
}; |
|
|
|
|
AvatarBroadcaster::AvatarBroadcaster(Core& _core) |
|
|
|
|
: core{_core} |
|
|
|
|
{} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set our current avatar. |
|
|
|
@ -47,15 +43,17 @@ static auto autoBroadcast = [](uint32_t friendId, Status::Status) {
@@ -47,15 +43,17 @@ static auto autoBroadcast = [](uint32_t friendId, Status::Status) {
|
|
|
|
|
*/ |
|
|
|
|
void AvatarBroadcaster::setAvatar(QByteArray data) |
|
|
|
|
{ |
|
|
|
|
if (avatarData == data) |
|
|
|
|
if (avatarData == data) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
avatarData = data; |
|
|
|
|
friendsSentTo.clear(); |
|
|
|
|
|
|
|
|
|
QVector<uint32_t> friends = Core::getInstance()->getFriendList(); |
|
|
|
|
for (uint32_t friendId : friends) |
|
|
|
|
QVector<uint32_t> friends = core.getFriendList(); |
|
|
|
|
for (uint32_t friendId : friends) { |
|
|
|
|
sendAvatarTo(friendId); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -64,11 +62,15 @@ void AvatarBroadcaster::setAvatar(QByteArray data)
@@ -64,11 +62,15 @@ void AvatarBroadcaster::setAvatar(QByteArray data)
|
|
|
|
|
*/ |
|
|
|
|
void AvatarBroadcaster::sendAvatarTo(uint32_t friendId) |
|
|
|
|
{ |
|
|
|
|
if (friendsSentTo.contains(friendId) && friendsSentTo[friendId]) |
|
|
|
|
if (friendsSentTo.contains(friendId) && friendsSentTo[friendId]) { |
|
|
|
|
return; |
|
|
|
|
if (!Core::getInstance()->isFriendOnline(friendId)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!core.isFriendOnline(friendId)) { |
|
|
|
|
return; |
|
|
|
|
CoreFile* coreFile = Core::getInstance()->getCoreFile(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CoreFile* coreFile = core.getCoreFile(); |
|
|
|
|
coreFile->sendAvatarFile(friendId, avatarData); |
|
|
|
|
friendsSentTo[friendId] = true; |
|
|
|
|
} |
|
|
|
@ -79,8 +81,9 @@ void AvatarBroadcaster::sendAvatarTo(uint32_t friendId)
@@ -79,8 +81,9 @@ void AvatarBroadcaster::sendAvatarTo(uint32_t friendId)
|
|
|
|
|
*/ |
|
|
|
|
void AvatarBroadcaster::enableAutoBroadcast(bool state) |
|
|
|
|
{ |
|
|
|
|
QObject::disconnect(autoBroadcastConn); |
|
|
|
|
if (state) |
|
|
|
|
autoBroadcastConn = |
|
|
|
|
QObject::connect(Core::getInstance(), &Core::friendStatusChanged, autoBroadcast); |
|
|
|
|
this->disconnect(&core, nullptr, this, nullptr); |
|
|
|
|
if (state) { |
|
|
|
|
connect(&core, &Core::friendStatusChanged, |
|
|
|
|
[=](uint32_t friendId, Status::Status) { this->sendAvatarTo(friendId); }); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|