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/FacebookRM/src/messages.cpp | |
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/FacebookRM/src/messages.cpp')
-rw-r--r-- | protocols/FacebookRM/src/messages.cpp | 57 |
1 files changed, 18 insertions, 39 deletions
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); } |