1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Fix some avatars saved with the wrong name

This commit is contained in:
tux3 2015-12-08 23:10:15 +01:00
parent 9905042434
commit 981588d630
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
3 changed files with 25 additions and 17 deletions

View File

@ -1094,16 +1094,7 @@ bool Core::hasFriendWithPublicKey(const QString &pubkey) const
QString Core::getFriendAddress(uint32_t friendNumber) const
{
// If we don't know the full address of the client, return just the id, otherwise get the full address
uint8_t rawid[TOX_PUBLIC_KEY_SIZE];
if (!tox_friend_get_public_key(tox, friendNumber, rawid, nullptr))
{
qWarning() << "getFriendAddress: Getting public key failed";
return QString();
}
QByteArray data((char*)rawid,TOX_PUBLIC_KEY_SIZE);
QString id = data.toHex().toUpper();
QString id = getFriendPublicKey(friendNumber);
QString addr = Settings::getInstance().getFriendAdress(id);
if (addr.size() > id.size())
return addr;
@ -1111,6 +1102,20 @@ QString Core::getFriendAddress(uint32_t friendNumber) const
return id;
}
QString Core::getFriendPublicKey(uint32_t friendNumber) const
{
uint8_t rawid[TOX_PUBLIC_KEY_SIZE];
if (!tox_friend_get_public_key(tox, friendNumber, rawid, nullptr))
{
qWarning() << "getFriendPublicKey: Getting public key failed";
return QString();
}
QByteArray data((char*)rawid, TOX_PUBLIC_KEY_SIZE);
QString id = data.toHex().toUpper();
return id;
}
QString Core::getFriendUsername(uint32_t friendnumber) const
{
size_t namesize = tox_friend_get_name_size(tox, friendnumber, nullptr);

View File

@ -64,8 +64,9 @@ public:
QString getGroupPeerName(int groupId, int peerId) const; ///< Get the name of a peer of a group
ToxId getGroupPeerToxId(int groupId, int peerId) const; ///< Get the public key of a peer of a group
QList<QString> getGroupPeerNames(int groupId) const; ///< Get the names of the peers of a group
QString getFriendAddress(uint32_t friendId) const; ///< Get the full address if known, or public key of a friend
QString getFriendUsername(uint32_t friendId) const; ///< Get the username of a friend
QString getFriendAddress(uint32_t friendNumber) const; ///< Get the full address if known, or public key of a friend
QString getFriendPublicKey(uint32_t friendNumber) const; ///< Get the public key part of the ToxID only
QString getFriendUsername(uint32_t friendNumber) const; ///< Get the username of a friend
bool isFriendOnline(uint32_t friendId) const; ///< Check if a friend is online. Unknown friends are considered offline.
bool hasFriendWithAddress(const QString &addr) const; ///< Check if we have a friend by address
bool hasFriendWithPublicKey(const QString &pubkey) const; ///< Check if we have a friend by public key

View File

@ -264,14 +264,13 @@ void CoreFile::onFileReceiveCallback(Tox*, uint32_t friendId, uint32_t fileId, u
if (kind == TOX_FILE_KIND_AVATAR)
{
QString friendAddr = core->getFriendAddress(friendId);
QString friendAddr = core->getFriendPublicKey(friendId);
if (!filesize)
{
qDebug() << QString("Received empty avatar request %1:%2").arg(friendId).arg(fileId);
// Avatars of size 0 means explicitely no avatar
emit core->friendAvatarRemoved(friendId);
QFile::remove(Settings::getInstance().getSettingsDirPath()+"avatars/"+friendAddr.left(64)+".png");
QFile::remove(Settings::getInstance().getSettingsDirPath()+"avatars/"+friendAddr.left(64)+".hash");
core->profile.removeAvatar(friendAddr);
return;
}
else
@ -334,7 +333,10 @@ void CoreFile::onFileControlCallback(Tox*, uint32_t friendId, uint32_t fileId,
}
else if (control == TOX_FILE_CONTROL_RESUME)
{
qDebug() << "onFileControlCallback: Received resume for file "<<friendId<<":"<<fileId;
if (file->direction == ToxFile::SENDING && file->fileKind == TOX_FILE_KIND_AVATAR)
qDebug() << "Avatar transfer"<<fileId<<"to friend"<<friendId<<"accepted";
else
qDebug() << "onFileControlCallback: Received resume for file "<<friendId<<":"<<fileId;
file->status = ToxFile::TRANSMITTING;
emit static_cast<Core*>(core)->fileTransferRemotePausedUnpaused(*file, false);
}
@ -437,7 +439,7 @@ void CoreFile::onFileRecvChunkCallback(Tox *tox, uint32_t friendId, uint32_t fil
if (!pic.isNull())
{
qDebug() << "Got"<<file->avatarData.size()<<"bytes of avatar data from" <<friendId;
core->profile.saveAvatar(file->avatarData, core->getFriendAddress(friendId));
core->profile.saveAvatar(file->avatarData, core->getFriendPublicKey(friendId));
emit core->friendAvatarChanged(friendId, pic);
}
}