summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Weimer <wishmaster51@googlemail.com>2017-02-12 21:43:13 +0100
committerTobias Weimer <wishmaster51@googlemail.com>2017-02-12 21:43:13 +0100
commit36c32a13878d3bd94e88bd9c764f1eadb05ea1ed (patch)
tree3407b05620aa32471e95499c2635d5f6de2ce776
parent646630b565d4fa2d95fd73143198b2d46deb937d (diff)
parent2651148625bef56f1fe32c638259d20abb001d68 (diff)
Merge branch 'master' of https://github.com/miranda-ng/miranda-ng
-rw-r--r--protocols/Discord/src/dispatch.cpp8
-rw-r--r--protocols/Discord/src/proto.h1
-rw-r--r--protocols/Discord/src/utils.cpp26
-rw-r--r--protocols/FacebookRM/src/client.h3
-rw-r--r--protocols/FacebookRM/src/communication.cpp5
-rw-r--r--protocols/FacebookRM/src/constants.h3
-rw-r--r--protocols/FacebookRM/src/events.cpp10
-rw-r--r--protocols/FacebookRM/src/process.cpp96
-rw-r--r--protocols/FacebookRM/src/proto.cpp14
-rw-r--r--protocols/FacebookRM/src/proto.h2
-rw-r--r--protocols/FacebookRM/src/requests/feeds.h4
-rw-r--r--protocols/FacebookRM/src/version.h2
12 files changed, 147 insertions, 27 deletions
diff --git a/protocols/Discord/src/dispatch.cpp b/protocols/Discord/src/dispatch.cpp
index 1f4f9b3993..0da160b973 100644
--- a/protocols/Discord/src/dispatch.cpp
+++ b/protocols/Discord/src/dispatch.cpp
@@ -370,6 +370,14 @@ void CDiscordProto::OnCommandMessage(const JSONNode &pRoot)
else {
debugLogA("store a message into the group channel id %lld", channelId);
+ SESSION_INFO *si = pci->SM_FindSession(wszChannelId, m_szModuleName);
+ if (si == NULL) {
+ debugLogA("nessage to unknown channal %lld ignored", channelId);
+ return;
+ }
+
+ ParseSpecialChars(si, wszText);
+
GCDEST gcd = { m_szModuleName, wszChannelId, GC_EVENT_MESSAGE };
GCEVENT gce = { &gcd };
gce.dwFlags = GCEF_ADDTOLOG;
diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h
index 29c0319719..133ff1f40c 100644
--- a/protocols/Discord/src/proto.h
+++ b/protocols/Discord/src/proto.h
@@ -206,6 +206,7 @@ class CDiscordProto : public PROTO<CDiscordProto>
void Chat_SendPrivateMessage(GCHOOK *gch);
void Chat_ProcessLogMenu(GCHOOK *gch);
+ void ParseSpecialChars(SESSION_INFO *si, CMStringW &str);
//////////////////////////////////////////////////////////////////////////////////////
// misc methods
diff --git a/protocols/Discord/src/utils.cpp b/protocols/Discord/src/utils.cpp
index f84ecfb61a..b1390a9ec0 100644
--- a/protocols/Discord/src/utils.cpp
+++ b/protocols/Discord/src/utils.cpp
@@ -268,3 +268,29 @@ void CDiscordProto::ProcessType(CDiscordUser *pUser, const JSONNode &pRoot)
break;
}
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+void CDiscordProto::ParseSpecialChars(SESSION_INFO *si, CMStringW &str)
+{
+ for (int i = 0; (i = str.Find('<', i)) != -1; i++) {
+ int iEnd = str.Find('>', i + 1);
+ if (iEnd == -1)
+ return;
+
+ CMStringW wszWord = str.Mid(i + 1, iEnd - i - 1);
+ if (wszWord[0] == '@' && wszWord[1] == '!') { // member highlight
+ USERINFO *ui = pci->UM_FindUser(si->pUsers, wszWord.c_str()+2);
+ if (ui != nullptr)
+ str.Replace(L"<" + wszWord + L">", CMStringW('@') + ui->pszNick);
+ }
+ else if (wszWord[0] == '#') {
+ CDiscordUser *pUser = FindUserByChannel(_wtoi64(wszWord.c_str() + 1));
+ if (pUser != nullptr) {
+ ptrW wszNick(getWStringA(pUser->hContact, "Nick"));
+ if (wszNick != NULL)
+ str.Replace(L"<" + wszWord + L">", wszNick);
+ }
+ }
+ }
+}
diff --git a/protocols/FacebookRM/src/client.h b/protocols/FacebookRM/src/client.h
index d563b8a6bd..6689fe8a4e 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);
////////////////////////////////////////////////////////////
@@ -160,7 +161,7 @@ public:
}
__inline const char *__rev() {
- return "2509236"; // FIXME: Some version of communication protocol? This version is from 17.8.2016
+ return "2828561"; // FIXME: Some version of communication protocol? This version is from 12.2.2017
}
////////////////////////////////////////////////////////////
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 6b8bf70949..5ed953a730 100644
--- a/protocols/FacebookRM/src/constants.h
+++ b/protocols/FacebookRM/src/constants.h
@@ -31,7 +31,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define FACEBOOK_URL_PROFILE "http://www.facebook.com/profile.php?id="
#define FACEBOOK_URL_GROUP "http://www.facebook.com/n/?home.php&sk=group_"
#define FACEBOOK_URL_PICTURE "http://graph.facebook.com/%s/picture"
-#define FACEBOOK_URL_CONVERSATION "http://www.facebook.com/messages/"
+#define FACEBOOK_URL_CONVERSATION "http://www.facebook.com/messages/t/"
//#define FACEBOOK_URL_STICKER "http://www.facebook.com/stickers/asset/?sticker_id=%s&image_type=BestEffortImage"
// Connection
@@ -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/events.cpp b/protocols/FacebookRM/src/events.cpp
index 4dce07fe7b..f46ad30d58 100644
--- a/protocols/FacebookRM/src/events.cpp
+++ b/protocols/FacebookRM/src/events.cpp
@@ -22,9 +22,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
-HWND FacebookProto::NotifyEvent(wchar_t* title, wchar_t* info, MCONTACT contact, EventType type, std::string *url, std::string *notification_id, const char *icon)
+HWND FacebookProto::NotifyEvent(wchar_t* title, wchar_t* text, MCONTACT contact, EventType type, std::string *url, std::string *notification_id, const char *icon)
{
- if (title == NULL || info == NULL)
+ if (title == NULL || text == NULL)
return NULL;
char name[256];
@@ -77,7 +77,7 @@ HWND FacebookProto::NotifyEvent(wchar_t* title, wchar_t* info, MCONTACT contact,
POPUPDATACLASS pd = { sizeof(pd) };
pd.pwszTitle = title;
- pd.pwszText = info;
+ pd.pwszText = text;
pd.pszClassName = name;
pd.hContact = contact;
if (icon != NULL) {
@@ -97,12 +97,12 @@ HWND FacebookProto::NotifyEvent(wchar_t* title, wchar_t* info, MCONTACT contact,
}
}
else {
- if (!Clist_TrayNotifyW(m_szModuleName, title, info, type == EVENT_CLIENT ? NIIF_WARNING : NIIF_INFO, 10000))
+ if (!Clist_TrayNotifyW(m_szModuleName, title, text, type == EVENT_CLIENT ? NIIF_WARNING : NIIF_INFO, 10000))
return NULL;
}
if (type == EVENT_CLIENT)
- MessageBox(NULL, info, title, MB_OK | MB_ICONERROR);
+ MessageBox(NULL, text, title, MB_OK | MB_ICONERROR);
return NULL;
}
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp
index 7cdec9f7fa..f03a8906eb 100644
--- a/protocols/FacebookRM/src/process.cpp
+++ b/protocols/FacebookRM/src/process.cpp
@@ -543,7 +543,7 @@ void parseFeeds(const std::string &text, std::vector<facebook_newsfeed *> &news,
DWORD new_time = last_post_time;
- while ((pos = text.find("<div class=\"userContentWrapper", pos)) != std::string::npos && limit <= 25)
+ while ((pos = text.find("<div class=\"fbUserContent", pos)) != std::string::npos && limit <= 25)
{
std::string post = text.substr(pos, text.find("</form>", pos) - pos);
pos += 5;
@@ -551,6 +551,9 @@ void parseFeeds(const std::string &text, std::vector<facebook_newsfeed *> &news,
std::string post_header = utils::text::source_get_value(&post, 3, "<h5", ">", "</h5>");
std::string post_message = utils::text::source_get_value(&post, 3, " userContent\"", ">", "<form");
std::string post_link = utils::text::source_get_value(&post, 4, "</h5>", "<a", "href=\"", "\"");
+ if (post_link == "#") {
+ post_link = utils::text::source_get_value(&post, 5, "</h5>", "<a", "<a", "href=\"", "\"");
+ }
std::string post_time = utils::text::source_get_value(&post, 3, "</h5>", "<abbr", "</a>");
std::string time = utils::text::source_get_value(&post_time, 2, "data-utime=\"", "\"");
@@ -597,10 +600,26 @@ void parseFeeds(const std::string &text, std::vector<facebook_newsfeed *> &news,
utils::text::remove_html(
post_header.substr(pos2, post_header.length() - pos2))));
- // Strip "Translate" link
- pos2 = post_message.find("role=\"button\">");
+ // Strip "Translate" and other buttons
+ do {
+ pos2 = post_message.find("role=\"button\"");
+ if (pos2 != std::string::npos) {
+ pos2 = post_message.find(">", pos2);
+ if (pos2 != std::string::npos) {
+ std::string::size_type pos3 = post_message.find("</a>", pos2);
+ std::string tmp = post_message.substr(0, pos2);
+ if (pos3 != std::string::npos) {
+ tmp += post_message.substr(pos3, post_message.length() - pos3);
+ }
+ post_message = tmp;
+ }
+ }
+ } while (pos2 != std::string::npos);
+
+ // Strip "See more" link
+ pos2 = post_message.find("<span class=\"see_more_link_inner\">");
if (pos2 != std::string::npos) {
- post_message = post_message.substr(0, pos2 + 14);
+ post_message = post_message.substr(0, pos2);
}
// Process attachment (if present)
@@ -676,17 +695,24 @@ 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);
http::response resp = facy.sendRequest(request);
- if (resp.code != HTTP_CODE_OK) {
+ if (resp.code != HTTP_CODE_OK || resp.data.empty()) {
facy.handle_error(__FUNCTION__);
return;
}
@@ -706,6 +732,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 +746,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 +1042,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 +1067,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 +1088,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 +1115,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 +1167,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 +1219,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 375ef125c9..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;
}
@@ -742,7 +738,7 @@ INT_PTR FacebookProto::VisitConversation(WPARAM wParam, LPARAM)
if (id == NULL)
return 1;
- std::string url = FACEBOOK_URL_CONVERSATION + std::string(isChat ? "conversation-" : "") + std::string(id);
+ std::string url = FACEBOOK_URL_CONVERSATION + std::string(id);
OpenUrl(url);
return 0;
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h
index 699de756cb..bcceed5864 100644
--- a/protocols/FacebookRM/src/proto.h
+++ b/protocols/FacebookRM/src/proto.h
@@ -261,6 +261,6 @@ public:
static void CALLBACK APC_callback(ULONG_PTR p);
// Information providing
- HWND NotifyEvent(wchar_t* title, wchar_t* info, MCONTACT contact, EventType type, std::string *url = NULL, std::string *notification_id = NULL, const char *icon = NULL);
+ HWND NotifyEvent(wchar_t* title, wchar_t* text, MCONTACT contact, EventType type, std::string *url = NULL, std::string *notification_id = NULL, const char *icon = NULL);
void ShowNotifications();
};
diff --git a/protocols/FacebookRM/src/requests/feeds.h b/protocols/FacebookRM/src/requests/feeds.h
index 729548b133..24d9836812 100644
--- a/protocols/FacebookRM/src/requests/feeds.h
+++ b/protocols/FacebookRM/src/requests/feeds.h
@@ -49,6 +49,10 @@ public:
<< "start_index=0"
<< "num_stories=20"
<< "last_section_header=0"
+ << "last_section_key=regular_story"
+ << "__af="
+ << "__be=-1"
+ << "__pc=PHASED:DEFAULT"
<< LONG_VALUE("timestamp", ::time(NULL))
<< CHAR_VALUE("__dyn", fc->__dyn())
<< CHAR_VALUE("__req", fc->__req())
diff --git a/protocols/FacebookRM/src/version.h b/protocols/FacebookRM/src/version.h
index 53755c373e..2465a65905 100644
--- a/protocols/FacebookRM/src/version.h
+++ b/protocols/FacebookRM/src/version.h
@@ -1,7 +1,7 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 3
#define __RELEASE_NUM 1
-#define __BUILD_NUM 0
+#define __BUILD_NUM 1
#include <stdver.h>