diff options
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/ICQ-WIM/src/poll.cpp | 37 | ||||
-rw-r--r-- | protocols/ICQ-WIM/src/proto.cpp | 57 | ||||
-rw-r--r-- | protocols/ICQ-WIM/src/proto.h | 16 | ||||
-rw-r--r-- | protocols/ICQ-WIM/src/stdafx.h | 3 |
4 files changed, 85 insertions, 28 deletions
diff --git a/protocols/ICQ-WIM/src/poll.cpp b/protocols/ICQ-WIM/src/poll.cpp index f794f82d57..4b66664cae 100644 --- a/protocols/ICQ-WIM/src/poll.cpp +++ b/protocols/ICQ-WIM/src/poll.cpp @@ -77,26 +77,50 @@ void CIcqProto::ProcessBuddyList(const JSONNode &ev) void CIcqProto::ProcessDiff(const JSONNode &ev) { + std::map<MCONTACT, bool> processed; + for (auto &block : ev) { CMStringW szType = block["type"].as_mstring(); - if (szType != "updated" && szType != "created") + if (szType != "updated" && szType != "created" && szType != "deleted") continue; for (auto &it : block["data"]) { int grpId = it["id"].as_int(); + CMStringW wszName = it["name"].as_mstring(); + auto *pGroup = m_arGroups.find((IcqGroup *)&grpId); if (pGroup == nullptr) { - debugLogA("Group %d isn't found", grpId); - continue; + if (szType != "created") { + debugLogA("Group %d isn't found", grpId); + continue; + } + + pGroup = new IcqGroup(grpId, wszName); + m_arGroups.insert(pGroup); + } + else { + pGroup->wszSrvName = wszName; + pGroup->SetName(wszName); } - bool bCreated = false; + bool bCreated = false, bDeleted = (szType == "deleted"); for (auto &buddy : it["buddies"]) { MCONTACT hContact = ParseBuddyInfo(buddy); if (hContact == INVALID_CONTACT_ID) continue; + if (bDeleted) { + if (processed[hContact]) + continue; + + // prepare contact for deletion + Clist_SetGroup(hContact, nullptr); + db_set_b(hContact, "CList", "NotOnList", 1); + continue; + } + + processed[hContact] = true; setWString(hContact, "IcqGroup", pGroup->wszName); ptrW wszGroup(Clist_GetGroup(hContact)); @@ -109,7 +133,12 @@ void CIcqProto::ProcessDiff(const JSONNode &ev) Clist_SetGroup(hContact, pGroup->wszName); } } + + if (bDeleted) + m_arGroups.remove(pGroup); } + + RefreshGroups(); } } diff --git a/protocols/ICQ-WIM/src/proto.cpp b/protocols/ICQ-WIM/src/proto.cpp index 819637f707..63a3a553e2 100644 --- a/protocols/ICQ-WIM/src/proto.cpp +++ b/protocols/ICQ-WIM/src/proto.cpp @@ -192,13 +192,10 @@ class CGroupEditDlg : public CIcqDlgBase { CCtrlListView groups; - void RefreshGroups() - { - for (auto &it : m_proto->m_arGroups.rev_iter()) - groups.AddItem(it->wszName, 0, (LPARAM)it); - } - public: + + static CGroupEditDlg *pDlg; + CGroupEditDlg(CIcqProto *ppro) : CIcqDlgBase(ppro, IDD_EDITGROUPS), groups(this, IDC_GROUPS) @@ -206,13 +203,25 @@ public: groups.OnBuildMenu = Callback(this, &CGroupEditDlg::onMenu); } + void RefreshGroups() + { + for (auto &it : m_proto->m_arGroups.rev_iter()) + groups.AddItem(it->wszName, 0, (LPARAM)it); + } + bool OnInitDialog() override { + pDlg = this; groups.AddColumn(0, TranslateT("Name"), 300); RefreshGroups(); return true; } + void OnDestroy() override + { + pDlg = nullptr; + } + void onMenu(void *) { int cur = groups.GetSelectionMark(); @@ -230,8 +239,6 @@ public: int cmd = TrackPopupMenu(hMenu, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, 0, m_hwnd, nullptr); DestroyMenu(hMenu); - CLISTGROUPCHANGE param = { pGroup->wszName, nullptr }; - if (cmd == 1) { // rename ENTER_STRING es = {}; es.cbSize = sizeof(es); @@ -240,22 +247,32 @@ public: if (!EnterString(&es)) return; - param.pszNewName = es.ptszResult; - m_proto->OnGroupChange(0, (LPARAM)¶m); + m_proto->Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/renameGroup") + << AIMSID(m_proto) << WCHAR_PARAM("oldGroup", pGroup->wszSrvName) << GROUP_PARAM("newGroup", es.ptszResult)); + mir_free(es.ptszResult); } else if (cmd == 2) { // delete - m_proto->OnGroupChange(0, (LPARAM)¶m); + m_proto->Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/removeGroup") + << AIMSID(m_proto) << WCHAR_PARAM("group", pGroup->wszSrvName)); } } }; +CGroupEditDlg *CGroupEditDlg::pDlg = nullptr; + INT_PTR CIcqProto::EditGroups(WPARAM, LPARAM) { (new CGroupEditDlg(this))->Show(); return 0; } +void RefreshGroups(void) +{ + if (CGroupEditDlg::pDlg != nullptr) + CGroupEditDlg::pDlg->RefreshGroups(); +} + ///////////////////////////////////////////////////////////////////////////////////////// INT_PTR CIcqProto::GetEmailCount(WPARAM, LPARAM) @@ -324,20 +341,22 @@ int CIcqProto::OnGroupChange(WPARAM hContact, LPARAM lParam) CLISTGROUPCHANGE *pParam = (CLISTGROUPCHANGE*)lParam; if (hContact == 0) { // whole group is changed - auto *pReq = new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/") << AIMSID(this); if (pParam->pszOldName == nullptr) { - pReq->m_szUrl += "addGroup"; - pReq << GROUP_PARAM("group", pParam->pszNewName); + for (auto &it : m_arGroups) + if (it->wszName == pParam->pszNewName) + return 0; + + Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/addGroup") + << AIMSID(this) << GROUP_PARAM("group", pParam->pszNewName)); } else if (pParam->pszNewName == nullptr) { - pReq->m_szUrl += "removeGroup"; - pReq << GROUP_PARAM("group", pParam->pszOldName); + Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/removeGroup") + << AIMSID(this) << GROUP_PARAM("group", pParam->pszOldName)); } else { - pReq->m_szUrl += "renameGroup"; - pReq << GROUP_PARAM("oldGroup", pParam->pszOldName) << GROUP_PARAM("newGroup", pParam->pszNewName); + Push(new AsyncHttpRequest(CONN_MAIN, REQUEST_GET, ICQ_API_SERVER "/buddylist/renameGroup") + << AIMSID(this) << GROUP_PARAM("oldGroup", pParam->pszOldName) << GROUP_PARAM("newGroup", pParam->pszNewName)); } - Push(pReq); } else MoveContactToGroup(hContact, getMStringW(hContact, "IcqGroup"), pParam->pszNewName); diff --git a/protocols/ICQ-WIM/src/proto.h b/protocols/ICQ-WIM/src/proto.h index 7aca4717bc..cc372d01f7 100644 --- a/protocols/ICQ-WIM/src/proto.h +++ b/protocols/ICQ-WIM/src/proto.h @@ -72,17 +72,23 @@ struct IcqGroup { IcqGroup(int _p1, const CMStringW &_p2) : id(_p1), - wszName(_p2) + wszSrvName(_p2) { + SetName(_p2); + } + + int id; + int level; + CMStringW wszName, wszSrvName; + + void SetName(const CMStringW &str) + { + wszName = str; level = wszName.SpanIncluding(L">").GetLength(); if (level != 0) wszName.Delete(0, level); wszName.Replace(L">", L"\\"); } - - int id; - int level; - CMStringW wszName; }; struct IcqCacheItem : public MZeroedObject diff --git a/protocols/ICQ-WIM/src/stdafx.h b/protocols/ICQ-WIM/src/stdafx.h index b216ec459a..1e08c2f1b7 100644 --- a/protocols/ICQ-WIM/src/stdafx.h +++ b/protocols/ICQ-WIM/src/stdafx.h @@ -41,6 +41,8 @@ #include <fcntl.h> #include <process.h> +#include <map> + // Miranda IM SDK includes #include <newpluginapi.h> // This must be included first #include <m_avatars.h> @@ -99,6 +101,7 @@ bool IsChat(const CMStringW &aimid); +void RefreshGroups(void); int StatusFromString(const CMStringW&); char* time2text(time_t time); |