summaryrefslogtreecommitdiff
path: root/protocols/WhatsApp/src/proto.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2015-01-28 23:20:50 +0000
committerGeorge Hazan <george.hazan@gmail.com>2015-01-28 23:20:50 +0000
commitebbf4ad769d99f07c6d5184d9fe4323e7eaf0246 (patch)
tree23edc80f39815511a97dc5c111564422b3a570da /protocols/WhatsApp/src/proto.cpp
parent998a7c4af898008db19fa3870c1df97d28b33eec (diff)
avatars are back
git-svn-id: http://svn.miranda-ng.org/main/trunk@11943 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/WhatsApp/src/proto.cpp')
-rw-r--r--protocols/WhatsApp/src/proto.cpp68
1 files changed, 65 insertions, 3 deletions
diff --git a/protocols/WhatsApp/src/proto.cpp b/protocols/WhatsApp/src/proto.cpp
index fcd64ebd8a..eaf6b3d358 100644
--- a/protocols/WhatsApp/src/proto.cpp
+++ b/protocols/WhatsApp/src/proto.cpp
@@ -21,6 +21,9 @@ WhatsAppProto::WhatsAppProto(const char* proto_name, const TCHAR* username) :
CreateProtoService(PS_JOINCHAT, &WhatsAppProto::OnJoinChat);
CreateProtoService(PS_LEAVECHAT, &WhatsAppProto::OnLeaveChat);
+ CreateProtoService(PS_GETAVATARINFOT, &WhatsAppProto::GetAvatarInfo);
+ CreateProtoService(PS_GETAVATARCAPS, &WhatsAppProto::GetAvatarCaps);
+
HookProtoEvent(ME_OPT_INITIALISE, &WhatsAppProto::OnOptionsInit);
HookProtoEvent(ME_SYSTEM_MODULESLOADED, &WhatsAppProto::OnModulesLoaded);
HookProtoEvent(ME_CLIST_PREBUILDSTATUSMENU, &WhatsAppProto::OnBuildStatusMenu);
@@ -41,7 +44,10 @@ WhatsAppProto::WhatsAppProto(const char* proto_name, const TCHAR* username) :
WASocketConnection::initNetwork(m_hNetlibUser);
- def_avatar_folder_ = std::tstring(VARST(_T("%miranda_avatarcache%"))) + _T("\\") + m_tszUserName;
+ m_tszAvatarFolder = std::tstring(VARST(_T("%miranda_avatarcache%"))) + _T("\\") + m_tszUserName;
+ DWORD dwAttributes = GetFileAttributes(m_tszAvatarFolder.c_str());
+ if (dwAttributes == 0xffffffff || (dwAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
+ CreateDirectoryTreeT(m_tszAvatarFolder.c_str());
SetAllContactStatuses(ID_STATUS_OFFLINE, true);
}
@@ -348,9 +354,65 @@ void WhatsAppProto::RequestFriendship(MCONTACT hContact)
}
}
-std::tstring WhatsAppProto::GetAvatarFolder()
+INT_PTR WhatsAppProto::GetAvatarInfo(WPARAM wParam, LPARAM lParam)
+{
+ PROTO_AVATAR_INFORMATIONT* AI = (PROTO_AVATAR_INFORMATIONT*)lParam;
+
+ ptrA id(getStringA(AI->hContact, WHATSAPP_KEY_ID));
+ if (id == NULL)
+ return GAIR_NOAVATAR;
+
+ std::tstring tszFileName = GetAvatarFileName(AI->hContact);
+ _tcsncpy_s(AI->filename, tszFileName.c_str(), _TRUNCATE);
+ AI->format = PA_FORMAT_JPEG;
+
+ ptrA szAvatarId(getStringA(AI->hContact, WHATSAPP_KEY_AVATAR_ID));
+ if (szAvatarId == NULL || (wParam & GAIF_FORCE) != 0)
+ if (AI->hContact != NULL && m_pConnection != NULL) {
+ m_pConnection->sendGetPicture((const char*)id, "image");
+ return GAIR_WAITFOR;
+ }
+
+ debugLogA("No avatar");
+ return GAIR_NOAVATAR;
+}
+
+INT_PTR WhatsAppProto::GetAvatarCaps(WPARAM wParam, LPARAM lParam)
+{
+ switch (wParam) {
+ case AF_PROPORTION:
+ return PIP_SQUARE;
+
+ case AF_FORMATSUPPORTED: // Jabber supports avatars of virtually all formats
+ return PA_FORMAT_JPEG;
+
+ case AF_ENABLED:
+ return TRUE;
+
+ case AF_MAXSIZE:
+ POINT *size = (POINT*)lParam;
+ if (size)
+ size->x = size->y = 96;
+ return 0;
+ }
+ return -1;
+}
+
+std::tstring WhatsAppProto::GetAvatarFileName(MCONTACT hContact)
{
- return def_avatar_folder_;
+ std::tstring result = m_tszAvatarFolder + _T("\\");
+
+ std::string jid;
+ if (hContact != NULL) {
+ ptrA szId(getStringA(hContact, "ID"));
+ if (szId == NULL)
+ return _T("");
+
+ jid = szId;
+ }
+ else jid = this->jid;
+
+ return result + std::tstring(_A2T(jid.c_str())) + _T(".jpg");
}
LRESULT CALLBACK PopupDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)