diff options
-rw-r--r-- | protocols/Icq10/src/proto.cpp | 34 | ||||
-rw-r--r-- | protocols/Icq10/src/proto.h | 17 | ||||
-rw-r--r-- | protocols/Icq10/src/server.cpp | 19 |
3 files changed, 43 insertions, 27 deletions
diff --git a/protocols/Icq10/src/proto.cpp b/protocols/Icq10/src/proto.cpp index a5c99219aa..db2bb4f98b 100644 --- a/protocols/Icq10/src/proto.cpp +++ b/protocols/Icq10/src/proto.cpp @@ -38,7 +38,6 @@ 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), @@ -54,6 +53,7 @@ CIcqProto::CIcqProto(const char* aProtoName, const wchar_t* aUserName) : CreateProtoService(PS_SETMYAVATAR, &CIcqProto::SetAvatar); // events + HookProtoEvent(ME_CLIST_GROUPCHANGE, &CIcqProto::OnGroupChange); HookProtoEvent(ME_DB_EVENT_MARKED_READ, &CIcqProto::OnDbEventRead); HookProtoEvent(ME_GC_EVENT, &CIcqProto::GroupchatEventHook); HookProtoEvent(ME_GC_BUILDMENU, &CIcqProto::GroupchatMenuHook); @@ -155,6 +155,38 @@ int CIcqProto::OnDbEventRead(WPARAM, LPARAM hDbEvent) return 0; } +int CIcqProto::OnGroupChange(WPARAM hContact, LPARAM lParam) +{ + if (!m_bOnline) + return 0; + + CLISTGROUPCHANGE *pParam = (CLISTGROUPCHANGE*)lParam; + if (hContact == 0) { // whole group is changed + auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/", &CIcqProto::OnUpdateGroup); + pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("r", pReq->m_reqId); + if (pParam->pszOldName == nullptr) { + pReq->m_szUrl += "addGroup"; + pReq << WCHAR_PARAM("group", pParam->pszNewName); + } + else if (pParam->pszNewName == nullptr) { + pReq->m_szUrl += "removeGroup"; + pReq << WCHAR_PARAM("group", pParam->pszOldName); + } + else { + pReq->m_szUrl += "renameGroup"; + pReq << WCHAR_PARAM("oldGroup", pParam->pszOldName) << WCHAR_PARAM("newGroup", pParam->pszNewName); + } + Push(pReq); + } + else { + auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/moveBuddy"); + pReq << CHAR_PARAM("f", "json") << CHAR_PARAM("aimsid", m_aimsid) << CHAR_PARAM("r", pReq->m_reqId) + << CHAR_PARAM("buddy", GetUserId(hContact)) << WCHAR_PARAM("group", db_get_wsm(hContact, "CList", "Group")) << WCHAR_PARAM("newGroup", pParam->pszNewName); + Push(pReq); + } + + return 0; +} //////////////////////////////////////////////////////////////////////////////////////// // PS_AddToList - adds a contact to the contact list diff --git a/protocols/Icq10/src/proto.h b/protocols/Icq10/src/proto.h index dbb7e24bf9..149723834b 100644 --- a/protocols/Icq10/src/proto.h +++ b/protocols/Icq10/src/proto.h @@ -42,20 +42,6 @@ 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) : @@ -132,6 +118,7 @@ class CIcqProto : public PROTO<CIcqProto> void OnSearchResults(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnSendMessage(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnStartSession(NETLIBHTTPREQUEST*, AsyncHttpRequest*); + void OnUpdateGroup(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void OnValidateSms(NETLIBHTTPREQUEST*, AsyncHttpRequest*); void ProcessBuddyList(const JSONNode&); @@ -185,7 +172,6 @@ class CIcqProto : public PROTO<CIcqProto> mir_cs m_csCache; OBJLIST<IcqCacheItem> m_arCache; - OBJLIST<IcqGroup> m_arGroups; void InitContactCache(void); IcqCacheItem* FindContactByUIN(DWORD); @@ -215,6 +201,7 @@ class CIcqProto : public PROTO<CIcqProto> //////////////////////////////////////////////////////////////////////////////////////// // events + int __cdecl OnGroupChange(WPARAM, LPARAM); int __cdecl OnDbEventRead(WPARAM, LPARAM); int __cdecl OnOptionsInit(WPARAM, LPARAM); diff --git a/protocols/Icq10/src/server.cpp b/protocols/Icq10/src/server.cpp index 3c9a12215c..2343253d8c 100644 --- a/protocols/Icq10/src/server.cpp +++ b/protocols/Icq10/src/server.cpp @@ -626,25 +626,22 @@ void CIcqProto::OnSendMessage(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq) CheckLastId(ownMsg->m_hContact, data); } +void CIcqProto::OnUpdateGroup(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest*) +{ + JsonReply root(pReply); + if (root.error() != 200) + return; + +} + ///////////////////////////////////////////////////////////////////////////////////////// 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) |