diff options
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r-- | protocols/Telegram/src/groupchat.cpp | 89 | ||||
-rw-r--r-- | protocols/Telegram/src/proto.h | 5 | ||||
-rw-r--r-- | protocols/Telegram/src/server.cpp | 10 | ||||
-rw-r--r-- | protocols/Telegram/src/utils.cpp | 10 |
4 files changed, 67 insertions, 47 deletions
diff --git a/protocols/Telegram/src/groupchat.cpp b/protocols/Telegram/src/groupchat.cpp index c92d605d4c..2f503581aa 100644 --- a/protocols/Telegram/src/groupchat.cpp +++ b/protocols/Telegram/src/groupchat.cpp @@ -406,41 +406,6 @@ void CTelegramProto::ProcessBasicGroupInfo(TD::updateBasicGroupFullInfo *pObj) } } -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); -} - void CTelegramProto::ProcessSuperGroupInfo(TD::updateSupergroupFullInfo *pObj) { auto *pChat = FindUser(pObj->supergroup_id_); @@ -506,3 +471,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); +} diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 69737ba35c..4040125506 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -101,7 +101,7 @@ struct TG_USER : public MZeroedObject int64_t id, chatId = -1; MCONTACT hContact; - int folderId = -1, nHistoryChunks; + int folderId = -1, nHistoryChunks, nTopics; bool isGroupChat, isChannel, isBot, isForum, bLoadMembers, bStartChat, bInited, bDelOwn = true, bDelAll = true; CMStringA szAvatarHash; CMStringW wszNick, wszFirstName, wszLastName; @@ -340,6 +340,7 @@ class CTelegramProto : public PROTO<CTelegramProto> TD::array<TD::int53> m_searchIds; void OnSearchResults(td::ClientManager::Response &response); + void OnGetTopics(td::ClientManager::Response &response, void *pUserInfo); bool CheckSearchUser(TG_USER *pUser); void ReportSearchUser(TG_USER *pUser); @@ -362,7 +363,7 @@ class CTelegramProto : public PROTO<CTelegramProto> int GetDefaultMute(const TG_USER *pUser); - MCONTACT GetRealContact(const TG_USER *pUser); + MCONTACT GetRealContact(const TG_USER *pUser, int64_t threadId = 0); void RemoveFromClist(TG_USER *pUser); void MarkRead(MCONTACT hContact, const CMStringA &szMaxId, bool bSent); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index b8206f8a39..9e7974035f 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -607,7 +607,7 @@ void CTelegramProto::ProcessChat(TD::updateNewChat *pObj) if (hContact != INVALID_CONTACT_ID) {
if (pUser->isForum) {
pUser->wszNick = Utf2T(szTitle.c_str());
- SendQuery(new TD::getForumTopics(pUser->chatId, "", 0, 0, 0, 100));
+ SendQuery(new TD::getForumTopics(pUser->chatId, "", 0, 0, 0, 100), &CTelegramProto::OnGetTopics, pUser);
}
else GcChangeTopic(pUser, szTitle);
}
@@ -972,13 +972,7 @@ void CTelegramProto::ProcessMessage(const TD::message *pMessage) Contact::RemoveFromList(pUser->hContact);
}
- MCONTACT hContact = GetRealContact(pUser);
- if (pMessage->message_thread_id_) {
- wchar_t buf[100];
- mir_snwprintf(buf, L"%lld_%lld", pMessage->chat_id_, pMessage->message_thread_id_);
- if (auto *si = Chat_Find(buf, m_szModuleName))
- hContact = si->hContact;
- }
+ MCONTACT hContact = GetRealContact(pUser, pMessage->message_thread_id_);
if (m_bResidentChannels && pUser->isChannel && pUser->m_si) {
GCEVENT gce = { pUser->m_si, GC_EVENT_MESSAGE };
diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 3d33b6b0c8..4e8a22192e 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -232,8 +232,14 @@ int CTelegramProto::GetDefaultMute(const TG_USER *pUser) return m_iDefaultMutePrivate;
}
-MCONTACT CTelegramProto::GetRealContact(const TG_USER *pUser)
+MCONTACT CTelegramProto::GetRealContact(const TG_USER *pUser, int64_t threadId)
{
+ if (threadId) {
+ wchar_t buf[100];
+ mir_snwprintf(buf, L"%lld_%lld", pUser->chatId, threadId);
+ if (auto *si = Chat_Find(buf, m_szModuleName))
+ return si->hContact;
+ }
return (pUser->hContact != 0) ? pUser->hContact : m_iSavedMessages;
}
@@ -452,7 +458,7 @@ bool CTelegramProto::GetMessageFile(const EmbeddedFile &F, TG_FILE_REQUEST::Type pRequest->m_fileName = Utf2T(pszFileName);
pRequest->m_fileSize = pFile->size_;
pRequest->m_bRecv = !F.pMsg->is_outgoing_;
- pRequest->m_hContact = GetRealContact(F.pUser);
+ pRequest->m_hContact = GetRealContact(F.pUser, F.pMsg->message_thread_id_);
if (mir_strlen(pszCaption))
F.szBody += pszCaption;
|