From 82325bdfe25ff24ea97822867b1c89b0622eedf7 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 17 Jan 2023 15:00:23 +0300 Subject: Telegram: avatars to be stored inside common avatars folder --- protocols/Telegram/src/avatars.cpp | 14 ++++++-------- protocols/Telegram/src/proto.cpp | 6 ++++++ protocols/Telegram/src/proto.h | 1 - 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/protocols/Telegram/src/avatars.cpp b/protocols/Telegram/src/avatars.cpp index 71ee97f3d6..a322e9fb11 100644 --- a/protocols/Telegram/src/avatars.cpp +++ b/protocols/Telegram/src/avatars.cpp @@ -20,10 +20,9 @@ along with this program. If not, see . CMStringW CTelegramProto::GetAvatarFilename(MCONTACT hContact) { CMStringW wszResult(GetAvatarPath()); - wszResult.AppendChar('\\'); const wchar_t *szFileType = ProtoGetAvatarExtension(getByte(hContact, "AvatarType", PA_FORMAT_JPEG)); - wszResult.AppendFormat(L"%s%s", getMStringW(hContact, DBKEY_ID).c_str(), szFileType); + wszResult.AppendFormat(L"\\%s%s", getMStringW(hContact, DBKEY_ID).c_str(), szFileType); return wszResult; } @@ -55,10 +54,7 @@ INT_PTR CTelegramProto::SvcGetAvatarInfo(WPARAM, LPARAM lParam) { auto *pai = (PROTO_AVATAR_INFORMATION *)lParam; - ptrW wszPath(getWStringA(pai->hContact, DBKEY_AVATAR_PATH)); - if (wszPath == nullptr) - return GAIR_NOAVATAR; - + CMStringW wszPath(GetAvatarFilename(pai->hContact)); pai->format = getByte(pai->hContact, DBKEY_AVATAR_TYPE, PA_FORMAT_JPEG); wcsncpy_s(pai->filename, wszPath, _TRUNCATE); @@ -89,13 +85,15 @@ void CTelegramProto::ProcessFile(TD::updateFile *pObj) for (auto &it : m_arUsers) { if (it->szAvatarHash == pFile->remote_->unique_id_.c_str()) { + CMStringW wszAvatarPath(GetAvatarFilename(it->hContact)); + PROTO_AVATAR_INFORMATION pai; - wcsncpy_s(pai.filename, Utf2T(pFile->local_->path_.c_str()), _TRUNCATE); pai.hContact = it->hContact; pai.format = ProtoGetAvatarFileFormat(pai.filename); + wcsncpy_s(pai.filename, wszAvatarPath, _TRUNCATE); setByte(pai.hContact, DBKEY_AVATAR_TYPE, pai.format); - setWString(pai.hContact, DBKEY_AVATAR_PATH, pai.filename); + MoveFileW(Utf2T(pFile->local_->path_.c_str()), wszAvatarPath); ProtoBroadcastAck(it->hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &pai); break; diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index 2767e7c059..84944a6b49 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -75,6 +75,12 @@ void CTelegramProto::OnModulesLoaded() m_arUsers.insert(new TG_USER(_atoi64(szId.c_str()), 0)); for (auto &cc : AccContacts()) { + ptrA szPath(getStringA(cc, "AvatarPath")); + if (szPath) { + delSetting(cc, "AvatarPath"); + delSetting(cc, DBKEY_AVATAR_HASH); + } + bool isGroupChat = isChatRoom(cc); szId = getMStringA(cc, isGroupChat ? "ChatRoomID" : DBKEY_ID); if (!szId.IsEmpty()) { diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 5ffe9e4222..bdb911ac51 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -5,7 +5,6 @@ #define DBKEY_ID "id" #define DBKEY_AVATAR_HASH "AvatarHash" -#define DBKEY_AVATAR_PATH "AvatarPath" #define DBKEY_AVATAR_TYPE "AvatarType" class CTelegramProto; -- cgit v1.2.3