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/api_groupchats.cpp | 5 ++- protocols/Tox/src/common.h | 3 ++ protocols/Tox/src/tox_accounts.cpp | 2 +- protocols/Tox/src/tox_chatrooms.cpp | 76 +++++++++++++++++++++--------------- protocols/Tox/src/tox_network.cpp | 1 - protocols/Tox/src/tox_proto.cpp | 8 ++-- protocols/Tox/src/tox_proto.h | 4 +- 7 files changed, 57 insertions(+), 42 deletions(-) (limited to 'protocols/Tox/src') diff --git a/protocols/Tox/src/api_groupchats.cpp b/protocols/Tox/src/api_groupchats.cpp index a84c4eaab9..eb8b01603d 100644 --- a/protocols/Tox/src/api_groupchats.cpp +++ b/protocols/Tox/src/api_groupchats.cpp @@ -39,11 +39,12 @@ int tox_del_groupchat(Tox *tox, int groupnumber) int tox_group_peer_pubkey(const Tox *tox, int groupnumber, int peernumber, uint8_t *pk) { -} +}*/ int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber) { -}*/ + return CreateFunction(__FUNCTION__)(tox, friendnumber, groupnumber); +} int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length) { diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h index 9d4b7dfedc..d450211fe8 100644 --- a/protocols/Tox/src/common.h +++ b/protocols/Tox/src/common.h @@ -39,11 +39,14 @@ #include #include +struct CToxProto; + #include "version.h" #include "resource.h" #include "tox_address.h" #include "tox_options.h" #include "tox_transfer.h" +#include "tox_chatrooms.h" #include "tox_proto.h" extern HINSTANCE g_hInstance; diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp index c2d84e9515..ce435043d7 100644 --- a/protocols/Tox/src/tox_accounts.cpp +++ b/protocols/Tox/src/tox_accounts.cpp @@ -28,7 +28,7 @@ int CToxProto::OnAccountLoaded(WPARAM, LPARAM) HookProtoEvent(ME_USERINFO_INITIALISE, &CToxProto::OnUserInfoInit); HookProtoEvent(ME_MSG_PRECREATEEVENT, &CToxProto::OnPreCreateMessage); - InitGroupChatModule(); + //InitGroupChatModule(); return 0; } 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); diff --git a/protocols/Tox/src/tox_network.cpp b/protocols/Tox/src/tox_network.cpp index ac39e053ff..694d966753 100644 --- a/protocols/Tox/src/tox_network.cpp +++ b/protocols/Tox/src/tox_network.cpp @@ -97,7 +97,6 @@ void CToxProto::TryConnect() debugLogA("CToxProto::PollingThread: successfuly connected to DHT"); ForkThread(&CToxProto::LoadFriendList, NULL); - ForkThread(&CToxProto::LoadChatRoomList, NULL); m_iStatus = m_iDesiredStatus; ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus); diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 117c7f8ec9..1a22017a6a 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -49,8 +49,8 @@ CToxProto::CToxProto(const char* protoName, const TCHAR* userName) : CreateProtoService(PS_SETMYNICKNAME, &CToxProto::SetMyNickname); // chat rooms - CreateProtoService(PS_JOINCHAT, &CToxProto::OnJoinChatRoom); - CreateProtoService(PS_LEAVECHAT, &CToxProto::OnLeaveChatRoom); + //CreateProtoService(PS_JOINCHAT, &CToxProto::OnJoinChatRoom); + //CreateProtoService(PS_LEAVECHAT, &CToxProto::OnLeaveChatRoom); // transfers transfers = new CTransferList(); @@ -290,8 +290,8 @@ int __cdecl CToxProto::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM case EV_PROTO_ONCONTACTDELETED: return OnContactDeleted(wParam, lParam); - case EV_PROTO_ONMENU: - return OnInitStatusMenu(); + //case EV_PROTO_ONMENU: + // return OnInitStatusMenu(); } return 1; diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 0ff5060f14..66225cc626 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -178,8 +178,8 @@ private: static void OnGroupChatInvite(Tox *tox, int32_t friendNumber, uint8_t type, const uint8_t *data, const uint16_t length, void *arg); - static void ChatValidateContact(HWND hwndList, const std::vector &contacts, MCONTACT hContact = NULL); - static void ChatPrepare(HWND hwndList, const std::vector &contacts, MCONTACT hContact = NULL); + void ChatValidateContact(HWND hwndList, const std::vector &contacts, MCONTACT hContact = NULL); + void ChatPrepare(HWND hwndList, const std::vector &contacts, MCONTACT hContact = NULL); static std::vector GetInvitedContacts(HWND hwndList, MCONTACT hContact = NULL); static INT_PTR CALLBACK ChatRoomInviteProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -- cgit v1.2.3