diff options
author | Robert Pösel <robyer@seznam.cz> | 2014-08-07 00:09:52 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2014-08-07 00:09:52 +0000 |
commit | 83a9913e0df76ce771a25e6816f8f8a0a58758f1 (patch) | |
tree | e6122a752923ff7ef9d7ef63fb9dde1b7368ce72 /protocols | |
parent | 868e1f90c63aec0b5a22db8bfd65ed482326b0f4 (diff) |
Facebook: Support for stickers as custom smileys
git-svn-id: http://svn.miranda-ng.org/main/trunk@10102 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/FacebookRM/res/facebook.rc | 2 | ||||
-rw-r--r-- | protocols/FacebookRM/src/constants.h | 1 | ||||
-rw-r--r-- | protocols/FacebookRM/src/json.cpp | 23 | ||||
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 57 | ||||
-rw-r--r-- | protocols/FacebookRM/src/process.cpp | 4 | ||||
-rw-r--r-- | protocols/FacebookRM/src/proto.h | 2 |
6 files changed, 41 insertions, 48 deletions
diff --git a/protocols/FacebookRM/res/facebook.rc b/protocols/FacebookRM/res/facebook.rc index 7241472d5f..1b0bbec481 100644 --- a/protocols/FacebookRM/res/facebook.rc +++ b/protocols/FacebookRM/res/facebook.rc @@ -157,7 +157,7 @@ BEGIN "Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,79,281,10
RTEXT "Use this server for opening links:",IDC_STATIC,13,94,139,8
COMBOBOX IDC_URL_SERVER,156,91,138,59,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
- CONTROL "Enable support for Custom smileys (EXPERIMENTAL + BUGGY!)",IDC_CUSTOM_SMILEYS,
+ CONTROL "Show stickers as custom smileys (EXPERIMENTAL)",IDC_CUSTOM_SMILEYS,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,129,281,10
CONTROL "Use local time for received messages",IDC_USE_LOCAL_TIME,
"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,142,281,10
diff --git a/protocols/FacebookRM/src/constants.h b/protocols/FacebookRM/src/constants.h index 6b24a79736..1f8d7df5bc 100644 --- a/protocols/FacebookRM/src/constants.h +++ b/protocols/FacebookRM/src/constants.h @@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #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_STICKER "http://www.facebook.com/stickers/asset/?sticker_id=%s&image_type=BestEffortImage"
// Connection
#define FACEBOOK_SERVER_REGULAR "www.facebook.com"
diff --git a/protocols/FacebookRM/src/json.cpp b/protocols/FacebookRM/src/json.cpp index 2470738b21..0c2c0024ce 100644 --- a/protocols/FacebookRM/src/json.cpp +++ b/protocols/FacebookRM/src/json.cpp @@ -294,7 +294,7 @@ bool ignore_duplicits(FacebookProto *proto, std::string mid, std::string text) return false; } -void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE *it) +void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE *it, std::string thread_id) { // Process attachements and stickers JSONNODE *has_attachment = json_get(it, "has_attachment"); @@ -333,6 +333,22 @@ void parseAttachments(FacebookProto *proto, std::string *message_text, JSONNODE filename.clear(); attachments_text += "\n" + (!filename.empty() ? "<" + filename + "> " : "") + link + "\n"; + + // Stickers as smileys + if (type == "sticker" && proto->getByte(FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) { + JSONNODE *metadata = json_get(itAttachment, "metadata"); + if (metadata != NULL) { + JSONNODE *stickerId_ = json_get(metadata, "stickerID"); + if (stickerId_ != NULL) { + std::string sticker = "[[sticker:" + json_as_pstring(stickerId_) + "]]"; + attachments_text += sticker; + + // FIXME: rewrite smileyadd to use custom smileys per protocol and not per contact and then remove this ugliness + MCONTACT hContact = proto->ContactIDToHContact(proto->ThreadIDToContactID(thread_id)); + proto->StickerAsSmiley(sticker, link, hContact); + } + } + } } } } @@ -488,11 +504,12 @@ int facebook_json_parser::parse_messages(void* data, std::vector< facebook_messa continue; std::string id = json_as_pstring(sender_fbid); + std::string thread_id = json_as_pstring(tid); std::string message_id = json_as_pstring(mid); std::string message_text = json_as_pstring(body); // Process attachements and stickers - parseAttachments(proto, &message_text, msg); + parseAttachments(proto, &message_text, msg, thread_id); // Ignore duplicits or messages sent from miranda if (body == NULL || ignore_duplicits(proto, message_id, message_text)) @@ -863,7 +880,7 @@ int facebook_json_parser::parse_thread_messages(void* data, std::vector< faceboo author_id = author_id.substr(pos+1); // Process attachements and stickers - parseAttachments(proto, &message_text, it); + parseAttachments(proto, &message_text, it, thread_id); if (json_as_bool(filtered) && message_text.empty()) message_text = Translate("This message is no longer available, because it was marked as abusive or spam."); diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index 841ca24f17..ec11ba3dec 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -3,7 +3,7 @@ Facebook plugin for Miranda Instant Messenger _____________________________________________ -Copyright � 2009-11 Michal Zelinka, 2011-13 Robert P�sel +Copyright © 2009-11 Michal Zelinka, 2011-13 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 @@ -47,8 +47,6 @@ void FacebookProto::SendMsgWorker(void *p) } else if (id == NULL) { ProtoBroadcastAck(data->hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, data->msgid, 0); } else { - //ParseSmileys(data->msg, data->hContact); - int retries = 5; std::string error_text = ""; bool result = false; @@ -196,44 +194,25 @@ void FacebookProto::ReadMessageWorker(void *p) facy.flap(REQUEST_MARK_READ, &data); } -void FacebookProto::ParseSmileys(std::string message, MCONTACT hContact) +void FacebookProto::StickerAsSmiley(std::string sticker, std::string url, MCONTACT hContact) { - if (!getByte(FACEBOOK_KEY_CUSTOM_SMILEYS, DEFAULT_CUSTOM_SMILEYS)) - return; - - HANDLE nlc = NULL; - std::string::size_type pos = 0; - bool anything = false; - while ((pos = message.find("[[", pos)) != std::string::npos) { - std::string::size_type pos2 = message.find("]]", pos); - if (pos2 == std::string::npos) - break; - - std::string smiley = message.substr(pos, pos2+2-pos); - pos = pos2; - - std::string url = FACEBOOK_URL_PICTURE; - utils::text::replace_first(&url, "%s", smiley.substr(2, smiley.length()-4)); - - std::string b64 = ptrA( mir_base64_encode((PBYTE)smiley.c_str(), (unsigned)smiley.length())); - b64 = utils::url::encode(b64); + std::string b64 = ptrA( mir_base64_encode((PBYTE)sticker.c_str(), (unsigned)sticker.length())); + b64 = utils::url::encode(b64); - std::tstring filename = GetAvatarFolder() + L"\\smileys\\" + (TCHAR*)_A2T(b64.c_str()) + _T(".jpg"); - FILE *f = _tfopen(filename.c_str(), _T("r")); - if (f) { - fclose(f); - } else { - facy.save_url(url, filename, nlc); - } - ptrT path( _tcsdup(filename.c_str())); + std::tstring filename = GetAvatarFolder() + _T("\\stickers\\") + (TCHAR*)_A2T(b64.c_str()) + _T(".png"); + + // Check if we have this sticker already and download it it not + if (GetFileAttributes(filename.c_str()) == INVALID_FILE_ATTRIBUTES) { + HANDLE nlc = NULL; + facy.save_url(url, filename, nlc); + Netlib_CloseHandle(nlc); + } - SMADD_CONT cont; - cont.cbSize = sizeof(SMADD_CONT); - cont.hContact = hContact; - cont.type = 1; - cont.path = path; + SMADD_CONT cont; + cont.cbSize = sizeof(SMADD_CONT); + cont.hContact = hContact; + cont.type = 1; + cont.path = ptrT(_tcsdup(filename.c_str())); - CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); - } - Netlib_CloseHandle(nlc); + CallService(MS_SMILEYADD_LOADCONTACTSMILEYS, 0, (LPARAM)&cont); } diff --git a/protocols/FacebookRM/src/process.cpp b/protocols/FacebookRM/src/process.cpp index 357e6dd655..a0a7980da7 100644 --- a/protocols/FacebookRM/src/process.cpp +++ b/protocols/FacebookRM/src/process.cpp @@ -655,8 +655,6 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, boo if (!tid || strcmp(tid, messages[i]->thread_id.c_str())) setString(hChatContact, FACEBOOK_KEY_TID, messages[i]->thread_id.c_str()); - ParseSmileys(messages[i]->message_text, hChatContact); - // TODO: support also system messages (rename chat, user quit, etc.)! (here? or it is somewhere else? // ... we must add some new "type" field into facebook_message structure and use it also for Pokes and similar) UpdateChat(tthread_id.c_str(), messages[i]->user_id.c_str(), messages[i]->sender_name.c_str(), messages[i]->message_text.c_str(), timestamp); @@ -700,8 +698,6 @@ void FacebookProto::ReceiveMessages(std::vector<facebook_message*> messages, boo if (!tid || strcmp(tid, messages[i]->thread_id.c_str())) setString(hContact, FACEBOOK_KEY_TID, messages[i]->thread_id.c_str()); - ParseSmileys(messages[i]->message_text, hContact); - if (messages[i]->isIncoming && messages[i]->isUnread) { PROTORECVEVENT recv = { 0 }; recv.flags = PREF_UTF; diff --git a/protocols/FacebookRM/src/proto.h b/protocols/FacebookRM/src/proto.h index 1472f96539..4a76454214 100644 --- a/protocols/FacebookRM/src/proto.h +++ b/protocols/FacebookRM/src/proto.h @@ -227,7 +227,7 @@ public: bool GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::string *url); void CheckAvatarChange(MCONTACT hContact, std::string image_url); void ToggleStatusMenuItems(BOOL bEnable); - void ParseSmileys(std::string message, MCONTACT hContact); + void StickerAsSmiley(std::string stickerId, std::string url, MCONTACT hContact); void SaveName(MCONTACT hContact, const facebook_user *fbu); void OpenUrl(std::string url); void __cdecl OpenUrlThread(void*); |