summaryrefslogtreecommitdiff
path: root/protocols/Facebook/src/server.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-09-22 10:55:48 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-09-22 10:55:48 +0300
commite6ef5a9fbfb199bd8248b3050fe9c9c9abdc50bf (patch)
tree46be50566dc74ac6c9ab8b0cbe9fb90580e8f138 /protocols/Facebook/src/server.cpp
parent297d42cdb650f70a190d0760c7f073da914e5982 (diff)
Facebook: fix for a random crash
Diffstat (limited to 'protocols/Facebook/src/server.cpp')
-rw-r--r--protocols/Facebook/src/server.cpp58
1 files changed, 32 insertions, 26 deletions
diff --git a/protocols/Facebook/src/server.cpp b/protocols/Facebook/src/server.cpp
index d2cb288e90..ce86f513ed 100644
--- a/protocols/Facebook/src/server.cpp
+++ b/protocols/Facebook/src/server.cpp
@@ -30,16 +30,26 @@ void FacebookProto::ConnectionFailed()
OnShutdown();
}
-void FacebookProto::NotifyDelivery(const CMStringA &szId)
+bool FacebookProto::ExtractOwnMessage(__int64 msgId, COwnMessage &res)
{
- __int64 msgid = _atoi64(szId);
- for (auto &it : arOwnMessages) {
- if (it->msgId == msgid) {
- ProtoBroadcastAck(it->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)it->reqId, (LPARAM)szId.c_str());
- if (g_bMessageState)
- CallService(MS_MESSAGESTATE_UPDATE, it->hContact, MRD_TYPE_DELIVERED);
+ mir_cslock lck(m_csOwnMessages);
+ for (auto &it : arOwnMessages)
+ if (it->msgId == msgId) {
+ res = *it;
arOwnMessages.removeItem(&it);
+ return true;
}
+
+ return false;
+}
+
+void FacebookProto::NotifyDelivery(const CMStringA &szId)
+{
+ COwnMessage tmp;
+ if (ExtractOwnMessage(_atoi64(szId), tmp)) {
+ ProtoBroadcastAck(tmp.hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)tmp.reqId, (LPARAM)szId.c_str());
+ if (g_bMessageState)
+ CallService(MS_MESSAGESTATE_UPDATE, tmp.hContact, MRD_TYPE_DELIVERED);
}
}
@@ -895,25 +905,21 @@ void FacebookProto::OnPublishSentMessage(const JSONNode &root)
return;
}
- for (auto &it : arOwnMessages) {
- if (it->msgId == offlineId) {
- if (pUser->bIsChat) {
- CMStringW wszId(FORMAT, L"%lld", m_uid);
- it->wszText.Replace(L"%", L"%%");
-
- GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE };
- gce.pszID.w = wszUserId;
- gce.dwFlags = GCEF_ADDTOLOG;
- gce.pszUID.w = wszId;
- gce.pszText.w = it->wszText;
- gce.time = time(0);
- gce.bIsMe = true;
- Chat_Event(&gce);
- }
- else ProtoBroadcastAck(pUser->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)it->reqId, (LPARAM)szId.c_str());
-
- arOwnMessages.removeItem(&it);
- break;
+ COwnMessage tmp;
+ if (ExtractOwnMessage(offlineId, tmp)) {
+ if (pUser->bIsChat) {
+ CMStringW wszId(FORMAT, L"%lld", m_uid);
+ tmp.wszText.Replace(L"%", L"%%");
+
+ GCEVENT gce = { m_szModuleName, 0, GC_EVENT_MESSAGE };
+ gce.pszID.w = wszUserId;
+ gce.dwFlags = GCEF_ADDTOLOG;
+ gce.pszUID.w = wszId;
+ gce.pszText.w = tmp.wszText;
+ gce.time = time(0);
+ gce.bIsMe = true;
+ Chat_Event(&gce);
}
+ else ProtoBroadcastAck(pUser->hContact, ACKTYPE_MESSAGE, ACKRESULT_SUCCESS, (HANDLE)tmp.reqId, (LPARAM)szId.c_str());
}
}