diff options
-rw-r--r-- | protocols/FacebookRM/src/client.h | 1 | ||||
-rw-r--r-- | protocols/FacebookRM/src/communication.cpp | 5 | ||||
-rw-r--r-- | protocols/FacebookRM/src/constants.h | 1 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 67 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 12 |
5 files changed, 74 insertions, 12 deletions
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h index d563b8a6bd..744d7cd578 100644 --- a/protocols/FacebookRM/src/client.h +++ b/protocols/FacebookRM/src/client.h @@ -96,6 +96,7 @@ public: // Client vs protocol communication
void client_notify(wchar_t* message);
+ void info_notify(wchar_t* message);
////////////////////////////////////////////////////////////
diff --git a/protocols/FacebookRM/src/communication.cpp b/protocols/FacebookRM/src/communication.cpp index 3ce901be9a..b9411a8e81 100644 --- a/protocols/FacebookRM/src/communication.cpp +++ b/protocols/FacebookRM/src/communication.cpp @@ -27,6 +27,11 @@ void facebook_client::client_notify(wchar_t* message) parent->NotifyEvent(parent->m_tszUserName, message, NULL, EVENT_CLIENT); } +void facebook_client::info_notify(wchar_t* message) +{ + parent->NotifyEvent(parent->m_tszUserName, message, NULL, EVENT_OTHER); +} + http::response facebook_client::sendRequest(HttpRequest *request) { http::response resp; diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index c1df1e23f7..5ed953a730 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -54,6 +54,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define FACEBOOK_NOTIFICATIONS_CHATROOM "_notifications"
#define FACEBOOK_CHATROOM_NAMES_COUNT 3 // number of participant names to use for chatrooms without specific name (on website it's 2)
#define FACEBOOK_NOTIFICATIONS_LOAD_COUNT 20 // number of last notifications to load on login to notify
+#define MANUALLY_TRIGGERED (void*)1 // to use as thread parameter to notify this action was activated by user, so we should show info popups
// Limits
#define FACEBOOK_MESSAGE_LIMIT 200000 // this is guessed limit, in reality it is bigger
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 7cdec9f7fa..8780dd262e 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -676,11 +676,18 @@ void parseFeeds(const std::string &text, std::vector<facebook_newsfeed *> &news, last_post_time = new_time; } -void FacebookProto::ProcessMemories(void*) +void FacebookProto::ProcessMemories(void *p) { if (isOffline()) return; + bool manuallyTriggered = (p == MANUALLY_TRIGGERED); + if (manuallyTriggered) { + facy.info_notify(TranslateT("Loading memories...")); + } + + int numMemories = 0; + facy.handle_entry(__FUNCTION__); HttpRequest *request = new MemoriesRequest(&facy); @@ -706,6 +713,8 @@ void FacebookProto::ProcessMemories(void*) SkinPlaySound("Memories"); } + numMemories = news.size(); + for (std::vector<facebook_newsfeed*>::size_type i = 0; i < news.size(); i++) { ptrW tszTitle(mir_utf8decodeW(news[i]->title.c_str())); @@ -718,6 +727,11 @@ void FacebookProto::ProcessMemories(void*) } } + if (manuallyTriggered) { + CMStringW text(FORMAT, TranslateT("Found %d memories."), numMemories); + facy.info_notify(text.GetBuffer()); + } + facy.handle_success(__FUNCTION__); } @@ -1009,11 +1023,16 @@ void FacebookProto::ShowNotifications() { } } -void FacebookProto::ProcessNotifications(void*) +void FacebookProto::ProcessNotifications(void *p) { if (isOffline()) return; + bool manuallyTriggered = (p == MANUALLY_TRIGGERED); + if (manuallyTriggered) { + facy.info_notify(TranslateT("Loading notifications...")); + } + facy.handle_entry("notifications"); // Get notifications @@ -1029,10 +1048,18 @@ void FacebookProto::ProcessNotifications(void*) debugLogA("*** Starting processing notifications"); try { + int numNotifications = facy.notifications.size(); + facebook_json_parser* p = new facebook_json_parser(this); p->parse_notifications(&(resp.data), &facy.notifications); delete p; + if (manuallyTriggered) { + numNotifications = facy.notifications.size() - numNotifications; + CMStringW text(FORMAT, TranslateT("Found %d notifications."), numNotifications); + facy.info_notify(text.GetBuffer()); + } + ShowNotifications(); debugLogA("*** Notifications processed"); @@ -1042,11 +1069,16 @@ void FacebookProto::ProcessNotifications(void*) } } -void FacebookProto::ProcessFriendRequests(void*) +void FacebookProto::ProcessFriendRequests(void *p) { if (isOffline()) return; + bool manuallyTriggered = (p == MANUALLY_TRIGGERED); + if (manuallyTriggered) { + facy.info_notify(TranslateT("Loading friendship requests...")); + } + facy.handle_entry("friendRequests"); // Get load friendships @@ -1064,6 +1096,9 @@ void FacebookProto::ProcessFriendRequests(void*) return; } + int numRequestsNew = 0; + int numRequestsOld = 0; + // Parse it std::string reqs = utils::text::source_get_value(&resp.data, 3, "id=\"friends_center_main\"", "</h3>", "/friends/center/suggestions/"); @@ -1113,18 +1148,37 @@ void FacebookProto::ProcessFriendRequests(void*) db_event_add(0, &dbei); } debugLogA(" < (%s) Friendship request [%s]", (isNew ? "New" : "Old"), time.c_str()); + + if (isNew) + numRequestsNew++; + else + numRequestsOld++; } else debugLogA("!!! Wrong friendship request:\n%s", req.c_str()); } + if (manuallyTriggered) { + CMStringW text; + if (numRequestsOld > 0) + 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.handle_success("friendRequests"); } -void FacebookProto::ProcessFeeds(void*) +void FacebookProto::ProcessFeeds(void *p) { if (!isOnline()) return; + bool manuallyTriggered = (p == MANUALLY_TRIGGERED); + if (manuallyTriggered) { + facy.info_notify(TranslateT("Loading wall posts...")); + } + facy.handle_entry("feeds"); // Get feeds @@ -1146,6 +1200,11 @@ void FacebookProto::ProcessFeeds(void*) SkinPlaySound("NewsFeed"); } + if (manuallyTriggered) { + CMStringW text(FORMAT, TranslateT("Found %d wall posts."), news.size()); + facy.info_notify(text.GetBuffer()); + } + 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.cpp b/protocols/FacebookRM/src/proto.cpp index b1abf860a0..30ca138e91 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -653,8 +653,7 @@ INT_PTR FacebookProto::CheckNewsfeeds(WPARAM, LPARAM) if (ctrlPressed) { facy.last_feeds_update_ = 0; } - NotifyEvent(m_tszUserName, TranslateT("Loading wall posts..."), NULL, EVENT_OTHER); - ForkThread(&FacebookProto::ProcessFeeds, NULL); + ForkThread(&FacebookProto::ProcessFeeds, MANUALLY_TRIGGERED); } return 0; } @@ -662,8 +661,7 @@ INT_PTR FacebookProto::CheckNewsfeeds(WPARAM, LPARAM) INT_PTR FacebookProto::CheckFriendRequests(WPARAM, LPARAM) { if (!isOffline()) { - NotifyEvent(m_tszUserName, TranslateT("Loading friendship requests..."), NULL, EVENT_OTHER); - ForkThread(&FacebookProto::ProcessFriendRequests, NULL); + ForkThread(&FacebookProto::ProcessFriendRequests, MANUALLY_TRIGGERED); } return 0; } @@ -671,8 +669,7 @@ INT_PTR FacebookProto::CheckFriendRequests(WPARAM, LPARAM) INT_PTR FacebookProto::CheckNotifications(WPARAM, LPARAM) { if (!isOffline()) { - NotifyEvent(m_tszUserName, TranslateT("Loading notifications..."), NULL, EVENT_OTHER); - ForkThread(&FacebookProto::ProcessNotifications, NULL); + ForkThread(&FacebookProto::ProcessNotifications, MANUALLY_TRIGGERED); } return 0; } @@ -680,8 +677,7 @@ INT_PTR FacebookProto::CheckNotifications(WPARAM, LPARAM) INT_PTR FacebookProto::CheckMemories(WPARAM, LPARAM) { if (!isOffline()) { - NotifyEvent(m_tszUserName, TranslateT("Loading memories..."), NULL, EVENT_OTHER); - ForkThread(&FacebookProto::ProcessMemories, NULL); + ForkThread(&FacebookProto::ProcessMemories, MANUALLY_TRIGGERED); } return 0; } |