summaryrefslogtreecommitdiff
path: root/protocols/Twitter/src/connection.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-11-15 21:08:55 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-11-15 21:08:55 +0300
commite0a5da7f6ff3bffc243e61a99156a2a837bcb0d9 (patch)
treeb4fbdbce9ff7e4ffc85b561438be667e0e740146 /protocols/Twitter/src/connection.cpp
parent70965c0f3ff0d7e7643fcbfbeea35c305f7c3f39 (diff)
Twitter: fix for our own ID parsing
Diffstat (limited to 'protocols/Twitter/src/connection.cpp')
-rw-r--r--protocols/Twitter/src/connection.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/protocols/Twitter/src/connection.cpp b/protocols/Twitter/src/connection.cpp
index a8c6651fca..bcd7274d00 100644
--- a/protocols/Twitter/src/connection.cpp
+++ b/protocols/Twitter/src/connection.cpp
@@ -192,9 +192,11 @@ bool CTwitterProto::NegotiateConnection()
}
auto *req = new AsyncHttpRequest(REQUEST_GET, "/account/verify_credentials.json");
- if (Execute(req).code != 200) {
+ auto resp(Execute(req));
+ if (resp.code != 200) {
debugLogA("**NegotiateConnection - Verifying credentials failed! No internet maybe?");
+LBL_Error:
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_FAILED, (HANDLE)old_status, m_iStatus);
// Set to offline
@@ -205,6 +207,13 @@ bool CTwitterProto::NegotiateConnection()
return false;
}
+ JSONNode root = JSONNode::parse(resp.data.c_str());
+ if (!root) {
+ debugLogA("unable to parse response");
+ goto LBL_Error;
+ }
+
+ m_szMyId = root["id_str"].as_mstring();
m_iStatus = m_iDesiredStatus;
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)old_status, m_iStatus);
return true;
@@ -556,8 +565,14 @@ void CTwitterProto::UpdateMessages(bool pre_read)
if (type != "message_create")
continue;
+ bool bIsMe = false;
auto &msgCreate = one["message_create"];
std::string sender = msgCreate["sender_id"].as_string();
+ if (m_szMyId == sender.c_str()) {
+ bIsMe = true;
+ sender = msgCreate["target"]["recipient_id"].as_string();
+ }
+
MCONTACT hContact = FindContactById(sender.c_str());
if (hContact == INVALID_CONTACT_ID) {
hContact = AddToClientList(sender.c_str(), "");
@@ -578,6 +593,8 @@ void CTwitterProto::UpdateMessages(bool pre_read)
PROTORECVEVENT recv = { 0 };
if (pre_read)
recv.flags |= PREF_CREATEREAD;
+ if (bIsMe)
+ recv.flags |= PREF_SENT;
recv.szMessage = const_cast<char*>(text.c_str());
recv.timestamp = static_cast<DWORD>(time);
recv.szMsgId = msgid.c_str();