diff options
author | George Hazan <george.hazan@gmail.com> | 2023-11-13 14:50:51 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2023-11-13 14:50:51 +0300 |
commit | ab7236480aa71a278e4882eabbfed20f386333d3 (patch) | |
tree | 4b7e6a7ae4dcd69cc5c3269bd06ade216beaa959 /protocols/Telegram | |
parent | 4e2a7eebd5e4e1a40450bbe02c48809059248624 (diff) |
Telegram: added error processing in message sending
Diffstat (limited to 'protocols/Telegram')
-rw-r--r-- | protocols/Telegram/src/proto.cpp | 11 | ||||
-rw-r--r-- | protocols/Telegram/src/server.cpp | 27 |
2 files changed, 31 insertions, 7 deletions
diff --git a/protocols/Telegram/src/proto.cpp b/protocols/Telegram/src/proto.cpp index 9a79af6d94..fff388caa5 100644 --- a/protocols/Telegram/src/proto.cpp +++ b/protocols/Telegram/src/proto.cpp @@ -491,7 +491,16 @@ int CTelegramProto::SendMsg(MCONTACT hContact, const char *pszMessage) if (szId == nullptr) return 0; - return SendTextMessage(_atoi64(szId), pszMessage); + __int64 id = _atoi64(szId); + auto *pUser = FindUser(id); + if (pUser == nullptr) + return 0; + + int msgid = SendTextMessage(pUser->chatId, pszMessage); + if (msgid != -1) + m_arOwnMsg.insert(new TG_OWN_MESSAGE(hContact, (HANDLE)msgid, -1)); + + return msgid; } int CTelegramProto::SetStatus(int iNewStatus) diff --git a/protocols/Telegram/src/server.cpp b/protocols/Telegram/src/server.cpp index f9c2d17fc0..0bd26786be 100644 --- a/protocols/Telegram/src/server.cpp +++ b/protocols/Telegram/src/server.cpp @@ -253,15 +253,30 @@ void CTelegramProto::OnSendMessage(td::ClientManager::Response &response) if (!response.object)
return;
- if (response.object->get_id() != TD::message::ID) {
+ switch(response.object->get_id()) {
+ case TD::error::ID:
+ for (auto &it : m_arOwnMsg)
+ if (it->hAck == (HANDLE)response.request_id) {
+ auto *pError= ((TD::error *)response.object.get());
+ CMStringW wszMsg(FORMAT, TranslateT("Error %d: %s"), pError->code_, TranslateW(Utf2T(pError->message_.c_str())));
+ ProtoBroadcastAck(it->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, it->hAck, (LPARAM)wszMsg.c_str());
+ break;
+ }
+ break;
+
+ case TD::message::ID:
+ for (auto &it : m_arOwnMsg)
+ if (it->hAck == (HANDLE)response.request_id) {
+ auto *pMessage = ((TD::message *)response.object.get());
+ it->tmpMsgId = pMessage->id_;
+ break;
+ }
+ break;
+
+ default:
debugLogA("Gotten class ID %d instead of %d, exiting", response.object->get_id(), TD::message::ID);
return;
}
-
- auto *pMessage = ((TD::message *)response.object.get());
- auto *pUser = FindChat(pMessage->chat_id_);
- if (pUser)
- m_arOwnMsg.insert(new TG_OWN_MESSAGE(pUser->hContact, (HANDLE)response.request_id, pMessage->id_));
}
int CTelegramProto::SendTextMessage(int64_t chatId, const char *pszMessage)
|