From e0a5da7f6ff3bffc243e61a99156a2a837bcb0d9 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 15 Nov 2021 21:08:55 +0300 Subject: Twitter: fix for our own ID parsing --- protocols/Twitter/src/connection.cpp | 19 ++++++++++++++++++- protocols/Twitter/src/proto.h | 1 + protocols/Twitter/src/version.h | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'protocols/Twitter/src') 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(text.c_str()); recv.timestamp = static_cast(time); recv.szMsgId = msgid.c_str(); diff --git a/protocols/Twitter/src/proto.h b/protocols/Twitter/src/proto.h index 3d195295ba..a33c4c1782 100644 --- a/protocols/Twitter/src/proto.h +++ b/protocols/Twitter/src/proto.h @@ -77,6 +77,7 @@ class CTwitterProto : public PROTO http::response Execute(AsyncHttpRequest *req); CMStringA m_szUserName; + CMStringA m_szMyId; CMStringA m_szPassword; CMStringA m_szConsumerKey; CMStringA m_szConsumerSecret; diff --git a/protocols/Twitter/src/version.h b/protocols/Twitter/src/version.h index 61a0406849..093632cee2 100644 --- a/protocols/Twitter/src/version.h +++ b/protocols/Twitter/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 1 #define __MINOR_VERSION 3 #define __RELEASE_NUM 1 -#define __BUILD_NUM 5 +#define __BUILD_NUM 6 #include -- cgit v1.2.3