From 326215e3557c3fdd0595d585cb9f645edeffedb9 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Mon, 23 Feb 2015 19:54:57 +0000 Subject: Tox: group chats are disabled, untill it won't be rewritten in tox core git-svn-id: http://svn.miranda-ng.org/main/trunk@12253 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_chatrooms.cpp | 76 +++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 32 deletions(-) (limited to 'protocols/Tox/src/tox_chatrooms.cpp') diff --git a/protocols/Tox/src/tox_chatrooms.cpp b/protocols/Tox/src/tox_chatrooms.cpp index 684cac1246..f17a5869a5 100644 --- a/protocols/Tox/src/tox_chatrooms.cpp +++ b/protocols/Tox/src/tox_chatrooms.cpp @@ -119,17 +119,39 @@ INT_PTR CToxProto::OnCreateChatRoom(WPARAM, LPARAM) { return 1; } - int groupNumber = tox_add_groupchat(tox); - if (groupNumber == TOX_ERROR) - { - return 1; - } - MCONTACT hContact = AddChatRoom(groupNumber); - if (!hContact) + + ChatRoomInviteParam param = { this }; + + if (DialogBoxParam( + g_hInstance, + MAKEINTRESOURCE(IDD_CHATROOM_INVITE), + NULL, + CToxProto::ChatRoomInviteProc, + (LPARAM)¶m) == IDOK && !param.invitedContacts.empty()) { - return 1; + int groupNumber = tox_add_groupchat(tox); + if (groupNumber == TOX_ERROR) + { + return 1; + } + for (std::vector::iterator it = param.invitedContacts.begin(); it != param.invitedContacts.end(); ++it) + { + ToxBinAddress pubKey = ptrA(getStringA(*it, TOX_SETTINGS_ID)); + int32_t friendNumber = tox_get_friend_number(tox, pubKey); + if (friendNumber == TOX_ERROR || tox_invite_friend(tox, friendNumber, groupNumber) == TOX_ERROR) + { + return 1; + } + } + MCONTACT hContact = AddChatRoom(groupNumber); + if (!hContact) + { + return 1; + } + return 0; } - return 0; + + return 1; } void CToxProto::InitGroupChatModule() @@ -190,7 +212,8 @@ void CToxProto::OnGroupChatInvite(Tox *tox, int32_t friendNumber, uint8_t type, void CToxProto::ChatValidateContact(HWND hwndList, const std::vector &contacts, MCONTACT hContact) { - //if (mir_strcmpi(GetContactProto(hContact), m_szModuleName) == 0 && !isChatRoom(hContact)) + bool isProtoContact = mir_strcmpi(GetContactProto(hContact), m_szModuleName) == 0; + if (isProtoContact && !isChatRoom(hContact)) { if (std::find(contacts.begin(), contacts.end(), hContact) != contacts.end()) { @@ -205,7 +228,7 @@ void CToxProto::ChatPrepare(HWND hwndList, const std::vector &contacts { if (hContact == NULL) { - hContact = (MCONTACT)::SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_ROOT, 0); + hContact = (MCONTACT)SendMessage(hwndList, CLM_GETNEXTITEM, CLGN_ROOT, 0); } while (hContact) { @@ -259,17 +282,17 @@ std::vector CToxProto::GetInvitedContacts(HWND hwndList, MCONTACT hCon INT_PTR CALLBACK CToxProto::ChatRoomInviteProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { HWND hwndList = GetDlgItem(hwndDlg, IDC_CCLIST); - CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + ChatRoomInviteParam *param = (ChatRoomInviteParam*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { - proto = (CToxProto*)lParam; + param = (ChatRoomInviteParam*)lParam; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); { - HWND hwndClist = GetDlgItem(hwndDlg, IDC_CCLIST); - SetWindowLongPtr(hwndClist, GWL_STYLE, GetWindowLongPtr(hwndClist, GWL_STYLE) & ~CLS_HIDEOFFLINE); + //HWND hwndClist = GetDlgItem(hwndDlg, IDC_CCLIST); + //SetWindowLongPtr(hwndClist, GWL_STYLE, GetWindowLongPtr(hwndClist, GWL_STYLE) & ~CLS_HIDEOFFLINE); } } break; @@ -288,15 +311,13 @@ INT_PTR CALLBACK CToxProto::ChatRoomInviteProc(HWND hwndDlg, UINT msg, WPARAM wP case CLN_NEWCONTACT: if ((nmc->flags & (CLNF_ISGROUP | CLNF_ISINFO)) == 0) { - std::vector invitedContacts; - proto->ChatValidateContact(nmc->hdr.hwndFrom, invitedContacts, (MCONTACT)nmc->hItem); + param->proto->ChatValidateContact(nmc->hdr.hwndFrom, param->invitedContacts, (MCONTACT)nmc->hItem); } break; case CLN_LISTREBUILT: { - std::vector invitedContacts; - proto->ChatPrepare(nmc->hdr.hwndFrom, invitedContacts); + param->proto->ChatPrepare(nmc->hdr.hwndFrom, param->invitedContacts); } break; } @@ -308,19 +329,10 @@ INT_PTR CALLBACK CToxProto::ChatRoomInviteProc(HWND hwndDlg, UINT msg, WPARAM wP switch (LOWORD(wParam)) { case IDOK: - { - std::vector invitedContacts = GetInvitedContacts(hwndList); - if (invitedContacts.empty()) - { - proto->ShowNotification(TranslateT("You did not select any contact")); - } - else - { - //SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - EndDialog(hwndDlg, IDOK); - } - } - break; + //SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + param->invitedContacts = param->proto->GetInvitedContacts(hwndList); + EndDialog(hwndDlg, IDOK); + break; case IDCANCEL: EndDialog(hwndDlg, IDCANCEL); -- cgit v1.2.3