diff --git a/external/solanaceae_tox b/external/solanaceae_tox index 178f08e..91ae067 160000 --- a/external/solanaceae_tox +++ b/external/solanaceae_tox @@ -1 +1 @@ -Subproject commit 178f08ee9617bd89e12bb16163a56ec4cafcf012 +Subproject commit 91ae0671b0d31276d4fa6495c28db1c3a0bd67eb diff --git a/src/main_screen.cpp b/src/main_screen.cpp index ac7a097..59495ab 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -67,7 +67,7 @@ MainScreen::MainScreen(const SimpleConfigModel& conf_, SDL_Renderer* renderer_, cg(conf, os, rmm, cs, sdlrtu, contact_tc, msg_tc, theme), sw(conf), osui(os), - tuiu(tc, conf, &tpi), + tuiu(tc, tcm, conf, &tpi), tdch(tpi), tnui(tpi), smui(os, sm), diff --git a/src/tox_ui_utils.cpp b/src/tox_ui_utils.cpp index 32f3191..7ba15ed 100644 --- a/src/tox_ui_utils.cpp +++ b/src/tox_ui_utils.cpp @@ -3,6 +3,7 @@ #include "./tox_client.hpp" #include +#include #include @@ -10,6 +11,9 @@ #include +#include +#include + #include #include @@ -17,9 +21,10 @@ ToxUIUtils::ToxUIUtils( ToxClient& tc, + ToxContactModel2& tcm, ConfigModelI& conf, ToxPrivateI* tp -) : _tc(tc), _conf(conf), _tp(tp) { +) : _tc(tc), _tcm(tcm), _conf(conf), _tp(tp) { } void ToxUIUtils::render(void) { @@ -29,7 +34,7 @@ void ToxUIUtils::render(void) { if (ImGui::BeginMenuBar()) { ImGui::Separator(); if (ImGui::BeginMenu("Tox")) { - ImGui::SeparatorText("Friends/Groups"); + ImGui::SeparatorText("Friends"); if (ImGui::MenuItem("add Friend by ID", nullptr, _show_add_friend_window)) { _show_add_friend_window = !_show_add_friend_window; @@ -37,6 +42,8 @@ void ToxUIUtils::render(void) { if (ImGui::MenuItem("copy own ToxID")) { ImGui::SetClipboardText(_tc.toxSelfGetAddressStr().c_str()); } + + ImGui::SeparatorText("Groups"); if (ImGui::MenuItem("join Group by ID (ngc)", nullptr, _show_add_group_window)) { _show_add_group_window = !_show_add_group_window; } @@ -62,6 +69,10 @@ void ToxUIUtils::render(void) { ImGui::EndMenu(); } + if (ImGui::MenuItem("new Group (ngc)", nullptr, _show_new_group_window)) { + _show_new_group_window = !_show_new_group_window; + } + ImGui::SeparatorText("DHT"); if (ImGui::MenuItem("rerun bootstrap")) { @@ -111,7 +122,10 @@ void ToxUIUtils::render(void) { static Tox_Err_Friend_Add err = Tox_Err_Friend_Add::TOX_ERR_FRIEND_ADD_OK; if (ImGui::Button("add")) { - auto [_, err_r] = _tc.toxFriendAdd(hex2bin(std::string_view{tox_id, std::size(tox_id)-1}), message); + auto [_, err_r] = _tcm.createContactFriend( + std::string_view{tox_id, std::size(tox_id)-1}, + message + ); err = err_r; { // reset everything @@ -143,8 +157,8 @@ void ToxUIUtils::render(void) { static Tox_Err_Group_Join err = Tox_Err_Group_Join::TOX_ERR_GROUP_JOIN_OK; if (ImGui::Button("join/reconnect")) { - auto [_, err_r] = _tc.toxGroupJoin( - hex2bin(std::string_view{_chat_id, std::size(_chat_id)-1}), + auto [_, err_r] = _tcm.createContactGroupJoin( + std::string_view{_chat_id, std::size(_chat_id)-1}, self_name, password ); @@ -168,5 +182,59 @@ void ToxUIUtils::render(void) { } ImGui::End(); } + + if (_show_new_group_window) { + if (ImGui::Begin("Tox new Group", &_show_new_group_window)) { + ImGui::TextDisabled("NGC refers to the New DHT enabled Group Chats."); + ImGui::TextDisabled("Connecting via ID might take a very long time."); + + static int privacy_state{Tox_Group_Privacy_State::TOX_GROUP_PRIVACY_STATE_PUBLIC}; + ImGui::Combo("privacy state", &privacy_state, "public\0private\0"); + ImGui::SetItemTooltip("Public groups get announced to the DHT.\nAnyone can scrape the DHT and find your group.\n\nPrivate groups can not be joined via ID (DHT lookup)."); + + static std::string name; + ImGui::InputText("name of the group", &name); + + static std::string self_name = _conf.get_string("tox", "name").value_or("default_tomato"); + ImGui::InputText("name of yourself", &self_name); + + static std::string password; + ImGui::InputText("password for group", &password); + + static Tox_Err_Group_New err = Tox_Err_Group_New::TOX_ERR_GROUP_NEW_OK; + static Tox_Err_Group_Set_Password err_pw = Tox_Err_Group_Set_Password::TOX_ERR_GROUP_SET_PASSWORD_OK; + if (ImGui::Button("create")) { + auto [new_c, err_r, err_pw_r] = _tcm.createContactGroupNew( + static_cast(privacy_state), + name, + self_name, + password + ); + err = err_r; + err_pw = err_pw_r; + + { // reset everything + for (size_t i = 0; i < name.size(); i++) { + name.at(i) = '\0'; + } + name.clear(); + + self_name = _conf.get_string("tox", "name").value_or("default_tomato"); + + for (size_t i = 0; i < password.size(); i++) { + password.at(i) = '\0'; + } + password.clear(); + } + } + if (err != Tox_Err_Group_New::TOX_ERR_GROUP_NEW_OK || err_pw != Tox_Err_Group_Set_Password::TOX_ERR_GROUP_SET_PASSWORD_OK) { + ImGui::SameLine(); + ImGui::Text("error creating group!"); + ImGui::Text("group: '%s' (%d)", tox_err_group_new_to_string(err), err); + ImGui::Text("pw: '%s' (%d)", tox_err_group_set_password_to_string(err_pw), err_pw); + } + } + ImGui::End(); + } } diff --git a/src/tox_ui_utils.hpp b/src/tox_ui_utils.hpp index db8da5c..9dffe80 100644 --- a/src/tox_ui_utils.hpp +++ b/src/tox_ui_utils.hpp @@ -5,12 +5,15 @@ class ToxClient; struct ConfigModelI; struct ToxPrivateI; +class ToxContactModel2; class ToxUIUtils { bool _show_add_friend_window {false}; bool _show_add_group_window {false}; + bool _show_new_group_window {false}; ToxClient& _tc; + ToxContactModel2& _tcm; ConfigModelI& _conf; ToxPrivateI* _tp {nullptr}; @@ -19,6 +22,7 @@ class ToxUIUtils { public: ToxUIUtils( ToxClient& tc, + ToxContactModel2& tcm, ConfigModelI& conf, ToxPrivateI* tp = nullptr );