summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-01-15 21:35:39 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-01-15 21:35:39 +0300
commitc2bdd8abc93b94228d5cb16aa55a0994a7d97d29 (patch)
treebbca2a3d021872d5c63cdc8591a157163ddd6577 /protocols
parent4491473110a95fe33b18334e828197974b141312 (diff)
fixes #1768 (ICQ10: add "Sync clist with server" button)
Diffstat (limited to 'protocols')
-rw-r--r--protocols/Icq10/src/proto.cpp41
-rw-r--r--protocols/Icq10/src/proto.h4
-rw-r--r--protocols/Icq10/src/server.cpp25
3 files changed, 62 insertions, 8 deletions
diff --git a/protocols/Icq10/src/proto.cpp b/protocols/Icq10/src/proto.cpp
index fbf6336b73..86fb3257fb 100644
--- a/protocols/Icq10/src/proto.cpp
+++ b/protocols/Icq10/src/proto.cpp
@@ -110,6 +110,40 @@ void CIcqProto::OnContactDeleted(MCONTACT hContact)
/////////////////////////////////////////////////////////////////////////////////////////
+void CIcqProto::OnBuildProtoMenu()
+{
+ CMenuItem mi(&g_plugin);
+ mi.root = Menu_GetProtocolRoot(this);
+ mi.flags = CMIF_UNMOVABLE;
+
+ // "Bookmarks..."
+ mi.pszService = "/UploadGroups";
+ CreateProtoService(mi.pszService, &CIcqProto::UploadGroups);
+ mi.name.a = LPGEN("Synchronize server groups");
+ mi.position = 200001;
+ mi.hIcolibItem = Skin_GetIconHandle(SKINICON_OTHER_GROUP);
+ m_hUploadGroups = Menu_AddProtoMenuItem(&mi, m_szModuleName);
+
+ Menu_ShowItem(m_hUploadGroups, false);
+}
+
+INT_PTR CIcqProto::UploadGroups(WPARAM, LPARAM)
+{
+ for (auto &it : AccContacts()) {
+ if (isChatRoom(it))
+ continue;
+
+ CMStringW wszIcqGroup(getMStringW(it, "IcqGroup")), wszMirGroup(db_get_wsm(it, "CList", "Group"));
+ if (wszMirGroup.IsEmpty())
+ wszMirGroup = L"General";
+ if (wszIcqGroup != wszMirGroup)
+ MoveContactToGroup(it, wszIcqGroup, wszMirGroup);
+ }
+ return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
void CIcqProto::MarkReadTimerProc(HWND hwnd, UINT, UINT_PTR id, DWORD)
{
CIcqProto *ppro = (CIcqProto*)id;
@@ -178,12 +212,7 @@ int CIcqProto::OnGroupChange(WPARAM hContact, LPARAM lParam)
}
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);
- }
+ else MoveContactToGroup(hContact, getMStringW(hContact, "IcqGroup"), pParam->pszNewName);
return 0;
}
diff --git a/protocols/Icq10/src/proto.h b/protocols/Icq10/src/proto.h
index ab09a29c12..46bcb56e8f 100644
--- a/protocols/Icq10/src/proto.h
+++ b/protocols/Icq10/src/proto.h
@@ -86,6 +86,7 @@ class CIcqProto : public PROTO<CIcqProto>
void CheckPassword(void);
void ConnectionFailed(int iReason);
CMStringA GetUserId(MCONTACT);
+ void MoveContactToGroup(MCONTACT hContact, const wchar_t *pwszGroup, const wchar_t *pwszNewGroup);
MCONTACT ParseBuddyInfo(const JSONNode &buddy, MCONTACT hContact = -1);
void ParseMessage(MCONTACT hContact, __int64 &lastMsgId, const JSONNode &msg);
void RetrieveUserHistory(MCONTACT, __int64 startMsgId, __int64 endMsgId);
@@ -138,6 +139,7 @@ class CIcqProto : public PROTO<CIcqProto>
CMStringA m_aimsid;
LONG m_msgId = 1;
int m_iRClientId;
+ HGENMENU m_hUploadGroups;
OBJLIST<IcqOwnMessage> m_arOwnIds;
@@ -196,6 +198,7 @@ class CIcqProto : public PROTO<CIcqProto>
INT_PTR __cdecl SetAvatar(WPARAM, LPARAM);
INT_PTR __cdecl CreateAccMgrUI(WPARAM, LPARAM);
+ INT_PTR __cdecl UploadGroups(WPARAM, LPARAM);
////////////////////////////////////////////////////////////////////////////////////////
// events
@@ -234,6 +237,7 @@ class CIcqProto : public PROTO<CIcqProto>
int UserIsTyping(MCONTACT hContact, int type) override;
+ void OnBuildProtoMenu(void) override;
void OnContactDeleted(MCONTACT) override;
void OnModulesLoaded() override;
void OnShutdown() override;
diff --git a/protocols/Icq10/src/server.cpp b/protocols/Icq10/src/server.cpp
index 4c440b9670..d77daf4075 100644
--- a/protocols/Icq10/src/server.cpp
+++ b/protocols/Icq10/src/server.cpp
@@ -95,6 +95,14 @@ void CIcqProto::ConnectionFailed(int iReason)
ShutdownSession();
}
+void CIcqProto::MoveContactToGroup(MCONTACT hContact, const wchar_t *pwszGroup, const wchar_t *pwszNewGroup)
+{
+ 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", pwszGroup) << WCHAR_PARAM("newGroup", pwszNewGroup);
+ Push(pReq);
+}
+
void CIcqProto::OnLoggedIn()
{
debugLogA("CIcqProto::OnLoggedIn");
@@ -631,6 +639,8 @@ void CIcqProto::OnSendMessage(NETLIBHTTPREQUEST *pReply, AsyncHttpRequest *pReq)
void CIcqProto::ProcessBuddyList(const JSONNode &ev)
{
+ bool bEnableMenu = false;
+
for (auto &it : ev["groups"]) {
CMStringW szGroup = it["name"].as_mstring();
bool bCreated = false;
@@ -640,7 +650,13 @@ void CIcqProto::ProcessBuddyList(const JSONNode &ev)
if (hContact == INVALID_CONTACT_ID)
continue;
- if (db_get_sm(hContact, "CList", "Group").IsEmpty()) {
+ setWString(hContact, "IcqGroup", szGroup);
+
+ CMStringW mirGroup(db_get_sm(hContact, "CList", "Group"));
+ if (mirGroup != szGroup)
+ bEnableMenu = true;
+
+ if (mirGroup.IsEmpty()) {
if (!bCreated) {
Clist_GroupCreate(0, szGroup);
bCreated = true;
@@ -651,6 +667,9 @@ void CIcqProto::ProcessBuddyList(const JSONNode &ev)
}
}
+ if (bEnableMenu)
+ Menu_ShowItem(m_hUploadGroups, true);
+
for (auto &it : m_arCache)
if (!it->m_bInList)
db_set_b(it->m_hContact, "CList", "NotOnList", 1);
@@ -660,7 +679,7 @@ void CIcqProto::ProcessDiff(const JSONNode &ev)
{
for (auto &block : ev) {
CMStringW szType = block["type"].as_mstring();
- if (szType != "updated")
+ if (szType != "updated" && szType != "created")
continue;
for (auto &it : block["data"]) {
@@ -672,6 +691,8 @@ void CIcqProto::ProcessDiff(const JSONNode &ev)
if (hContact == INVALID_CONTACT_ID)
continue;
+ setWString(hContact, "IcqGroup", szGroup);
+
if (db_get_sm(hContact, "CList", "Group").IsEmpty()) {
if (!bCreated) {
Clist_GroupCreate(0, szGroup);