|
|
|
@ -185,8 +185,11 @@ void AvatarManager::uploadDefault(const QString& source, quint64 server) { |
|
|
|
if (!m_ready || m_preparing || !server || !gui_bridge_is_uasync_ready()) return; |
|
|
|
if (!m_ready || m_preparing || !server || !gui_bridge_is_uasync_ready()) return; |
|
|
|
m_preparing = true; emit statusChanged(text("Preparing avatar…")); |
|
|
|
m_preparing = true; emit statusChanged(text("Preparing avatar…")); |
|
|
|
const QString directory = m_directory; const quint64 generation = ++m_generation; cancelUploads(); |
|
|
|
const QString directory = m_directory; const quint64 generation = ++m_generation; cancelUploads(); |
|
|
|
m_pool.start(QRunnable::create([this, source, directory, server, generation] { |
|
|
|
QStringList pinned; if (!m_defaultHash.isEmpty()) pinned << m_defaultHash; |
|
|
|
|
|
|
|
for (const auto& job : m_jobs) if (job.upload) pinned << job.ref.hash; |
|
|
|
|
|
|
|
m_pool.start(QRunnable::create([this, source, directory, server, generation, pinned] { |
|
|
|
const auto result = AvatarCache::prepare(source, directory); |
|
|
|
const auto result = AvatarCache::prepare(source, directory); |
|
|
|
|
|
|
|
if (!result.image.isNull()) { auto keep = pinned; keep << result.hash; AvatarCache::prune(directory, keep); } |
|
|
|
QMetaObject::invokeMethod(this, [this, result, server, generation] { |
|
|
|
QMetaObject::invokeMethod(this, [this, result, server, generation] { |
|
|
|
m_preparing = false; |
|
|
|
m_preparing = false; |
|
|
|
if (generation != m_generation) return; |
|
|
|
if (generation != m_generation) return; |
|
|
|
@ -314,6 +317,10 @@ void AvatarManager::onTransfer(const uint8_t* data, int length) { |
|
|
|
if (length != 51 || data[50] != 2) return; |
|
|
|
if (length != 51 || data[50] != 2) return; |
|
|
|
const quint64 id = mf_get64(data); if (!m_jobs.contains(id)) return; |
|
|
|
const quint64 id = mf_get64(data); if (!m_jobs.contains(id)) return; |
|
|
|
auto& job = m_jobs[id]; const int status = data[48] | (int(data[49]) << 8); |
|
|
|
auto& job = m_jobs[id]; const int status = data[48] | (int(data[49]) << 8); |
|
|
|
|
|
|
|
if (job.stage != 99 || job.ref.group != mf_get64(data + 8) || job.ref.server != mf_get64(data + 16) || |
|
|
|
|
|
|
|
job.ref.owner != mf_get64(data + 24)) { |
|
|
|
|
|
|
|
DEBUG_WARN(DEBUG_CATEGORY_MEDIA, "avatar: stale or mismatched transfer completion id=%llu", (unsigned long long)id); return; |
|
|
|
|
|
|
|
} |
|
|
|
if (status) { finish(id, status); return; } |
|
|
|
if (status) { finish(id, status); return; } |
|
|
|
if (job.upload) { publish(job); return; } |
|
|
|
if (job.upload) { publish(job); return; } |
|
|
|
const Job snapshot = job; const QString directory = m_directory; job.stage = 101; |
|
|
|
const Job snapshot = job; const QString directory = m_directory; job.stage = 101; |
|
|
|
|