From 586cfe1dc5e8ca0aad7c958f311d2a501f10e54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Wed, 6 Aug 2014 12:36:26 +0000 Subject: =?UTF-8?q?Facebook:=20Fixed=20downloading=20bigger=20sizes=20of?= =?UTF-8?q?=20avatars=20(thanks=20Vojt=C4=9Bch=20Kinkor)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.miranda-ng.org/main/trunk@10089 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/avatars.cpp | 58 +++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'protocols/FacebookRM') diff --git a/protocols/FacebookRM/src/avatars.cpp b/protocols/FacebookRM/src/avatars.cpp index ea247fac1f..fbbada49e4 100644 --- a/protocols/FacebookRM/src/avatars.cpp +++ b/protocols/FacebookRM/src/avatars.cpp @@ -38,7 +38,7 @@ bool FacebookProto::GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &ai, std::string * if (!getTString(ai.hContact, FACEBOOK_KEY_ID, &dbv)) { std::string ext = new_url.substr(new_url.rfind('.'), 4); std::tstring filename = GetAvatarFolder() + L'\\' + dbv.ptszVal + (TCHAR*)_A2T(ext.c_str()); - db_free(&dbv); + db_free(&dbv); _tcsncpy_s(ai.filename, filename.c_str(), _TRUNCATE); ai.format = ProtoGetAvatarFormat(ai.filename); @@ -53,35 +53,39 @@ void FacebookProto::CheckAvatarChange(MCONTACT hContact, std::string image_url) // Facebook contacts always have some avatar - keep avatar in database even if we have loaded empty one (e.g. for 'On Mobile' contacts) if (image_url.empty()) return; - + + // First remove all eventual parameters + std::tstring::size_type pos = image_url.find("?"); + if (pos != std::tstring::npos) + image_url = image_url.substr(0, pos); + + utils::text::replace_first(&image_url, "/v/", "/"); + // We've got url to avatar of default size 32x32px, let's change it to bigger one - if (image_url.find("oh=") == std::tstring::npos) { - // We can change avatar size only when there are no parameters (hashes) in URL - if (getBool(FACEBOOK_KEY_BIG_AVATARS, DEFAULT_BIG_AVATARS)) { - // Remove cropping and use bigger size - std::tstring::size_type pos = image_url.find("/t1.0-1/"); - if (pos != std::tstring::npos) { - pos += 8; - - std::tstring::size_type pos2 = image_url.find("/", pos); - if (pos2 != std::tstring::npos && image_url.find("/", pos2 + 1) != std::tstring::npos) - pos2 = image_url.find("/", pos2 + 1); - - // TODO: crop it somehow to square image - - if (pos2 != std::tstring::npos) - image_url.replace(pos, pos2 - pos, "p180x180"); - - // Allow big images - if ((pos = image_url.rfind("_s.")) != std::tstring::npos || (pos = image_url.rfind("_t.")) != std::tstring::npos) { - image_url = image_url.replace(pos, 3, "_q."); - } + if (getBool(FACEBOOK_KEY_BIG_AVATARS, DEFAULT_BIG_AVATARS)) { + // Remove cropping and use bigger size + pos = image_url.find("/t1.0-1/"); + if (pos != std::tstring::npos) { + pos += 8; + + std::tstring::size_type pos2 = image_url.find("/", pos); + if (pos2 != std::tstring::npos && image_url.find("/", pos2 + 1) != std::tstring::npos) + pos2 = image_url.find("/", pos2 + 1); + + // TODO: crop it somehow to square image + + if (pos2 != std::tstring::npos) + image_url.replace(pos, pos2 - pos, "p180x180"); + + // Allow big images + if ((pos = image_url.rfind("_s.")) != std::tstring::npos || (pos = image_url.rfind("_t.")) != std::tstring::npos) { + image_url = image_url.replace(pos, 3, "_q."); } - } else { - // Try to get slighly bigger (but still square) image - utils::text::replace_first(&image_url, ".32.32/", ".50.50/"); - utils::text::replace_first(&image_url, "32x32/", "50x50/"); } + } else { + // Try to get slighly bigger (but still square) image + utils::text::replace_first(&image_url, ".32.32/", ".50.50/"); + utils::text::replace_first(&image_url, "32x32/", "50x50/"); } // Check for avatar change -- cgit v1.2.3