summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-12-29 22:19:43 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-12-29 22:19:43 +0300
commitad3174415c91079ff97c73de835aa81573724343 (patch)
tree5f49f630229b1381fa4e1ca7d025171304e2465e
parent8b5aedc9a9697f4138017fd0ecb40b5a6fcbc279 (diff)
fixes #1686 (ICQ10: implement own avatar changing)
-rw-r--r--protocols/Icq10/src/proto.h1
-rw-r--r--protocols/Icq10/src/server.cpp43
-rw-r--r--protocols/Icq10/src/utils.cpp47
3 files changed, 67 insertions, 24 deletions
diff --git a/protocols/Icq10/src/proto.h b/protocols/Icq10/src/proto.h
index 2f34bdc739..b8bf2304b6 100644
--- a/protocols/Icq10/src/proto.h
+++ b/protocols/Icq10/src/proto.h
@@ -65,6 +65,7 @@ struct IcqOwnMessage
class CIcqProto : public PROTO<CIcqProto>
{
bool m_bOnline = false, m_bTerminated = false;
+ void CheckAvatarChange(MCONTACT hContact, const JSONNode&);
void CheckPassword(void);
void ConnectionFailed(int iReason);
void OnLoggedIn(void);
diff --git a/protocols/Icq10/src/server.cpp b/protocols/Icq10/src/server.cpp
index 39a74bdfd1..1889f56a94 100644
--- a/protocols/Icq10/src/server.cpp
+++ b/protocols/Icq10/src/server.cpp
@@ -22,6 +22,20 @@
#pragma comment(lib, "libeay32.lib")
+void CIcqProto::CheckAvatarChange(MCONTACT hContact, const JSONNode &ev)
+{
+ CMStringW wszIconId(ev["iconId"].as_mstring());
+ CMStringW oldIconID(getMStringW(hContact, "IconId"));
+ if (wszIconId != oldIconID) {
+ setWString(hContact, "IconId", wszIconId);
+
+ CMStringA szUrl(ev["buddyIcon"].as_mstring());
+ auto *p = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, szUrl, &CIcqProto::OnReceiveAvatar);
+ p->pUserInfo = (void*)hContact;
+ Push(p);
+ }
+}
+
void CIcqProto::CheckPassword()
{
char mirVer[100];
@@ -102,17 +116,7 @@ MCONTACT CIcqProto::ParseBuddyInfo(const JSONNode &buddy)
else
db_set_ws(hContact, "CList", "StatusMsg", str);
- CMStringW wszIconId(buddy["iconId"].as_mstring());
- CMStringW oldIconID(getMStringW(hContact, "IconId"));
- if (wszIconId != oldIconID) {
- setWString(hContact, "IconId", wszIconId);
-
- CMStringA szUrl(buddy["buddyIcon"].as_mstring());
- auto *p = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, szUrl, &CIcqProto::OnReceiveAvatar);
- p->pUserInfo = (void*)hContact;
- Push(p);
- }
-
+ CheckAvatarChange(hContact, buddy);
return hContact;
}
@@ -520,24 +524,19 @@ void CIcqProto::ProcessMyInfo(const JSONNode &ev)
if (!wszNick.IsEmpty())
setWString("Nick", wszNick);
- CMStringW wszIconId(ev["iconId"].as_mstring());
- CMStringW oldIconID(getMStringW("IconId"));
- if (wszIconId != oldIconID) {
- setWString("IconId", wszIconId);
-
- CMStringA szUrl(ev["buddyIcon"].as_mstring());
- Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, szUrl, &CIcqProto::OnReceiveAvatar));
- }
+ CheckAvatarChange(0, ev);
}
void CIcqProto::ProcessPresence(const JSONNode &ev)
{
DWORD dwUin = _wtol(ev["aimId"].as_mstring());
- int iStatus = StatusFromString(ev["state"].as_mstring());
IcqCacheItem *pCache = FindContactByUIN(dwUin);
- if (pCache)
- setDword(pCache->m_hContact, "Status", iStatus);
+ if (pCache) {
+ setDword(pCache->m_hContact, "Status", StatusFromString(ev["state"].as_mstring()));
+
+ CheckAvatarChange(pCache->m_hContact, ev);
+ }
}
void CIcqProto::ProcessTyping(const JSONNode &ev)
diff --git a/protocols/Icq10/src/utils.cpp b/protocols/Icq10/src/utils.cpp
index d3364dd58c..49c9ad0d03 100644
--- a/protocols/Icq10/src/utils.cpp
+++ b/protocols/Icq10/src/utils.cpp
@@ -137,9 +137,52 @@ INT_PTR __cdecl CIcqProto::GetAvatarInfo(WPARAM, LPARAM lParam)
return GAIR_NOAVATAR;
}
-INT_PTR __cdecl CIcqProto::SetAvatar(WPARAM, LPARAM)
+INT_PTR __cdecl CIcqProto::SetAvatar(WPARAM, LPARAM lParam)
{
- return 1; // TODO
+ wchar_t* pwszFileName = (wchar_t*)lParam;
+
+ wchar_t wszOldName[MAX_PATH];
+ GetAvatarFileName(0, wszOldName, _countof(wszOldName));
+ _wremove(wszOldName);
+
+ auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_POST, ICQ_API_SERVER "/expressions/upload");
+ pReq->m_szUrl.AppendFormat("?f=json&aimsid=%s&r=%s&type=largeBuddyIcon", ptrA(mir_urlEncode(m_aimsid.c_str())), pReq->m_reqId);
+
+ if (pwszFileName == nullptr)
+ delSetting("AvatarHash");
+ else {
+ int fileId = _wopen(pwszFileName, _O_RDONLY | _O_BINARY, _S_IREAD);
+ if (fileId < 0) {
+ delete pReq;
+ return 1;
+ }
+
+ unsigned dwSize = (unsigned)_filelengthi64(fileId);
+ char* pData = (char*)mir_alloc(dwSize);
+ if (pData == nullptr) {
+ _close(fileId);
+ delete pReq;
+ return 2;
+ }
+
+ _read(fileId, pData, dwSize);
+ _close(fileId);
+
+ pReq->pData = pData;
+ pReq->dataLength = dwSize;
+
+ int iAvatarType = ProtoGetBufferFormat(pData);
+ if (iAvatarType == PA_FORMAT_UNKNOWN) {
+ delete pReq;
+ delete pData;
+ return 3;
+ }
+
+ pReq->AddHeader("Content-Type", _T2A(ProtoGetAvatarMimeType(iAvatarType)));
+ }
+ Push(pReq);
+
+ return 0; // TODO
}
/////////////////////////////////////////////////////////////////////////////////////////