diff options
author | Robert Pösel <robyer@seznam.cz> | 2016-08-28 12:00:33 +0000 |
---|---|---|
committer | Robert Pösel <robyer@seznam.cz> | 2016-08-28 12:00:33 +0000 |
commit | e14eff0ba253de426d0cb2bb8f47ca171e199b1e (patch) | |
tree | 96ad98f4bd49c53d09042be4a539bd8e00312015 /protocols/SkypeWeb/src/skype_chatrooms.cpp | |
parent | c98539ee79a0d7e6ee2c20172a3387d6e38674d7 (diff) |
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
Diffstat (limited to 'protocols/SkypeWeb/src/skype_chatrooms.cpp')
-rw-r--r-- | protocols/SkypeWeb/src/skype_chatrooms.cpp | 49 |
1 files changed, 34 insertions, 15 deletions
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;
|