diff options
author | Robert Pösel <robyer@seznam.cz> | 2013-05-17 15:06:51 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2013-05-17 15:06:51 +0000 |
commit | 1c917ac3f485ffac7b4316d633a344fbafcedb78 (patch) | |
tree | 32a83a846c37fc3e3551624bf9ed1ac2e75f8165 /protocols/FacebookRM/src | |
parent | df406e92b92925501b224a01962ef9e9dee84d3b (diff) |
Facebook: Ability to open links on different server (mobile, touch,...).
git-svn-id: http://svn.miranda-ng.org/main/trunk@4702 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src')
-rw-r--r-- | protocols/FacebookRM/src/db.h | 1 | ||||
-rw-r--r-- | protocols/FacebookRM/src/dialogs.cpp | 12 | ||||
-rw-r--r-- | protocols/FacebookRM/src/entities.h | 12 | ||||
-rw-r--r-- | protocols/FacebookRM/src/events.cpp | 35 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 3 | ||||
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 6 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 28 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.cpp | 42 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 5 |
9 files changed, 78 insertions, 66 deletions
diff --git a/protocols/FacebookRM/src/db.h b/protocols/FacebookRM/src/db.h index f8d0e857ac..a25fb0c20a 100644 --- a/protocols/FacebookRM/src/db.h +++ b/protocols/FacebookRM/src/db.h @@ -70,6 +70,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define FACEBOOK_KEY_LOCAL_TIMESTAMP "UseLocalTimestamp" // [HIDDEN] - 0 = use facebook timestamps for messages, 1 = use local timestamps
#define FACEBOOK_KEY_MARK_READ "MarkRead" // [HIDDEN] - 0 = marking messages as read without "Seen" info, 1 = with "Seen" info
#define FACEBOOK_KEY_LOCALE "Locale" // [HIDDEN] - en_US, cs_CZ, etc.
+#define FACEBOOK_KEY_SERVER "Server" // [HIDDEN] - for rewrite links to open: m.facebook.com, touch.facebook.com, etc.
#define FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE "EventNotificationsEnable"
#define FACEBOOK_KEY_EVENT_FEEDS_ENABLE "EventFeedsEnable"
diff --git a/protocols/FacebookRM/src/dialogs.cpp b/protocols/FacebookRM/src/dialogs.cpp index f27adefe2e..4f4ee0a581 100644 --- a/protocols/FacebookRM/src/dialogs.cpp +++ b/protocols/FacebookRM/src/dialogs.cpp @@ -38,7 +38,7 @@ static BOOL StoreDBCheckState(FacebookProto* ppro, HWND hwnd, int idCtrl, const INT_PTR CALLBACK FBAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
- FacebookProto *proto;
+ FacebookProto *proto = reinterpret_cast<FacebookProto*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
switch (message)
{
@@ -73,8 +73,7 @@ INT_PTR CALLBACK FBAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp case WM_COMMAND:
if (LOWORD(wparam) == IDC_NEWACCOUNTLINK)
{
- CallService(MS_UTILS_OPENURL,1,reinterpret_cast<LPARAM>
- (FACEBOOK_URL_HOMEPAGE));
+ proto->OpenUrl(std::string(FACEBOOK_URL_HOMEPAGE));
return TRUE;
}
@@ -92,7 +91,6 @@ INT_PTR CALLBACK FBAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp case WM_NOTIFY:
if (reinterpret_cast<NMHDR*>(lparam)->code == PSN_APPLY)
{
- proto = reinterpret_cast<FacebookProto*>(GetWindowLongPtr(hwnd,GWLP_USERDATA));
char str[128];
GetDlgItemTextA(hwnd,IDC_UN,str,sizeof(str));
@@ -229,11 +227,11 @@ INT_PTR CALLBACK FBOptionsProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lp } return TRUE;
- case WM_COMMAND: {
+ case WM_COMMAND:
+ {
if (LOWORD(wparam) == IDC_NEWACCOUNTLINK)
{
- CallService(MS_UTILS_OPENURL,1,reinterpret_cast<LPARAM>
- (FACEBOOK_URL_HOMEPAGE));
+ proto->OpenUrl(std::string(FACEBOOK_URL_HOMEPAGE));
return TRUE;
}
diff --git a/protocols/FacebookRM/src/entities.h b/protocols/FacebookRM/src/entities.h index 76fe5cf965..acb395d52a 100644 --- a/protocols/FacebookRM/src/entities.h +++ b/protocols/FacebookRM/src/entities.h @@ -108,7 +108,6 @@ struct facebook_newsfeed }
};
-
struct send_chat
{
send_chat(const std::string &chat_id,const std::string &msg) : chat_id(chat_id), msg(msg) {}
@@ -116,7 +115,6 @@ struct send_chat std::string msg;
};
-
struct send_direct
{
send_direct(HANDLE hContact,const std::string &msg, HANDLE msgid) : hContact(hContact), msg(msg), msgid(msgid) {}
@@ -132,9 +130,9 @@ struct send_typing int status;
};
-struct send_messaging
+struct popup_data
{
- send_messaging(const std::string &user_id, const int type) : user_id(user_id), type(type) {}
- std::string user_id;
- int type;
-};
+ popup_data(FacebookProto *proto, std::string url) : proto(proto), url(url) {}
+ FacebookProto *proto;
+ std::string url;
+};
\ No newline at end of file diff --git a/protocols/FacebookRM/src/events.cpp b/protocols/FacebookRM/src/events.cpp index fa116bf1e6..7944090c1f 100644 --- a/protocols/FacebookRM/src/events.cpp +++ b/protocols/FacebookRM/src/events.cpp @@ -49,15 +49,9 @@ LRESULT CALLBACK PopupDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case WM_COMMAND:
{
//Get the plugin data (we need the PopUp service to do it)
- TCHAR* data = (TCHAR*)PUGetPluginData(hwnd);
+ popup_data *data = (popup_data *)PUGetPluginData(hwnd);
if (data != NULL)
- {
- std::string url = mir_t2a_cp(data,CP_UTF8);
- if (url.substr(0,4) != "http")
- url = FACEBOOK_URL_HOMEPAGE + url; // make absolute url
-
- CallService(MS_UTILS_OPENURL, (WPARAM) 1, (LPARAM) url.c_str());
- }
+ data->proto->OpenUrl(data->url);
// After a click, destroy popup
PUDeletePopUp(hwnd);
@@ -70,9 +64,9 @@ LRESULT CALLBACK PopupDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case UM_FREEPLUGINDATA:
{
// After close, free
- TCHAR* url = (TCHAR*)PUGetPluginData(hwnd);
- if (url != NULL)
- mir_free(url);
+ popup_data *data = (popup_data *)PUGetPluginData(hwnd);
+ if (data != NULL)
+ mir_free(data);
} return FALSE;
default:
@@ -82,7 +76,7 @@ LRESULT CALLBACK PopupDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return DefWindowProc(hwnd, message, wParam, lParam);
};
-void FacebookProto::NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD flags, TCHAR* szUrl)
+void FacebookProto::NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD flags, std::string szUrl)
{
int ret; int timeout; COLORREF colorBack = 0; COLORREF colorText = 0;
@@ -90,7 +84,7 @@ void FacebookProto::NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD {
case FACEBOOK_EVENT_CLIENT:
if (!getByte(FACEBOOK_KEY_EVENT_CLIENT_ENABLE, DEFAULT_EVENT_CLIENT_ENABLE))
- goto exit;
+ return;
if (!getByte(FACEBOOK_KEY_EVENT_CLIENT_DEFAULT, 0))
{
colorBack = getDword(FACEBOOK_KEY_EVENT_CLIENT_COLBACK, DEFAULT_EVENT_COLBACK);
@@ -102,7 +96,7 @@ void FacebookProto::NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD case FACEBOOK_EVENT_NEWSFEED:
if (!getByte(FACEBOOK_KEY_EVENT_FEEDS_ENABLE, DEFAULT_EVENT_FEEDS_ENABLE))
- goto exit;
+ return;
if (!getByte(FACEBOOK_KEY_EVENT_FEEDS_DEFAULT, 0))
{
colorBack = getDword(FACEBOOK_KEY_EVENT_FEEDS_COLBACK, DEFAULT_EVENT_COLBACK);
@@ -115,7 +109,7 @@ void FacebookProto::NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD case FACEBOOK_EVENT_NOTIFICATION:
if (!getByte(FACEBOOK_KEY_EVENT_NOTIFICATIONS_ENABLE, DEFAULT_EVENT_NOTIFICATIONS_ENABLE))
- goto exit;
+ return;
if (!getByte(FACEBOOK_KEY_EVENT_NOTIFICATIONS_DEFAULT, 0))
{
colorBack = getDword(FACEBOOK_KEY_EVENT_NOTIFICATIONS_COLBACK, DEFAULT_EVENT_COLBACK);
@@ -128,7 +122,7 @@ void FacebookProto::NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD case FACEBOOK_EVENT_OTHER:
if (!getByte(FACEBOOK_KEY_EVENT_OTHER_ENABLE, DEFAULT_EVENT_OTHER_ENABLE))
- goto exit;
+ return;
if (!getByte(FACEBOOK_KEY_EVENT_OTHER_DEFAULT, 0))
{
colorBack = getDword(FACEBOOK_KEY_EVENT_OTHER_COLBACK, DEFAULT_EVENT_COLBACK);
@@ -150,7 +144,8 @@ void FacebookProto::NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD pd.iSeconds = timeout;
pd.lchContact = contact;
pd.lchIcon = Skin_GetIconByHandle(m_hProtoIcon); // TODO: Icon test
- pd.PluginData = szUrl;
+ if (!szUrl.empty())
+ pd.PluginData = new popup_data(this, szUrl);
pd.PluginWindowProc = (WNDPROC)PopupDlgProc;
lstrcpy(pd.lptzContactName, title);
lstrcpy(pd.lptzText, info);
@@ -177,14 +172,10 @@ void FacebookProto::NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD ret = CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM) & err);
if (ret == 0)
- goto exit;
+ return;
}
}
if (FLAG_CONTAINS(flags, FACEBOOK_EVENT_CLIENT))
MessageBox(NULL, info, title, MB_OK | MB_ICONINFORMATION);
-
-exit:
- if (szUrl != NULL)
- mir_free(szUrl);
}
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index b07f6244b2..18e84f6f81 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -435,8 +435,7 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa TCHAR* szTitle = mir_utf8decodeT(title.c_str());
TCHAR* szText = mir_utf8decodeT(popup_text.c_str());
- TCHAR* szUrl = mir_utf8decodeT(url.c_str());
- proto->NotifyEvent(szTitle,szText,NULL,FACEBOOK_EVENT_OTHER, szUrl);
+ proto->NotifyEvent(szTitle,szText,NULL,FACEBOOK_EVENT_OTHER, url);
mir_free(szTitle);
mir_free(szText);
}
diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index 02c130756f..bb3808c225 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -47,7 +47,7 @@ void FacebookProto::SendMsgWorker(void *p) }
else if (!db_get_s(data->hContact,m_szModuleName,FACEBOOK_KEY_ID,&dbv))
{
- //parseSmileys(data->msg, data->hContact);
+ //ParseSmileys(data->msg, data->hContact);
int retries = 5;
std::string error_text = "";
@@ -197,7 +197,7 @@ void FacebookProto::ReadMessageWorker(void *p) }
}
-void FacebookProto::parseSmileys(std::string message, HANDLE hContact)
+void FacebookProto::ParseSmileys(std::string message, HANDLE hContact)
{
if (!db_get_b(NULL,m_szModuleName,FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS))
return;
@@ -246,4 +246,4 @@ void FacebookProto::parseSmileys(std::string message, HANDLE hContact) mir_free(path);
//}
}
-}
\ No newline at end of file +}
diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 321d4a66d2..8bfe27d0ad 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -125,10 +125,8 @@ void FacebookProto::ProcessBuddyList(void* data) std::string url = FACEBOOK_URL_PROFILE + fbu->user_id;
TCHAR* szTitle = mir_utf8decodeT(fbu->real_name.c_str());
- TCHAR* szUrl = mir_utf8decodeT(url.c_str());
- NotifyEvent(szTitle, TranslateT("Contact is back on server-list."), fbu->handle, FACEBOOK_EVENT_OTHER, szUrl);
+ NotifyEvent(szTitle, TranslateT("Contact is back on server-list."), fbu->handle, FACEBOOK_EVENT_OTHER, url);
mir_free(szTitle);
- // mir_free(szUrl); // url is free'd in popup procedure
}
// Check avatar change
@@ -216,10 +214,8 @@ void FacebookProto::ProcessFriendList(void* data) std::string url = FACEBOOK_URL_PROFILE + fbu->user_id;
TCHAR* szTitle = mir_utf8decodeT(fbu->real_name.c_str());
- TCHAR* szUrl = mir_utf8decodeT(url.c_str());
- NotifyEvent(szTitle, TranslateT("Contact is back on server-list."), hContact, FACEBOOK_EVENT_OTHER, szUrl);
+ NotifyEvent(szTitle, TranslateT("Contact is back on server-list."), hContact, FACEBOOK_EVENT_OTHER, url);
mir_free(szTitle);
- // mir_free(szUrl); // url is free'd in popup procedure
}
// Check avatar change
@@ -247,10 +243,8 @@ void FacebookProto::ProcessFriendList(void* data) std::string url = FACEBOOK_URL_PROFILE + id;
TCHAR* szTitle = mir_utf8decodeT(contactname.c_str());
- TCHAR* szUrl = mir_utf8decodeT(url.c_str());
- NotifyEvent(szTitle, TranslateT("Contact is no longer on server-list."), hContact, FACEBOOK_EVENT_OTHER, szUrl);
+ NotifyEvent(szTitle, TranslateT("Contact is no longer on server-list."), hContact, FACEBOOK_EVENT_OTHER, url);
mir_free(szTitle);
- // mir_free(szUrl); // url is free'd in popup procedure
}
}
}
@@ -421,7 +415,7 @@ void FacebookProto::ProcessUnreadMessage(void *tid_data) LOG("Got unread message: \"%s\"", message_text.c_str());
- parseSmileys(message_text, hContact);
+ ParseSmileys(message_text, hContact);
if (!message_attachments.empty()) {
if (!message_text.empty())
@@ -482,7 +476,7 @@ void FacebookProto::ProcessMessages(void* data) // TODO: if contact is newly added, get his user info
// TODO: maybe create new "receiveMsg" function and use it for offline and channel messages?
- parseSmileys(messages[i]->message_text, hContact);
+ ParseSmileys(messages[i]->message_text, hContact);
PROTORECVEVENT recv = {0};
recv.flags = PREF_UTF;
@@ -499,11 +493,9 @@ void FacebookProto::ProcessMessages(void* data) LOG(" Got notification: %s", notifications[i]->text.c_str());
TCHAR* szTitle = mir_utf8decodeT(this->m_szModuleName);
TCHAR* szText = mir_utf8decodeT(notifications[i]->text.c_str());
- TCHAR* szUrl = mir_utf8decodeT(notifications[i]->link.c_str());
- NotifyEvent(szTitle, szText, ContactIDToHContact(notifications[i]->user_id), FACEBOOK_EVENT_NOTIFICATION, szUrl);
+ NotifyEvent(szTitle, szText, ContactIDToHContact(notifications[i]->user_id), FACEBOOK_EVENT_NOTIFICATION, notifications[i]->link);
mir_free(szTitle);
mir_free(szText);
-// mir_free(szUrl); // URL is free'd in popup procedure
delete notifications[i];
}
@@ -559,11 +551,9 @@ void FacebookProto::ProcessNotifications(void*) LOG(" Got notification: %s", notifications[i]->text.c_str());
TCHAR* szTitle = mir_utf8decodeT(this->m_szModuleName);
TCHAR* szText = mir_utf8decodeT(notifications[i]->text.c_str());
- TCHAR* szUrl = mir_utf8decodeT(notifications[i]->link.c_str());
- NotifyEvent(szTitle, szText, ContactIDToHContact(notifications[i]->user_id), FACEBOOK_EVENT_NOTIFICATION, szUrl);
+ NotifyEvent(szTitle, szText, ContactIDToHContact(notifications[i]->user_id), FACEBOOK_EVENT_NOTIFICATION, notifications[i]->link);
mir_free(szTitle);
mir_free(szText);
-// mir_free(szUrl); // URL is free'd in popup procedure
delete notifications[i];
}
@@ -755,11 +745,9 @@ void FacebookProto::ProcessFeeds(void* data) LOG(" Got newsfeed: %s %s", news[i]->title.c_str(), news[i]->text.c_str());
TCHAR* szTitle = mir_utf8decodeT(news[i]->title.c_str());
TCHAR* szText = mir_utf8decodeT(news[i]->text.c_str());
- TCHAR* szUrl = mir_utf8decodeT(news[i]->link.c_str());
- NotifyEvent(szTitle,szText,this->ContactIDToHContact(news[i]->user_id),FACEBOOK_EVENT_NEWSFEED, szUrl);
+ NotifyEvent(szTitle,szText,this->ContactIDToHContact(news[i]->user_id),FACEBOOK_EVENT_NEWSFEED, news[i]->link);
mir_free(szTitle);
mir_free(szText);
-// mir_free(szUrl); // URL is free'd in popup procedure
delete news[i];
}
news.clear();
diff --git a/protocols/FacebookRM/src/proto.cpp b/protocols/FacebookRM/src/proto.cpp index c6c0f4401b..87edd10ce4 100644 --- a/protocols/FacebookRM/src/proto.cpp +++ b/protocols/FacebookRM/src/proto.cpp @@ -454,7 +454,7 @@ int FacebookProto::VisitProfile(WPARAM wParam,LPARAM lParam) HANDLE hContact = reinterpret_cast<HANDLE>(wParam);
// TODO: why isn't wParam == 0 when is status menu moved to main menu?
- if (wParam == 0 || !IsMyContact(hContact))
+ if (wParam != 0 && !IsMyContact(hContact))
return 1;
std::string url = FACEBOOK_URL_PROFILE;
@@ -470,7 +470,7 @@ int FacebookProto::VisitProfile(WPARAM wParam,LPARAM lParam) db_set_s(hContact, m_szModuleName, "Homepage", url.c_str());
}
- CallService(MS_UTILS_OPENURL, 1, reinterpret_cast<LPARAM>(url.c_str()));
+ OpenUrl(url);
return 0;
}
@@ -487,7 +487,7 @@ int FacebookProto::VisitFriendship(WPARAM wParam,LPARAM lParam) url += facy.self_.user_id;
url += "&and=" + std::string(id);
- CallService(MS_UTILS_OPENURL, 1, reinterpret_cast<LPARAM>(url.c_str()));
+ OpenUrl(url);
return 0;
}
@@ -600,3 +600,39 @@ HANDLE FacebookProto::HContactFromAuthEvent(HANDLE hEvent) return DbGetAuthEventContact(&dbei);
}
+
+void FacebookProto::OpenUrl(std::string url)
+{
+ std::string facebookDomain = "facebook.com";
+ std::string::size_type pos = url.find(facebookDomain);
+ bool isFacebookUrl = (pos != std::string::npos);
+ bool isRelativeUrl = (url.substr(0, 4) != "http");
+
+ if (isFacebookUrl || isRelativeUrl) {
+
+ // Make realtive url
+ if (!isRelativeUrl) {
+ url = url.substr(pos + facebookDomain.length());
+
+ // Strip eventual port
+ pos = url.find("/");
+ if (pos != std::string::npos && pos != 0)
+ url = url.substr(pos);
+ }
+
+ // Make absolute url
+ bool useHttps = db_get_b(NULL, m_szModuleName, FACEBOOK_KEY_FORCE_HTTPS, 1) > 0;
+ std::string newUrl = (useHttps ? HTTP_PROTO_SECURE : HTTP_PROTO_REGULAR);
+
+ ptrA server = db_get_sa(NULL, m_szModuleName, FACEBOOK_KEY_SERVER);
+ if (server != NULL)
+ newUrl += server;
+ else
+ newUrl += FACEBOOK_SERVER_REGULAR;
+
+ url = newUrl + url;
+ }
+
+ ptrT data = mir_utf8decodeT(url.c_str());
+ CallService(MS_UTILS_OPENURL, (WPARAM)OUF_TCHAR, (LPARAM)data);
+}
diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index c0cf2fc56b..4032d10438 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -187,7 +187,8 @@ public: bool GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::string *url);
void CheckAvatarChange(HANDLE hContact, std::string image_url);
void ToggleStatusMenuItems(BOOL bEnable);
- void parseSmileys(std::string message, HANDLE hContact);
+ void ParseSmileys(std::string message, HANDLE hContact);
+ void OpenUrl(std::string url);
// Handles, Locks
HGENMENU m_hMenuRoot, m_hMenuServicesRoot, m_hStatusMind;
@@ -208,5 +209,5 @@ public: // Information providing
int Log(const char *fmt,...);
- void NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD flags, TCHAR* url=NULL);
+ void NotifyEvent(TCHAR* title, TCHAR* info, HANDLE contact, DWORD flags, std::string url = "");
};
|