diff options
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 20 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 16 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 34 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 9 |
4 files changed, 32 insertions, 47 deletions
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 13b20e0066..c8f0f4572a 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -878,8 +878,24 @@ bool facebook_client::channel() } else if (!type.empty()) { // for "msg", "fullReload" and maybe also other types // Something has been received, throw to new thread to process - std::string* response_data = new std::string(resp.data); - parent->ForkThread(&FacebookProto::ProcessMessages, response_data); + { + parent->debugLogA("*** Starting processing messages"); + + try { + std::vector<facebook_message> messages; + parent->ParseMessages(resp.data, messages); + + parent->ReceiveMessages(messages); + + if (parent->getBool(FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE)) + parent->ShowNotifications(); + + parent->debugLogA("*** Messages processed"); + } + catch (const std::exception &e) { + parent->debugLogA("*** Error processing messages: %s", e.what()); + } + } // Get new sequence number std::string seq = utils::text::source_get_value2(&resp.data, "\"seq\":", ",}"); diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 04db951136..cbf9715466 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -475,7 +475,7 @@ bool FacebookProto::ParseMessageMetadata(facebook_message &message, const JSONNo return true; } -bool FacebookProto::ProcessSpecialMessage(std::vector<facebook_message>* messages, const JSONNode &meta_, MessageType messageType, const std::string &messageData) +bool FacebookProto::ProcessSpecialMessage(std::vector<facebook_message> &messages, const JSONNode &meta_, MessageType messageType, const std::string &messageData) { facebook_message message; message.type = messageType; @@ -492,7 +492,7 @@ bool FacebookProto::ProcessSpecialMessage(std::vector<facebook_message>* message return false; } - messages->push_back(message); + messages.push_back(message); return true; } @@ -572,7 +572,7 @@ const char* FacebookProto::ParseIcon(const std::string &url) return (itr == reactions.end()) ? nullptr : itr->second.c_str(); } -int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_message>* messages) +int FacebookProto::ParseMessages(std::string &pData, std::vector<facebook_message> &messages) { // remove old received messages from map for (auto it = facy.messages_ignore.begin(); it != facy.messages_ignore.end();) { @@ -584,7 +584,7 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag } } - JSONNode root = JSONNode::parse(pData->substr(9).c_str()); + JSONNode root = JSONNode::parse(pData.substr(9).c_str()); if (!root) return EXIT_FAILURE; @@ -628,7 +628,7 @@ int FacebookProto::ParseMessages(std::string *pData, std::vector<facebook_messag ParseAttachments(messageText, delta_, (message.isChat ? "" : message.user_id), false); message.message_text = utils::text::trim(messageText, true); - messages->push_back(message); + messages.push_back(message); } else if (cls == "ReplaceMessage") { // revised 5.3.2017 //const JSONNode &newMessage_ = delta_["newMessage"]; @@ -1335,7 +1335,7 @@ int FacebookProto::ParseThreadMessages(std::string *data, std::vector< facebook_ return hasResult ? EXIT_SUCCESS : EXIT_FAILURE; } -int FacebookProto::ParseHistory(std::string *data, std::vector< facebook_message > *messages, std::string* firstTimestamp) +int FacebookProto::ParseHistory(std::string *data, std::vector< facebook_message > &messages, std::string* firstTimestamp) { size_t len = data->find("\r\n"); if (len != data->npos) @@ -1417,13 +1417,13 @@ int FacebookProto::ParseHistory(std::string *data, std::vector< facebook_message ParseMessageType(message, log_type_, log_body_, log_data_); - messages->push_back(message); + messages.push_back(message); } return EXIT_SUCCESS; } -int FacebookProto::ParseThreadInfo(std::string *data, std::string* user_id) +int FacebookProto::ParseThreadInfo(std::string *data, std::string *user_id) { std::string jsonData = data->substr(9); diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 4a413b4035..4455126c61 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -369,7 +369,7 @@ void FacebookProto::LoadHistory(void *pParam) try { messages.clear(); - ParseHistory(&resp.data, &messages, &firstTimestamp); + ParseHistory(&resp.data, messages, &firstTimestamp); // Receive messages std::string previousFirstMessageId = firstMessageId; @@ -890,38 +890,6 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message> &messages, boo delete hChatContacts; } -void FacebookProto::ProcessMessages(void* data) -{ - if (data == nullptr) - return; - - std::string* resp = (std::string*)data; - - if (isOffline()) { - delete resp; - return; - } - - debugLogA("*** Starting processing messages"); - - try { - std::vector<facebook_message> messages; - ParseMessages(resp, &messages); - - ReceiveMessages(messages); - - if (getBool(FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE)) - ShowNotifications(); - - debugLogA("*** Messages processed"); - } - catch (const std::exception &e) { - debugLogA("*** Error processing messages: %s", e.what()); - } - - delete resp; -} - void FacebookProto::ShowNotifications() { mir_cslock s(facy.notifications_lock_); diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 03c3920150..98262699ff 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -26,8 +26,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. class FacebookProto : public PROTO<FacebookProto> { + friend class facebook_client; + bool IgnoreDuplicates(const std::string &mid); - bool ProcessSpecialMessage(std::vector<facebook_message>* messages, const JSONNode &meta_, MessageType messageType, const std::string &messageData = ""); + bool ProcessSpecialMessage(std::vector<facebook_message> &messages, const JSONNode &meta_, MessageType messageType, const std::string &messageData = ""); void ParseAttachments(std::string &message_text, const JSONNode &delta_, std::string other_user_fbid, bool legacy); void ParseMessageType(facebook_message &message, const JSONNode &log_type_, const JSONNode &log_body_, const JSONNode &log_data_); @@ -36,8 +38,8 @@ class FacebookProto : public PROTO<FacebookProto> int ParseChatInfo(std::string* data, facebook_chatroom* fbc); int ParseChatParticipants(std::string *data, std::map<std::string, chatroom_participant>* participants); int ParseFriends(std::string*, std::map< std::string, facebook_user* >*, bool); - int ParseHistory(std::string* data, std::vector<facebook_message>* messages, std::string* firstTimestamp); - int ParseMessages(std::string*, std::vector< facebook_message >*); + int ParseHistory(std::string* data, std::vector<facebook_message> &messages, std::string *firstTimestamp); + int ParseMessages(std::string &data, std::vector< facebook_message >&); int ParseMessagesCount(std::string *data, int *messagesCount, int *unreadCount); int ParseNotifications(std::string*, std::map< std::string, facebook_notification* >*); int ParseThreadInfo(std::string* data, std::string* user_id); @@ -184,7 +186,6 @@ public: // Processing threads void __cdecl ProcessFriendList(void*); - void __cdecl ProcessMessages(void*); void __cdecl ProcessUnreadMessages(void*); void __cdecl ProcessUnreadMessage(void*); void __cdecl ProcessFeeds(void*); |