summaryrefslogtreecommitdiff
path: root/protocols
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
parent297d42cdb650f70a190d0760c7f073da914e5982 (diff)
Facebook: fix for a random crash
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Facebook/src/groupchats.cpp2
-rw-r--r--protocols/Facebook/src/proto.cpp1
-rw-r--r--protocols/Facebook/src/proto.h9
-rw-r--r--protocols/Facebook/src/server.cpp58
4 files changed, 44 insertions, 26 deletions
diff --git a/protocols/Facebook/src/groupchats.cpp b/protocols/Facebook/src/groupchats.cpp
index 2aea1370d2..00f441e8d8 100644
--- a/protocols/Facebook/src/groupchats.cpp
+++ b/protocols/Facebook/src/groupchats.cpp
@@ -164,6 +164,8 @@ int FacebookProto::GroupchatEventHook(WPARAM, LPARAM lParam)
Chat_UnescapeTags(wszText);
int mid = SendMsg(si->hContact, 0, T2Utf(wszText));
+
+ mir_cslock lck(m_csOwnMessages);
for (auto &msg : arOwnMessages)
if (msg->reqId == mid)
msg->wszText = wszText;
diff --git a/protocols/Facebook/src/proto.cpp b/protocols/Facebook/src/proto.cpp
index 993e85a0f6..b161469507 100644
--- a/protocols/Facebook/src/proto.cpp
+++ b/protocols/Facebook/src/proto.cpp
@@ -220,6 +220,7 @@ int FacebookProto::SendMsg(MCONTACT hContact, int, const char *pszSrc)
JSONNode root; root << CHAR_PARAM("body", pszSrc) << INT64_PARAM("msgid", msgId) << INT64_PARAM("sender_fbid", m_uid) << CHAR_PARAM("to", userId);
MqttPublish("/send_message2", root);
+ mir_cslock lck(m_csOwnMessages);
arOwnMessages.insert(new COwnMessage(msgId, m_mid, hContact));
return m_mid;
}
diff --git a/protocols/Facebook/src/proto.h b/protocols/Facebook/src/proto.h
index b1232b96e1..4c2a2310e0 100644
--- a/protocols/Facebook/src/proto.h
+++ b/protocols/Facebook/src/proto.h
@@ -365,6 +365,13 @@ struct COwnMessage
MCONTACT hContact;
CMStringW wszText;
+ COwnMessage() :
+ msgId(0),
+ reqId(0),
+ hContact(0)
+ {
+ }
+
COwnMessage(__int64 _id, int _reqId, MCONTACT _hContact) :
msgId(_id),
reqId(_reqId),
@@ -456,7 +463,9 @@ class FacebookProto : public PROTO<FacebookProto>
CMStringA m_szAuthToken; // calculated
+ mir_cs m_csOwnMessages;
OBJLIST<COwnMessage> arOwnMessages;
+ bool ExtractOwnMessage(__int64 msgId, COwnMessage &res);
OBJLIST<FacebookUser> m_users;
FacebookUser* FindUser(__int64 id)
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());
}
}