From b9eed106e74a7725f57b8175bc580a1520e1fe24 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 23 Jan 2014 20:29:14 +0000 Subject: patch for avatars reading optimization (by wsx22) git-svn-id: http://svn.miranda-ng.org/main/trunk@7843 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- include/delphi/m_avatars.inc | 13 +++++++++---- include/m_avatars.h | 15 ++++++++++----- plugins/AVS/src/poll.cpp | 7 ++++--- plugins/AVS/src/utils.cpp | 12 ++++++++++-- protocols/AimOscar/src/services.cpp | 3 ++- protocols/FacebookRM/src/avatars.cpp | 3 ++- protocols/Gadu-Gadu/src/services.cpp | 3 ++- protocols/IcqOscarJ/src/icqosc_svcs.cpp | 3 ++- protocols/Skype/src/skype_avatars.cpp | 3 ++- protocols/Tlen/src/tlen_svc.cpp | 6 +++--- protocols/VKontakte/src/vk_avatars.cpp | 3 ++- 11 files changed, 48 insertions(+), 23 deletions(-) diff --git a/include/delphi/m_avatars.inc b/include/delphi/m_avatars.inc index d9a7bb7328..595f65dd70 100644 --- a/include/delphi/m_avatars.inc +++ b/include/delphi/m_avatars.inc @@ -41,7 +41,7 @@ have been disabled in the option dialog). It also does not actively fetch avatars for protocols which are in invisible status mode (may cause privacy issues and some protocols like MSN don't allow any outbound client communication when in invisible status mode) - unless AF_FETCHALWAYS is set. + unless AF_FETCHIFPROTONOTVISIBLE is set. - TODO - maintain recent avatars (store the last hashes to avoid re-fetching) @@ -379,11 +379,16 @@ const // return = the time, in ms AF_DELAYAFTERFAIL = 7; -// Fetching avatars is always possible and allowed +// Fetching avatars is allowed when protocol's status is invisible // lParam = 0 -// return = 1 (always) or 0 (depending on our or contacts status mode) - AF_FETCHALWAYS = 8; +// return = 1 (allowed) or 0 (depending on our protocol status mode) + AF_FETCHIFPROTONOTVISIBLE = 8; +// Fetching avatars is allowed when contact is in offline status +// lParam = 0 +// return = 1 (allowed) or 0 (depending on remote contact status mode) + AF_FETCHIFCONTACTOFFLINE = 9; + { Query avatar caps for a protocol wParam = One of AF_* diff --git a/include/m_avatars.h b/include/m_avatars.h index ce5fd20949..a91ca7ffb4 100644 --- a/include/m_avatars.h +++ b/include/m_avatars.h @@ -43,7 +43,7 @@ protocols which do not report avatar capabilities via PF4_AVATARS or for protoco have been disabled in the option dialog). It also does not actively fetch avatars for protocols which are in invisible status mode (may cause privacy issues and some protocols like MSN don't allow any outbound client communication when in invisible status mode) -unless AF_FETCHALWAYS is set. +unless AF_FETCHIFPROTONOTVISIBLE is set. - TODO - maintain recent avatars (store the last hashes to avoid re-fetching) @@ -218,7 +218,7 @@ typedef struct _contactAvatarChangedNotification { // fired when the contacts avatar is changed by the contact // wParam = hContact -// lParam = struct CONTACTAVATARCHANGENOTIFICATION *cacn +// lParam = struct CONTACTAVATARCHANGEDNOTIFICATION *cacn // the event CAN pass a NULL pointer in lParam which means that the contact deleted its avatar #define ME_AV_CONTACTAVATARCHANGED "SV_Avatars/ContactAvatarChanged" @@ -350,10 +350,15 @@ return=0 for sucess // return = the time, in ms #define AF_DELAYAFTERFAIL 7 -// Fetching avatars is always possible and allowed +// Fetching avatars is allowed when protocol's status is invisible // lParam = 0 -// return = 1 (always) or 0 (depending on our or contacts status mode) -#define AF_FETCHALWAYS 8 +// return = 1 (allowed) or 0 (depending on our protocol status mode) +#define AF_FETCHIFPROTONOTVISIBLE 8 + +// Fetching avatars is allowed when contact is in offline status +// lParam = 0 +// return = 1 (allowed) or 0 (depending on remote contact status mode) +#define AF_FETCHIFCONTACTOFFLINE 9 /* diff --git a/plugins/AVS/src/poll.cpp b/plugins/AVS/src/poll.cpp index 840c3d78b9..beefe4e8ee 100644 --- a/plugins/AVS/src/poll.cpp +++ b/plugins/AVS/src/poll.cpp @@ -48,7 +48,8 @@ extern HANDLE hShutdownEvent; extern int DeleteAvatar(HANDLE hContact); extern void MakePathRelative(HANDLE hContact, TCHAR *path); int Proto_GetDelayAfterFail(const char *proto); -BOOL Proto_IsFetchingAlwaysAllowed(const char *proto); +BOOL Proto_IsFetchingWhenProtoNotVisibleAllowed(const char *proto); +BOOL Proto_IsFetchingWhenContactOfflineAllowed(const char *proto); #ifdef _DEBUG int _DebugTrace(const char *fmt, ...); @@ -89,7 +90,7 @@ static BOOL PollProtocolCanHaveAvatar(const char *szProto) int status = CallProtoService(szProto, PS_GETSTATUS, 0, 0); return (pCaps & PF4_AVATARS) && (g_szMetaName == NULL || strcmp(g_szMetaName, szProto)) - && ((status > ID_STATUS_OFFLINE && status != ID_STATUS_INVISIBLE) || Proto_IsFetchingAlwaysAllowed(szProto)); + && ((status > ID_STATUS_OFFLINE && status != ID_STATUS_INVISIBLE) || Proto_IsFetchingWhenProtoNotVisibleAllowed(szProto)); } // Return true if this protocol has to be checked @@ -102,7 +103,7 @@ static BOOL PollCheckProtocol(const char *szProto) static BOOL PollContactCanHaveAvatar(HANDLE hContact, const char *szProto) { int status = db_get_w(hContact, szProto, "Status", ID_STATUS_OFFLINE); - return (Proto_IsFetchingAlwaysAllowed(szProto) || status != ID_STATUS_OFFLINE) + return (Proto_IsFetchingWhenContactOfflineAllowed(szProto) || status != ID_STATUS_OFFLINE) && !db_get_b(hContact, "CList", "NotOnList", 0) && db_get_b(hContact, "CList", "ApparentMode", 0) != ID_STATUS_OFFLINE; } diff --git a/plugins/AVS/src/utils.cpp b/plugins/AVS/src/utils.cpp index ab79fc7b85..e72921dc62 100644 --- a/plugins/AVS/src/utils.cpp +++ b/plugins/AVS/src/utils.cpp @@ -475,10 +475,18 @@ int Proto_GetDelayAfterFail(const char *proto) return 0; } -BOOL Proto_IsFetchingAlwaysAllowed(const char *proto) +BOOL Proto_IsFetchingWhenProtoNotVisibleAllowed(const char *proto) { if ( ProtoServiceExists(proto, PS_GETAVATARCAPS)) - return CallProtoService(proto, PS_GETAVATARCAPS, AF_FETCHALWAYS, 0); + return CallProtoService(proto, PS_GETAVATARCAPS, AF_FETCHIFPROTONOTVISIBLE, 0); + + return FALSE; +} + +BOOL Proto_IsFetchingWhenContactOfflineAllowed(const char *proto) +{ + if ( ProtoServiceExists(proto, PS_GETAVATARCAPS)) + return CallProtoService(proto, PS_GETAVATARCAPS, AF_FETCHIFCONTACTOFFLINE, 0); return FALSE; } diff --git a/protocols/AimOscar/src/services.cpp b/protocols/AimOscar/src/services.cpp index eeac20232e..05ab61d12e 100644 --- a/protocols/AimOscar/src/services.cpp +++ b/protocols/AimOscar/src/services.cpp @@ -424,7 +424,8 @@ INT_PTR CAimProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) case AF_ENABLED: case AF_DONTNEEDDELAYS: - case AF_FETCHALWAYS: + case AF_FETCHIFPROTONOTVISIBLE: + case AF_FETCHIFCONTACTOFFLINE: res = 1; break; } diff --git a/protocols/FacebookRM/src/avatars.cpp b/protocols/FacebookRM/src/avatars.cpp index ab9011b8b4..196497a291 100644 --- a/protocols/FacebookRM/src/avatars.cpp +++ b/protocols/FacebookRM/src/avatars.cpp @@ -165,7 +165,8 @@ INT_PTR FacebookProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) case AF_ENABLED: case AF_DONTNEEDDELAYS: - case AF_FETCHALWAYS: + case AF_FETCHIFPROTONOTVISIBLE: + case AF_FETCHIFCONTACTOFFLINE: res = 1; break; } diff --git a/protocols/Gadu-Gadu/src/services.cpp b/protocols/Gadu-Gadu/src/services.cpp index 3a1ae69ecd..f666244462 100644 --- a/protocols/Gadu-Gadu/src/services.cpp +++ b/protocols/Gadu-Gadu/src/services.cpp @@ -162,7 +162,8 @@ INT_PTR GGPROTO::getavatarcaps(WPARAM wParam, LPARAM lParam) return 1; case AF_MAXFILESIZE: return 307200; - case AF_FETCHALWAYS: + case AF_FETCHIFPROTONOTVISIBLE: + case AF_FETCHIFCONTACTOFFLINE: return 1; } return 0; diff --git a/protocols/IcqOscarJ/src/icqosc_svcs.cpp b/protocols/IcqOscarJ/src/icqosc_svcs.cpp index 9c71183f02..485e41a908 100644 --- a/protocols/IcqOscarJ/src/icqosc_svcs.cpp +++ b/protocols/IcqOscarJ/src/icqosc_svcs.cpp @@ -361,7 +361,8 @@ INT_PTR CIcqProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) return 1 * 60 * 60 * 1000; // one hour // avatars can be fetched all the time (server only operation) - if (wParam == AF_FETCHALWAYS) + if (wParam == AF_FETCHIFPROTONOTVISIBLE) + if (wParam == AF_FETCHIFCONTACTOFFLINE) return 1; return 0; diff --git a/protocols/Skype/src/skype_avatars.cpp b/protocols/Skype/src/skype_avatars.cpp index 9ca9b0dddd..a42bd24dc3 100644 --- a/protocols/Skype/src/skype_avatars.cpp +++ b/protocols/Skype/src/skype_avatars.cpp @@ -98,7 +98,8 @@ INT_PTR __cdecl CSkypeProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam) // do not request avatar again if server gave an error return 1;// * 60 * 60 * 1000; // one hour - case AF_FETCHALWAYS: + case AF_FETCHIFPROTONOTVISIBLE: + case AF_FETCHIFCONTACTOFFLINE: // avatars can be fetched all the time (server only operation) return 1; } diff --git a/protocols/Tlen/src/tlen_svc.cpp b/protocols/Tlen/src/tlen_svc.cpp index 7ee18ce37c..4fcd953033 100644 --- a/protocols/Tlen/src/tlen_svc.cpp +++ b/protocols/Tlen/src/tlen_svc.cpp @@ -688,7 +688,7 @@ INT_PTR TlenProtocol::GetAvatarInfo(WPARAM wParam, LPARAM lParam) if ((avatarHash == NULL || avatarHash[0] == '\0') && !downloadingAvatar) return GAIR_NOAVATAR; - + if (avatarHash != NULL && !downloadingAvatar) { TlenGetAvatarFileName(this, item, AI->filename, sizeof(AI->filename)); AI->format = ( AI->hContact == NULL ) ? threadData->avatarFormat : item->avatarFormat; @@ -1156,8 +1156,8 @@ INT_PTR TlenProtocol::GetAvatarCaps(WPARAM wParam, LPARAM lParam) return 1; case AF_MAXFILESIZE: return 10 * 1024; - case AF_DELAYAFTERFAIL: - return 0; + case AF_FETCHIFCONTACTOFFLINE: + return 1; } return 0; } diff --git a/protocols/VKontakte/src/vk_avatars.cpp b/protocols/VKontakte/src/vk_avatars.cpp index dfd4939692..3784b08b8c 100644 --- a/protocols/VKontakte/src/vk_avatars.cpp +++ b/protocols/VKontakte/src/vk_avatars.cpp @@ -51,7 +51,8 @@ INT_PTR CVkProto::SvcGetAvatarCaps(WPARAM wParam, LPARAM lParam) case AF_FORMATSUPPORTED: case AF_ENABLED: case AF_DONTNEEDDELAYS: - case AF_FETCHALWAYS: + case AF_FETCHIFPROTONOTVISIBLE: + case AF_FETCHIFCONTACTOFFLINE: return 1; } -- cgit v1.2.3