From 40b63e431bc8c68c91a32ca7a62337b97da30b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sun, 18 May 2014 09:47:16 +0000 Subject: Facebook: Refactor getting small avatars Now they are always square, 50x50 or 32x32 (if we couldn't get bigger one). git-svn-id: http://svn.miranda-ng.org/main/trunk@9216 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/FacebookRM/src/avatars.cpp | 85 +++++++++++++++++------------------ protocols/FacebookRM/src/contacts.cpp | 3 +- 2 files changed, 41 insertions(+), 47 deletions(-) (limited to 'protocols/FacebookRM') diff --git a/protocols/FacebookRM/src/avatars.cpp b/protocols/FacebookRM/src/avatars.cpp index f02a4a2e52..c0ac06fd22 100644 --- a/protocols/FacebookRM/src/avatars.cpp +++ b/protocols/FacebookRM/src/avatars.cpp @@ -54,55 +54,50 @@ void FacebookProto::CheckAvatarChange(MCONTACT hContact, std::string image_url) if (image_url.empty()) return; - bool big_avatars = getBool(FACEBOOK_KEY_BIG_AVATARS, DEFAULT_BIG_AVATARS); - // We've got url to avatar of default size 32x32px, let's change it to bigger one - std::tstring::size_type pos, pos2; - - // Remove cropping and use bigger size - pos = image_url.find("/t1.0-1/"); - if (pos != std::tstring::npos) { - pos += 8; - - 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, big_avatars ? "p180x180" : "p50x50"); + 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."); + } + } + } 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/"); + } } - // Allow big images - pos = image_url.rfind("_s."); - if (pos == std::tstring::npos) - pos = image_url.rfind("_t."); - - if (pos != std::tstring::npos) - image_url = image_url.replace(pos, 3, "_q."); - - DBVARIANT dbv; - bool update_required = true; - if (!getString(hContact, FACEBOOK_KEY_AV_URL, &dbv)) - { - update_required = image_url != dbv.pszVal; - db_free(&dbv); - } - if (update_required || !hContact) - { + // Check for avatar change + ptrA old_url(getStringA(hContact, FACEBOOK_KEY_AV_URL)); + bool update_required = (old_url == NULL || image_url.compare(old_url) != 0); + + if (update_required) setString(hContact, FACEBOOK_KEY_AV_URL, image_url.c_str()); - if (hContact) - { - db_set_b(hContact, "ContactPhoto", "NeedUpdate", 1); - ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0); - } - else - { - PROTO_AVATAR_INFORMATIONT ai = {sizeof(ai)}; - if (GetAvatarInfo(update_required ? GAIF_FORCE : 0, (LPARAM)&ai) != GAIR_WAITFOR) - CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName, 0); - } + + if (!hContact) { + PROTO_AVATAR_INFORMATIONT ai = { sizeof(ai) }; + if (GetAvatarInfo(update_required ? GAIF_FORCE : 0, (LPARAM)&ai) != GAIR_WAITFOR) + CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName, 0); + } else if (update_required) { + db_set_b(hContact, "ContactPhoto", "NeedUpdate", 1); + ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_STATUS, NULL, 0); } } diff --git a/protocols/FacebookRM/src/contacts.cpp b/protocols/FacebookRM/src/contacts.cpp index 07c123b6c5..5c82419ac1 100644 --- a/protocols/FacebookRM/src/contacts.cpp +++ b/protocols/FacebookRM/src/contacts.cpp @@ -222,8 +222,7 @@ MCONTACT FacebookProto::AddToContactList(facebook_user* fbu, ContactType type, b if (fbu->gender) setByte(hContact, "Gender", fbu->gender); - if (!fbu->image_url.empty()) - setString(hContact, FACEBOOK_KEY_AV_URL, fbu->image_url.c_str()); + CheckAvatarChange(hContact, fbu->image_url); } return hContact; -- cgit v1.2.3