summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src/groupchat.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/src/groupchat.cpp')
-rw-r--r--protocols/Telegram/src/groupchat.cpp145
1 files changed, 84 insertions, 61 deletions
diff --git a/protocols/Telegram/src/groupchat.cpp b/protocols/Telegram/src/groupchat.cpp
index e3a646dc03..c4f134f6d9 100644
--- a/protocols/Telegram/src/groupchat.cpp
+++ b/protocols/Telegram/src/groupchat.cpp
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2012-24 Miranda NG team (https://miranda-ng.org)
+Copyright (C) 2012-25 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
@@ -46,7 +46,7 @@ void CTelegramProto::InitGroupChat(TG_USER *pUser, const wchar_t *pwszTitle)
if (pUser->bLoadMembers) {
pUser->m_si = si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszId, pwszTitle, pUser);
- if (!si->pStatuses) {
+ if (!si->arStatuses.getCount()) {
Chat_AddGroup(si, TranslateT("Creator"));
Chat_AddGroup(si, TranslateT("Admin"));
Chat_AddGroup(si, TranslateT("Participant"));
@@ -61,7 +61,7 @@ void CTelegramProto::InitGroupChat(TG_USER *pUser, const wchar_t *pwszTitle)
}
else {
pUser->m_si = si = Chat_NewSession(GCW_CHANNEL, m_szModuleName, wszId, pwszTitle, pUser);
- if (!si->pStatuses) {
+ if (!si->arStatuses.getCount()) {
Chat_AddGroup(si, TranslateT("SuperAdmin"));
Chat_AddGroup(si, TranslateT("Visitor"));
@@ -391,67 +391,36 @@ void CTelegramProto::ProcessBasicGroup(TD::updateBasicGroup *pObj)
pUser->bLoadMembers = true;
}
-void CTelegramProto::ProcessBasicGroupInfo(TD::updateBasicGroupFullInfo *pObj)
+void CTelegramProto::ProcessBasicGroupInfo(TG_USER *pChat, TD::basicGroupFullInfo *pInfo)
{
- auto *pChat = FindUser(pObj->basic_group_id_);
- if (pChat == nullptr || pChat->m_si == nullptr)
- return;
-
- if (auto *pInfo = pObj->basic_group_full_info_.get()) {
- if (!pInfo->description_.empty())
- GcChangeTopic(pChat, pInfo->description_);
-
- g_chatApi.UM_RemoveAll(pChat->m_si);
- GcAddMembers(pChat, pInfo->members_, true);
- }
-}
-
-void CTelegramProto::ProcessForum(TD::updateForumTopicInfo *pForum)
-{
- auto *pUser = FindChat(pForum->chat_id_);
- if (!pUser) {
- debugLogA("Uknown chat id %lld, skipping", pForum->chat_id_);
- return;
- }
-
- auto *pInfo = pForum->info_.get();
- if (pUser->m_si == nullptr) {
- debugLogA("No parent chat for id %lld, skipping", pForum->chat_id_);
- return;
- }
-
- if (pInfo->is_general_) {
- SetId(pUser->m_si->hContact, pForum->info_->message_thread_id_, DBKEY_THREAD);
- return;
+ if (!pInfo->description_.empty()) {
+ setUString(pChat->hContact, "About", pInfo->description_.c_str());
+ GcChangeTopic(pChat, pInfo->description_);
}
- wchar_t wszId[100];
- mir_snwprintf(wszId, L"%lld_%lld", pForum->chat_id_, pForum->info_->message_thread_id_);
-
- auto *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszId, Utf2T(pForum->info_->name_.c_str()), pUser);
- si->pParent = pUser->m_si;
-
- SetId(si->hContact, pForum->info_->message_thread_id_, DBKEY_THREAD);
- SetId(si->hContact, pUser->id, DBKEY_OWNER);
-
- Chat_Mute(si->hContact, Chat_IsMuted(pUser->hContact));
- Clist_SetGroup(si->hContact, ptrW(Clist_GetGroup(pUser->hContact)));
-
- Chat_Control(si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE);
- Chat_Control(si, SESSION_ONLINE);
+ g_chatApi.UM_RemoveAll(pChat->m_si);
+ GcAddMembers(pChat, pInfo->members_, true);
}
-void CTelegramProto::ProcessSuperGroupInfo(TD::updateSupergroupFullInfo *pObj)
+void CTelegramProto::ProcessSuperGroupInfo(TG_USER *pUser, TD::supergroupFullInfo *pInfo)
{
- auto *pChat = FindUser(pObj->supergroup_id_);
- if (pChat == nullptr) {
- debugLogA("Uknown super group id %lld, skipping", pObj->supergroup_id_);
- return;
+ setDword(pUser->hContact, "MemberCount", pInfo->member_count_);
+
+ if (auto *pLink = pInfo->invite_link_.get())
+ setUString(pUser->hContact, "Link", pLink->invite_link_.c_str());
+ else if (auto *pGroup = FindSuperGroup(pUser->id)) {
+ if (pGroup->group->usernames_) {
+ CMStringA szLink(FORMAT, "https://t.me/%s", pGroup->group->usernames_->editable_username_.c_str());
+ setString(pUser->hContact, "Link", szLink);
+ }
+ else delSetting(pUser->hContact, "Link");
}
+ else delSetting(pUser->hContact, "Link");
- auto *pInfo = pObj->supergroup_full_info_.get();
- if (!pInfo->description_.empty())
- GcChangeTopic(pChat, pInfo->description_);
+ if (!pInfo->description_.empty()) {
+ setUString(pUser->hContact, "About", pInfo->description_.c_str());
+ GcChangeTopic(pUser, pInfo->description_);
+ }
}
void CTelegramProto::ProcessSuperGroup(TD::updateSupergroup *pObj)
@@ -462,16 +431,16 @@ void CTelegramProto::ProcessSuperGroup(TD::updateSupergroup *pObj)
return;
}
- TG_SUPER_GROUP tmp(pObj->supergroup_->id_, 0);
- auto *pGroup = m_arSuperGroups.find(&tmp);
+ auto id = pObj->supergroup_->id_;
+ auto *pGroup = FindSuperGroup(id);
if (pGroup == nullptr) {
- pGroup = new TG_SUPER_GROUP(tmp.id, std::move(pObj->supergroup_));
+ pGroup = new TG_SUPER_GROUP(id, std::move(pObj->supergroup_));
m_arSuperGroups.insert(pGroup);
}
else pGroup->group = std::move(pObj->supergroup_);
if (iStatusId == TD::chatMemberStatusLeft::ID) {
- auto *pUser = AddFakeUser(tmp.id, true);
+ auto *pUser = AddFakeUser(id, true);
pUser->isForum = pGroup->group->is_forum_;
if (pUser->hContact == INVALID_CONTACT_ID) {
// cache some information for the search
@@ -482,7 +451,7 @@ void CTelegramProto::ProcessSuperGroup(TD::updateSupergroup *pObj)
else RemoveFromClist(pUser);
}
else {
- auto *pChat = AddUser(tmp.id, true);
+ auto *pChat = AddUser(id, true);
pChat->isForum = pGroup->group->is_forum_;
if (!pGroup->group->is_channel_)
pChat->bLoadMembers = true;
@@ -506,3 +475,57 @@ void CTelegramProto::ProcessSuperGroup(TD::updateSupergroup *pObj)
}
}
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// forums
+
+void CTelegramProto::OnGetTopics(td::ClientManager::Response &response, void *pUserInfo)
+{
+ if (!response.object)
+ return;
+
+ if (response.object->get_id() != TD::forumTopics::ID)
+ return;
+
+ auto *pUser = (TG_USER *)pUserInfo;
+
+ auto *pInfo = (TD::forumTopics *)response.object.get();
+ if (pInfo->topics_.size() >= 100)
+ SendQuery(new TD::getForumTopics(pUser->chatId, "", pInfo->next_offset_date_, pInfo->next_offset_message_id_, pInfo->next_offset_message_thread_id_, 100),
+ &CTelegramProto::OnGetTopics, pUser);
+}
+
+void CTelegramProto::ProcessForum(TD::updateForumTopicInfo *pForum)
+{
+ auto *pUser = FindChat(pForum->chat_id_);
+ if (!pUser) {
+ debugLogA("Uknown chat id %lld, skipping", pForum->chat_id_);
+ return;
+ }
+
+ auto *pInfo = pForum->info_.get();
+ if (pUser->m_si == nullptr) {
+ debugLogA("No parent chat for id %lld, skipping", pForum->chat_id_);
+ return;
+ }
+
+ if (pInfo->is_general_) {
+ SetId(pUser->m_si->hContact, pForum->info_->message_thread_id_, DBKEY_THREAD);
+ return;
+ }
+
+ wchar_t wszId[100];
+ mir_snwprintf(wszId, L"%lld_%lld", pForum->chat_id_, pForum->info_->message_thread_id_);
+
+ auto *si = Chat_NewSession(GCW_CHATROOM, m_szModuleName, wszId, Utf2T(pForum->info_->name_.c_str()), pUser);
+ si->pParent = pUser->m_si;
+
+ SetId(si->hContact, pForum->info_->message_thread_id_, DBKEY_THREAD);
+ SetId(si->hContact, pUser->id, DBKEY_OWNER);
+
+ Chat_Mute(si->hContact, Chat_IsMuted(pUser->hContact));
+ Clist_SetGroup(si->hContact, ptrW(Clist_GetGroup(pUser->hContact)));
+
+ Chat_Control(si, m_bHideGroupchats ? WINDOW_HIDDEN : SESSION_INITDONE);
+ Chat_Control(si, SESSION_ONLINE);
+}