From a8f00a9c70de2fafbba97941fc65879b3863db6f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 13 May 2024 15:41:01 +0300 Subject: Telegram: reactions processing --- protocols/Telegram/src/proto.h | 1 + protocols/Telegram/src/server.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) (limited to 'protocols') diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h index 786883aaa3..deff69a9b0 100644 --- a/protocols/Telegram/src/proto.h +++ b/protocols/Telegram/src/proto.h @@ -274,6 +274,7 @@ class CTelegramProto : public PROTO void ProcessMarkRead(TD::updateChatReadInbox *pObj); void ProcessMessage(const TD::message *pMsg); void ProcessMessageContent(TD::updateMessageContent *pObj); + void ProcessMessageReactions(TD::updateMessageInteractionInfo *pObj); void ProcessOption(TD::updateOption *pObj); void ProcessStatus(TD::updateUserStatus *pObj); void ProcessSuperGroup(TD::updateSupergroup *pObj); diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 4cbc0acf94..f5bd3677d7 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -267,6 +267,10 @@ void CTelegramProto::ProcessResponse(td::ClientManager::Response response) ProcessMessageContent((TD::updateMessageContent *)response.object.get()); break; + case TD::updateMessageInteractionInfo::ID: + ProcessMessageReactions((TD::updateMessageInteractionInfo *)response.object.get()); + break; + case TD::updateMessageSendSucceeded::ID: { auto *pUpdate = (TD::updateMessageSendSucceeded *)response.object.get(); @@ -977,6 +981,41 @@ void CTelegramProto::ProcessMessageContent(TD::updateMessageContent *pObj) db_event_edit(hDbEvent, &dbei, true); } +void CTelegramProto::ProcessMessageReactions(TD::updateMessageInteractionInfo *pObj) +{ + auto *pUser = FindChat(pObj->chat_id_); + if (pUser == nullptr) { + debugLogA("message from unknown chat/user, ignored"); + return; + } + + CMStringA szMsgId(msg2id(pObj->chat_id_, pObj->message_id_)); + DB::EventInfo dbei(db_event_getById(m_szModuleName, szMsgId)); + if (!dbei) { + debugLogA("Unknown message with id=%lld (chat id %lld, ignored", pObj->message_id_, pObj->chat_id_); + return; + } + + JSONNode reactions; reactions.set_name("r"); + 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_); + } + + auto &json = dbei.setJson(); + auto it = json.find("r"); + if (it != json.end()) + json.erase(it); + + json << reactions; + dbei.flushJson(); + + db_event_edit(dbei.getEvent(), &dbei, true); +} + ///////////////////////////////////////////////////////////////////////////////////////// static char *sttBotIds[] = { -- cgit v1.2.3