From cebfc5c8facbf6ae335499f7f4b3dc57a60af999 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 29 Sep 2024 19:03:55 +0300 Subject: TDLIB update up to the current state --- protocols/Telegram/src/auth.cpp | 1 - protocols/Telegram/src/menus.cpp | 2 +- protocols/Telegram/src/options.cpp | 2 +- protocols/Telegram/src/proto.cpp | 6 +-- protocols/Telegram/src/server.cpp | 33 ++++++------ protocols/Telegram/src/utils.cpp | 106 +++++++++++++++++++------------------ protocols/Telegram/src/utils.h | 2 + protocols/Telegram/src/version.h | 4 +- 8 files changed, 79 insertions(+), 77 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/auth.cpp b/protocols/Telegram/src/auth.cpp index 97b0792bb7..0d757d13fe 100644 --- a/protocols/Telegram/src/auth.cpp +++ b/protocols/Telegram/src/auth.cpp @@ -116,7 +116,6 @@ void CTelegramProto::ProcessAuth(TD::updateAuthorizationState *pObj) request->system_language_code_ = Langpack_GetDefaultLocaleName(); request->device_model_ = T2Utf(m_wszDeviceName).get(); request->application_version_ = text; - request->enable_storage_optimizer_ = true; SendQuery(request, &CTelegramProto::OnUpdateAuth); } break; diff --git a/protocols/Telegram/src/menus.cpp b/protocols/Telegram/src/menus.cpp index acdbb6e54b..413193d8b0 100644 --- a/protocols/Telegram/src/menus.cpp +++ b/protocols/Telegram/src/menus.cpp @@ -121,7 +121,7 @@ public: auto *pUser = m_proto->FindUser(m_proto->GetId(hContact)); TD::array ids = message_ids; - m_proto->SendQuery(new TD::forwardMessages(pUser->chatId, 0, pMe->chatId, std::move(ids), 0, false, false, false)); + m_proto->SendQuery(new TD::forwardMessages(pUser->chatId, 0, pMe->chatId, std::move(ids), 0, false, false)); } } diff --git a/protocols/Telegram/src/options.cpp b/protocols/Telegram/src/options.cpp index 8b3bd7d1e7..c89d8518e1 100644 --- a/protocols/Telegram/src/options.cpp +++ b/protocols/Telegram/src/options.cpp @@ -324,7 +324,7 @@ void CTelegramProto::OnGetSessions(td::ClientManager::Response &response, void * pwszType = TranslateT("Unknown"); } pList->SetItemText(iItem, 1, pwszType); - pList->SetItemText(iItem, 2, Utf2T(pSession->country_.c_str())); + pList->SetItemText(iItem, 2, Utf2T(pSession->location_.c_str())); wchar_t wszLastLogin[100]; TimeZone_PrintTimeStamp(0, pSession->last_active_date_, L"d t", wszLastLogin, _countof(wszLastLogin), 0); diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index 714796a3e4..98572eea52 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -254,8 +254,8 @@ void CTelegramProto::OnEventEdited(MCONTACT hContact, MEVENT, const DBEVENTINFO if (dbei.szId && dbei.cbBlob && dbei.pBlob && dbei.eventType == EVENTTYPE_MESSAGE) { auto text = formatBbcodes((char*)dbei.pBlob); - auto content = TD::make_object(std::move(text), false, false); - SendQuery(new TD::editMessageText(pUser->chatId, dbei2id(dbei), 0, std::move(content))); + // auto content = TD::make_object(std::move(text), 0, false); + // SendQuery(new TD::editMessageText(pUser->chatId, dbei2id(dbei), 0, std::move(content))); } } @@ -683,7 +683,7 @@ int CTelegramProto::UserIsTyping(MCONTACT hContact, int type) { if (auto *pUser = FindUser(GetId(hContact))) if (type == PROTOTYPE_SELFTYPING_ON) - SendQuery(new TD::sendChatAction(pUser->chatId, 0, TD::make_object())); + SendQuery(new TD::sendChatAction(pUser->chatId, 0, "", TD::make_object())); return 0; } diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index d5f3caa43b..c2c8d3c1f2 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -378,7 +378,8 @@ int CTelegramProto::SendTextMessage(int64_t chatId, int64_t threadId, int64_t re pMessage->chat_id_ = chatId; pMessage->input_message_content_ = std::move(pContent); pMessage->message_thread_id_ = threadId; - pMessage->reply_to_message_id_ = replyId; + if (replyId) + pMessage->reply_to_.reset(new TD::inputMessageReplyToMessage(replyId, 0)); return SendQuery(pMessage, &CTelegramProto::OnSendMessage); } @@ -461,8 +462,8 @@ void CTelegramProto::OnGetHistory(td::ClientManager::Response &response, void *p dbei.flags |= DBEF_SENT; if (this->GetGcUserId(pUser, pMsg, szUserId)) dbei.szUserId = szUserId; - if (pMsg->reply_to_message_id_) { - szReplyId = msg2id(pMsg->chat_id_, pMsg->reply_to_message_id_); + if (auto iReplyId = getReplyId(pMsg->reply_to_.get())) { + szReplyId = msg2id(pMsg->chat_id_, iReplyId); dbei.szReplyId = szReplyId; } db_event_add(GetRealContact(pUser), &dbei); @@ -671,11 +672,6 @@ void CTelegramProto::ProcessChatNotification(TD::updateChatNotificationSettings void CTelegramProto::ProcessChatPosition(TD::updateChatPosition *pObj) { - if (pObj->position_->get_id() != TD::chatPosition::ID) { - debugLogA("Unsupport position"); - return; - } - auto *pUser = FindChat(pObj->chat_id_); if (pUser == nullptr) { debugLogA("Unknown chat, skipping"); @@ -939,8 +935,8 @@ void CTelegramProto::ProcessMessage(const TD::message *pMessage) dbei.flags |= DBEF_READ; if (GetGcUserId(pUser, pMessage, szUserId)) dbei.szUserId = szUserId; - if (pMessage->reply_to_message_id_) { - szReplyId = msg2id(pMessage->chat_id_, pMessage->reply_to_message_id_); + if (auto iReplyId = getReplyId(pMessage->reply_to_.get())) { + szReplyId = msg2id(pMessage->chat_id_, iReplyId); dbei.szReplyId = szReplyId; } @@ -1009,15 +1005,16 @@ void CTelegramProto::ProcessMessageReactions(TD::updateMessageInteractionInfo *p } JSONNode reactions; reactions.set_name("r"); - if (pObj->interaction_info_) { - for (auto &it : pObj->interaction_info_->reactions_) { - if (it->type_->get_id() != TD::reactionTypeEmoji::ID) - continue; - - auto *pEmoji = (TD::reactionTypeEmoji *)it->type_.get(); - reactions << INT_PARAM(pEmoji->emoji_.c_str(), it->total_count_); + if (pObj->interaction_info_) + if (pObj->interaction_info_->reactions_) { + for (auto &it : pObj->interaction_info_->reactions_->reactions_) { + if (it->type_->get_id() != TD::reactionTypeEmoji::ID) + continue; + + auto *pEmoji = (TD::reactionTypeEmoji *)it->type_.get(); + reactions << INT_PARAM(pEmoji->emoji_.c_str(), it->total_count_); + } } - } auto &json = dbei.setJson(); auto it = json.find("r"); diff --git a/protocols/Telegram/src/utils.cpp b/protocols/Telegram/src/utils.cpp index 618265af56..c823896051 100644 --- a/protocols/Telegram/src/utils.cpp +++ b/protocols/Telegram/src/utils.cpp @@ -84,36 +84,32 @@ TD::object_ptr formatBbcodes(const char *pszText) CMStringA CTelegramProto::GetFormattedText(TD::object_ptr &pText) { - if (pText->get_id() == TD::formattedText::ID) { - CMStringW ret(Utf2T(pText->text_.c_str())); - unsigned offset = 0; - - for (auto &it : pText->entities_) { - int iCode; - switch (it->type_->get_id()) { - case TD::textEntityTypeBold::ID: iCode = 0; break; - case TD::textEntityTypeItalic::ID: iCode = 1; break; - case TD::textEntityTypeStrikethrough::ID: iCode = 2; break; - case TD::textEntityTypeUnderline::ID: iCode = 3; break; - case TD::textEntityTypeCode::ID: iCode = 5; break; - case TD::textEntityTypeUrl::ID: - if (!m_bUrlPreview) - continue; - iCode = 4; - break; - default: + CMStringW ret(Utf2T(pText->text_.c_str())); + unsigned offset = 0; + + for (auto &it : pText->entities_) { + int iCode; + switch (it->type_->get_id()) { + case TD::textEntityTypeBold::ID: iCode = 0; break; + case TD::textEntityTypeItalic::ID: iCode = 1; break; + case TD::textEntityTypeStrikethrough::ID: iCode = 2; break; + case TD::textEntityTypeUnderline::ID: iCode = 3; break; + case TD::textEntityTypeCode::ID: iCode = 5; break; + case TD::textEntityTypeUrl::ID: + if (!m_bUrlPreview) continue; - } - - auto &bb = bbCodes[iCode]; - ret.Insert(offset + it->offset_ + it->length_, bb.end); - ret.Insert(offset + it->offset_, bb.begin); - offset += bb.len1 + bb.len2; + iCode = 4; + break; + default: + continue; } - return T2Utf(ret).get(); + + auto &bb = bbCodes[iCode]; + ret.Insert(offset + it->offset_ + it->length_, bb.end); + ret.Insert(offset + it->offset_, bb.begin); + offset += bb.len1 + bb.len2; } - - return ""; + return T2Utf(ret).get(); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -170,6 +166,20 @@ TG_FILE_REQUEST::Type AutoDetectType(const wchar_t *pwszFilename) return TG_FILE_REQUEST::FILE; } +TD::int53 getReplyId(const TD::MessageReplyTo *pReply) +{ + if (pReply) { + switch (pReply->get_id()) { + case TD::messageReplyToMessage::ID: + return ((TD::messageReplyToMessage *)pReply)->message_id_; + + case TD::inputMessageReplyToExternalMessage::ID: + return ((TD::inputMessageReplyToExternalMessage *)pReply)->message_id_; + } + } + return 0; +} + CMStringW TG_USER::getDisplayName() const { if (hContact != 0) { @@ -422,11 +432,6 @@ bool CTelegramProto::GetGcUserId(TG_USER *pUser, const TD::message *pMsg, char * bool CTelegramProto::GetMessageFile(const EmbeddedFile &F, TG_FILE_REQUEST::Type iType, const TD::file *pFile, const char *pszFileName, const char *pszCaption) { - if (pFile->get_id() != TD::file::ID) { - debugLogA("Document contains unsupported type %d, exiting", pFile->get_id()); - return false; - } - auto *pRequest = new TG_FILE_REQUEST(iType, pFile->id_, pFile->remote_->id_.c_str()); pRequest->m_fileName = Utf2T(pszFileName); pRequest->m_fileSize = pFile->size_; @@ -447,8 +452,8 @@ bool CTelegramProto::GetMessageFile(const EmbeddedFile &F, TG_FILE_REQUEST::Type dbei.flags |= DBEF_SENT; if (!F.pUser->bInited || F.bRead) dbei.flags |= DBEF_READ; - if (F.pMsg->reply_to_message_id_) { - _i64toa(F.pMsg->reply_to_message_id_, szReplyId, 10); + if (auto iReplyId = getReplyId(F.pMsg->reply_to_.get())) { + _i64toa(iReplyId, szReplyId, 10); dbei.szReplyId = szReplyId; } @@ -540,20 +545,20 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg if (auto *pForward = pMsg->forward_info_.get()) { CMStringW wszNick; switch (pForward->origin_->get_id()) { - case TD::messageForwardOriginUser::ID: - if (auto *p = FindUser(((TD::messageForwardOriginUser *)pForward->origin_.get())->sender_user_id_)) + case TD::messageOriginUser::ID: + if (auto *p = FindUser(((TD::messageOriginUser *)pForward->origin_.get())->sender_user_id_)) wszNick = p->getDisplayName(); break; - case TD::messageForwardOriginChat::ID: - if (auto *p = FindChat(((TD::messageForwardOriginChat *)pForward->origin_.get())->sender_chat_id_)) + case TD::messageOriginChat::ID: + if (auto *p = FindChat(((TD::messageOriginChat *)pForward->origin_.get())->sender_chat_id_)) wszNick = p->getDisplayName(); break; - case TD::messageForwardOriginHiddenUser::ID: - if (auto *p = (TD::messageForwardOriginHiddenUser *)pForward->origin_.get()) + case TD::messageOriginHiddenUser::ID: + if (auto *p = (TD::messageOriginHiddenUser *)pForward->origin_.get()) wszNick = Utf2T(p->sender_name_.c_str()); break; - case TD::messageForwardOriginChannel::ID: - if (auto *p = FindChat(((TD::messageForwardOriginChannel *)pForward->origin_.get())->chat_id_)) + case TD::messageOriginChannel::ID: + if (auto *p = FindChat(((TD::messageOriginChannel *)pForward->origin_.get())->chat_id_)) wszNick = p->getDisplayName(); break; default: @@ -728,9 +733,7 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg case TD::messageInvoice::ID: if (auto *pInvoice = ((TD::messageInvoice *)pBody)) { ret.Format("%s: %.2lf %s", TranslateU("You received an invoice"), double(pInvoice->total_amount_)/100.0, pInvoice->currency_.c_str()); - if (!pInvoice->title_.empty()) - ret.AppendFormat("\r\n%s: %s", TranslateU("Title"), pInvoice->title_.c_str()); - if (auto pszText = GetFormattedText(pInvoice->description_)) + if (auto pszText = GetFormattedText(pInvoice->paid_media_caption_)) ret.AppendFormat("\r\n%s", pszText.c_str()); } break; @@ -739,18 +742,19 @@ CMStringA CTelegramProto::GetMessageText(TG_USER *pUser, const TD::message *pMsg if (auto *pText = ((TD::messageText *)pBody)) { ret = GetFormattedText(pText->text_); - if (auto *pWeb = pText->web_page_.get()) { - if (!pWeb->embed_url_.empty() && m_bUrlPreview) - ret.AppendFormat("\r\n[url]%s[/url]", pWeb->embed_url_.c_str()); + if (auto *pWeb = pText->link_preview_.get()) { + if (!pWeb->display_url_.empty() && m_bUrlPreview) + ret.AppendFormat("\r\n[url]%s[/url]", pWeb->display_url_.c_str()); - if (pWeb->photo_) { + if (pWeb->type_->get_id() == TD::linkPreviewTypePhoto::ID) { + auto *pPhoto = ((TD::linkPreviewTypePhoto *)pWeb->type_.get())->photo_.get(); const TD::photoSize *pSize = nullptr; - for (auto &it : pWeb->photo_->sizes_) + for (auto &it : pPhoto->sizes_) if (it->type_ == "m") pSize = it.get(); if (pSize == nullptr) - pSize = pWeb->photo_->sizes_[0].get(); + pSize = pPhoto->sizes_[0].get(); if (auto szText = GetMessagePreview(pSize->photo_.get())) ret.AppendFormat("\r\n[img=%s][/img]", szText.c_str()); diff --git a/protocols/Telegram/src/utils.h b/protocols/Telegram/src/utils.h index b6b3bd62da..81d60e239d 100644 --- a/protocols/Telegram/src/utils.h +++ b/protocols/Telegram/src/utils.h @@ -2,6 +2,8 @@ const char *getName(const TD::usernames *pName); +TD::int53 getReplyId(const TD::MessageReplyTo *pReply); + TD::object_ptr makeFile(const wchar_t *pwszFilename); TD::object_ptr formatBbcodes(const char *pszText); diff --git a/protocols/Telegram/src/version.h b/protocols/Telegram/src/version.h index ac231a237f..ea7e3f3bab 100644 --- a/protocols/Telegram/src/version.h +++ b/protocols/Telegram/src/version.h @@ -1,6 +1,6 @@ #define __MAJOR_VERSION 0 -#define __MINOR_VERSION 11 -#define __RELEASE_NUM 0 +#define __MINOR_VERSION 96 +#define __RELEASE_NUM 6 #define __BUILD_NUM 1 #include -- cgit v1.2.3