summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src/groupchat.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2023-02-01 16:58:06 +0300
committerGeorge Hazan <ghazan@miranda.im>2023-02-01 16:58:06 +0300
commit55cae2b76c0f4bebd69ca50113fbda8b7fd4b641 (patch)
tree6d086cfbddce119fab635fa9de3a66965d5598b6 /protocols/Telegram/src/groupchat.cpp
parente24a98864045837ff4a7d22b770b3768e90b86a1 (diff)
Telegram: group chats support (initial version)
Diffstat (limited to 'protocols/Telegram/src/groupchat.cpp')
-rw-r--r--protocols/Telegram/src/groupchat.cpp125
1 files changed, 125 insertions, 0 deletions
diff --git a/protocols/Telegram/src/groupchat.cpp b/protocols/Telegram/src/groupchat.cpp
new file mode 100644
index 0000000000..c0f815aa8a
--- /dev/null
+++ b/protocols/Telegram/src/groupchat.cpp
@@ -0,0 +1,125 @@
+/*
+Copyright (C) 2012-23 Miranda NG team (https://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h"
+
+void CTelegramProto::InitGroupChat(TG_USER *pUser, const TD::chat *pChat, bool bUpdateMembers)
+{
+ if (pUser->m_si)
+ return;
+
+ wchar_t wszId[100];
+ _i64tow(pUser->id, wszId, 10);
+ auto *si = pUser->m_si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszId, Utf2T(pChat->title_.c_str()), pUser);
+
+ if (bUpdateMembers) {
+ Chat_AddGroup(si, TranslateT("Creator"));
+ Chat_AddGroup(si, TranslateT("Admin"));
+ Chat_AddGroup(si, TranslateT("Participant"));
+
+ // push async query to fetch users
+ SendQuery(new TD::getBasicGroupFullInfo(pUser->id), &CTelegramProto::StartGroupChat, pUser);
+ }
+ else {
+ Chat_AddGroup(si, TranslateT("SuperAdmin"));
+ Chat_AddGroup(si, TranslateT("Visitor"));
+
+ ptrW wszUserId(getWStringA(DBKEY_ID)), wszNick(Contact::GetInfo(CNF_DISPLAY, 0, m_szModuleName));
+
+ GCEVENT gce = { si, GC_EVENT_JOIN };
+ gce.pszUID.w = wszUserId;
+ gce.pszNick.w = wszNick;
+ gce.bIsMe = true;
+ gce.pszStatus.w = TranslateT("Visitor");
+ Chat_Event(&gce);
+
+ gce.bIsMe = false;
+ gce.pszUID.w = L"---";
+ gce.pszNick.w = TranslateT("Admin");
+ gce.pszStatus.w = TranslateT("SuperAdmin");
+ Chat_Event(&gce);
+
+ Chat_Control(si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE);
+ Chat_Control(si, SESSION_ONLINE);
+ }
+}
+
+void CTelegramProto::StartGroupChat(td::ClientManager::Response &response, void *pUserData)
+{
+ if (!response.object)
+ return;
+
+ if (response.object->get_id() != TD::basicGroupFullInfo::ID) {
+ debugLogA("Gotten class ID %d instead of %d, exiting", response.object->get_id(), TD::basicGroupFullInfo::ID);
+ return;
+ }
+
+ auto *pInfo = ((TD::basicGroupFullInfo *)response.object.get());
+ auto *pUser = (TG_USER *)pUserData;
+
+ for (auto &it : pInfo->members_) {
+ auto *pMember = it.get();
+ const wchar_t *pwszRole;
+
+ switch (pMember->status_->get_id()) {
+ case TD::chatMemberStatusCreator::ID:
+ pwszRole = TranslateT("Creator");
+ break;
+ case TD::chatMemberStatusAdministrator::ID:
+ pwszRole = TranslateT("Admin");
+ break;
+ case TD::chatMemberStatusMember::ID:
+ default:
+ pwszRole = TranslateT("Participant");
+ break;
+ }
+
+ if (pMember->member_id_->get_id() != TD::messageSenderUser::ID)
+ continue;
+
+ int64_t memberId = ((TD::messageSenderUser *)pMember->member_id_.get())->user_id_;
+ auto *pChatUser = FindUser(memberId);
+ if (pChatUser == nullptr)
+ continue;
+
+ wchar_t wszUserId[100];
+ _i64tow(memberId, wszUserId, 10);
+
+ GCEVENT gce = { pUser->m_si, GC_EVENT_JOIN };
+ gce.pszUID.w = wszUserId;
+ gce.pszStatus.w = pwszRole;
+
+ switch (pChatUser->hContact) {
+ case 0:
+ gce.bIsMe = true;
+ __fallthrough;
+
+ case INVALID_CONTACT_ID:
+ gce.pszNick.w = pChatUser->wszNick.c_str();
+ break;
+
+ default:
+ gce.pszNick.w = Clist_GetContactDisplayName(pChatUser->hContact);
+ break;
+ }
+
+ Chat_Event(&gce);
+ }
+
+ Chat_Control(pUser->m_si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE);
+ Chat_Control(pUser->m_si, SESSION_ONLINE);
+}