diff options
author | George Hazan <ghazan@miranda.im> | 2019-01-14 19:25:59 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-01-14 19:25:59 +0300 |
commit | e83b486418ad19cb38191dff491d827b39aa8a77 (patch) | |
tree | db27edd3bfd271987250d41f38172acf99e23784 /protocols | |
parent | 5099d733650bb2634596e33c309f5f1ec9acaac7 (diff) |
ICQ10:
- groups' list added;
- code cleaning
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/Icq10/src/groupchats.cpp | 2 | ||||
-rw-r--r-- | protocols/Icq10/src/http.h | 1 | ||||
-rw-r--r-- | protocols/Icq10/src/proto.cpp | 12 | ||||
-rw-r--r-- | protocols/Icq10/src/proto.h | 15 | ||||
-rw-r--r-- | protocols/Icq10/src/server.cpp | 65 |
5 files changed, 55 insertions, 40 deletions
diff --git a/protocols/Icq10/src/groupchats.cpp b/protocols/Icq10/src/groupchats.cpp index 0951df4d0f..5d4253bc15 100644 --- a/protocols/Icq10/src/groupchats.cpp +++ b/protocols/Icq10/src/groupchats.cpp @@ -145,7 +145,7 @@ public: if (m_clc.GetCheck(hItem)) { if (!szMembers.IsEmpty()) szMembers.AppendChar(','); - szMembers.AppendFormat("%d", m_proto->getDword(hContact, DB_KEY_UIN)); + szMembers.Append(m_proto->GetUserId(hContact)); } } } diff --git a/protocols/Icq10/src/http.h b/protocols/Icq10/src/http.h index 58dbba4060..bdcac34f50 100644 --- a/protocols/Icq10/src/http.h +++ b/protocols/Icq10/src/http.h @@ -9,6 +9,7 @@ enum IcqConnection struct AsyncHttpRequest : public MTHttpRequest<CIcqProto> { IcqConnection m_conn; + MCONTACT hContact; char m_reqId[50]; AsyncHttpRequest(IcqConnection, int type, const char *szUrl, MTHttpRequestHandler pFunc = nullptr); diff --git a/protocols/Icq10/src/proto.cpp b/protocols/Icq10/src/proto.cpp index 4b0aa787f0..a5c99219aa 100644 --- a/protocols/Icq10/src/proto.cpp +++ b/protocols/Icq10/src/proto.cpp @@ -38,6 +38,7 @@ CIcqProto::CIcqProto(const char* aProtoName, const wchar_t* aUserName) : m_arHttpQueue(10), m_arOwnIds(1), m_arCache(20, NumericKeySortT), + m_arGroups(10, NumericKeySortT), arMarkReadQueue(10, NumericKeySortT), m_evRequestsQueue(CreateEvent(nullptr, FALSE, FALSE, nullptr)), m_dwUin(this, DB_KEY_UIN, 0), @@ -117,12 +118,9 @@ void CIcqProto::MarkReadTimerProc(HWND hwnd, UINT, UINT_PTR id, DWORD) while (ppro->arMarkReadQueue.getCount()) { IcqCacheItem *pUser = ppro->arMarkReadQueue[0]; - char buf[100]; - itoa(ppro->getDword(pUser->m_hContact, DB_KEY_UIN), buf, 10); - auto *pReq = new AsyncHttpRequest(CONN_RAPI, REQUEST_POST, ICQ_ROBUST_SERVER); JSONNode request, params; params.set_name("params"); - params << CHAR_PARAM("sn", buf) << INT64_PARAM("lastRead", ppro->getId(pUser->m_hContact, DB_KEY_LASTMSGID)); + params << CHAR_PARAM("sn", ppro->GetUserId(pUser->m_hContact)) << INT64_PARAM("lastRead", ppro->getId(pUser->m_hContact, DB_KEY_LASTMSGID)); request << CHAR_PARAM("method", "setDlgStateWim") << CHAR_PARAM("reqId", pReq->m_reqId) << CHAR_PARAM("authToken", ppro->m_szRToken) << INT_PARAM("clientId", ppro->m_iRClientId) << params; pReq->m_szParam = ptrW(json_write(&request)); @@ -186,9 +184,9 @@ int CIcqProto::AuthRequest(MCONTACT hContact, const wchar_t* szMessage) { auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_POST, ICQ_API_SERVER "/buddylist/addBuddy", &CIcqProto::OnAddBuddy); pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("r", pReq->m_reqId) << WCHAR_PARAM("authorizationMsg", szMessage) - << INT_PARAM("buddy", getDword(hContact, DB_KEY_UIN)) << CHAR_PARAM("group", "General") << INT_PARAM("preAuthorized", 1); + << CHAR_PARAM("buddy", GetUserId(hContact)) << CHAR_PARAM("group", "General") << INT_PARAM("preAuthorized", 1); pReq->flags |= NLHRF_NODUMPSEND; - pReq->pUserInfo = (void*)hContact; + pReq->hContact = hContact; Push(pReq); return 0; } @@ -408,7 +406,7 @@ int CIcqProto::UserIsTyping(MCONTACT hContact, int type) auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/im/setTyping"); pReq->flags |= NLHRF_NODUMPSEND; pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("f", "json") - << INT_PARAM("t", getDword(hContact, DB_KEY_UIN)) << CHAR_PARAM("r", pReq->m_reqId) + << CHAR_PARAM("t", GetUserId(hContact)) << CHAR_PARAM("r", pReq->m_reqId) << CHAR_PARAM("typingStatus", (type == PROTOTYPE_SELFTYPING_ON) ? "typing" : "typed"); Push(pReq); return 0; diff --git a/protocols/Icq10/src/proto.h b/protocols/Icq10/src/proto.h index 70f0c9855f..dbb7e24bf9 100644 --- a/protocols/Icq10/src/proto.h +++ b/protocols/Icq10/src/proto.h @@ -42,6 +42,20 @@ enum ChatMenuItems IDM_INVITE = 10, IDM_LEAVE }; +struct IcqGroup +{ + IcqGroup(int icqId, const CMStringW &wszName) : + m_iIcqId(icqId), + m_wszName(wszName) + { + m_iMirId = ::Clist_GroupExists(wszName); + } + + MGROUP m_iMirId; + int m_iIcqId; + CMStringW m_wszName; +}; + struct IcqCacheItem { IcqCacheItem(DWORD _uin, MCONTACT _contact) : @@ -171,6 +185,7 @@ class CIcqProto : public PROTO<CIcqProto> mir_cs m_csCache; OBJLIST<IcqCacheItem> m_arCache; + OBJLIST<IcqGroup> m_arGroups; void InitContactCache(void); IcqCacheItem* FindContactByUIN(DWORD); diff --git a/protocols/Icq10/src/server.cpp b/protocols/Icq10/src/server.cpp index 6033b73b14..3c9a12215c 100644 --- a/protocols/Icq10/src/server.cpp +++ b/protocols/Icq10/src/server.cpp @@ -30,9 +30,9 @@ void CIcqProto::CheckAvatarChange(MCONTACT hContact, const JSONNode &ev) 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); + auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, szUrl, &CIcqProto::OnReceiveAvatar); + pReq->hContact = hContact; + Push(pReq); } } @@ -307,8 +307,8 @@ void CIcqProto::RetrieveUserInfo(MCONTACT hContact) { auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/presence/get", &CIcqProto::OnGetUserInfo); pReq->flags |= NLHRF_NODUMPSEND; - pReq->pUserInfo = (void*)hContact; - pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << INT_PARAM("mdir", 1) << INT_PARAM("t", getDword(hContact, DB_KEY_UIN)); + pReq->hContact = hContact; + pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << INT_PARAM("mdir", 1) << CHAR_PARAM("t", GetUserId(hContact)); Push(pReq); } @@ -323,14 +323,11 @@ void CIcqProto::RetrieveUserHistory(MCONTACT hContact, __int64 startMsgId, __int return; auto *pReq = new AsyncHttpRequest(CONN_RAPI, REQUEST_POST, ICQ_ROBUST_SERVER, &CIcqProto::OnGetUserHistory); - //pReq->flags |= NLHRF_NODUMPSEND; - pReq->pUserInfo = (void*)hContact; - - char buf[100]; - itoa(getDword(hContact, DB_KEY_UIN), buf, 10); + pReq->flags |= NLHRF_NODUMPSEND; + pReq->hContact = hContact; JSONNode request, params; params.set_name("params"); - params << CHAR_PARAM("sn", buf) << INT64_PARAM("fromMsgId", startMsgId); + params << CHAR_PARAM("sn", GetUserId(hContact)) << INT64_PARAM("fromMsgId", startMsgId); if (endMsgId != -1) params << INT64_PARAM("tillMsgId", endMsgId); params << INT_PARAM("count", 1000) << CHAR_PARAM("aimSid", m_aimsid) << CHAR_PARAM("patchVersion", "1") << CHAR_PARAM("language", "ru-ru"); @@ -422,12 +419,10 @@ void CIcqProto::StartSession() void CIcqProto::OnAddBuddy(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) { - MCONTACT hContact = (MCONTACT)pReq->pUserInfo; - JsonReply root(pReply); if (root.error() == 200) { - RetrieveUserInfo(getDword(hContact, DB_KEY_UIN)); - db_unset(hContact, "CList", "NotOnList"); + RetrieveUserInfo(pReq->hContact); + db_unset(pReq->hContact, "CList", "NotOnList"); } } @@ -487,36 +482,32 @@ void CIcqProto::OnCheckPassword(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*) void CIcqProto::OnGetUserHistory(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) { - MCONTACT hContact = (MCONTACT)pReq->pUserInfo; - RobustReply root(pReply); if (root.error() != 20000) return; - __int64 lastMsgId = getId(hContact, DB_KEY_LASTMSGID); + __int64 lastMsgId = getId(pReq->hContact, DB_KEY_LASTMSGID); const JSONNode &results = root.results(); for (auto &it : results["messages"]) - ParseMessage(hContact, lastMsgId, it); + ParseMessage(pReq->hContact, lastMsgId, it); - setId(hContact, DB_KEY_LASTMSGID, lastMsgId); + setId(pReq->hContact, DB_KEY_LASTMSGID, lastMsgId); } void CIcqProto::OnGetUserInfo(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) { - MCONTACT hContact = (MCONTACT)pReq->pUserInfo; - JsonReply root(pReply); if (root.error() != 200) { - ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, nullptr); + ProtoBroadcastAck(pReq->hContact, ACKTYPE_GETINFO, ACKRESULT_FAILED, nullptr); return; } const JSONNode &data = root.data(); for (auto &it : data["users"]) - ParseBuddyInfo(it, hContact); + ParseBuddyInfo(it, pReq->hContact); - ProtoBroadcastAck(hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, nullptr); + ProtoBroadcastAck(pReq->hContact, ACKTYPE_GETINFO, ACKRESULT_SUCCESS, nullptr); } void CIcqProto::OnStartSession(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*) @@ -554,20 +545,19 @@ void CIcqProto::OnStartSession(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*) void CIcqProto::OnReceiveAvatar(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) { - MCONTACT hContact = (MCONTACT)pReq->pUserInfo; PROTO_AVATAR_INFORMATION ai = {}; - ai.hContact = hContact; + ai.hContact = pReq->hContact; if (pReply->resultCode != 200 || pReply->pData == nullptr) { LBL_Error: - ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, HANDLE(&ai), 0); + ProtoBroadcastAck(pReq->hContact, ACKTYPE_AVATAR, ACKRESULT_FAILED, HANDLE(&ai), 0); return; } const wchar_t *pwszExtension; ai.format = ProtoGetBufferFormat(pReply->pData, &pwszExtension); - setByte(hContact, "AvatarType", ai.format); - GetAvatarFileName(hContact, ai.filename, _countof(ai.filename)); + setByte(pReq->hContact, "AvatarType", ai.format); + GetAvatarFileName(pReq->hContact, ai.filename, _countof(ai.filename)); FILE *out = _wfopen(ai.filename, L"wb"); if (out == nullptr) @@ -576,8 +566,8 @@ LBL_Error: fwrite(pReply->pData, pReply->dataLength, 1, out); fclose(out); - if (hContact != 0) { - ProtoBroadcastAck(hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, HANDLE(&ai), 0); + if (pReq->hContact != 0) { + ProtoBroadcastAck(pReq->hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, HANDLE(&ai), 0); debugLogW(L"Broadcast new avatar: %s", ai.filename); } else CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName, 0); @@ -641,9 +631,20 @@ void CIcqProto::OnSendMessage(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) void CIcqProto::ProcessBuddyList(const JSONNode &ev) { for (auto &it : ev["groups"]) { + int id = it["id"].as_int(); CMStringW szGroup = it["name"].as_mstring(); bool bCreated = false; + bool bFound = false; + for (auto &grp : m_arGroups) + if (grp->m_iIcqId == id) { + bFound = true; + break; + } + + if (!bFound) + m_arGroups.insert(new IcqGroup(id, szGroup)); + for (auto &buddy : it["buddies"]) { MCONTACT hContact = ParseBuddyInfo(buddy); if (hContact == INVALID_CONTACT_ID) |