summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-05-13 15:41:01 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-05-13 15:41:01 +0300
commita8f00a9c70de2fafbba97941fc65879b3863db6f (patch)
treefbb4cce2b65e92d7db9df883189ec4e644bd08cd
parente600680869747dbf6fd5848397512cd6625539ad (diff)
Telegram: reactions processing
-rw-r--r--protocols/Telegram/src/proto.h1
-rw-r--r--protocols/Telegram/src/server.cpp39
2 files changed, 40 insertions, 0 deletions
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<CTelegramProto>
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[] = {