summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-02-28 13:15:47 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-02-28 13:15:47 +0300
commit85f4f03bbd0159e200c226061633cb924c56ccb8 (patch)
tree832b478b44bee09bff5a8562a34493b3e51ba44a /protocols/Telegram/src
parent667ded1639b12b365a009441677d6962642bd914 (diff)
Telegram: support for settings our own avatar
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r--protocols/Telegram/src/avatars.cpp22
-rw-r--r--protocols/Telegram/src/proto.h1
2 files changed, 20 insertions, 3 deletions
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<TD::InputFile> localFile(new TD::inputFileLocal(T2Utf(pwszFileName).get()));
+ TD::object_ptr<TD::InputChatPhoto> 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<CTelegramProto>
{ 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);