summaryrefslogtreecommitdiff
path: root/protocols/Telegram/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-06-03 18:31:18 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-06-03 18:31:18 +0300
commit6e83622d2af1cec3c759f4cff6efe4df2fe3328c (patch)
tree67a6224019f59e38d6496d32eefd72188bdbc61c /protocols/Telegram/src
parent6cade9acbd5067761f068ba819008eb3084239b4 (diff)
Telegram: fix for a trick with temporary message id that led to duplicated messages
Diffstat (limited to 'protocols/Telegram/src')
-rw-r--r--protocols/Telegram/src/proto.cpp5
-rw-r--r--protocols/Telegram/src/proto.h16
-rw-r--r--protocols/Telegram/src/server.cpp26
3 files changed, 39 insertions, 8 deletions
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp
index a7fe012792..2dc3c0a908 100644
--- a/protocols/Telegram/src/proto.cpp
+++ b/protocols/Telegram/src/proto.cpp
@@ -24,6 +24,10 @@ static int CompareUsers(const TG_USER *p1, const TG_USER *p2)
{ return CompareId(p1->id, p2->id);
}
+static int CompareOwnMsg(const TG_OWN_MESSAGE *p1, const TG_OWN_MESSAGE *p2)
+{ return CompareId(p1->tmpMsgId, p2->tmpMsgId);
+}
+
static int CompareBasicGroups(const TG_BASIC_GROUP *p1, const TG_BASIC_GROUP *p2)
{ return CompareId(p1->id, p2->id);
}
@@ -38,6 +42,7 @@ CTelegramProto::CTelegramProto(const char* protoName, const wchar_t* userName) :
m_arFiles(1, PtrKeySortT),
m_arChats(100, CompareChats),
m_arUsers(100, CompareUsers),
+ m_arOwnMsg(1, CompareOwnMsg),
m_arRequests(10, CompareRequests),
m_arBasicGroups(10, CompareBasicGroups),
m_arSuperGroups(10, CompareSuperGroups),
diff --git a/protocols/Telegram/src/proto.h b/protocols/Telegram/src/proto.h
index e03405560a..7181a92bce 100644
--- a/protocols/Telegram/src/proto.h
+++ b/protocols/Telegram/src/proto.h
@@ -125,6 +125,19 @@ struct TG_BASIC_GROUP
TD::object_ptr<TD::basicGroup> group;
};
+struct TG_OWN_MESSAGE
+{
+ TG_OWN_MESSAGE(MCONTACT _1, HANDLE _2, int64_t _3) :
+ hContact(_1),
+ hAck(_2),
+ tmpMsgId(_3)
+ {}
+
+ int64_t tmpMsgId;
+ HANDLE hAck;
+ MCONTACT hContact;
+};
+
class CTelegramProto : public PROTO<CTelegramProto>
{
friend class CForwardDlg;
@@ -179,7 +192,8 @@ class CTelegramProto : public PROTO<CTelegramProto>
bool m_bAuthorized, m_bTerminated, m_bUnregister = false, m_bSmileyAdd = false;
int32_t m_iClientId, m_iMsgId;
int64_t m_iQueryId;
-
+
+ OBJLIST<TG_OWN_MESSAGE> m_arOwnMsg;
OBJLIST<TG_REQUEST_BASE> m_arRequests;
mir_cs m_csFiles;
diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp
index 493b88bb7e..2bd4283763 100644
--- a/protocols/Telegram/src/server.cpp
+++ b/protocols/Telegram/src/server.cpp
@@ -181,7 +181,18 @@ void CTelegramProto::ProcessResponse(td::ClientManager::Response response)
break;
case TD::updateMessageSendSucceeded::ID:
- ProcessMessage(((TD::updateMessageSendSucceeded *)response.object.get())->message_.get());
+ {
+ auto *pMessage = (TD::updateMessageSendSucceeded *)response.object.get();
+ ProcessMessage(pMessage->message_.get());
+
+ if (auto *pOwnMsg = m_arOwnMsg.find((TG_OWN_MESSAGE *)&pMessage->old_message_id_)) {
+ char szMsgId[100];
+ _i64toa(pMessage->message_->id_, szMsgId, 10);
+ ProtoBroadcastAck(pOwnMsg->hContact ? pOwnMsg->hContact : m_iSavedMessages, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, pOwnMsg->hAck, (LPARAM)szMsgId);
+
+ m_arOwnMsg.remove(pOwnMsg);
+ }
+ }
break;
case TD::updateNewChat::ID:
@@ -189,7 +200,11 @@ void CTelegramProto::ProcessResponse(td::ClientManager::Response response)
break;
case TD::updateNewMessage::ID:
- ProcessMessage(((TD::updateNewMessage *)response.object.get())->message_.get());
+ {
+ auto *pMessage = ((TD::updateNewMessage *)response.object.get())->message_.get();
+ if (!m_arOwnMsg.find((TG_OWN_MESSAGE*)&pMessage->id_))
+ ProcessMessage(pMessage);
+ }
break;
case TD::updateOption::ID:
@@ -224,11 +239,8 @@ void CTelegramProto::OnSendMessage(td::ClientManager::Response &response, void *
auto *pMessage = ((TD::message *)response.object.get());
auto *pUser = FindChat(pMessage->chat_id_);
- if (pUser) {
- char szMsgId[100];
- _i64toa(pMessage->id_, szMsgId, 10);
- ProtoBroadcastAck(pUser->hContact ? pUser->hContact : m_iSavedMessages, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, pUserInfo, (LPARAM)szMsgId);
- }
+ if (pUser)
+ m_arOwnMsg.insert(new TG_OWN_MESSAGE(pUser->hContact, pUserInfo, pMessage->id_));
}
int CTelegramProto::SendTextMessage(int64_t chatId, const char *pszMessage)