diff options
author | George Hazan <ghazan@miranda.im> | 2022-12-26 19:47:52 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-12-26 19:47:52 +0300 |
commit | 1bc6c4d659736f451d736b910f543872ca339e8a (patch) | |
tree | c0b8ecc3f6017342a742faf29ce23752c8f2ac73 | |
parent | 016f5b27df751bc8a605aeb9c97c844892458eeb (diff) |
Telegram: chat filters support for contacts
-rw-r--r-- | protocols/Telegram/src/mt_proto.h | 1 | ||||
-rw-r--r-- | protocols/Telegram/src/server.cpp | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/protocols/Telegram/src/mt_proto.h b/protocols/Telegram/src/mt_proto.h index 75f6869ad5..f3232592ce 100644 --- a/protocols/Telegram/src/mt_proto.h +++ b/protocols/Telegram/src/mt_proto.h @@ -116,6 +116,7 @@ class CMTProto : public PROTO<CMTProto> void ProcessAuth(TD::updateAuthorizationState *pObj); void ProcessChat(TD::updateNewChat *pObj); + void ProcessChatPosition(TD::updateChatPosition *pObj); void ProcessGroups(TD::updateChatFilters *pObj); void ProcessMessage(TD::updateNewMessage *pObj); void ProcessStatus(TD::updateUserStatus *pObj); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 9c1cf79d45..91ebc98fd0 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -105,6 +105,10 @@ void CMTProto::ProcessResponse(td::ClientManager::Response response) ProcessGroups((TD::updateChatFilters *)response.object.get()); break; + case TD::updateChatPosition::ID: + ProcessChatPosition((TD::updateChatPosition *)response.object.get()); + break; + case TD::updateNewChat::ID: ProcessChat((TD::updateNewChat *)response.object.get()); break; @@ -191,6 +195,35 @@ void CMTProto::ProcessChat(TD::updateNewChat *pObj) setUString(pUser->hContact, "Nick", pChat->title_.c_str()); } +void CMTProto::ProcessChatPosition(TD::updateChatPosition *pObj) +{ + if (pObj->position_->get_id() != TD::chatPosition::ID) { + debugLogA("Unsupport position"); + return; + } + + auto *pUser = FindUser(pObj->chat_id_); + if (pUser == nullptr) { + debugLogA("Unknown chat, skipping"); + return; + } + + auto *pPos = (TD::chatPosition *)pObj->position_.get(); + if (pPos->list_) { + auto *pList = (TD::chatListFilter*)pPos->list_.get(); + + CMStringA szSetting(FORMAT, "ChatFilter%d", pList->chat_filter_id_); + CMStringW wszGroup(getMStringW(szSetting)); + if (!wszGroup.IsEmpty()) { + ptrW pwszExistingGroup(Clist_GetGroup(pUser->hContact)); + if (!pwszExistingGroup || !mir_wstrcmp(pwszExistingGroup, m_wszDefaultGroup)) { + CMStringW wszNewGroup(FORMAT, L"%s\\%s", (wchar_t *)m_wszDefaultGroup, wszGroup.c_str()); + Clist_SetGroup(pUser->hContact, wszNewGroup); + } + } + } +} + void CMTProto::ProcessGroups(TD::updateChatFilters *pObj) { for (auto &grp : pObj->chat_filters_) { |