From fb4c135b8674a43dd3e49c7bfc71b3d7b83f03ca Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 12 Dec 2023 19:53:18 +0300 Subject: fixes #4043 (Telegram: problem with reply ids) --- protocols/Telegram/src/server.cpp | 49 ++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'protocols/Telegram/src') diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index 7965335227..51d427c531 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -754,12 +754,11 @@ void CTelegramProto::ProcessMessage(const TD::message *pMessage) if (pMessage->sending_state_->get_id() == TD::messageSendingStatePending::ID) return; - char szUserId[100], szReplyId[100]; + char szUserId[100]; auto szMsgId(msg2id(pMessage)); - if (db_event_getById(m_szModuleName, szMsgId)) - return; + MEVENT hOldEvent = db_event_getById(m_szModuleName, szMsgId); - CMStringA szText(GetMessageText(pUser, pMessage)); + CMStringA szText(GetMessageText(pUser, pMessage)), szReplyId; if (szText.IsEmpty()) { debugLogA("this message was not processed, ignored"); return; @@ -776,19 +775,37 @@ void CTelegramProto::ProcessMessage(const TD::message *pMessage) Contact::RemoveFromList(pUser->hContact); } - PROTORECVEVENT pre = {}; - pre.szMessage = szText.GetBuffer(); - pre.szMsgId = szMsgId; - pre.timestamp = pMessage->date_; - if (pMessage->is_outgoing_) - pre.flags |= PREF_SENT; - if (GetGcUserId(pUser, pMessage, szUserId)) - pre.szUserId = szUserId; - if (pMessage->reply_to_message_id_) { - _i64toa(pMessage->reply_to_message_id_, szReplyId, 10); - pre.szReplyId = szReplyId; + if (hOldEvent) { + DB::EventInfo dbei(hOldEvent); + mir_free(dbei.pBlob); + dbei.cbBlob = szText.GetLength(); + dbei.pBlob = (uint8_t *)szText.Detach(); + dbei.timestamp = pMessage->date_; + if (pMessage->is_outgoing_) + dbei.flags |= DBEF_SENT; + if (GetGcUserId(pUser, pMessage, szUserId)) + dbei.szUserId = szUserId; + if (pMessage->reply_to_message_id_) { + szReplyId = msg2id(pMessage->chat_id_, pMessage->reply_to_message_id_); + dbei.szReplyId = szReplyId; + } + db_event_edit(hOldEvent, &dbei, true); + } + else { + PROTORECVEVENT pre = {}; + pre.szMessage = szText.GetBuffer(); + pre.szMsgId = szMsgId; + pre.timestamp = pMessage->date_; + if (pMessage->is_outgoing_) + pre.flags |= PREF_SENT; + if (GetGcUserId(pUser, pMessage, szUserId)) + pre.szUserId = szUserId; + if (pMessage->reply_to_message_id_) { + szReplyId = msg2id(pMessage->chat_id_, pMessage->reply_to_message_id_); + pre.szReplyId = szReplyId; + } + ProtoChainRecvMsg(GetRealContact(pUser), &pre); } - ProtoChainRecvMsg(GetRealContact(pUser), &pre); } void CTelegramProto::ProcessMessageContent(TD::updateMessageContent *pObj) -- cgit v1.2.3