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:
parent
9905042434
commit
981588d630
|
@ -1094,20 +1094,25 @@ 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
|
||||
QString id = getFriendPublicKey(friendNumber);
|
||||
QString addr = Settings::getInstance().getFriendAdress(id);
|
||||
if (addr.size() > id.size())
|
||||
return addr;
|
||||
|
||||
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() << "getFriendAddress: Getting public key failed";
|
||||
qWarning() << "getFriendPublicKey: Getting public key failed";
|
||||
return QString();
|
||||
}
|
||||
QByteArray data((char*)rawid, TOX_PUBLIC_KEY_SIZE);
|
||||
QString id = data.toHex().toUpper();
|
||||
|
||||
QString addr = Settings::getInstance().getFriendAdress(id);
|
||||
if (addr.size() > id.size())
|
||||
return addr;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,6 +333,9 @@ void CoreFile::onFileControlCallback(Tox*, uint32_t friendId, uint32_t fileId,
|
|||
}
|
||||
else if (control == TOX_FILE_CONTROL_RESUME)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user