summaryrefslogtreecommitdiff
path: root/protocols/Teams/src/teams_messages.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2025-04-24 17:43:33 +0300
committerGeorge Hazan <george.hazan@gmail.com>2025-04-24 17:43:33 +0300
commit53e0b5f3ff938adf11b2237727510e07e23ffdb6 (patch)
treef1b89510e1ce480200ca9c85df4914a3641795db /protocols/Teams/src/teams_messages.cpp
parentcb1fe45eefc98557069ac57bee75762e25f91e1e (diff)
Teams: fix for private messages sending
Diffstat (limited to 'protocols/Teams/src/teams_messages.cpp')
-rw-r--r--protocols/Teams/src/teams_messages.cpp66
1 files changed, 35 insertions, 31 deletions
diff --git a/protocols/Teams/src/teams_messages.cpp b/protocols/Teams/src/teams_messages.cpp
index e55b83816c..9c29ee3827 100644
--- a/protocols/Teams/src/teams_messages.cpp
+++ b/protocols/Teams/src/teams_messages.cpp
@@ -22,25 +22,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
void CTeamsProto::OnMessageSent(MHttpResponse *response, AsyncHttpRequest *pRequest)
{
+ // to delete it in any case
+ std::unique_ptr<COwnMessage> pMessage((COwnMessage *)pRequest->pUserInfo);
+
MCONTACT hContact = pRequest->hContact;
if (Contact::IsGroupChat(hContact))
return;
- if (response != nullptr) {
- if (response->resultCode != 201) {
- std::string strError = Translate("Unknown error!");
+ if (response == nullptr) {
+ ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, pRequest->pUserInfo, (LPARAM)TranslateT("Network error!"));
+ return;
+ }
+
+ if (response->resultCode == 201) {
+ JsonReply reply(response);
+ auto &pRoot = reply.data();
+ CMStringA msgId(pRoot["OriginalArrivalTime"].as_mstring());
- if (!response->body.IsEmpty()) {
- JSONNode jRoot = JSONNode::parse(response->body);
- const JSONNode &jErr = jRoot["errorCode"];
- if (jErr)
- strError = jErr.as_string();
- }
+ if (pMessage) {
+ pMessage->iTimestamp = _atoi64(msgId);
+ ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)pMessage->hMessage, (LPARAM)msgId.c_str());
- ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, pRequest->pUserInfo, _A2T(strError.c_str()));
+ mir_cslock lck(m_lckOutMessagesList);
+ m_OutMessages.remove(pMessage.get());
}
}
- else ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, pRequest->pUserInfo, (LPARAM)TranslateT("Network error!"));
+ else {
+ std::string strError = Translate("Unknown error!");
+
+ if (!response->body.IsEmpty()) {
+ JSONNode jRoot = JSONNode::parse(response->body);
+ const JSONNode &jErr = jRoot["errorCode"];
+ if (jErr)
+ strError = jErr.as_string();
+ }
+
+ ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, pRequest->pUserInfo, _A2T(strError.c_str()));
+ }
}
// outcoming message flow
@@ -58,10 +76,6 @@ int CTeamsProto::SendServerMsg(MCONTACT hContact, const char *szMessage, int64_t
if (existingMsgId)
szUrl.AppendFormat("/%lld", existingMsgId);
- AsyncHttpRequest *pReq = new AsyncHttpRequest(existingMsgId ? REQUEST_PUT : REQUEST_POST, HOST_DEFAULT, szUrl, &CTeamsProto::OnMessageSent);
- pReq->hContact = hContact;
- pReq->pUserInfo = (HANDLE)m_iMessageId;
-
JSONNode node;
node << CHAR_PARAM("messagetype", bRich ? "RichText" : "Text") << CHAR_PARAM("contenttype", "text");
if (strncmp(str, "/me ", 4) == 0)
@@ -69,15 +83,19 @@ int CTeamsProto::SendServerMsg(MCONTACT hContact, const char *szMessage, int64_t
else
node << CHAR_PARAM("content", str);
+ COwnMessage *pOwnMessage = nullptr;
if (!existingMsgId) {
int64_t iRandomId = getRandomId();
node << INT64_PARAM("clientmessageid", iRandomId);
mir_cslock lck(m_lckOutMessagesList);
- m_OutMessages.insert(new COwnMessage(m_iMessageId, iRandomId));
+ m_OutMessages.insert(pOwnMessage = new COwnMessage(m_iMessageId, iRandomId));
}
- pReq->m_szParam = node.write().c_str();
+ AsyncHttpRequest *pReq = new AsyncHttpRequest(existingMsgId ? REQUEST_PUT : REQUEST_POST, HOST_DEFAULT, szUrl, &CTeamsProto::OnMessageSent);
+ pReq->hContact = hContact;
+ pReq->pUserInfo = pOwnMessage;
+ pReq->m_szParam = node.write().c_str();
PushRequest(pReq);
return m_iMessageId;
@@ -127,20 +145,6 @@ LBL_Deleted:
}
if (strMessageType == "Text" || strMessageType == "RichText") {
- if (dbei.bSent && dbei.szId) {
- for (auto &it: m_OutMessages) {
- if (it->hClientMessageId == _atoi64(dbei.szId)) {
- it->iTimestamp = dbei.iTimestamp;
-
- ProtoBroadcastAck(dbei.hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)it->hMessage, (LPARAM)dbei.szId);
-
- mir_cslock lck(m_lckOutMessagesList);
- m_OutMessages.removeItem(&it);
- return false;
- }
- }
- }
-
if (strMessageType == "RichText")
wszContent = RemoveHtml(wszContent);