From e14eff0ba253de426d0cb2bb8f47ca171e199b1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Sun, 28 Aug 2016 12:00:33 +0000 Subject: SkypeWeb: Improve setting custom nick for chat contact; version bump * Fixed memleak (pForm.ptszResult must be freed) * Fixed target groupchat (use gch->pDest->ptszID instead of id of user) * Setting empty name will delete the custom nick * When new nick is same as current, do nothing git-svn-id: http://svn.miranda-ng.org/main/trunk@17212 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/SkypeWeb/src/skype_chatrooms.cpp | 49 +++++++++++++++++++++--------- protocols/SkypeWeb/src/version.h | 2 +- 2 files changed, 35 insertions(+), 16 deletions(-) (limited to 'protocols/SkypeWeb/src') diff --git a/protocols/SkypeWeb/src/skype_chatrooms.cpp b/protocols/SkypeWeb/src/skype_chatrooms.cpp index 2e67171846..a254720323 100644 --- a/protocols/SkypeWeb/src/skype_chatrooms.cpp +++ b/protocols/SkypeWeb/src/skype_chatrooms.cpp @@ -210,29 +210,48 @@ int CSkypeProto::OnGroupChatEventHook(WPARAM, LPARAM lParam) SendRequest(new InviteUserToChatRequest(chat_id, user_id, "User", li)); break; case 50: + ptrW tnick_old(GetChatContactNick(chat_id, _T2A(gch->ptszUID), _T2A(gch->ptszText))); ENTER_STRING pForm = { sizeof(pForm) }; pForm.type = ESF_COMBO; pForm.recentCount = 0; pForm.caption = TranslateT("Enter new nickname"); - pForm.ptszInitVal = gch->ptszUID; + pForm.ptszInitVal = tnick_old; pForm.szModuleName = m_szModuleName; pForm.szDataPrefix = "renamenick_"; - GCDEST gcd = { m_szModuleName, gch->ptszUID, GC_EVENT_NICK }; - GCEVENT gce = { sizeof(GCEVENT), &gcd }; - - EnterString(&pForm); - - gce.ptszNick = gch->ptszUID; - gce.bIsMe = IsMe(user_id); - gce.ptszUID = gch->ptszUID; - gce.ptszText = pForm.ptszResult; - gce.dwFlags = GCEF_ADDTOLOG; - gce.time = time(NULL); - CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); - - db_set_ws(FindChatRoom(chat_id), "UsersNicks", _T2A(gch->ptszUID), pForm.ptszResult); + if (EnterString(&pForm)) + { + MCONTACT hChatContact = FindChatRoom(chat_id); + if (hChatContact == NULL) + break; // This probably shouldn't happen, but if chat is NULL for some reason, do nothing + + ptrW tnick_new(pForm.ptszResult); + bool reset = (tnick_new == NULL || tnick_new[0] == '\0'); + if (reset) + { + // User fill blank name, which means we reset the custom nick + db_unset(hChatContact, "UsersNicks", _T2A(gch->ptszUID)); + tnick_new = GetChatContactNick(chat_id, _T2A(gch->ptszUID), _T2A(gch->ptszText)); + } + + if (!mir_wstrcmp(tnick_old, tnick_new)) + break; // New nick is same, do nothing + + GCDEST gcd = { m_szModuleName, gch->pDest->ptszID, GC_EVENT_NICK }; + GCEVENT gce = { sizeof(GCEVENT), &gcd }; + + gce.ptszNick = tnick_old; + gce.bIsMe = IsMe(user_id); + gce.ptszUID = gch->ptszUID; + gce.ptszText = tnick_new; + gce.dwFlags = GCEF_ADDTOLOG; + gce.time = time(NULL); + CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce); + + if (!reset) + db_set_ws(hChatContact, "UsersNicks", _T2A(gch->ptszUID), tnick_new); + } break; diff --git a/protocols/SkypeWeb/src/version.h b/protocols/SkypeWeb/src/version.h index 1ffd7b7600..f66e9decdd 100644 --- a/protocols/SkypeWeb/src/version.h +++ b/protocols/SkypeWeb/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 12 #define __RELEASE_NUM 2 -#define __BUILD_NUM 2 +#define __BUILD_NUM 3 #include -- cgit v1.2.3