diff options
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r-- | protocols/FacebookRM/src/chat.cpp | 19 | ||||
-rw-r--r-- | protocols/FacebookRM/src/client.h | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 17 | ||||
-rw-r--r-- | protocols/FacebookRM/src/contacts.cpp | 17 | ||||
-rw-r--r-- | protocols/FacebookRM/src/events.cpp | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 228 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/version.h | 2 |
8 files changed, 123 insertions, 168 deletions
diff --git a/protocols/FacebookRM/src/chat.cpp b/protocols/FacebookRM/src/chat.cpp index f44f9e93f3..030e6ca4c0 100644 --- a/protocols/FacebookRM/src/chat.cpp +++ b/protocols/FacebookRM/src/chat.cpp @@ -488,14 +488,11 @@ void FacebookProto::LoadParticipantsNames(facebook_chatroom *fbc) userIds.destroy(); if (resp.code == HTTP_CODE_OK) { - try { - // TODO: We can cache these results and next time (e.g. for different chatroom) we can use that already cached names - ParseChatParticipants(&resp.data, &fbc->participants); + // TODO: We can cache these results and next time (e.g. for different chatroom) we can use that already cached names + if (EXIT_SUCCESS == ParseChatParticipants(&resp.data, &fbc->participants)) debugLogA("*** Participant names processed"); - } - catch (const std::exception &e) { - debugLogA("*** Error processing participant names: %s", e.what()); - } + else + debugLogA("*** Error processing participant names"); } } } @@ -526,9 +523,7 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc) return; } - try { - ParseChatInfo(&resp.data, fbc); - + if (ParseChatInfo(&resp.data, fbc) == EXIT_SUCCESS) { // Load missing participants names LoadParticipantsNames(fbc); @@ -540,9 +535,7 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc) debugLogA("*** Chat thread info processed"); } - catch (const std::exception &e) { - debugLogA("*** Error processing chat thread info: %s", e.what()); - } + else debugLogA("*** Error processing chat thread info"); facy.handle_success("LoadChatInfo"); } diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index bd3104114c..0935cca235 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -82,8 +82,8 @@ public: ////////////////////////////////////////////////////////////
// Client vs protocol communication
- void client_notify(wchar_t* message);
- void info_notify(wchar_t* message);
+ void client_notify(const wchar_t *message);
+ void info_notify(const wchar_t *message);
////////////////////////////////////////////////////////////
// Cookies, Data storage
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index e7ca35788c..f9d5b1f5af 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -22,12 +22,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" -void facebook_client::client_notify(wchar_t* message) +void facebook_client::client_notify(const wchar_t *message) { parent->NotifyEvent(parent->m_tszUserName, message, 0, EVENT_CLIENT); } -void facebook_client::info_notify(wchar_t* message) +void facebook_client::info_notify(const wchar_t *message) { parent->NotifyEvent(parent->m_tszUserName, message, 0, EVENT_OTHER); } @@ -878,13 +878,10 @@ 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 + parent->debugLogA("*** Starting processing messages"); { - parent->debugLogA("*** Starting processing messages"); - - try { - std::vector<facebook_message> messages; - parent->ParseMessages(resp.data, messages); - + std::vector<facebook_message> messages; + if (parent->ParseMessages(resp.data, messages) == EXIT_SUCCESS) { parent->ReceiveMessages(messages); if (parent->getBool(FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE)) @@ -892,9 +889,7 @@ bool facebook_client::channel() parent->debugLogA("*** Messages processed"); } - catch (const std::exception &e) { - parent->debugLogA("*** Error processing messages: %s", e.what()); - } + else parent->debugLogA("*** Error processing messages"); } // Get new sequence number diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index 0fbb9a07ed..d6eff8c2e2 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -175,17 +175,13 @@ std::string FacebookProto::ThreadIDToContactID(const std::string &thread_id) std::string user_id; if (resp.code == HTTP_CODE_OK) { - try { - ParseThreadInfo(&resp.data, &user_id); - + if (ParseThreadInfo(&resp.data, &user_id) == EXIT_SUCCESS) { if (!user_id.empty()) facy.thread_id_to_user_id.insert(std::make_pair(thread_id, user_id)); debugLogA("*** Thread info processed"); } - catch (const std::exception &e) { - debugLogA("*** Error processing thread info: %s", e.what()); - } + else debugLogA("*** Error processing thread info"); } return user_id; @@ -205,13 +201,10 @@ void FacebookProto::LoadContactInfo(facebook_user* fbu) userIds.destroy(); if (resp.code == HTTP_CODE_OK) { - try { - ParseUserInfo(&resp.data, fbu); + if (ParseUserInfo(&resp.data, fbu) == EXIT_SUCCESS) debugLogA("*** Contact thread info processed"); - } - catch (const std::exception &e) { - debugLogA("*** Error processing contact thread info: %s", e.what()); - } + else + debugLogA("*** Error processing contact thread info"); } } diff --git a/protocols/FacebookRM/src/events.cpp b/protocols/FacebookRM/src/events.cpp index f0f2d6abbb..c3a5879a74 100644 --- a/protocols/FacebookRM/src/events.cpp +++ b/protocols/FacebookRM/src/events.cpp @@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h" -HWND FacebookProto::NotifyEvent(wchar_t* title, wchar_t* text, MCONTACT contact, EventType type, std::string *url, std::string *notification_id, const char *icon) +HWND FacebookProto::NotifyEvent(const wchar_t* title, const wchar_t* text, MCONTACT contact, EventType type, std::string *url, std::string *notification_id, const char *icon) { if (title == nullptr || text == nullptr) return nullptr; diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 47eba0b4b7..629b2eb7d0 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -42,113 +42,112 @@ void FacebookProto::ProcessFriendList(void*) debugLogA("*** Starting processing friend list"); - try { - bool loadAllContacts = getBool(FACEBOOK_KEY_LOAD_ALL_CONTACTS, DEFAULT_LOAD_ALL_CONTACTS); - bool pagesAlwaysOnline = getBool(FACEBOOK_KEY_PAGES_ALWAYS_ONLINE, DEFAULT_PAGES_ALWAYS_ONLINE); - std::map<std::string, facebook_user*> friends; - ParseFriends(&resp.data, &friends, loadAllContacts); + bool loadAllContacts = getBool(FACEBOOK_KEY_LOAD_ALL_CONTACTS, DEFAULT_LOAD_ALL_CONTACTS); + bool pagesAlwaysOnline = getBool(FACEBOOK_KEY_PAGES_ALWAYS_ONLINE, DEFAULT_PAGES_ALWAYS_ONLINE); - // Check and update old contacts - for (auto &hContact : AccContacts()) { - if (isChatRoom(hContact)) - continue; + std::map<std::string, facebook_user*> friends; + if (ParseFriends(&resp.data, &friends, loadAllContacts) != EXIT_SUCCESS) { + debugLogA("*** Error processing friend list"); + return; + } - // TODO RM: change name of "Deleted" key to "DeletedTS", remove this code in some next version - int deletedTS = getDword(hContact, "Deleted", 0); - if (deletedTS != 0) { - delSetting(hContact, "Deleted"); - setDword(hContact, FACEBOOK_KEY_DELETED, deletedTS); - } + // Check and update old contacts + for (auto &hContact : AccContacts()) { + if (isChatRoom(hContact)) + continue; - // If this contact is page, set it as invisible (if enabled in options) - if (pagesAlwaysOnline && getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE) == CONTACT_PAGE) - setWord(hContact, "Status", ID_STATUS_INVISIBLE); + // TODO RM: change name of "Deleted" key to "DeletedTS", remove this code in some next version + int deletedTS = getDword(hContact, "Deleted", 0); + if (deletedTS != 0) { + delSetting(hContact, "Deleted"); + setDword(hContact, FACEBOOK_KEY_DELETED, deletedTS); + } - ptrA id(getStringA(hContact, FACEBOOK_KEY_ID)); - if (id != nullptr) { - std::map< std::string, facebook_user* >::iterator iter; + // If this contact is page, set it as invisible (if enabled in options) + if (pagesAlwaysOnline && getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE) == CONTACT_PAGE) + setWord(hContact, "Status", ID_STATUS_INVISIBLE); - if ((iter = friends.find(std::string(id))) != friends.end()) { - // Found contact, update it and remove from map - facebook_user *fbu = iter->second; + ptrA id(getStringA(hContact, FACEBOOK_KEY_ID)); + if (id != nullptr) { + std::map< std::string, facebook_user* >::iterator iter; - // TODO RM: remove, because contacts cant change it, so its only for "first run" - // - but what with contacts, that was added after logon? - // Update gender - setByte(hContact, "Gender", (int)fbu->gender); + if ((iter = friends.find(std::string(id))) != friends.end()) { + // Found contact, update it and remove from map + facebook_user *fbu = iter->second; - // TODO: remove this in some future version? - // Remove old useless "RealName" field - delSetting(hContact, "RealName"); + // TODO RM: remove, because contacts cant change it, so its only for "first run" + // - but what with contacts, that was added after logon? + // Update gender + setByte(hContact, "Gender", (int)fbu->gender); - // Update real name and nick - if (!fbu->real_name.empty()) - SaveName(hContact, fbu); + // TODO: remove this in some future version? + // Remove old useless "RealName" field + delSetting(hContact, "RealName"); - // Update username - if (!fbu->username.empty()) - setString(hContact, FACEBOOK_KEY_USERNAME, fbu->username.c_str()); - else - delSetting(hContact, FACEBOOK_KEY_USERNAME); + // Update real name and nick + if (!fbu->real_name.empty()) + SaveName(hContact, fbu); - // Update contact type - setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, fbu->type); - // TODO: remove that popup and use "Contact added you" event? + // Update username + if (!fbu->username.empty()) + setString(hContact, FACEBOOK_KEY_USERNAME, fbu->username.c_str()); + else + delSetting(hContact, FACEBOOK_KEY_USERNAME); - // Wasn't contact removed from "server-list" someday? And is it friend now? (as we can get also non-friends from this request now)? - if (fbu->type == CONTACT_FRIEND && getDword(hContact, FACEBOOK_KEY_DELETED, 0)) { - delSetting(hContact, FACEBOOK_KEY_DELETED); + // Update contact type + setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, fbu->type); + // TODO: remove that popup and use "Contact added you" event? - // Notify it, if user wants to be notified - if (getByte(FACEBOOK_KEY_EVENT_FRIENDSHIP_ENABLE, DEFAULT_EVENT_FRIENDSHIP_ENABLE)) { - std::string url = FACEBOOK_URL_PROFILE + fbu->user_id; - NotifyEvent(Clist_GetContactDisplayName(hContact), TranslateT("Contact is back on server-list."), hContact, EVENT_FRIENDSHIP, &url); - } + // Wasn't contact removed from "server-list" someday? And is it friend now? (as we can get also non-friends from this request now)? + if (fbu->type == CONTACT_FRIEND && getDword(hContact, FACEBOOK_KEY_DELETED, 0)) { + delSetting(hContact, FACEBOOK_KEY_DELETED); + + // Notify it, if user wants to be notified + if (getByte(FACEBOOK_KEY_EVENT_FRIENDSHIP_ENABLE, DEFAULT_EVENT_FRIENDSHIP_ENABLE)) { + std::string url = FACEBOOK_URL_PROFILE + fbu->user_id; + NotifyEvent(Clist_GetContactDisplayName(hContact), TranslateT("Contact is back on server-list."), hContact, EVENT_FRIENDSHIP, &url); } + } - // Check avatar change - CheckAvatarChange(hContact, fbu->image_url); + // Check avatar change + CheckAvatarChange(hContact, fbu->image_url); - // Mark this contact as deleted ("processed") and delete them later (as there may be some duplicit contacts to use) - fbu->deleted = true; - } - else { - // Contact is not on "server-list", notify it was removed (if it was real friend before) + // Mark this contact as deleted ("processed") and delete them later (as there may be some duplicit contacts to use) + fbu->deleted = true; + } + else { + // Contact is not on "server-list", notify it was removed (if it was real friend before) - // Was this real friend before? - if (getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE) == CONTACT_FRIEND) { - setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE); + // Was this real friend before? + if (getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE) == CONTACT_FRIEND) { + setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE); - // Wasn't we already been notified about this contact? - if (!getDword(hContact, FACEBOOK_KEY_DELETED, 0)) { - setDword(hContact, FACEBOOK_KEY_DELETED, ::time(0)); + // Wasn't we already been notified about this contact? + if (!getDword(hContact, FACEBOOK_KEY_DELETED, 0)) { + setDword(hContact, FACEBOOK_KEY_DELETED, ::time(0)); - // Notify it, if user wants to be notified - if (getByte(FACEBOOK_KEY_EVENT_FRIENDSHIP_ENABLE, DEFAULT_EVENT_FRIENDSHIP_ENABLE)) { - std::string url = FACEBOOK_URL_PROFILE + std::string(id); - NotifyEvent(Clist_GetContactDisplayName(hContact), TranslateT("Contact is no longer on server-list."), hContact, EVENT_FRIENDSHIP, &url); - } + // Notify it, if user wants to be notified + if (getByte(FACEBOOK_KEY_EVENT_FRIENDSHIP_ENABLE, DEFAULT_EVENT_FRIENDSHIP_ENABLE)) { + std::string url = FACEBOOK_URL_PROFILE + std::string(id); + NotifyEvent(Clist_GetContactDisplayName(hContact), TranslateT("Contact is no longer on server-list."), hContact, EVENT_FRIENDSHIP, &url); } } } } } + } - // Check remaining contacts in map and add them to contact list - for (auto &it : friends) { - if (!it.second->deleted) - AddToContactList(it.second, true); // we know this contact doesn't exists, so we force add it - - delete it.second; - } - friends.clear(); + // Check remaining contacts in map and add them to contact list + for (auto &it : friends) { + if (!it.second->deleted) + AddToContactList(it.second, true); // we know this contact doesn't exists, so we force add it - debugLogA("*** Friend list processed"); - } - catch (const std::exception &e) { - debugLogA("*** Error processing friend list: %s", e.what()); + delete it.second; } + friends.clear(); + + debugLogA("*** Friend list processed"); } void FacebookProto::ProcessUnreadMessages(void*) @@ -164,17 +163,12 @@ void FacebookProto::ProcessUnreadMessages(void*) return; } - try { - std::vector<std::string> threads; - ParseUnreadThreads(&resp.data, &threads); - + std::vector<std::string> threads; + if (ParseUnreadThreads(&resp.data, &threads) == EXIT_SUCCESS) { ForkThread(&FacebookProto::ProcessUnreadMessage, new std::vector<std::string>(threads)); - debugLogA("*** Unread threads list processed"); } - catch (const std::exception &e) { - debugLogA("*** Error processing unread threads list: %s", e.what()); - } + else debugLogA("*** Error processing unread threads list"); facy.handle_success("ProcessUnreadMessages"); } @@ -210,16 +204,12 @@ void FacebookProto::ProcessUnreadMessage(void *pParam) ids.destroy(); if (resp.code == HTTP_CODE_OK) { - try { - std::vector<facebook_message> messages; - ParseThreadMessages(&resp.data, &messages, false); - + std::vector<facebook_message> messages; + if (ParseThreadMessages(&resp.data, &messages, false) == EXIT_SUCCESS) { ReceiveMessages(messages, true); debugLogA("*** Unread messages processed"); } - catch (const std::exception &e) { - debugLogA("*** Error processing unread messages: %s", e.what()); - } + else debugLogA("*** Error processing unread messages"); facy.handle_success("ProcessUnreadMessage"); } @@ -269,16 +259,12 @@ void FacebookProto::LoadLastMessages(void *pParam) // Temporarily disable marking messages as read for this contact facy.ignore_read.insert(hContact); - try { - std::vector<facebook_message> messages; - ParseThreadMessages(&resp.data, &messages, false); - + std::vector<facebook_message> messages; + if (ParseThreadMessages(&resp.data, &messages, false) == EXIT_SUCCESS) { ReceiveMessages(messages, true); debugLogA("*** Thread messages processed"); } - catch (const std::exception &e) { - debugLogA("*** Error processing thread messages: %s", e.what()); - } + else debugLogA("*** Error processing thread messages"); facy.handle_success("LoadLastMessages"); @@ -366,11 +352,9 @@ void FacebookProto::LoadHistory(void *pParam) } // Parse the result - try { - messages.clear(); - - ParseHistory(&resp.data, messages, &firstTimestamp); + messages.clear(); + if (ParseHistory(&resp.data, messages, &firstTimestamp) == EXIT_SUCCESS) { // Receive messages std::string previousFirstMessageId = firstMessageId; for (std::vector<facebook_message*>::size_type i = 0; i < messages.size(); i++) { @@ -418,8 +402,8 @@ void FacebookProto::LoadHistory(void *pParam) debugLogA("*** Load history messages processed"); } - catch (const std::exception &e) { - debugLogA("*** Error processing load history messages: %s", e.what()); + else { + debugLogA("*** Error processing load history messages"); break; } @@ -641,10 +625,8 @@ void FacebookProto::ProcessMemories(void *p) } } - if (manuallyTriggered) { - CMStringW text(FORMAT, TranslateT("Found %d memories."), numMemories); - facy.info_notify(text.GetBuffer()); - } + if (manuallyTriggered) + facy.info_notify(CMStringW(FORMAT, TranslateT("Found %d memories."), numMemories)); facy.handle_success(__FUNCTION__); } @@ -928,24 +910,18 @@ void FacebookProto::ProcessNotifications(void *p) // Process notifications debugLogA("*** Starting processing notifications"); - try { - size_t numNotifications = facy.notifications.size(); - - ParseNotifications(&resp.data, &facy.notifications); - + size_t numNotifications = facy.notifications.size(); + if (ParseNotifications(&resp.data, &facy.notifications) == EXIT_SUCCESS) { if (manuallyTriggered) { numNotifications = facy.notifications.size() - numNotifications; - CMStringW text(FORMAT, TranslateT("Found %d notifications."), numNotifications); - facy.info_notify(text.GetBuffer()); + facy.info_notify(CMStringW(FORMAT, TranslateT("Found %d notifications."), numNotifications)); } ShowNotifications(); debugLogA("*** Notifications processed"); } - catch (const std::exception &e) { - debugLogA("*** Error processing notifications: %s", e.what()); - } + else debugLogA("*** Error processing notifications"); } void FacebookProto::ProcessFriendRequests(void *p) @@ -1042,7 +1018,7 @@ void FacebookProto::ProcessFriendRequests(void *p) text.AppendFormat(TranslateT("Found %d friendship requests (%d seen)."), numRequestsNew, numRequestsOld); else text.AppendFormat(TranslateT("Found %d friendship requests."), numRequestsNew); - facy.info_notify(text.GetBuffer()); + facy.info_notify(text); } facy.handle_success("friendRequests"); @@ -1075,10 +1051,8 @@ void FacebookProto::ProcessFeeds(void *p) if (!news.empty()) Skin_PlaySound("NewsFeed"); - if (manuallyTriggered) { - CMStringW text(FORMAT, TranslateT("Found %d wall posts."), news.size()); - facy.info_notify(text.GetBuffer()); - } + if (manuallyTriggered) + facy.info_notify(CMStringW(FORMAT, TranslateT("Found %d wall posts."), news.size())); for (std::vector<facebook_newsfeed*>::size_type i = 0; i < news.size(); i++) { ptrW tszTitle(mir_utf8decodeW(news[i]->title.c_str())); diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 4b66e7d779..13c9824668 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -283,7 +283,7 @@ public: std::map<std::string, std::string> reactions; // Information providing - HWND NotifyEvent(wchar_t* title, wchar_t* text, MCONTACT contact, EventType type, std::string *url = nullptr, std::string *notification_id = nullptr, const char *icon = nullptr); + HWND NotifyEvent(const wchar_t* title, const wchar_t* text, MCONTACT contact, EventType type, std::string *url = nullptr, std::string *notification_id = nullptr, const char *icon = nullptr); void ShowNotifications(); }; diff --git a/protocols/FacebookRM/src/version.h b/protocols/FacebookRM/src/version.h index 5c4c0f4f93..13a8b0d0bd 100644 --- a/protocols/FacebookRM/src/version.h +++ b/protocols/FacebookRM/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 4 #define __RELEASE_NUM 1 -#define __BUILD_NUM 3 +#define __BUILD_NUM 4 #include <stdver.h> |