mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Correctly send avatar hashs as file_idS
This commit is contained in:
parent
eda513b6cf
commit
9fdf382d7b
|
@ -36,11 +36,12 @@ void CoreFile::sendAvatarFile(Core* core, uint32_t friendId, const QByteArray& d
|
||||||
{
|
{
|
||||||
QMutexLocker mlocker(&fileSendMutex);
|
QMutexLocker mlocker(&fileSendMutex);
|
||||||
|
|
||||||
uint8_t filename[TOX_HASH_LENGTH];
|
static_assert(TOX_HASH_LENGTH <= TOX_FILE_ID_LENGTH, "TOX_HASH_LENGTH > TOX_FILE_ID_LENGTH!");
|
||||||
tox_hash(filename, (uint8_t*)data.data(), data.size());
|
uint8_t avatarHash[TOX_HASH_LENGTH];
|
||||||
|
tox_hash(avatarHash, (uint8_t*)data.data(), data.size());
|
||||||
uint64_t filesize = data.size();
|
uint64_t filesize = data.size();
|
||||||
uint32_t fileNum = tox_file_send(core->tox, friendId, TOX_FILE_KIND_AVATAR, filesize,
|
uint32_t fileNum = tox_file_send(core->tox, friendId, TOX_FILE_KIND_AVATAR, filesize,
|
||||||
nullptr, filename, TOX_HASH_LENGTH, nullptr);
|
avatarHash, avatarHash, TOX_HASH_LENGTH, nullptr);
|
||||||
if (fileNum == std::numeric_limits<uint32_t>::max())
|
if (fileNum == std::numeric_limits<uint32_t>::max())
|
||||||
{
|
{
|
||||||
qWarning() << "sendAvatarFile: Can't create the Tox file sender";
|
qWarning() << "sendAvatarFile: Can't create the Tox file sender";
|
||||||
|
@ -50,7 +51,7 @@ void CoreFile::sendAvatarFile(Core* core, uint32_t friendId, const QByteArray& d
|
||||||
|
|
||||||
ToxFile file{fileNum, friendId, "", "", ToxFile::SENDING};
|
ToxFile file{fileNum, friendId, "", "", ToxFile::SENDING};
|
||||||
file.filesize = filesize;
|
file.filesize = filesize;
|
||||||
file.fileName = QByteArray((char*)filename, TOX_HASH_LENGTH);
|
file.fileName = QByteArray((char*)avatarHash, TOX_HASH_LENGTH);
|
||||||
file.fileKind = TOX_FILE_KIND_AVATAR;
|
file.fileKind = TOX_FILE_KIND_AVATAR;
|
||||||
file.avatarData = data;
|
file.avatarData = data;
|
||||||
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
file.resumeFileId.resize(TOX_FILE_ID_LENGTH);
|
||||||
|
@ -246,7 +247,12 @@ void CoreFile::onFileReceiveCallback(Tox*, uint32_t friendId, uint32_t fileId, u
|
||||||
QFile::remove(QDir(Settings::getSettingsDirPath()).filePath("avatars/"+friendAddr.left(64)+".hash"));
|
QFile::remove(QDir(Settings::getSettingsDirPath()).filePath("avatars/"+friendAddr.left(64)+".hash"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (Settings::getInstance().getAvatarHash(friendAddr) == QByteArray((char*)fname, fnameLen))
|
else
|
||||||
|
{
|
||||||
|
static_assert(TOX_HASH_LENGTH <= TOX_FILE_ID_LENGTH, "TOX_HASH_LENGTH > TOX_FILE_ID_LENGTH!");
|
||||||
|
uint8_t avatarHash[TOX_FILE_ID_LENGTH];
|
||||||
|
tox_file_get_file_id(core->tox, friendId, fileId, avatarHash, nullptr);
|
||||||
|
if (Settings::getInstance().getAvatarHash(friendAddr) == QByteArray((char*)avatarHash, TOX_HASH_LENGTH))
|
||||||
{
|
{
|
||||||
// If it's an avatar but we already have it cached, cancel
|
// If it's an avatar but we already have it cached, cancel
|
||||||
tox_file_control(core->tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, nullptr);
|
tox_file_control(core->tox, friendId, fileId, TOX_FILE_CONTROL_CANCEL, nullptr);
|
||||||
|
@ -258,6 +264,7 @@ void CoreFile::onFileReceiveCallback(Tox*, uint32_t friendId, uint32_t fileId, u
|
||||||
tox_file_control(core->tox, friendId, fileId, TOX_FILE_CONTROL_RESUME, nullptr);
|
tox_file_control(core->tox, friendId, fileId, TOX_FILE_CONTROL_RESUME, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ToxFile file{fileId, friendId,
|
ToxFile file{fileId, friendId,
|
||||||
CString::toString(fname,fnameLen).toUtf8(), "", ToxFile::RECEIVING};
|
CString::toString(fname,fnameLen).toUtf8(), "", ToxFile::RECEIVING};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user