diff options
author | George Hazan <george.hazan@gmail.com> | 2015-05-25 18:09:42 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-05-25 18:09:42 +0000 |
commit | 99bea7a69e782c02d371f94a2988d49d0825fd7e (patch) | |
tree | 17331d8d614c1fe1751a351030a790bbfa5eae29 /protocols | |
parent | fae17e42b5d32ff133426893ca115310d499ab64 (diff) |
FB json parsing rewritten for new headers
git-svn-id: http://svn.miranda-ng.org/main/trunk@13832 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/FacebookRM/src/chat.cpp | 53 | ||||
-rw-r--r-- | protocols/FacebookRM/src/client.h | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 7 | ||||
-rw-r--r-- | protocols/FacebookRM/src/contacts.cpp | 16 | ||||
-rw-r--r-- | protocols/FacebookRM/src/entities.h | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 730 | ||||
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 6 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 12 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 14 | ||||
-rw-r--r-- | protocols/FacebookRM/src/version.h | 4 |
10 files changed, 393 insertions, 457 deletions
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp index c1e2f6d71a..2b9af2ddcb 100644 --- a/protocols/FacebookRM/src/chat.cpp +++ b/protocols/FacebookRM/src/chat.cpp @@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <m_history.h> #include <m_userinfo.h> -void FacebookProto::UpdateChat(const TCHAR *tchat_id, const char *id, const char *name, const char *message, DWORD timestamp, bool is_old) +void FacebookProto::UpdateChat(const char *chat_id, const char *id, const char *name, const char *message, DWORD timestamp, bool is_old) { // replace % to %% to not interfere with chat color codes std::string smessage = message; @@ -33,6 +33,7 @@ void FacebookProto::UpdateChat(const TCHAR *tchat_id, const char *id, const char ptrT tid(mir_a2t(id)); ptrT tnick(mir_a2t_cp(name, CP_UTF8)); ptrT ttext(mir_a2t_cp(smessage.c_str(), CP_UTF8)); + ptrT tchat_id(mir_a2t(chat_id)); GCDEST gcd = { m_szModuleName, tchat_id, GC_EVENT_MESSAGE }; GCEVENT gce = { sizeof(gce), &gcd }; @@ -49,7 +50,7 @@ void FacebookProto::UpdateChat(const TCHAR *tchat_id, const char *id, const char gce.ptszUID = tid; CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce)); - facy.erase_reader(ChatIDToHContact(std::tstring(tchat_id))); + facy.erase_reader(ChatIDToHContact(chat_id)); } void FacebookProto::RenameChat(const char *chat_id, const char *name) @@ -162,11 +163,12 @@ int FacebookProto::OnGCEvent(WPARAM, LPARAM lParam) return 0; } -void FacebookProto::AddChatContact(const TCHAR *tchat_id, const char *id, const char *name) +void FacebookProto::AddChatContact(const char *chat_id, const char *id, const char *name) { - if (IsChatContact(tchat_id, id)) + if (IsChatContact(chat_id, id)) return; + ptrT tchat_id(mir_a2t(chat_id)); ptrT tnick(mir_a2t_cp(name, CP_UTF8)); ptrT tid(mir_a2t(id)); @@ -194,12 +196,13 @@ void FacebookProto::AddChatContact(const TCHAR *tchat_id, const char *id, const CallServiceSync(MS_GC_EVENT, 0, reinterpret_cast<LPARAM>(&gce)); } -void FacebookProto::RemoveChatContact(const TCHAR *tchat_id, const char *id, const char *name) +void FacebookProto::RemoveChatContact(const char *chat_id, const char *id, const char *name) { // We dont want to remove our self-contact from chat. Ever. if (!mir_strcmp(id, facy.self_.user_id.c_str())) return; + ptrT tchat_id(mir_a2t(chat_id)); ptrT tnick(mir_a2t_cp(name, CP_UTF8)); ptrT tid(mir_a2t(id)); @@ -215,26 +218,30 @@ void FacebookProto::RemoveChatContact(const TCHAR *tchat_id, const char *id, con } /** Caller must free result */ -char *FacebookProto::GetChatUsers(const TCHAR *chat_id) +char *FacebookProto::GetChatUsers(const char *chat_id) { + ptrT ptszChatID(mir_a2t(chat_id)); + GC_INFO gci = { 0 }; gci.Flags = GCF_USERS; gci.pszModule = m_szModuleName; - gci.pszID = chat_id; + gci.pszID = ptszChatID; CallService(MS_GC_GETINFO, 0, (LPARAM)&gci); // mir_free(gci.pszUsers); return gci.pszUsers; } -bool FacebookProto::IsChatContact(const TCHAR *chat_id, const char *id) +bool FacebookProto::IsChatContact(const char *chat_id, const char *id) { ptrA users(GetChatUsers(chat_id)); return (users != NULL && strstr(users, id) != NULL); } -void FacebookProto::AddChat(const TCHAR *tid, const TCHAR *tname) +void FacebookProto::AddChat(const char *id, const TCHAR *tname) { + ptrT tid(mir_a2t(id)); + // Create the group chat session GCSESSION gcw = { sizeof(gcw) }; gcw.iType = GCW_PRIVMESS; @@ -263,7 +270,7 @@ void FacebookProto::AddChat(const TCHAR *tid, const TCHAR *tname) bool hideChats = getBool(FACEBOOK_KEY_HIDE_CHATS, DEFAULT_HIDE_CHATS); // Add self contact - AddChatContact(tid, facy.self_.user_id.c_str(), facy.self_.real_name.c_str()); + AddChatContact(id, facy.self_.user_id.c_str(), facy.self_.real_name.c_str()); CallServiceSync(MS_GC_EVENT, (hideChats ? WINDOW_HIDDEN : SESSION_INITDONE), reinterpret_cast<LPARAM>(&gce)); CallServiceSync(MS_GC_EVENT, SESSION_ONLINE, reinterpret_cast<LPARAM>(&gce)); } @@ -275,15 +282,15 @@ INT_PTR FacebookProto::OnJoinChat(WPARAM hContact, LPARAM) ptrT idT(getTStringA(hContact, "ChatRoomID")); ptrT nameT(getTStringA(hContact, "Nick")); - ptrT threadIdT(getTStringA(hContact, FACEBOOK_KEY_TID)); + ptrA threadId(getStringA(hContact, FACEBOOK_KEY_TID)); - if (!idT || !nameT || !threadIdT) + if (!idT || !nameT || !threadId) return 0; facebook_chatroom *fbc; - std::tstring tthread_id = threadIdT; + std::string tthread_id = threadId; - std::map<std::tstring, facebook_chatroom*>::iterator it = facy.chat_rooms.find(tthread_id); + auto it = facy.chat_rooms.find(tthread_id); if (it != facy.chat_rooms.end()) { fbc = it->second; } @@ -331,11 +338,11 @@ INT_PTR FacebookProto::OnLeaveChat(WPARAM wParam, LPARAM) facy.clear_chatrooms(); } else if (!IsSpecialChatRoom(wParam)) { - ptrT threadIdT(getTStringA(wParam, FACEBOOK_KEY_TID)); - if (!threadIdT) + ptrA threadId(getStringA(wParam, FACEBOOK_KEY_TID)); + if (!threadId) return 0; - std::map<std::tstring, facebook_chatroom*>::iterator it = facy.chat_rooms.find(std::tstring(threadIdT)); + auto it = facy.chat_rooms.find(std::string(threadId)); if (it != facy.chat_rooms.end()) { delete it->second; facy.chat_rooms.erase(it); @@ -396,8 +403,8 @@ bool FacebookProto::IsSpecialChatRoom(MCONTACT hContact) { if (!isChatRoom(hContact)) return false; - ptrT idT(getTStringA(hContact, "ChatRoomID")); - return idT && !mir_tstrcmp(idT, _T(FACEBOOK_NOTIFICATIONS_CHATROOM)); + ptrA id(getStringA(hContact, "ChatRoomID")); + return id && !mir_strcmp(id, FACEBOOK_NOTIFICATIONS_CHATROOM); } void FacebookProto::PrepareNotificationsChatRoom() { @@ -405,9 +412,7 @@ void FacebookProto::PrepareNotificationsChatRoom() { return; // Prepare notifications chatroom if not exists - TCHAR *gidT = _T(FACEBOOK_NOTIFICATIONS_CHATROOM); - - MCONTACT hNotificationsChatRoom = ChatIDToHContact(gidT); + MCONTACT hNotificationsChatRoom = ChatIDToHContact(FACEBOOK_NOTIFICATIONS_CHATROOM); if (hNotificationsChatRoom == NULL || getDword(hNotificationsChatRoom, "Status", ID_STATUS_OFFLINE) != ID_STATUS_ONLINE) { TCHAR nameT[200]; mir_sntprintf(nameT, SIZEOF(nameT), _T("%s: %s"), m_tszUserName, TranslateT("Notifications")); @@ -415,13 +420,13 @@ void FacebookProto::PrepareNotificationsChatRoom() { // Create the group chat session GCSESSION gcw = { sizeof(gcw) }; gcw.iType = GCW_PRIVMESS; - gcw.ptszID = gidT; + gcw.ptszID = _T(FACEBOOK_NOTIFICATIONS_CHATROOM); gcw.pszModule = m_szModuleName; gcw.ptszName = nameT; CallServiceSync(MS_GC_NEWSESSION, 0, (LPARAM)&gcw); // Send setting events - GCDEST gcd = { m_szModuleName, gidT, GC_EVENT_CONTROL }; + GCDEST gcd = { m_szModuleName, _T(FACEBOOK_NOTIFICATIONS_CHATROOM), GC_EVENT_CONTROL }; GCEVENT gce = { sizeof(gce), &gcd }; gce.time = ::time(NULL); diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index f89c7ebff8..0f9853ca26 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -101,12 +101,12 @@ public: std::map<std::string, std::string> cookies;
std::map<std::string, std::string> pages;
- std::map<std::tstring, facebook_chatroom*> chat_rooms;
+ std::map<std::string, facebook_chatroom*> chat_rooms;
std::map<std::string, facebook_notification*> notifications;
// Contact/thread id caches
std::map<std::string, std::string> thread_id_to_user_id;
- std::map<std::tstring, MCONTACT> chat_id_to_hcontact;
+ std::map<std::string, MCONTACT> chat_id_to_hcontact;
std::map<std::string, MCONTACT> user_id_to_hcontact;
std::string get_newsfeed_type();
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 7329b1ea6a..009b277417 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -619,7 +619,7 @@ void facebook_client::clear_notifications() { ScopedLock s(notifications_lock_); - for (std::map<std::string, facebook_notification*>::iterator it = notifications.begin(); it != notifications.end();) { + for (auto it = notifications.begin(); it != notifications.end();) { if (it->second->hWndPopup != NULL) PUDeletePopup(it->second->hWndPopup); // close popup @@ -632,7 +632,7 @@ void facebook_client::clear_notifications() void facebook_client::clear_chatrooms() { - for (std::map<std::tstring, facebook_chatroom*>::iterator it = chat_rooms.begin(); it != chat_rooms.end();) { + for (auto it = chat_rooms.begin(); it != chat_rooms.end();) { delete it->second; it = chat_rooms.erase(it); } @@ -645,9 +645,8 @@ void facebook_client::clear_chatrooms() void facebook_client::clear_readers() { for (std::map<MCONTACT, time_t>::iterator it = readers.begin(); it != readers.end();) { - if (parent->isChatRoom(it->first)) { + if (parent->isChatRoom(it->first)) parent->delSetting(it->first, FACEBOOK_KEY_MESSAGE_READERS); - } parent->delSetting(it->first, FACEBOOK_KEY_MESSAGE_READ); it = readers.erase(it); diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index 71f9b5b36e..e94b84f6a7 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -75,7 +75,7 @@ bool FacebookProto::IsMyContact(MCONTACT hContact, bool include_chat) return false; } -MCONTACT FacebookProto::ChatIDToHContact(const std::tstring &chat_id) +MCONTACT FacebookProto::ChatIDToHContact(const std::string &chat_id) { if (chat_id.empty()) { debugLogA("!!! Calling ChatIDToContactID() with empty chat_id"); @@ -83,7 +83,7 @@ MCONTACT FacebookProto::ChatIDToHContact(const std::tstring &chat_id) } // First check cache - std::map<std::tstring, MCONTACT>::iterator it = facy.chat_id_to_hcontact.find(chat_id); + auto it = facy.chat_id_to_hcontact.find(chat_id); if (it != facy.chat_id_to_hcontact.end()) { // Check if contact is still valid if (CallService(MS_DB_CONTACT_IS, (WPARAM)it->second, 0) == 1) @@ -97,8 +97,8 @@ MCONTACT FacebookProto::ChatIDToHContact(const std::tstring &chat_id) if (!IsMyContact(hContact, true)) continue; - ptrT id(getTStringA(hContact, "ChatRoomID")); - if (id && !mir_tstrcmp(id, chat_id.c_str())) { + ptrA id(getStringA(hContact, "ChatRoomID")); + if (id && !mir_strcmp(id, chat_id.c_str())) { facy.chat_id_to_hcontact.insert(std::make_pair(chat_id, hContact)); return hContact; } @@ -269,7 +269,7 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc) data += "&fb_dtsg=" + facy.dtsg_; data += "&__a=1&__dyn=&__req=&ttstamp=" + facy.ttstamp(); - std::string thread_id = utils::url::encode(std::string(_T2A(fbc->thread_id.c_str()))); + std::string thread_id = utils::url::encode(fbc->thread_id); // request info about thread data += "&threads[thread_ids][0]=" + thread_id; @@ -319,7 +319,7 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc) // If there are no participants to create a name from, use just thread_id if (fbc->chat_name.empty()) - fbc->chat_name = fbc->thread_id; // TODO: is this needed? Isn't it showed automatically as id if there is no name? + fbc->chat_name = std::tstring(_A2T(fbc->thread_id.c_str())); // TODO: is this needed? Isn't it showed automatically as id if there is no name? } //ReceiveMessages(messages, true); // don't let it fall into infinite cycle, solve it somehow... @@ -668,9 +668,9 @@ int FacebookProto::OnContactDeleted(WPARAM wParam, LPARAM) facy.thread_id_to_user_id.erase(std::string(tid)); if (isChatRoom(hContact)) { - ptrT chat_id(getTStringA(hContact, "ChatRoomID")); + ptrA chat_id(getStringA(hContact, "ChatRoomID")); if (chat_id) - facy.chat_id_to_hcontact.erase(std::tstring(chat_id)); + facy.chat_id_to_hcontact.erase(std::string(chat_id)); } // Cancel friendship (with confirmation) diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h index b335c6cf43..0b88c0b016 100644 --- a/protocols/FacebookRM/src/entities.h +++ b/protocols/FacebookRM/src/entities.h @@ -71,11 +71,11 @@ struct facebook_user struct facebook_chatroom { - std::tstring thread_id; + std::string thread_id; std::tstring chat_name; std::map<std::string, std::string> participants; - facebook_chatroom(std::tstring thread_id) : thread_id(thread_id) {} + facebook_chatroom(std::string thread_id) : thread_id(thread_id) {} }; struct facebook_message diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 36dcc6aae9..02082009c5 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -27,17 +27,17 @@ int facebook_json_parser::parse_buddy_list(std::string *data, List::List< facebo facebook_user* current = NULL; std::string jsonData = data->substr(9); - JSONROOT root(jsonData.c_str()); - if (root == NULL) + JSONNode root = JSONNode::parse(jsonData.c_str()); + if (root.empty()) return EXIT_FAILURE; - JSONNODE *payload = json_get(root, "payload"); - if (payload == NULL) { + const JSONNode &payload = root["payload"]; + if (payload.empty()) { return EXIT_FAILURE; } - JSONNODE *list = json_get(payload, "buddy_list"); - if (list == NULL) { + const JSONNode &list = payload["buddy_list"]; + if (list.empty()) { return EXIT_FAILURE; } @@ -47,145 +47,130 @@ int facebook_json_parser::parse_buddy_list(std::string *data, List::List< facebo } // Load last active times - JSONNODE *lastActive = json_get(list, "last_active_times"); - if (lastActive != NULL) { - for (unsigned int i = 0; i < json_size(lastActive); i++) { - JSONNODE *it = json_at(lastActive, i); - const char *id = json_name(it); + const JSONNode &lastActive = list["last_active_times"]; + for (auto it = lastActive.begin(); it != lastActive.end(); ++it) { + const char *id = (*it).name(); + current = buddy_list->find(id); + if (current == NULL) { + buddy_list->insert(std::make_pair(id, new facebook_user())); current = buddy_list->find(id); - if (current == NULL) { - buddy_list->insert(std::make_pair(id, new facebook_user())); - current = buddy_list->find(id); - current->user_id = id; - } - - current->last_active = json_as_int(it); + current->user_id = id; } + + current->last_active = (*it).as_int(); } // Find mobile friends - JSONNODE *mobileFriends = json_get(list, "mobile_friends"); - if (mobileFriends != NULL) { - for (unsigned int i = 0; i < json_size(mobileFriends); i++) { - JSONNODE *it = json_at(mobileFriends, i); - std::string id = json_as_pstring(it); + const JSONNode &mobileFriends = list["mobile_friends"]; + for (auto it = mobileFriends.begin(); it != mobileFriends.end(); ++it) { + std::string id = (*it).as_string(); + current = buddy_list->find(id); + if (current == NULL) { + buddy_list->insert(std::make_pair(id, new facebook_user())); current = buddy_list->find(id); - if (current == NULL) { - buddy_list->insert(std::make_pair(id, new facebook_user())); - current = buddy_list->find(id); - current->user_id = id; - } - - current->status_id = ID_STATUS_OFFLINE; - current->client = CLIENT_MOBILE; + current->user_id = id; } + + current->status_id = ID_STATUS_OFFLINE; + current->client = CLIENT_MOBILE; } // Find now available contacts - JSONNODE *nowAvailable = json_get(list, "nowAvailableList"); - if (nowAvailable != NULL) { - for (unsigned int i = 0; i < json_size(nowAvailable); i++) { - JSONNODE *it = json_at(nowAvailable, i); - const char *id = json_name(it); + const JSONNode &nowAvailable = list["nowAvailableList"]; + for (auto it = nowAvailable.begin(); it != nowAvailable.end(); ++it) { + const char *id = (*it).name(); + current = buddy_list->find(id); + if (current == NULL) { + buddy_list->insert(std::make_pair(id, new facebook_user())); current = buddy_list->find(id); - if (current == NULL) { - buddy_list->insert(std::make_pair(id, new facebook_user())); - current = buddy_list->find(id); - current->user_id = id; - } - - current->status_id = ID_STATUS_ONLINE; + current->user_id = id; + } - JSONNODE *p = json_get(it, "p"); - if (p != NULL) { - JSONNODE *status = json_get(p, "status"); // this seems to be "active" everytime - JSONNODE *webStatus = json_get(p, "webStatus"); // "active", "idle" or "offline" - JSONNODE *fbAppStatus = json_get(p, "fbAppStatus"); // "offline" or "active" - JSONNODE *messengerStatus = json_get(p, "messengerStatus"); // "offline" or "active" - JSONNODE *otherStatus = json_get(p, "otherStatus"); // "offline" or "active" - this seems to be "active" when webStatus is "idle" or "active" only + current->status_id = ID_STATUS_ONLINE; - // this may never happen - if (json_as_pstring(status) != "active") - current->status_id = ID_STATUS_OFFLINE; + const JSONNode &p = (*it)["p"]; + if (p != NULL) { + std::string status = p["status"].as_string(); // this seems to be "active" everytime + std::string webStatus = p["webStatus"].as_string(); // "active", "idle" or "offline" + std::string fbAppStatus = p["fbAppStatus"].as_string(); // "offline" or "active" + std::string messengerStatus = p["messengerStatus"].as_string(); // "offline" or "active" + std::string otherStatus = p["otherStatus"].as_string(); // "offline" or "active" - this seems to be "active" when webStatus is "idle" or "active" only - bool b; + // this may never happen + if (status != "active") + current->status_id = ID_STATUS_OFFLINE; - // "webStatus" and "otherStatus" are marked as "WEB" on FB website - if ((b = (json_as_pstring(webStatus) == "active")) || json_as_pstring(otherStatus) == "active") { - current->status_id = ID_STATUS_ONLINE; - current->client = b ? CLIENT_WEB : CLIENT_OTHER; - } + bool b; - // "fbAppStatus" and "messengerStatus" are marked as "MOBILE" on FB website - if ((b = (json_as_pstring(fbAppStatus) == "active")) || json_as_pstring(messengerStatus) == "active") { - current->status_id = ID_STATUS_ONTHEPHONE; - current->client = b ? CLIENT_APP : CLIENT_MESSENGER; - } + // "webStatus" and "otherStatus" are marked as "WEB" on FB website + if ((b = (webStatus == "active")) || otherStatus == "active") { + current->status_id = ID_STATUS_ONLINE; + current->client = b ? CLIENT_WEB : CLIENT_OTHER; + } - // this is not marked anyhow on website (yet?) - current->idle = json_as_pstring(webStatus) == "idle" - || json_as_pstring(otherStatus) == "idle" - || json_as_pstring(fbAppStatus) == "idle" - || json_as_pstring(messengerStatus) == "idle"; + // "fbAppStatus" and "messengerStatus" are marked as "MOBILE" on FB website + if ((b = (fbAppStatus == "active")) || messengerStatus == "active") { + current->status_id = ID_STATUS_ONTHEPHONE; + current->client = b ? CLIENT_APP : CLIENT_MESSENGER; } + + // this is not marked anyhow on website (yet?) + current->idle = webStatus == "idle" || otherStatus == "idle" || fbAppStatus == "idle" || messengerStatus == "idle"; } } // Get aditional informations about contacts (if available) - JSONNODE *userInfos = json_get(list, "userInfos"); - if (userInfos != NULL) { - for (unsigned int i = 0; i < json_size(userInfos); i++) { - JSONNODE *it = json_at(userInfos, i); - const char *id = json_name(it); + const JSONNode &userInfos = list["userInfos"]; + for (auto it = userInfos.begin(); it != userInfos.end(); ++it) { + const char *id = (*it).name(); - current = buddy_list->find(id); - if (current == NULL) - continue; + current = buddy_list->find(id); + if (current == NULL) + continue; - JSONNODE *name = json_get(it, "name"); - JSONNODE *thumbSrc = json_get(it, "thumbSrc"); + std::string name = (*it)["name"].as_string(); + if (!name.empty()) + current->real_name = utils::text::slashu_to_utf8(name); - if (name != NULL) - current->real_name = utils::text::slashu_to_utf8(json_as_pstring(name)); - if (thumbSrc != NULL) - current->image_url = utils::text::slashu_to_utf8(json_as_pstring(thumbSrc)); - } + std::string thumbSrc = (*it)["thumbSrc"].as_string(); + if (!thumbSrc.empty()) + current->image_url = utils::text::slashu_to_utf8(thumbSrc); } return EXIT_SUCCESS; } -void parseUser(JSONNODE *it, facebook_user *fbu) +void parseUser(const JSONNode &it, facebook_user *fbu) { - fbu->user_id = json_name(it); + fbu->user_id = it.name(); - JSONNODE *id = json_get(it, "id"); - if (id == NULL || json_as_pstring(id) == "0" || json_as_pstring(id).empty()) { + std::string id = it["id"].as_string(); + if (id.empty() || id == "0") { // this user has deleted account or is just unavailable for us (e.g., ignore list) -> don't read dummy name and avatar and rather ignore that completely return; } - JSONNODE *name = json_get(it, "name"); - JSONNODE *thumbSrc = json_get(it, "thumbSrc"); - JSONNODE *gender = json_get(it, "gender"); - JSONNODE *vanity = json_get(it, "vanity"); // username - //JSONNODE *uri = json_get(it, "uri"); // profile url - //JSONNODE *is_friend = json_get(it, "is_friend"); // e.g. "True" - //JSONNODE *type = json_get(it, "type"); // e.g. "friend" (classic contact) or "user" (disabled/deleted account) + std::string name = it["name"].as_string(); + std::string thumbSrc = it["thumbSrc"].as_string(); + std::string vanity = it["vanity"].as_string(); // username + int gender = it["gender"].as_int(); + //const JSONNode &uri = it["uri"); // profile url + //const JSONNode &is_friend = it["is_friend"); // e.g. "True" + //const JSONNode &type = it["type"); // e.g. "friend" (classic contact) or "user" (disabled/deleted account) - if (name) - fbu->real_name = utils::text::slashu_to_utf8(json_as_pstring(name)); - if (thumbSrc) - fbu->image_url = utils::text::slashu_to_utf8(json_as_pstring(thumbSrc)); - if (vanity) - fbu->username = utils::text::slashu_to_utf8(json_as_pstring(vanity)); + if (!name.empty()) + fbu->real_name = utils::text::slashu_to_utf8(name); + if (!thumbSrc.empty()) + fbu->image_url = utils::text::slashu_to_utf8(thumbSrc); + if (!vanity.empty()) + fbu->username = utils::text::slashu_to_utf8(vanity); - if (gender) - switch (json_as_int(gender)) { + if (gender) { + switch (gender) { case 1: // female fbu->gender = 70; break; @@ -193,6 +178,7 @@ void parseUser(JSONNODE *it, facebook_user *fbu) fbu->gender = 77; break; // case 7: not available female? + } } } @@ -200,20 +186,17 @@ int facebook_json_parser::parse_friends(std::string *data, std::map< std::string { std::string jsonData = data->substr(9); - JSONROOT root(jsonData.c_str()); - if (root == NULL) + JSONNode root = JSONNode::parse(jsonData.c_str()); + if (root.empty()) return EXIT_FAILURE; - JSONNODE *payload = json_get(root, "payload"); - if (payload == NULL) { + const JSONNode &payload = root["payload"]; + if (payload.empty()) return EXIT_FAILURE; - } - - for (unsigned int i = 0; i < json_size(payload); i++) { - JSONNODE *it = json_at(payload, i); + for (auto it = payload.begin(); it != payload.end(); ++it) { facebook_user *fbu = new facebook_user(); - parseUser(it, fbu); + parseUser(*it, fbu); friends->insert(std::make_pair(fbu->user_id, fbu)); } @@ -226,43 +209,40 @@ int facebook_json_parser::parse_notifications(std::string *data, std::map< std:: { std::string jsonData = data->substr(9); - JSONROOT root(jsonData.c_str()); - if (root == NULL) + JSONNode root = JSONNode::parse(jsonData.c_str()); + if (root.empty()) return EXIT_FAILURE; - JSONNODE *payload = json_get(root, "payload"); - if (payload == NULL) { + const JSONNode &payload = root["payload"]; + if (payload.empty()) return EXIT_FAILURE; - } - JSONNODE *list = json_get(payload, "notifications"); - if (list == NULL) { + const JSONNode &list = payload["notifications"]; + if (list.empty()) return EXIT_FAILURE; - } // Create notifications chatroom (if it doesn't exists), because we will be writing to it new notifications here proto->PrepareNotificationsChatRoom(); - for (unsigned int i = 0; i < json_size(list); i++) { - JSONNODE *it = json_at(list, i); - const char *id = json_name(it); + for (auto it = payload.begin(); it != payload.end(); ++it) { + const char *id = (*it).name(); - JSONNODE *markup = json_get(it, "markup"); - JSONNODE *unread = json_get(it, "unread"); - JSONNODE *time = json_get(it, "time"); + const JSONNode &markup = (*it)["markup"]; + const JSONNode &unread = (*it)["unread"]; + const JSONNode &time = (*it)["time"]; // Ignore empty and old notifications - if (markup == NULL || unread == NULL || time == NULL || json_as_int(unread) == 0) + if (markup == NULL || unread == NULL || time == NULL || unread.as_int() == 0) continue; - std::string text = utils::text::html_entities_decode(utils::text::slashu_to_utf8(json_as_pstring(markup))); + std::string text = utils::text::html_entities_decode(utils::text::slashu_to_utf8(markup.as_string())); facebook_notification* notification = new facebook_notification(); notification->id = id; notification->link = utils::text::source_get_value(&text, 3, "<a ", "href=\"", "\""); notification->text = utils::text::remove_html(utils::text::source_get_value(&text, 1, "<abbr")); - notification->time = utils::time::from_string(json_as_pstring(time)); + notification->time = utils::time::from_string(time.as_string()); // Write notification to chatroom proto->UpdateNotificationsChatRoom(notification); @@ -293,27 +273,26 @@ bool ignore_duplicits(FacebookProto *proto, const std::string &mid, const std::s return false; } -void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE *it, const std::string &thread_id, std::string other_user_fbid) +void parseAttachments(FacebookProto *proto, std::string *message_text, const JSONNode &it, const std::string &thread_id, std::string other_user_fbid) { // Process attachements and stickers - JSONNODE *has_attachment = json_get(it, "has_attachment"); - if (has_attachment != NULL && json_as_bool(has_attachment)) { + const JSONNode &has_attachment = it["has_attachment"]; + if (!has_attachment.empty() && has_attachment.as_bool()) { // Append attachements std::string type; std::string attachments_text; - JSONNODE *attachments = json_get(it, "attachments"); - for (unsigned int j = 0; j < json_size(attachments); j++) { - JSONNODE *itAttachment = json_at(attachments, j); - JSONNODE *attach_type = json_get(itAttachment, "attach_type"); // "sticker", "photo", "file" + const JSONNode &attachments = it["attachments"]; + for (auto itAttachment = attachments.begin(); itAttachment != attachments.end(); ++itAttachment) { + const JSONNode &attach_type = (*itAttachment)["attach_type"]; // "sticker", "photo", "file" if (attach_type != NULL) { // Get attachment type - "file" has priority over other types if (type.empty() || type != "file") - type = json_as_pstring(attach_type); + type = attach_type.as_string(); } - JSONNODE *name = json_get(itAttachment, "name"); - JSONNODE *url = json_get(itAttachment, "url"); + const JSONNode &name = (*itAttachment)["name"]; + const JSONNode &url = (*itAttachment)["url"]; if (url != NULL) { - std::string link = json_as_pstring(url); + std::string link = url.as_string(); if (link.find("/ajax/mercury/attachments/photo/view/") != std::string::npos) link = utils::url::decode(utils::text::source_get_value(&link, 2, "?uri=", "&")); // fix photo url @@ -323,7 +302,7 @@ void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE if (!link.empty()) { std::string filename; if (name != NULL) - filename = json_as_pstring(name); + filename = name.as_string(); if (filename == "null") filename.clear(); @@ -331,16 +310,15 @@ void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE // Stickers as smileys if (type == "sticker" && proto->getByte(FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) { - JSONNODE *metadata = json_get(itAttachment, "metadata"); + const JSONNode &metadata = (*itAttachment)["metadata"]; if (metadata != NULL) { - JSONNODE *stickerId_ = json_get(metadata, "stickerID"); + const JSONNode &stickerId_ = metadata["stickerID"]; if (stickerId_ != NULL) { - std::string sticker = "[[sticker:" + json_as_pstring(stickerId_) + "]]"; + std::string sticker = "[[sticker:" + stickerId_.as_string() + "]]"; attachments_text += sticker; - if (other_user_fbid.empty() && !thread_id.empty()) { + if (other_user_fbid.empty() && !thread_id.empty()) other_user_fbid = proto->ThreadIDToContactID(thread_id); - } // FIXME: rewrite smileyadd to use custom smileys per protocol and not per contact and then remove this ugliness if (!other_user_fbid.empty()) { @@ -360,18 +338,18 @@ void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE if (!attachments_text.empty()) { // we can't use this as offline messages doesn't have it - /* JSONNODE *admin_snippet = json_get(it, "admin_snippet"); + /* const JSONNode &admin_snippet = it["admin_snippet"); if (admin_snippet != NULL) { - *message_text += json_as_pstring(admin_snippet); + *message_text += admin_snippet); } */ std::tstring newText; if (type == "sticker") newText = TranslateT("a sticker"); else if (type == "file") - newText = (json_size(attachments) > 1) ? TranslateT("files") : TranslateT("a file"); + newText = (attachments.size() > 1) ? TranslateT("files") : TranslateT("a file"); else if (type == "photo") - newText = (json_size(attachments) > 1) ? TranslateT("photos") : TranslateT("a photo"); + newText = (attachments.size() > 1) ? TranslateT("photos") : TranslateT("a photo"); else newText = _A2T(type.c_str()); @@ -403,46 +381,43 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo std::string jsonData = data->substr(9); - JSONROOT root(jsonData.c_str()); - if (root == NULL) + JSONNode root = JSONNode::parse(jsonData.c_str()); + if (root.empty()) return EXIT_FAILURE; - JSONNODE *ms = json_get(root, "ms"); - if (ms == NULL) { + const JSONNode &ms = root["ms"]; + if (ms == NULL) return EXIT_FAILURE; - } - - for (unsigned int i = 0; i < json_size(ms); i++) { - JSONNODE *it = json_at(ms, i); - JSONNODE *type = json_get(it, "type"); + for (auto it = ms.begin(); it != ms.end(); ++it) { + const JSONNode &type = (*it)["type"]; if (type == NULL) continue; - std::string t = json_as_pstring(type); + std::string t = type.as_string(); if (t == "messaging") { // various messaging stuff (received and sent messages, getting seen info) - JSONNODE *type = json_get(it, "event"); + const JSONNode &type = (*it)["event"]; if (type == NULL) continue; - std::string t = json_as_pstring(type); + std::string t = type.as_string(); if (t == "read_receipt") { // user read message - JSONNODE *reader_ = json_get(it, "reader"); - JSONNODE *time_ = json_get(it, "time"); + const JSONNode &reader_ = (*it)["reader"]; + const JSONNode &time_ = (*it)["time"]; if (reader_ == NULL || time_ == NULL) continue; - time_t timestamp = utils::time::from_string(json_as_pstring(time_)); + time_t timestamp = utils::time::from_string(time_.as_string()); MCONTACT hContact = NULL; std::tstring reader; - std::string readerId = json_as_pstring(reader_); - JSONNODE *threadid = json_get(it, "tid"); + std::string readerId = reader_.as_string(); + const JSONNode &threadid = (*it)["tid"]; if (threadid == NULL) { // classic contact hContact = proto->ContactIDToHContact(readerId); @@ -451,9 +426,9 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo if (!proto->m_enableChat) continue; - std::tstring tid = ptrT(json_as_string(threadid)); + std::string tid = threadid.as_string(); - std::map<std::tstring, facebook_chatroom*>::iterator it = proto->facy.chat_rooms.find(tid); + std::map<std::string, facebook_chatroom*>::iterator it = proto->facy.chat_rooms.find(tid); if (it != proto->facy.chat_rooms.end()) { facebook_chatroom *chatroom = it->second; std::map<std::string, std::string> participants = chatroom->participants; @@ -481,33 +456,33 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo else if (t == "deliver") { // inbox message (multiuser or direct) - JSONNODE *msg = json_get(it, "message"); - JSONNODE *folder = json_get(it, "folder"); + const JSONNode &msg = (*it)["message"]; + const JSONNode &folder = (*it)["folder"]; - if (inboxOnly && json_as_pstring(folder) != "inbox") + if (inboxOnly && folder.as_string() != "inbox") continue; - JSONNODE *sender_fbid = json_get(msg, "sender_fbid"); - JSONNODE *sender_name = json_get(msg, "sender_name"); - JSONNODE *body = json_get(msg, "body"); + const JSONNode &sender_fbid = msg["sender_fbid"]; + const JSONNode &sender_name = msg["sender_name"]; + const JSONNode &body = msg["body"]; // looks like there is either "tid" or "other_user_fbid" - or "tid" is removed forever? - JSONNODE *tid = json_get(msg, "tid"); - JSONNODE *other_user_id_ = json_get(msg, "other_user_fbid"); + const JSONNode &tid = msg["tid"]; + const JSONNode &other_user_id_ = msg["other_user_fbid"]; - JSONNODE *mid = json_get(msg, "mid"); - JSONNODE *timestamp = json_get(msg, "timestamp"); - JSONNODE *filtered = json_get(it, "is_filtered_content"); + const JSONNode &mid = msg["mid"]; + const JSONNode ×tamp = msg["timestamp"]; + const JSONNode &filtered = (*it)["is_filtered_content"]; if (sender_fbid == NULL || sender_name == NULL || body == NULL || mid == NULL || timestamp == NULL) continue; - std::string id = json_as_pstring(sender_fbid); - std::string message_id = json_as_pstring(mid); - std::string message_text = json_as_pstring(body); + std::string id = sender_fbid.as_string(); + std::string message_id = mid.as_string(); + std::string message_text = body.as_string(); - std::string thread_id = (tid != NULL ? json_as_pstring(tid) : ""); - std::string other_user_id = (other_user_id_ != NULL ? json_as_pstring(other_user_id_) : ""); + std::string thread_id = (tid != NULL ? tid.as_string() : ""); + std::string other_user_id = (other_user_id_ != NULL ? other_user_id_.as_string() : ""); // Process attachements and stickers parseAttachments(proto, &message_text, msg, thread_id, other_user_id); @@ -516,7 +491,7 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo if (body == NULL || ignore_duplicits(proto, message_id, message_text)) continue; - if (json_as_bool(filtered) && message_text.empty()) + if (filtered.as_bool() && message_text.empty()) message_text = Translate("This message is no longer available, because it was marked as abusive or spam."); message_text = utils::text::trim(utils::text::slashu_to_utf8(message_text), true); @@ -527,14 +502,14 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo message->isUnread = true; message->isIncoming = (id != proto->facy.self_.user_id); message->message_text = message_text; - message->time = utils::time::from_string(json_as_pstring(timestamp)); + message->time = utils::time::from_string(timestamp.as_string()); message->user_id = id; message->message_id = message_id; - message->sender_name = utils::text::slashu_to_utf8(json_as_pstring(sender_name)); // TODO: or if not incomming use my own name from facy.self_ ? - message->thread_id = json_as_pstring(tid); // TODO: or if not incomming use my own id from facy.self_ ? + message->sender_name = utils::text::slashu_to_utf8(sender_name.as_string()); // TODO: or if not incomming use my own name from facy.self_ ? + message->thread_id = tid.as_string(); // TODO: or if not incomming use my own id from facy.self_ ? - JSONNODE *gthreadinfo = json_get(msg, "group_thread_info"); - message->isChat = (gthreadinfo != NULL && json_as_pstring(gthreadinfo) != "null"); + const JSONNode >hreadinfo = msg["group_thread_info"]; + message->isChat = (gthreadinfo != NULL && gthreadinfo.as_string() != "null"); if (!message->isChat && !message->isIncoming) { message->sender_name.clear(); @@ -546,38 +521,36 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo } else if (t == "notification_json") { // event notification - JSONNODE *nodes = json_get(it, "nodes"); + const JSONNode &nodes = (*it)["nodes"]; // Create notifications chatroom (if it doesn't exists), because we will be writing to it new notifications here proto->PrepareNotificationsChatRoom(); - for (unsigned int j = 0; j < json_size(nodes); j++) { - JSONNODE *itNodes = json_at(nodes, j); - - //JSONNODE *text = json_get(itNodes, "title/text"); // use this when popups will be ready to allow changes of their content - JSONNODE *text_ = json_get(itNodes, "unaggregatedTitle"); // notifications one by one, not grouped + for (auto itNodes = nodes.begin(); itNodes != nodes.end(); ++itNodes) { + const JSONNode &text_ = (*itNodes)["unaggregatedTitle"]; // notifications one by one, not grouped if (text_ == NULL) continue; - JSONNODE *text = json_get(text_, "text"); - JSONNODE *url = json_get(itNodes, "url"); - JSONNODE *alert_id = json_get(itNodes, "alert_id"); + + const JSONNode &text = text_["text"]; + const JSONNode &url = (*itNodes)["url"]; + const JSONNode &alert_id = (*itNodes)["alert_id"]; - JSONNODE *time_ = json_get(itNodes, "timestamp"); + const JSONNode &time_ = (*itNodes)["timestamp"]; if (time_ == NULL) continue; - JSONNODE *time = json_get(time_, "time"); + const JSONNode &time = time_["time"]; if (time == NULL || text == NULL || url == NULL || alert_id == NULL) continue; - time_t timestamp = utils::time::from_string(json_as_pstring(time)); + time_t timestamp = utils::time::from_string(time.as_string()); if (timestamp > proto->facy.last_notification_time_) { // Only new notifications proto->facy.last_notification_time_ = timestamp; facebook_notification* notification = new facebook_notification(); - notification->text = utils::text::slashu_to_utf8(json_as_pstring(text)); - notification->link = json_as_pstring(url); - notification->id = json_as_pstring(alert_id); + notification->text = utils::text::slashu_to_utf8(text.as_string()); + notification->link = url.as_string(); + notification->id = alert_id.as_string(); notification->time = timestamp; std::string::size_type pos = notification->id.find(":"); @@ -596,29 +569,29 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo } } else if (t == "m_notification") { - JSONNODE *data = json_get(it, "data"); + const JSONNode &data = (*it)["data"]; if (data == NULL) continue; - JSONNODE *appId_ = json_get(data, "app_id"); - JSONNODE *type_ = json_get(data, "type"); + const JSONNode &appId_ = data["app_id"]; + const JSONNode &type_ = data["type"]; - if ((appId_ && json_as_pstring(appId_) == "2356318349") || (type_ && json_as_pstring(type_) == "friend_confirmed")) { + if (appId_.as_string() == "2356318349" || type_.as_string() == "friend_confirmed") { // Friendship notifications - JSONNODE *body_ = json_get(data, "body"); - JSONNODE *html_ = (body_ ? json_get(body_, "__html") : NULL); + const JSONNode &body_ = data["body"]; + const JSONNode &html_ = body_["__html"]; - JSONNODE *href_ = json_get(data, "href"); - JSONNODE *unread_ = json_get(data, "unread"); - JSONNODE *alertId_ = json_get(data, "alert_id"); + const JSONNode &href_ = data["href"]; + const JSONNode &unread_ = data["unread"]; + const JSONNode &alertId_ = data["alert_id"]; - if (html_ == NULL || href_ == NULL || unread_ == NULL || json_as_int(unread_) == 0) + if (html_ == NULL || href_ == NULL || unread_ == NULL || unread_.as_int() == 0) continue; - std::string text = utils::text::remove_html(utils::text::slashu_to_utf8(json_as_pstring(html_))); - std::string url = json_as_pstring(href_); - std::string alert_id = (alertId_ ? json_as_pstring(alertId_) : ""); + std::string text = utils::text::remove_html(utils::text::slashu_to_utf8(html_.as_string())); + std::string url = href_.as_string(); + std::string alert_id = alertId_.as_string(); proto->NotifyEvent(proto->m_tszUserName, ptrT(mir_utf8decodeT(text.c_str())), NULL, FACEBOOK_EVENT_FRIENDSHIP, &url, alert_id.empty() ? NULL : &alert_id); } @@ -630,17 +603,17 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo else if (t == "typ") { // chat typing notification - JSONNODE *from = json_get(it, "from"); + const JSONNode &from = (*it)["from"]; if (from == NULL) continue; facebook_user fbu; - fbu.user_id = json_as_pstring(from); + fbu.user_id = from.as_string(); MCONTACT hContact = proto->AddToContactList(&fbu, CONTACT_FRIEND); // only friends are able to send typing notifications - JSONNODE *st = json_get(it, "st"); - if (json_as_int(st) == 1) + const JSONNode &st = (*it)["st"]; + if (st.as_int() == 1) proto->StartTyping(hContact); else proto->StopTyping(hContact); @@ -650,17 +623,17 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo if (!proto->m_enableChat) continue; - JSONNODE *from_ = json_get(it, "from"); - JSONNODE *thread_ = json_get(it, "thread"); - JSONNODE *st_ = json_get(it, "st"); + const JSONNode &from_ = (*it)["from"]; + const JSONNode &thread_ = (*it)["thread"]; + const JSONNode &st_ = (*it)["st"]; if (from_ == NULL || thread_ == NULL || st_ == NULL) continue; - std::tstring tid = ptrT(json_as_string(thread_)); - std::string from_id = json_as_pstring(from_); + std::string tid = thread_.as_string(); + std::string from_id = from_.as_string(); - std::map<std::tstring, facebook_chatroom*>::iterator it = proto->facy.chat_rooms.find(tid); + std::map<std::string, facebook_chatroom*>::iterator it = proto->facy.chat_rooms.find(thread_.as_string()); if (it != proto->facy.chat_rooms.end()) { facebook_chatroom *chatroom = it->second; std::map<std::string, std::string> participants = chatroom->participants; @@ -677,7 +650,7 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo MCONTACT hChatContact = proto->ChatIDToHContact(tid); ptrT name(mir_utf8decodeT(participant->second.c_str())); - if (json_as_int(st_) == 1) { + if (st_.as_int() == 1) { StatusTextData st = { 0 }; st.cbSize = sizeof(st); @@ -696,18 +669,18 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo else if (t == "privacy_changed") { // settings changed - JSONNODE *event_type = json_get(it, "event"); - JSONNODE *event_data = json_get(it, "data"); + const JSONNode &event_type = (*it)["event"]; + const JSONNode &event_data = (*it)["data"]; if (event_type == NULL || event_data == NULL) continue; - std::string t = json_as_pstring(event_type); + std::string t = event_type.as_string(); if (t == "visibility_update") { // change of chat status - JSONNODE *visibility = json_get(event_data, "visibility"); + const JSONNode &visibility = event_data["visibility"]; - bool isVisible = (visibility != NULL) && json_as_bool(visibility); + bool isVisible = (visibility != NULL) && visibility.as_bool(); proto->debugLogA(" Requested chat switch to %s", isVisible ? "Online" : "Offline"); proto->SetStatus(isVisible ? ID_STATUS_ONLINE : ID_STATUS_INVISIBLE); } @@ -716,10 +689,10 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo // we opened/closed chat window - pretty useless info for us continue; } else if (t == "ticker_update:home") { - JSONNODE *actor_ = json_get(it, "actor"); - JSONNODE *story_ = json_get(it, "story_xhp"); + const JSONNode &actor_ = (*it)["actor"]; + const JSONNode &story_ = (*it)["story_xhp"]; - std::string text = json_as_pstring(story_); + std::string text = story_.as_string(); text = utils::text::html_entities_decode(utils::text::slashu_to_utf8(text)); std::string url = utils::text::source_get_value(&text, 3, "\"tickerStoryLink\"", "href=\"", "\""); @@ -728,7 +701,7 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo text = utils::text::trim(utils::text::remove_html(text)); - std::string userId = (actor_ != NULL ? json_as_pstring(actor_) : ""); + std::string userId = actor_.as_string(); MCONTACT hContact = proto->ContactIDToHContact(userId); @@ -740,43 +713,43 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo else if (t == "mercury") { // rename multi user chat, video call, ... - JSONNODE *actions_ = json_get(it, "actions"); + const JSONNode &actions_ = (*it)["actions"]; if (actions_ == NULL) continue; - for (unsigned int i = 0; i < json_size(actions_); i++) { - JSONNODE *action_ = json_at(actions_, i); + for (unsigned int i = 0; i < actions_.size(); i++) { + const JSONNode &action_ = actions_[i]; - JSONNODE *thread_id_ = json_get(action_, "thread_id"); - JSONNODE *log_body_ = json_get(action_, "log_message_body"); - JSONNODE *log_data_ = json_get(action_, "log_message_data"); - JSONNODE *log_type_ = json_get(action_, "log_message_type"); - if (!log_data_ || !log_body_ || !thread_id_ || !log_type_) + const JSONNode &thread_id_ = action_["thread_id"]; + const JSONNode &log_body_ = action_["log_message_body"]; + const JSONNode &log_data_ = action_["log_message_data"]; + const JSONNode &log_type_ = action_["log_message_type"]; + if (log_data_ == NULL || log_body_ == NULL || thread_id_ == NULL || log_type_ == NULL) continue; - std::tstring thread_id = ptrT(json_as_string(thread_id_)); - std::string type = json_as_pstring(log_type_); - std::string message_text = json_as_pstring(log_body_); + std::string thread_id = thread_id_.as_string(); + std::string type = log_type_.as_string(); + std::string message_text = log_body_.as_string(); if (type == "log:video-call") { - JSONNODE *other_user_fbid_ = json_get(action_, "other_user_fbid"); - std::string id = json_as_pstring(other_user_fbid_); + const JSONNode &other_user_fbid_ = action_["other_user_fbid"]; + std::string id = other_user_fbid_.as_string(); - JSONNODE *timestamp = json_get(action_, "timestamp"); - JSONNODE *mid_ = json_get(action_, "message_id"); + const JSONNode ×tamp = action_["timestamp"]; + const JSONNode &mid_ = action_["message_id"]; - std::string message_id = json_as_pstring(mid_); + std::string message_id = mid_.as_string(); facebook_message* message = new facebook_message(); message->isChat = false; message->isUnread = true; message->isIncoming = (id != proto->facy.self_.user_id); message->message_text = message_text; - message->time = utils::time::from_string(json_as_pstring(timestamp)); + message->time = utils::time::from_string(timestamp.as_string()); message->user_id = id; message->message_id = message_id; message->sender_name.clear(); - message->thread_id = json_as_pstring(thread_id_); + message->thread_id = thread_id; message->type = CALL; messages->push_back(message); @@ -787,8 +760,8 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo if (!proto->m_enableChat) continue; - JSONNODE *name_ = json_get(log_data_, "name"); - std::string name = json_as_pstring(name_); + const JSONNode &name_ = log_data_["name"]; + std::string name = name_.as_string(); // proto->RenameChat(thread_id.c_str(), name.c_str()); // this don't work, why? proto->setStringUtf(proto->ChatIDToHContact(thread_id), FACEBOOK_KEY_NICK, name.c_str()); @@ -800,11 +773,10 @@ int facebook_json_parser::parse_messages(std::string *data, std::vector< faceboo else if (t == "notifications_read" || t == "notifications_seen") { ScopedLock s(proto->facy.notifications_lock_); - JSONNODE *alerts = json_get(it, "alert_ids"); + const JSONNode &alerts = (*it)["alert_ids"]; - for (unsigned int j = 0; j < json_size(alerts); j++) { - JSONNODE *itAlerts = json_at(alerts, j); - std::string id = json_as_pstring(itAlerts); + for (auto itAlerts = alerts.begin(); itAlerts != alerts.end(); ++itAlerts) { + std::string id = (*itAlerts).as_string(); std::map<std::string, facebook_notification*>::iterator it = notifications->find(id); if (it != notifications->end()) { @@ -827,33 +799,27 @@ int facebook_json_parser::parse_unread_threads(std::string *data, std::vector< s { std::string jsonData = data->substr(9); - JSONROOT root(jsonData.c_str()); - if (root == NULL) + JSONNode root = JSONNode::parse(jsonData.c_str()); + if (root.empty()) return EXIT_FAILURE; - JSONNODE *payload = json_get(root, "payload"); - if (payload == NULL) { + const JSONNode &payload = root["payload"]; + if (payload == NULL) return EXIT_FAILURE; - } - JSONNODE *unread_threads = json_get(payload, "unread_thread_ids"); - if (unread_threads == NULL) { + const JSONNode &unread_threads = payload["unread_thread_ids"]; + if (unread_threads == NULL) return EXIT_FAILURE; - } - for (unsigned int i = 0; i < json_size(unread_threads); i++) { - JSONNODE *it = json_at(unread_threads, i); + for (auto it = unread_threads.begin(); it != unread_threads.end(); ++it) { + const JSONNode &folder = (*it)["folder"]; + const JSONNode &thread_ids = (*it)["thread_ids"]; - JSONNODE *folder = json_get(it, "folder"); - JSONNODE *thread_ids = json_get(it, "thread_ids"); - - if (inboxOnly && json_as_pstring(folder) != "inbox") + if (inboxOnly && folder.as_string() != "inbox") continue; - for (unsigned int j = 0; j < json_size(thread_ids); j++) { - JSONNODE *id = json_at(thread_ids, j); - threads->push_back(json_as_pstring(id)); - } + for (auto it2 = thread_ids.begin(); it2 != thread_ids.end(); ++it2) + threads->push_back((*it2).as_string()); } return EXIT_SUCCESS; @@ -863,64 +829,59 @@ int facebook_json_parser::parse_thread_messages(std::string *data, std::vector< { std::string jsonData = data->substr(9); - JSONROOT root(jsonData.c_str()); - if (root == NULL) + JSONNode root = JSONNode::parse(jsonData.c_str()); + if (root.empty()) return EXIT_FAILURE; - JSONNODE *payload = json_get(root, "payload"); + const JSONNode &payload = root["payload"]; if (payload == NULL) { return EXIT_FAILURE; } - JSONNODE *actions = json_get(payload, "actions"); - JSONNODE *threads = json_get(payload, "threads"); + const JSONNode &actions = payload["actions"]; + const JSONNode &threads = payload["threads"]; if (actions == NULL || threads == NULL) { return EXIT_FAILURE; } - JSONNODE *roger = json_get(payload, "roger"); - if (roger != NULL) { - for (unsigned int i = 0; i < json_size(roger); i++) { - JSONNODE *it = json_at(roger, i); - std::tstring id = _A2T(json_name(it)); - - // Ignore "wrong" (duplicit) identifiers - these that doesn't begin with "id." - if (id.substr(0, 3) == _T("id.")) { - facebook_chatroom *room = new facebook_chatroom(id); - chatrooms->insert(std::make_pair((char*)_T2A(room->thread_id.c_str()), room)); - } + const JSONNode &roger = payload["roger"]; + for (auto it = roger.begin(); it != roger.end(); ++it) { + std::string id = (*it).name(); + + // Ignore "wrong" (duplicit) identifiers - these that doesn't begin with "id." + if (id.substr(0, 3) == "id.") { + facebook_chatroom *room = new facebook_chatroom(id); + chatrooms->insert(std::make_pair(id, room)); } } std::map<std::string, std::string> thread_ids; - for (unsigned int i = 0; i < json_size(threads); i++) { - JSONNODE *it = json_at(threads, i); - JSONNODE *is_canonical_user = json_get(it, "is_canonical_user"); - JSONNODE *canonical = json_get(it, "canonical_fbid"); - JSONNODE *thread_id = json_get(it, "thread_id"); - JSONNODE *name = json_get(it, "name"); - //JSONNODE *message_count = json_get(it, "message_count"); - //JSONNODE *unread_count = json_get(it, "unread_count"); // TODO: use it to check against number of loaded messages... but how? - JSONNODE *folder = json_get(it, "folder"); + for (auto it = threads.begin(); it != threads.end(); ++it) { + const JSONNode &is_canonical_user = (*it)["is_canonical_user"]; + const JSONNode &canonical = (*it)["canonical_fbid"]; + const JSONNode &thread_id = (*it)["thread_id"]; + const JSONNode &name = (*it)["name"]; + //const JSONNode &message_count = (*it)["message_count"); + //const JSONNode &unread_count = (*it)["unread_count"); // TODO: use it to check against number of loaded messages... but how? + const JSONNode &folder = (*it)["folder"]; if (canonical == NULL || thread_id == NULL) continue; - std::string id = json_as_pstring(canonical); - std::string tid = json_as_pstring(thread_id); + std::string id = canonical.as_string(); + std::string tid = thread_id.as_string(); std::map<std::string, facebook_chatroom*>::iterator iter = chatrooms->find(tid); if (iter != chatrooms->end()) { - if (json_as_bool(is_canonical_user)) { + if (is_canonical_user.as_bool()) { chatrooms->erase(iter); // this is not chatroom } else { - iter->second->chat_name = ptrT(json_as_string(name)); // TODO: create name from users if there is no name... + iter->second->chat_name = std::tstring(ptrT(mir_utf8decodeT(name.as_string().c_str()))); // TODO: create name from users if there is no name... - JSONNODE *participants = json_get(it, "participants"); - for (unsigned int j = 0; j < json_size(participants); j++) { - JSONNODE *jt = json_at(it, j); - std::string user_id = json_name(jt); + const JSONNode &participants = (*it)["participants"]; + for (auto it2 = participants.begin(); it2 != participants.end(); ++it2) { + std::string user_id = (*it2).name(); iter->second->participants.insert(std::make_pair(user_id, user_id)); // TODO: get name somehow } } @@ -931,7 +892,7 @@ int facebook_json_parser::parse_thread_messages(std::string *data, std::vector< chatrooms->erase(iter); // this is not chatroom } - if (inboxOnly && json_as_pstring(folder) != "inbox") + if (inboxOnly && folder.as_string() != "inbox") continue; if (id == "null") @@ -940,44 +901,42 @@ int facebook_json_parser::parse_thread_messages(std::string *data, std::vector< thread_ids.insert(std::make_pair(tid, id)); } - for (unsigned int i = 0; i < json_size(actions); i++) { - JSONNODE *it = json_at(actions, i); - - JSONNODE *author = json_get(it, "author"); - JSONNODE *author_email = json_get(it, "author_email"); - JSONNODE *body = json_get(it, "body"); - JSONNODE *tid = json_get(it, "thread_id"); - JSONNODE *mid = json_get(it, "message_id"); - JSONNODE *timestamp = json_get(it, "timestamp"); - JSONNODE *filtered = json_get(it, "is_filtered_content"); - JSONNODE *folder = json_get(it, "folder"); - JSONNODE *is_unread = json_get(it, "is_unread"); + for (auto it = actions.begin(); it != actions.end(); ++it) { + const JSONNode &author = (*it)["author"]; + const JSONNode &author_email = (*it)["author_email"]; + const JSONNode &body = (*it)["body"]; + const JSONNode &tid = (*it)["thread_id"]; + const JSONNode &mid = (*it)["message_id"]; + const JSONNode ×tamp = (*it)["timestamp"]; + const JSONNode &filtered = (*it)["is_filtered_content"]; + const JSONNode &folder = (*it)["folder"]; + const JSONNode &is_unread = (*it)["is_unread"]; if (author == NULL || body == NULL || mid == NULL || tid == NULL || timestamp == NULL) continue; - if (inboxOnly && json_as_pstring(folder) != "inbox") + if (inboxOnly && folder.as_string() != "inbox") continue; - std::string thread_id = json_as_pstring(tid); - std::string message_id = json_as_pstring(mid); - std::string message_text = json_as_pstring(body); - std::string author_id = json_as_pstring(author); + std::string thread_id = tid.as_string(); + std::string message_id = mid.as_string(); + std::string message_text = body.as_string(); + std::string author_id = author.as_string(); std::string::size_type pos = author_id.find(":"); if (pos != std::string::npos) author_id = author_id.substr(pos + 1); // Process attachements and stickers - parseAttachments(proto, &message_text, it, thread_id, ""); // FIXME: is here supported other_user_fbid ? + parseAttachments(proto, &message_text, *it, thread_id, ""); // FIXME: is here supported other_user_fbid ? - if (json_as_bool(filtered) && message_text.empty()) + if (filtered.as_bool() && message_text.empty()) message_text = Translate("This message is no longer available, because it was marked as abusive or spam."); message_text = utils::text::trim(utils::text::slashu_to_utf8(message_text), true); if (message_text.empty()) continue; - bool isUnread = (is_unread != NULL && json_as_bool(is_unread)); + bool isUnread = is_unread.as_bool(); // Ignore read messages if we want only unread messages if (unreadOnly && !isUnread) @@ -986,8 +945,8 @@ int facebook_json_parser::parse_thread_messages(std::string *data, std::vector< facebook_message* message = new facebook_message(); message->message_text = message_text; if (author_email != NULL) - message->sender_name = json_as_pstring(author_email); - message->time = utils::time::from_string(json_as_pstring(timestamp)); + message->sender_name = author_email.as_string(); + message->time = utils::time::from_string(timestamp.as_string()); message->thread_id = thread_id; message->message_id = message_id; message->isIncoming = (author_id != proto->facy.self_.user_id); @@ -1021,31 +980,24 @@ int facebook_json_parser::parse_thread_info(std::string *data, std::string* user { std::string jsonData = data->substr(9); - JSONROOT root(jsonData.c_str()); - if (root == NULL) + JSONNode root = JSONNode::parse(jsonData.c_str()); + if (root.empty()) return EXIT_FAILURE; - JSONNODE *payload = json_get(root, "payload"); - if (payload == NULL) { + const JSONNode &threads = root["payload"].at("threads"); + if (threads == NULL) return EXIT_FAILURE; - } - - JSONNODE *threads = json_get(payload, "threads"); - if (threads == NULL) { - return EXIT_FAILURE; - } //std::map<std::string, std::string> thread_ids; - for (unsigned int i = 0; i < json_size(threads); i++) { - JSONNODE *it = json_at(threads, i); - JSONNODE *canonical = json_get(it, "canonical_fbid"); - JSONNODE *thread_id = json_get(it, "thread_id"); - //JSONNODE *message_count = json_get(it, "message_count"); // TODO: this could be useful for loading history from server + for (auto it = threads.begin(); it != threads.end(); ++it) { + const JSONNode &canonical = (*it)["canonical_fbid"]; + const JSONNode &thread_id = (*it)["thread_id"]; + //const JSONNode &message_count = (*it)["message_count"); // TODO: this could be useful for loading history from server if (canonical == NULL || thread_id == NULL) continue; - std::string id = json_as_pstring(canonical); + std::string id = canonical.as_string(); if (id == "null") continue; @@ -1060,29 +1012,21 @@ int facebook_json_parser::parse_user_info(std::string *data, facebook_user* fbu) { std::string jsonData = data->substr(9); - JSONROOT root(jsonData.c_str()); - if (root == NULL) + JSONNode root = JSONNode::parse(jsonData.c_str()); + if (root.empty()) return EXIT_FAILURE; - JSONNODE *payload = json_get(root, "payload"); - if (payload == NULL) { + const JSONNode &profiles = root["payload"].at("profiles"); + if (profiles == NULL) return EXIT_FAILURE; - } - - JSONNODE *profiles = json_get(payload, "profiles"); - if (profiles == NULL) { - return EXIT_FAILURE; - } //std::map<std::string, std::string> user_ids; - for (unsigned int i = 0; i < json_size(profiles); i++) { - JSONNODE *it = json_at(profiles, i); - + for (auto it = profiles.begin(); it != profiles.end(); ++it) { // TODO: allow more users to parse at once - std::string id = json_name(it); + std::string id = (*it).name(); if (fbu->user_id == id) { - parseUser(it, fbu); + parseUser(*it, fbu); break; } } @@ -1094,25 +1038,18 @@ int facebook_json_parser::parse_chat_info(std::string *data, facebook_chatroom* { std::string jsonData = data->substr(9); - JSONROOT root(jsonData.c_str()); - if (root == NULL) - return EXIT_FAILURE; - - JSONNODE *payload = json_get(root, "payload"); - if (payload == NULL) { + JSONNode root = JSONNode::parse(jsonData.c_str()); + if (root.empty()) return EXIT_FAILURE; - } - //JSONNODE *actions = json_get(payload, "actions"); - JSONNODE *threads = json_get(payload, "threads"); - if (/*actions == NULL || */threads == NULL) { + const JSONNode &threads = root["payload"].at("threads"); + if (threads == NULL) return EXIT_FAILURE; - } - /*JSONNODE *roger = json_get(payload, "roger"); + /*const JSONNode &roger = payload, "roger"); if (roger != NULL) { for (unsigned int i = 0; i < json_size(roger); i++) { - JSONNODE *it = json_at(roger, i); + const JSONNode &it = json_at(roger, i); std::tstring id = _A2T(json_name(it)); // Ignore "wrong" (duplicit) identifiers - these that doesn't begin with "id." @@ -1125,34 +1062,29 @@ int facebook_json_parser::parse_chat_info(std::string *data, facebook_chatroom* } }*/ - //std::map<std::string, std::string> thread_ids; - for (unsigned int i = 0; i < json_size(threads); i++) { - JSONNODE *it = json_at(threads, i); - - JSONNODE *is_canonical_user_ = json_get(it, "is_canonical_user"); - JSONNODE *thread_id_ = json_get(it, "thread_id"); - JSONNODE *name_ = json_get(it, "name"); - //JSONNODE *message_count_ = json_get(it, "message_count"); - //JSONNODE *unread_count_ = json_get(it, "unread_count"); // TODO: use it to check against number of loaded messages... but how? + for (auto it = threads.begin(); it != threads.end(); ++it) { + const JSONNode &is_canonical_user_ = (*it)["is_canonical_user"]; + const JSONNode &thread_id_ = (*it)["thread_id"]; + const JSONNode &name_ = (*it)["name"]; + //const JSONNode &message_count_ = (*it)["message_count"); + //const JSONNode &unread_count_ = (*it)["unread_count"); // TODO: use it to check against number of loaded messages... but how? - if (thread_id_ == NULL || is_canonical_user_ == NULL || json_as_bool(is_canonical_user_)) + if (thread_id_ == NULL || is_canonical_user_ == NULL || is_canonical_user_.as_bool()) continue; - std::tstring tid = ptrT(json_as_string(thread_id_)); + std::string tid = thread_id_.as_string(); // TODO: allow more users to parse at once - if (fbc->thread_id != tid) { + if (fbc->thread_id != tid) continue; - } - JSONNODE *participants = json_get(it, "participants"); - for (unsigned int j = 0; j < json_size(participants); j++) { - JSONNODE *jt = json_at(participants, j); - std::string user_id = json_as_pstring(jt); + const JSONNode &participants = (*it)["participants"]; + for (auto jt = participants.begin(); jt != participants.end(); ++jt) { + std::string user_id = (*jt).as_string(); fbc->participants.insert(std::make_pair(user_id.substr(5), "")); } - fbc->chat_name = ptrT(json_as_string(name_)); + fbc->chat_name = std::tstring(ptrT(mir_utf8decodeT(name_.as_string().c_str()))); } return EXIT_SUCCESS; diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index 1ef728d654..6d31e15ed0 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -80,7 +80,7 @@ void FacebookProto::SendChatMsgWorker(void *p) // replace %% back to %, because chat automatically does this to sent messages utils::text::replace_all(&data->msg, "%%", "%"); - MCONTACT hContact = ChatIDToHContact(std::tstring(_A2T(data->chat_id.c_str()))); + MCONTACT hContact = ChatIDToHContact(data->chat_id); if (hContact) { ptrA tid_(getStringA(hContact, FACEBOOK_KEY_TID)); std::string tid; @@ -103,9 +103,9 @@ void FacebookProto::SendChatMsgWorker(void *p) if (!tid.empty()) { if (facy.send_message(0, hContact, data->msg, &err_message) == SEND_MESSAGE_OK) - UpdateChat(_A2T(data->chat_id.c_str()), facy.self_.user_id.c_str(), facy.self_.real_name.c_str(), data->msg.c_str()); + UpdateChat(data->chat_id.c_str(), facy.self_.user_id.c_str(), facy.self_.real_name.c_str(), data->msg.c_str()); else - UpdateChat(_A2T(data->chat_id.c_str()), NULL, NULL, err_message.c_str()); + UpdateChat(data->chat_id.c_str(), NULL, NULL, err_message.c_str()); } } diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index fe9651aff0..6cc40d8391 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -631,7 +631,7 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, boo for (std::vector<facebook_message*>::size_type i = 0; i < messages.size(); i++) { MCONTACT hContact = messages[i]->isChat - ? ChatIDToHContact(std::tstring(_A2T(messages[i]->thread_id.c_str()))) + ? ChatIDToHContact(messages[i]->thread_id) : ContactIDToHContact(messages[i]->user_id); if (hContact == NULL) @@ -676,9 +676,9 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, boo debugLogA(" < Got chat message ID: %s", messages[i]->message_id.c_str()); facebook_chatroom *fbc; - std::tstring tthread_id = _A2T(messages[i]->thread_id.c_str()); + std::string tthread_id = messages[i]->thread_id.c_str(); - std::map<std::tstring, facebook_chatroom*>::iterator it = facy.chat_rooms.find(tthread_id); + auto it = facy.chat_rooms.find(tthread_id); if (it != facy.chat_rooms.end()) { fbc = it->second; } @@ -698,12 +698,12 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, boo MCONTACT hChatContact = NULL; // RM TODO: better use check if chatroom exists/is in db/is online... no? // like: if (ChatIDToHContact(tthread_id) == NULL) { - ptrA users(GetChatUsers(tthread_id.c_str())); + ptrA users(GetChatUsers(fbc->thread_id.c_str())); if (users == NULL) { AddChat(fbc->thread_id.c_str(), fbc->chat_name.c_str()); hChatContact = ChatIDToHContact(fbc->thread_id); // Set thread id (TID) for later - setTString(hChatContact, FACEBOOK_KEY_TID, fbc->thread_id.c_str()); + setString(hChatContact, FACEBOOK_KEY_TID, fbc->thread_id.c_str()); for (std::map<std::string, std::string>::iterator jt = fbc->participants.begin(); jt != fbc->participants.end(); ++jt) { AddChatContact(fbc->thread_id.c_str(), jt->first.c_str(), jt->second.c_str()); @@ -737,7 +737,7 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, boo // TODO: support also system messages (rename chat, user quit, etc.)! (here? or it is somewhere else? // ... we must add some new "type" field into facebook_message structure and use it also for Pokes and similar) - UpdateChat(tthread_id.c_str(), messages[i]->user_id.c_str(), messages[i]->sender_name.c_str(), messages[i]->message_text.c_str(), messages[i]->time); + UpdateChat(fbc->thread_id.c_str(), messages[i]->user_id.c_str(), messages[i]->sender_name.c_str(), messages[i]->message_text.c_str(), messages[i]->time); // Automatically mark message as read because chatroom doesn't support onRead event (yet) hChatContacts->insert(hChatContact); // std::set checks duplicates at insert automatically diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 59b5ce751c..f4b4d208de 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -191,7 +191,7 @@ public: // Contacts handling bool IsMyContact(MCONTACT, bool include_chat = false); MCONTACT ContactIDToHContact(const std::string&); - MCONTACT ChatIDToHContact(const std::tstring&); + MCONTACT ChatIDToHContact(const std::string&); std::string ThreadIDToContactID(const std::string&); void LoadContactInfo(facebook_user* fbu); MCONTACT AddToContactList(facebook_user*, ContactType type, bool force_add = false, bool add_temporarily = false); @@ -201,13 +201,13 @@ public: void StopTyping(MCONTACT hContact); // Chats handling - void AddChat(const TCHAR *id, const TCHAR *name); - void UpdateChat(const TCHAR *chat_id, const char *id, const char *name, const char *message, DWORD timestamp = 0, bool is_old = false); + void AddChat(const char *chat_id, const TCHAR *name); + void UpdateChat(const char *chat_id, const char *id, const char *name, const char *message, DWORD timestamp = 0, bool is_old = false); void RenameChat(const char *chat_id, const char *name); - bool IsChatContact(const TCHAR *chat_id, const char *id); - void AddChatContact(const TCHAR *chat_id, const char *id, const char *name); - void RemoveChatContact(const TCHAR *chat_id, const char *id, const char *name); - char *GetChatUsers(const TCHAR *chat_id); + bool IsChatContact(const char *chat_id, const char *id); + void AddChatContact(const char *chat_id, const char *id, const char *name); + void RemoveChatContact(const char *chat_id, const char *id, const char *name); + char *GetChatUsers(const char *chat_id); void ReceiveMessages(std::vector<facebook_message*> messages, bool check_duplicates = false); void LoadChatInfo(facebook_chatroom* fbc); void LoadParticipantsNames(facebook_chatroom *fbc); diff --git a/protocols/FacebookRM/src/version.h b/protocols/FacebookRM/src/version.h index 6837029385..2f40a5d383 100644 --- a/protocols/FacebookRM/src/version.h +++ b/protocols/FacebookRM/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 2
-#define __RELEASE_NUM 10
-#define __BUILD_NUM 8
+#define __RELEASE_NUM 11
+#define __BUILD_NUM 1
#include <stdver.h>
|