summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'protocols')
-rw-r--r--protocols/FacebookRM/src/contacts.cpp67
-rw-r--r--protocols/FacebookRM/src/definitions.h43
-rw-r--r--protocols/FacebookRM/src/events.cpp14
-rw-r--r--protocols/FacebookRM/src/process.cpp500
-rw-r--r--protocols/FacebookRM/src/stdafx.h1
5 files changed, 271 insertions, 354 deletions
diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp
index 1d780d6e72..cb67ff7a0f 100644
--- a/protocols/FacebookRM/src/contacts.cpp
+++ b/protocols/FacebookRM/src/contacts.cpp
@@ -199,22 +199,19 @@ std::string FacebookProto::ThreadIDToContactID(const std::string &thread_id)
http::response resp = facy.flap(REQUEST_THREAD_INFO, &data); // NOTE: Request revised 17.8.2016
if (resp.code == HTTP_CODE_OK) {
- CODE_BLOCK_TRY
-
+ try {
facebook_json_parser* p = new facebook_json_parser(this);
- p->parse_thread_info(&resp.data, &user_id);
- delete p;
-
- if (!user_id.empty())
- facy.thread_id_to_user_id.insert(std::make_pair(thread_id, user_id));
-
- debugLogA("*** Thread info processed");
+ p->parse_thread_info(&resp.data, &user_id);
+ delete p;
- CODE_BLOCK_CATCH
+ 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());
-
- CODE_BLOCK_END
+ }
}
return user_id;
@@ -239,19 +236,16 @@ void FacebookProto::LoadContactInfo(facebook_user* fbu)
http::response resp = facy.flap(REQUEST_USER_INFO, &data); // NOTE: Request revised 17.8.2016
if (resp.code == HTTP_CODE_OK) {
- CODE_BLOCK_TRY
-
+ try {
facebook_json_parser* p = new facebook_json_parser(this);
p->parse_user_info(&resp.data, fbu);
delete p;
debugLogA("*** Contact thread info processed");
-
- CODE_BLOCK_CATCH
-
+ }
+ catch (const std::exception &e) {
debugLogA("*** Error processing contact thread info: %s", e.what());
-
- CODE_BLOCK_END
+ }
}
}
@@ -317,21 +311,17 @@ void FacebookProto::LoadParticipantsNames(facebook_chatroom *fbc)
http::response resp = facy.flap(REQUEST_USER_INFO, &data); // NOTE: Request revised 17.8.2016
if (resp.code == HTTP_CODE_OK) {
- CODE_BLOCK_TRY
-
- // TODO: We can cache these results and next time (e.g. for different chatroom) we can use that already cached names
-
- facebook_json_parser* p = new facebook_json_parser(this);
- p->parse_chat_participant_names(&resp.data, &fbc->participants);
- delete p;
-
- debugLogA("*** Participant names processed");
-
- CODE_BLOCK_CATCH
+ try {
+ // TODO: We can cache these results and next time (e.g. for different chatroom) we can use that already cached names
+ facebook_json_parser* p = new facebook_json_parser(this);
+ p->parse_chat_participant_names(&resp.data, &fbc->participants);
+ delete p;
+ debugLogA("*** Participant names processed");
+ }
+ catch (const std::exception &e) {
debugLogA("*** Error processing participant names: %s", e.what());
-
- CODE_BLOCK_END
+ }
}
}
}
@@ -381,8 +371,7 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc)
return;
}
- CODE_BLOCK_TRY
-
+ try {
facebook_json_parser* p = new facebook_json_parser(this);
p->parse_chat_info(&resp.data, fbc);
delete p;
@@ -406,7 +395,7 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc)
std::wstring tname = _A2T(participant.c_str(), CP_UTF8);
fbc->chat_name += utils::text::prepare_name(tname, false);
-
+
if (++namesUsed >= FACEBOOK_CHATROOM_NAMES_COUNT)
break;
}
@@ -423,12 +412,10 @@ void FacebookProto::LoadChatInfo(facebook_chatroom *fbc)
}
debugLogA("*** Chat thread info processed");
-
- CODE_BLOCK_CATCH
-
+ }
+ catch (const std::exception &e) {
debugLogA("*** Error processing chat thread info: %s", e.what());
-
- CODE_BLOCK_END
+ }
facy.handle_success("LoadChatInfo");
}
diff --git a/protocols/FacebookRM/src/definitions.h b/protocols/FacebookRM/src/definitions.h
deleted file mode 100644
index 1fd4102920..0000000000
--- a/protocols/FacebookRM/src/definitions.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
-
-Facebook plugin for Miranda Instant Messenger
-_____________________________________________
-
-Copyright © 2009-11 Michal Zelinka, 2011-16 Robert Pösel
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#pragma once
-
-#define CODE_BLOCK_BEGIN {
-#define CODE_BLOCK_TRY try {
-#define CODE_BLOCK_CATCH } catch(const std::exception &e) {
-#define CODE_BLOCK_INFINITE while(true) {
-#define CODE_BLOCK_END }
-
-#define FLAG_CONTAINS(x,y) ((x & y) == y)
-#define REMOVE_FLAG(x,y) (x = (x & ~y))
-
-#define LOG_NOTIFY 0
-#define LOG_WARNING 1
-#define LOG_ALERT 2
-#define LOG_FAILURE 3
-#define LOG_CRITICAL 4
-
-
-#define NIIF_INTERN_TCHAR NIIF_INTERN_UNICODE // m_clist.h
-#define mir_wstrdup mir_wstrdup // m_system.h
-
diff --git a/protocols/FacebookRM/src/events.cpp b/protocols/FacebookRM/src/events.cpp
index 660b2424f5..be0306148f 100644
--- a/protocols/FacebookRM/src/events.cpp
+++ b/protocols/FacebookRM/src/events.cpp
@@ -108,23 +108,21 @@ HWND FacebookProto::NotifyEvent(wchar_t* title, wchar_t* info, MCONTACT contact,
{
MIRANDASYSTRAYNOTIFY err;
int niif_flags = flags;
- REMOVE_FLAG(niif_flags, FACEBOOK_EVENT_CLIENT |
- FACEBOOK_EVENT_NEWSFEED |
- FACEBOOK_EVENT_NOTIFICATION |
- FACEBOOK_EVENT_OTHER |
- FACEBOOK_EVENT_FRIENDSHIP);
+
+ niif_flags = niif_flags & ~(FACEBOOK_EVENT_CLIENT | FACEBOOK_EVENT_NEWSFEED | FACEBOOK_EVENT_NOTIFICATION | FACEBOOK_EVENT_OTHER | FACEBOOK_EVENT_FRIENDSHIP);
+
err.szProto = m_szModuleName;
err.cbSize = sizeof(err);
- err.dwInfoFlags = NIIF_INTERN_TCHAR | niif_flags;
+ err.dwInfoFlags = NIIF_INTERN_UNICODE | niif_flags;
err.tszInfoTitle = title;
err.tszInfo = info;
err.uTimeout = 10000;
- if (CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)& err) == 0)
+ if (CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&err) == 0)
return NULL;
}
}
- if (FLAG_CONTAINS(flags, FACEBOOK_EVENT_CLIENT))
+ if ((flags & FACEBOOK_EVENT_CLIENT) == FACEBOOK_EVENT_CLIENT)
MessageBox(NULL, info, title, MB_OK | MB_ICONERROR);
return NULL;
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index 4a64b638db..b6c4f1b709 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -63,127 +63,123 @@ void FacebookProto::ProcessFriendList(void*)
debugLogA("*** Starting processing friend list");
- CODE_BLOCK_TRY
-
+ try {
std::map<std::string, facebook_user*> friends;
- facebook_json_parser* p = new facebook_json_parser(this);
- p->parse_friends(&resp.data, &friends);
- delete p;
-
+ facebook_json_parser* p = new facebook_json_parser(this);
+ p->parse_friends(&resp.data, &friends);
+ delete p;
- // Check and update old contacts
- for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
- if (isChatRoom(hContact))
- continue;
+ // Check and update old contacts
+ for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) {
+ if (isChatRoom(hContact))
+ continue;
- // 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);
- }
+ // 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);
+ }
- facebook_user *fbu;
- ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
- if (id != NULL) {
- std::map< std::string, facebook_user* >::iterator iter;
-
- if ((iter = friends.find(std::string(id))) != friends.end()) {
- // Found contact, update it and remove from map
- fbu = iter->second;
-
- // 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
- if (getByte(hContact, "Gender", 0) != (int)fbu->gender)
- setByte(hContact, "Gender", fbu->gender);
-
- // TODO: remove this in some future version?
- // Remove old useless "RealName" field
- ptrA realname(getStringA(hContact, "RealName"));
- if (realname != NULL) {
- delSetting(hContact, "RealName");
- }
+ facebook_user *fbu;
+ ptrA id(getStringA(hContact, FACEBOOK_KEY_ID));
+ if (id != NULL) {
+ std::map< std::string, facebook_user* >::iterator iter;
+
+ if ((iter = friends.find(std::string(id))) != friends.end()) {
+ // Found contact, update it and remove from map
+ fbu = iter->second;
+
+ // 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
+ if (getByte(hContact, "Gender", 0) != (int)fbu->gender)
+ setByte(hContact, "Gender", fbu->gender);
+
+ // TODO: remove this in some future version?
+ // Remove old useless "RealName" field
+ ptrA realname(getStringA(hContact, "RealName"));
+ if (realname != NULL) {
+ delSetting(hContact, "RealName");
+ }
- // Update real name and nick
- if (!fbu->real_name.empty()) {
- SaveName(hContact, fbu);
- }
+ // Update real name and nick
+ if (!fbu->real_name.empty()) {
+ SaveName(hContact, fbu);
+ }
- // Update username
- ptrA username(getStringA(hContact, FACEBOOK_KEY_USERNAME));
- if (!username || mir_strcmp(username, fbu->username.c_str())) {
- if (!fbu->username.empty())
- setString(hContact, FACEBOOK_KEY_USERNAME, fbu->username.c_str());
- else
- delSetting(hContact, FACEBOOK_KEY_USERNAME);
- }
+ // Update username
+ ptrA username(getStringA(hContact, FACEBOOK_KEY_USERNAME));
+ if (!username || mir_strcmp(username, fbu->username.c_str())) {
+ if (!fbu->username.empty())
+ setString(hContact, FACEBOOK_KEY_USERNAME, fbu->username.c_str());
+ else
+ delSetting(hContact, FACEBOOK_KEY_USERNAME);
+ }
- // Update contact type
- if (getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE) != fbu->type) {
- setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, fbu->type);
- // TODO: remove that popup and use "Contact added you" event?
- }
+ // Update contact type
+ if (getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE) != fbu->type) {
+ setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, fbu->type);
+ // TODO: remove that popup and use "Contact added you" event?
+ }
- // Wasn't contact removed from "server-list" someday?
- if (getDword(hContact, FACEBOOK_KEY_DELETED, 0)) {
- delSetting(hContact, FACEBOOK_KEY_DELETED);
+ // Wasn't contact removed from "server-list" someday?
+ if (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;
- std::string contactname = getContactName(this, hContact, !fbu->real_name.empty() ? fbu->real_name.c_str() : fbu->user_id.c_str());
+ // 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;
+ std::string contactname = getContactName(this, hContact, !fbu->real_name.empty() ? fbu->real_name.c_str() : fbu->user_id.c_str());
- ptrW szTitle(mir_utf8decodeW(contactname.c_str()));
- NotifyEvent(szTitle, TranslateT("Contact is back on server-list."), hContact, FACEBOOK_EVENT_FRIENDSHIP, &url);
+ ptrW szTitle(mir_utf8decodeW(contactname.c_str()));
+ NotifyEvent(szTitle, TranslateT("Contact is back on server-list."), hContact, FACEBOOK_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 was removed from "server-list", notify it
-
- // Wasn't we already been notified about this contact? And was this real friend?
- if (!getDword(hContact, FACEBOOK_KEY_DELETED, 0) && getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) == CONTACT_FRIEND) {
- setDword(hContact, FACEBOOK_KEY_DELETED, ::time(NULL));
- setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE);
-
- // 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);
- std::string contactname = getContactName(this, hContact, id);
-
- ptrW szTitle(mir_utf8decodeW(contactname.c_str()));
- NotifyEvent(szTitle, TranslateT("Contact is no longer on server-list."), hContact, FACEBOOK_EVENT_FRIENDSHIP, &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 was removed from "server-list", notify it
+
+ // Wasn't we already been notified about this contact? And was this real friend?
+ if (!getDword(hContact, FACEBOOK_KEY_DELETED, 0) && getByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, 0) == CONTACT_FRIEND) {
+ setDword(hContact, FACEBOOK_KEY_DELETED, ::time(NULL));
+ setByte(hContact, FACEBOOK_KEY_CONTACT_TYPE, CONTACT_NONE);
+
+ // 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);
+ std::string contactname = getContactName(this, hContact, id);
+
+ ptrW szTitle(mir_utf8decodeW(contactname.c_str()));
+ NotifyEvent(szTitle, TranslateT("Contact is no longer on server-list."), hContact, FACEBOOK_EVENT_FRIENDSHIP, &url);
+ }
}
}
}
}
- }
-
- // Check remaining contacts in map and add them to contact list
- for (std::map< std::string, facebook_user* >::iterator it = friends.begin(); it != friends.end();) {
- if (!it->second->deleted)
- AddToContactList(it->second, true); // we know this contact doesn't exists, so we force add it
-
- delete it->second;
- it = friends.erase(it);
- }
- friends.clear();
- debugLogA("*** Friend list processed");
+ // Check remaining contacts in map and add them to contact list
+ for (std::map< std::string, facebook_user* >::iterator it = friends.begin(); it != friends.end();) {
+ if (!it->second->deleted)
+ AddToContactList(it->second, true); // we know this contact doesn't exists, so we force add it
- CODE_BLOCK_CATCH
+ delete it->second;
+ it = friends.erase(it);
+ }
+ friends.clear();
+ debugLogA("*** Friend list processed");
+ }
+ catch (const std::exception &e) {
debugLogA("*** Error processing friend list: %s", e.what());
-
- CODE_BLOCK_END
+ }
}
void FacebookProto::ProcessUnreadMessages(void*)
@@ -208,8 +204,7 @@ void FacebookProto::ProcessUnreadMessages(void*)
return;
}
- CODE_BLOCK_TRY
-
+ try {
std::vector<std::string> threads;
facebook_json_parser* p = new facebook_json_parser(this);
@@ -219,14 +214,12 @@ void FacebookProto::ProcessUnreadMessages(void*)
ForkThread(&FacebookProto::ProcessUnreadMessage, new std::vector<std::string>(threads));
debugLogA("*** Unread threads list processed");
-
- CODE_BLOCK_CATCH
-
+ }
+ catch (const std::exception &e) {
debugLogA("*** Error processing unread threads list: %s", e.what());
+ }
- CODE_BLOCK_END
-
- facy.handle_success("ProcessUnreadMessages");
+ facy.handle_success("ProcessUnreadMessages");
}
void FacebookProto::ProcessUnreadMessage(void *pParam)
@@ -277,54 +270,50 @@ void FacebookProto::ProcessUnreadMessage(void *pParam)
resp = facy.flap(REQUEST_THREAD_INFO, &data); // NOTE: Request revised 17.8.2016
if (resp.code == HTTP_CODE_OK) {
+ try {
+ std::vector<facebook_message> messages;
+ std::map<std::string, facebook_chatroom*> chatrooms;
+
+ facebook_json_parser* p = new facebook_json_parser(this);
+ p->parse_thread_messages(&resp.data, &messages, &chatrooms, false);
+ delete p;
+
+ for (std::map<std::string, facebook_chatroom*>::iterator it = chatrooms.begin(); it != chatrooms.end();) {
+
+ // TODO: refactor this too!
+ // TODO: have all chatrooms in facy, in memory, and then handle them as needed... somehow think about it...
+ /* facebook_chatroom *room = it->second;
+ MCONTACT hChatContact = NULL;
+ ptrA users(GetChatUsers(room->thread_id.c_str()));
+ if (users == NULL) {
+ AddChat(room->thread_id.c_str(), room->chat_name.c_str());
+ hChatContact = ChatIDToHContact(room->thread_id);
+ // Set thread id (TID) for later
+ setWString(hChatContact, FACEBOOK_KEY_TID, room->thread_id.c_str());
+
+ for (std::map<std::string, std::string>::iterator jt = room->participants.begin(); jt != room->participants.end(); ) {
+ AddChatContact(room->thread_id.c_str(), jt->first.c_str(), jt->second.c_str());
+ ++jt;
+ }
+ }
- CODE_BLOCK_TRY
-
- std::vector<facebook_message> messages;
- std::map<std::string, facebook_chatroom*> chatrooms;
-
- facebook_json_parser* p = new facebook_json_parser(this);
- p->parse_thread_messages(&resp.data, &messages, &chatrooms, false);
- delete p;
-
- for (std::map<std::string, facebook_chatroom*>::iterator it = chatrooms.begin(); it != chatrooms.end();) {
+ if (!hChatContact)
+ hChatContact = ChatIDToHContact(room->thread_id);
- // TODO: refactor this too!
- // TODO: have all chatrooms in facy, in memory, and then handle them as needed... somehow think about it...
- /* facebook_chatroom *room = it->second;
- MCONTACT hChatContact = NULL;
- ptrA users(GetChatUsers(room->thread_id.c_str()));
- if (users == NULL) {
- AddChat(room->thread_id.c_str(), room->chat_name.c_str());
- hChatContact = ChatIDToHContact(room->thread_id);
- // Set thread id (TID) for later
- setWString(hChatContact, FACEBOOK_KEY_TID, room->thread_id.c_str());
+ ForkThread(&FacebookProto::ReadMessageWorker, (void*)hChatContact);*/
- for (std::map<std::string, std::string>::iterator jt = room->participants.begin(); jt != room->participants.end(); ) {
- AddChatContact(room->thread_id.c_str(), jt->first.c_str(), jt->second.c_str());
- ++jt;
- }
+ delete it->second;
+ it = chatrooms.erase(it);
}
+ chatrooms.clear();
- if (!hChatContact)
- hChatContact = ChatIDToHContact(room->thread_id);
+ ReceiveMessages(messages, true);
- ForkThread(&FacebookProto::ReadMessageWorker, (void*)hChatContact);*/
-
- delete it->second;
- it = chatrooms.erase(it);
+ debugLogA("*** Unread messages processed");
+ }
+ catch (const std::exception &e) {
+ debugLogA("*** Error processing unread messages: %s", e.what());
}
- chatrooms.clear();
-
- ReceiveMessages(messages, true);
-
- debugLogA("*** Unread messages processed");
-
- CODE_BLOCK_CATCH
-
- debugLogA("*** Error processing unread messages: %s", e.what());
-
- CODE_BLOCK_END
facy.handle_success("ProcessUnreadMessage");
}
@@ -400,54 +389,51 @@ void FacebookProto::LoadLastMessages(void *pParam)
// Temporarily disable marking messages as read for this contact
facy.ignore_read.insert(hContact);
- CODE_BLOCK_TRY
-
- std::vector<facebook_message> messages;
- std::map<std::string, facebook_chatroom*> chatrooms;
-
- facebook_json_parser* p = new facebook_json_parser(this);
- p->parse_thread_messages(&resp.data, &messages, &chatrooms, false);
- delete p;
+ try {
+ std::vector<facebook_message> messages;
+ std::map<std::string, facebook_chatroom*> chatrooms;
- // TODO: do something with this, chat is loading somewhere else... (in receiveMessages method right now)
- /*for (std::map<std::string, facebook_chatroom*>::iterator it = chatrooms.begin(); it != chatrooms.end();) {
-
- facebook_chatroom *room = it->second;
- MCONTACT hChatContact = NULL;
- ptrA users(GetChatUsers(room->thread_id.c_str()));
- if (users == NULL) {
- AddChat(room->thread_id.c_str(), room->chat_name.c_str());
- hChatContact = ChatIDToHContact(room->thread_id);
- // Set thread id (TID) for later
- setWString(hChatContact, FACEBOOK_KEY_TID, room->thread_id.c_str());
-
- for (std::map<std::string, std::string>::iterator jt = room->participants.begin(); jt != room->participants.end();) {
- AddChatContact(room->thread_id.c_str(), jt->first.c_str(), jt->second.c_str());
- ++jt;
- }
- }
+ facebook_json_parser* p = new facebook_json_parser(this);
+ p->parse_thread_messages(&resp.data, &messages, &chatrooms, false);
+ delete p;
- if (!hChatContact)
- hChatContact = ChatIDToHContact(room->thread_id);
+ // TODO: do something with this, chat is loading somewhere else... (in receiveMessages method right now)
+ /*for (std::map<std::string, facebook_chatroom*>::iterator it = chatrooms.begin(); it != chatrooms.end();) {
- ForkThread(&FacebookProto::ReadMessageWorker, (void*)hChatContact);
+ facebook_chatroom *room = it->second;
+ MCONTACT hChatContact = NULL;
+ ptrA users(GetChatUsers(room->thread_id.c_str()));
+ if (users == NULL) {
+ AddChat(room->thread_id.c_str(), room->chat_name.c_str());
+ hChatContact = ChatIDToHContact(room->thread_id);
+ // Set thread id (TID) for later
+ setWString(hChatContact, FACEBOOK_KEY_TID, room->thread_id.c_str());
+
+ for (std::map<std::string, std::string>::iterator jt = room->participants.begin(); jt != room->participants.end();) {
+ AddChatContact(room->thread_id.c_str(), jt->first.c_str(), jt->second.c_str());
+ ++jt;
+ }
+ }
- delete it->second;
- it = chatrooms.erase(it);
- }
- chatrooms.clear();*/
+ if (!hChatContact)
+ hChatContact = ChatIDToHContact(room->thread_id);
- ReceiveMessages(messages, true);
+ ForkThread(&FacebookProto::ReadMessageWorker, (void*)hChatContact);
- debugLogA("*** Thread messages processed");
+ delete it->second;
+ it = chatrooms.erase(it);
+ }
+ chatrooms.clear();*/
- CODE_BLOCK_CATCH
+ ReceiveMessages(messages, true);
+ debugLogA("*** Thread messages processed");
+ }
+ catch (const std::exception &e) {
debugLogA("*** Error processing thread messages: %s", e.what());
+ }
- CODE_BLOCK_END
-
- facy.handle_success("LoadLastMessages");
+ facy.handle_success("LoadLastMessages");
// Enable marking messages as read for this contact
facy.ignore_read.erase(hContact);
@@ -565,75 +551,71 @@ void FacebookProto::LoadHistory(void *pParam)
}
// Parse the result
- CODE_BLOCK_TRY
+ try {
+ messages.clear();
- messages.clear();
+ p->parse_history(&resp.data, &messages, &firstTimestamp);
- p->parse_history(&resp.data, &messages, &firstTimestamp);
+ // Receive messages
+ std::string previousFirstMessageId = firstMessageId;
+ for (std::vector<facebook_message*>::size_type i = 0; i < messages.size(); i++) {
+ facebook_message &msg = messages[i];
- // Receive messages
- std::string previousFirstMessageId = firstMessageId;
- for (std::vector<facebook_message*>::size_type i = 0; i < messages.size(); i++) {
- facebook_message &msg = messages[i];
-
- // First message might overlap (as we are using it's timestamp for the next loading), so we need to check for it
- if (i == 0) {
- firstMessageId = msg.message_id;
- }
- if (previousFirstMessageId == msg.message_id) {
- continue;
- }
- lastMessageId = msg.message_id;
+ // First message might overlap (as we are using it's timestamp for the next loading), so we need to check for it
+ if (i == 0) {
+ firstMessageId = msg.message_id;
+ }
+ if (previousFirstMessageId == msg.message_id) {
+ continue;
+ }
+ lastMessageId = msg.message_id;
- if (msg.isIncoming && msg.isUnread && msg.type == MESSAGE) {
- PROTORECVEVENT recv = { 0 };
- recv.szMessage = const_cast<char*>(msg.message_text.c_str());
- recv.timestamp = msg.time;
- ProtoChainRecvMsg(hContact, &recv);
- }
- else {
- DBEVENTINFO dbei = { 0 };
- dbei.cbSize = sizeof(dbei);
+ if (msg.isIncoming && msg.isUnread && msg.type == MESSAGE) {
+ PROTORECVEVENT recv = { 0 };
+ recv.szMessage = const_cast<char*>(msg.message_text.c_str());
+ recv.timestamp = msg.time;
+ ProtoChainRecvMsg(hContact, &recv);
+ }
+ else {
+ DBEVENTINFO dbei = { 0 };
+ dbei.cbSize = sizeof(dbei);
+
+ if (msg.type == MESSAGE)
+ dbei.eventType = EVENTTYPE_MESSAGE;
+ else if (msg.type == VIDEO_CALL || msg.type == PHONE_CALL)
+ dbei.eventType = FACEBOOK_EVENTTYPE_CALL;
+ else
+ dbei.eventType = EVENTTYPE_URL; // FIXME: Use better and specific type for our other event types.
- if (msg.type == MESSAGE)
- dbei.eventType = EVENTTYPE_MESSAGE;
- else if (msg.type == VIDEO_CALL || msg.type == PHONE_CALL)
- dbei.eventType = FACEBOOK_EVENTTYPE_CALL;
- else
- dbei.eventType = EVENTTYPE_URL; // FIXME: Use better and specific type for our other event types.
+ dbei.flags = DBEF_UTF;
- dbei.flags = DBEF_UTF;
+ if (!msg.isIncoming)
+ dbei.flags |= DBEF_SENT;
- if (!msg.isIncoming)
- dbei.flags |= DBEF_SENT;
+ if (!msg.isUnread)
+ dbei.flags |= DBEF_READ;
- if (!msg.isUnread)
- dbei.flags |= DBEF_READ;
+ dbei.szModule = m_szModuleName;
+ dbei.timestamp = msg.time;
+ dbei.cbBlob = (DWORD)msg.message_text.length() + 1;
+ dbei.pBlob = (PBYTE)msg.message_text.c_str();
+ db_event_add(hContact, &dbei);
+ }
- dbei.szModule = m_szModuleName;
- dbei.timestamp = msg.time;
- dbei.cbBlob = (DWORD)msg.message_text.length() + 1;
- dbei.pBlob = (PBYTE)msg.message_text.c_str();
- db_event_add(hContact, &dbei);
+ loadedMessages++;
}
- loadedMessages++;
- }
+ // Save last message id of first batch which is latest message completely, because we're going backwards
+ if (batch == 0 && !lastMessageId.empty()) {
+ setString(hContact, FACEBOOK_KEY_MESSAGE_ID, lastMessageId.c_str());
+ }
- // Save last message id of first batch which is latest message completely, because we're going backwards
- if (batch == 0 && !lastMessageId.empty()) {
- setString(hContact, FACEBOOK_KEY_MESSAGE_ID, lastMessageId.c_str());
+ debugLogA("*** Load history messages processed");
+ }
+ catch (const std::exception &e) {
+ debugLogA("*** Error processing load history messages: %s", e.what());
+ break;
}
-
- debugLogA("*** Load history messages processed");
-
- CODE_BLOCK_CATCH
-
- debugLogA("*** Error processing load history messages: %s", e.what());
-
- break;
-
- CODE_BLOCK_END
// Update progress popup
CMStringW text;
@@ -1120,9 +1102,8 @@ void FacebookProto::ProcessMessages(void* data)
debugLogA("*** Starting processing messages");
- CODE_BLOCK_TRY
-
- std::vector<facebook_message> messages;
+ try {
+ std::vector<facebook_message> messages;
facebook_json_parser* p = new facebook_json_parser(this);
p->parse_messages(resp, &messages, &facy.notifications);
@@ -1134,12 +1115,10 @@ void FacebookProto::ProcessMessages(void* data)
ShowNotifications();
debugLogA("*** Messages processed");
-
- CODE_BLOCK_CATCH
-
+ }
+ catch (const std::exception &e) {
debugLogA("*** Error processing messages: %s", e.what());
-
- CODE_BLOCK_END
+ }
delete resp;
}
@@ -1191,21 +1170,18 @@ void FacebookProto::ProcessNotifications(void*)
// Process notifications
debugLogA("*** Starting processing notifications");
- CODE_BLOCK_TRY
-
- facebook_json_parser* p = new facebook_json_parser(this);
- p->parse_notifications(&(resp.data), &facy.notifications);
- delete p;
-
- ShowNotifications();
-
- debugLogA("*** Notifications processed");
+ try {
+ facebook_json_parser* p = new facebook_json_parser(this);
+ p->parse_notifications(&(resp.data), &facy.notifications);
+ delete p;
- CODE_BLOCK_CATCH
+ ShowNotifications();
+ debugLogA("*** Notifications processed");
+ }
+ catch (const std::exception &e) {
debugLogA("*** Error processing notifications: %s", e.what());
-
- CODE_BLOCK_END
+ }
}
void FacebookProto::ProcessFriendRequests(void*)
diff --git a/protocols/FacebookRM/src/stdafx.h b/protocols/FacebookRM/src/stdafx.h
index 1549e7ccf9..11e70db53f 100644
--- a/protocols/FacebookRM/src/stdafx.h
+++ b/protocols/FacebookRM/src/stdafx.h
@@ -68,7 +68,6 @@ class FacebookProto;
#include "../../utils/std_string_utils.h"
#include "constants.h"
-#include "definitions.h"
#include "entities.h"
#include "http.h"
#include "list.hpp"