diff options
author | Robert Pösel <robyer@seznam.cz> | 2016-03-25 00:38:54 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2016-03-25 00:38:54 +0000 |
commit | 68e1a7d81c92574eaf7b95f37879507c2a8b6532 (patch) | |
tree | 18b37bb40a3ee8fab170f6fe5a8b3867486c03d1 /protocols | |
parent | 79412831126e49d990a44506af1ae69f78797d6c (diff) |
Facebook: Fix receiving messages (part I, chats and attachments doesn't work yet)
git-svn-id: http://svn.miranda-ng.org/main/trunk@16540 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 68 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 2 |
2 files changed, 68 insertions, 2 deletions
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 51acc6a6c9..1235b081ac 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -411,7 +411,73 @@ int facebook_json_parser::parse_messages(std::string *pData, std::vector< facebo continue; std::string t = type.as_string(); - if (t == "messaging") { + if (t == "delta") { + // new messaging stuff + + const JSONNode &delta_ = (*it)["delta"]; + if (!delta_) + continue; + + const JSONNode &cls_ = delta_["class"]; + std::string cls = cls_.as_string(); + if (cls == "NewMessage") { + // TODO: Support for "folders" was probably removed, we should remove the "inboxOnly" option too - but first check how does that "allow messages request" works + + const JSONNode &meta_ = delta_["messageMetadata"]; + if (!meta_) { + proto->debugLogA("json::parse_messages - No messageMetadata element"); + continue; + } + + const JSONNode &sender_fbid = meta_["actorFbId"]; + const JSONNode &body = delta_["body"]; + + const JSONNode &mid = meta_["messageId"]; + const JSONNode ×tamp = meta_["timestamp"]; + if (!sender_fbid || !body || !mid || !timestamp) + continue; + + std::string id = sender_fbid.as_string(); + std::string message_id = mid.as_string(); + std::string message_text = body.as_string(); + + std::string other_user_id = meta_["threadKey"]["otherUserFbId"].as_string(); + + // Process attachements and stickers + parseAttachments(proto, &message_text, delta_, "", other_user_id); // FIXME: Rework and fix parsing attachments + + // Ignore duplicits or messages sent from miranda + if (!body || ignore_duplicits(proto, message_id, message_text)) + continue; + + message_text = utils::text::trim(utils::text::slashu_to_utf8(message_text), true); + if (message_text.empty()) { + proto->debugLogA("json::parse_messages - Received empty message. Received only some attachment?"); + // continue; + } + + facebook_message* message = new facebook_message(); + message->isUnread = true; + message->isIncoming = (id != proto->facy.self_.user_id); + message->message_text = message_text; + message->time = utils::time::from_string(timestamp.as_string()); + message->user_id = id; + message->message_id = message_id; + // message->thread_id = tid.as_string(); // TODO: or if not incomming use my own id from facy.self_ ? + message->isChat = false; // FIXME: Determine whether this is chat or not + + /* if (!message->isChat && !message->isIncoming) { + message->sender_name.clear(); + message->user_id = !other_user_id.empty() ? other_user_id : proto->ThreadIDToContactID(message->thread_id); // TODO: Check if we have contact with this user_id in friendlist and otherwise do something different? + } */ + + messages->push_back(message); + } + else { + proto->debugLogA("json::parse_messages - Unknown class '%s'", cls.c_str()); + } + } + else if (t == "messaging") { // various messaging stuff (received and sent messages, getting seen info) const JSONNode &ev_ = (*it)["event"]; diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index eb64a99f8f..a1f5938fee 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -979,7 +979,7 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, boo // Save TID if not exists already ptrA tid(getStringA(hContact, FACEBOOK_KEY_TID)); - if (!tid || mir_strcmp(tid, messages[i]->thread_id.c_str())) + if ((!tid || mir_strcmp(tid, messages[i]->thread_id.c_str())) && !messages[i]->thread_id.empty()) setString(hContact, FACEBOOK_KEY_TID, messages[i]->thread_id.c_str()); if (messages[i]->isIncoming && messages[i]->isUnread && messages[i]->type == MESSAGE) { |