From 85f4f03bbd0159e200c226061633cb924c56ccb8 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 28 Feb 2024 13:15:47 +0300 Subject: Telegram: support for settings our own avatar --- protocols/Telegram/src/avatars.cpp | 22 +++++++++++++++++++--- protocols/Telegram/src/proto.h | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) (limited to 'protocols/Telegram') diff --git a/protocols/Telegram/src/avatars.cpp b/protocols/Telegram/src/avatars.cpp index 0875ad21d2..4c9cca1d58 100644 --- a/protocols/Telegram/src/avatars.cpp +++ b/protocols/Telegram/src/avatars.cpp @@ -72,9 +72,26 @@ INT_PTR CTelegramProto::SvcGetMyAvatar(WPARAM wParam, LPARAM lParam) return 0; } -INT_PTR CTelegramProto::SvcSetMyAvatar(WPARAM, LPARAM) +///////////////////////////////////////////////////////////////////////////////////////// + +void CTelegramProto::OnAvatarSet(td::ClientManager::Response&, void *pUserInfo) { - return 1; + ptrW pwszFileName((wchar_t *)pUserInfo); + DeleteFileW(pwszFileName); +} + +INT_PTR CTelegramProto::SvcSetMyAvatar(WPARAM, LPARAM lParam) +{ + auto *pwszFileName = (const wchar_t *)lParam; + if (ProtoGetAvatarFileFormat(pwszFileName) != PA_FORMAT_JPEG) { + Popup(0, TranslateT("Avatar file must be a picture in JPEG format"), TranslateT("Error setting avatar")); + return 1; + } + + TD::object_ptr localFile(new TD::inputFileLocal(T2Utf(pwszFileName).get())); + TD::object_ptr photo(new TD::inputChatPhotoStatic(std::move(localFile))); + SendQuery(new TD::setProfilePhoto(std::move(photo), true), &CTelegramProto::OnAvatarSet, mir_wstrdup(pwszFileName)); + return -1; } ///////////////////////////////////////////////////////////////////////////////////////// @@ -103,7 +120,6 @@ void CTelegramProto::OnGetFileLink(td::ClientManager::Response &response) { if (!response.object) return; - } void __cdecl CTelegramProto::OfflineFileThread(void *pParam) diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 2b628abfc2..9e755fb1c6 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -222,6 +222,7 @@ class CTelegramProto : public PROTO { return CMStringW(VARSW(L"%miranda_userdata%")) + L"\\" + _A2T(m_szModuleName); } + void OnAvatarSet(td::ClientManager::Response &response, void *pUserInfo); void OnEndSession(td::ClientManager::Response &response); void OnGetFileInfo(td::ClientManager::Response &response, void *pUserInfo); void OnGetFileLink(td::ClientManager::Response &response); -- cgit v1.2.3