("Disclaimer:
Liability for Contents
"
- "The contents of our pages were created with the greatest care. However, we cannot guarantee the correctness, completeness, and topicality of the contents. As a service provider, we are responsible for our own content on these pages in accordance with § 7 para.1 TMG (German Telemedia Act) and general laws. According to §§ 8 to 10 TMG, however, we are not obliged as service providers to monitor transmitted or stored third-party information or to investigate circumstances that indicate illegal activity. Obligations to remove or block the use of information under general law remain unaffected. However, liability in this regard is only possible from the time of knowledge of a concrete infringement. If we become aware of any such legal infringements, we will remove the content immediately.
Liability for Links
"
- "Our offer contains links to external websites of third parties, on whose contents we have no influence. Therefore, we cannot assume any liability for these external contents. The respective provider or operator of the pages is always responsible for the contents of the linked pages. The linked pages were checked for possible legal violations at the time of linking. Illegal contents were not recognizable at the time of linking. However, permanent monitoring of the content of the linked pages is not reasonable without concrete evidence of a violation of the law. If we become aware of any infringements, we will remove such links immediately.
Data Protection
"
- "The use of our website is usually possible without providing personal data. As far as personal data (e.g., name, address, or email addresses) is collected on our website, this is always done on a voluntary basis as far as possible. This data will not be passed on to third parties without your express consent.
"
- "We would like to point out that data transmission over the Internet (e.g., communication by email) can have security gaps. A complete protection of data against access by third parties is not possible.
"
- "The use of contact data published within the scope of the imprint obligation by third parties for sending unsolicited advertising and information materials is hereby expressly prohibited. The operators of these pages expressly reserve the right to take legal action in the event of unsolicited sending of advertising information, such as spam emails.
"
- "
", Wt::TextFormat::UnsafeXHTML);
- imprintDialog->contents()->addNew("
"
- "Imprint from Imprint Generator of Kanzlei Hasselbach, Lawyers for Labor Law and Family Law ", Wt::TextFormat::UnsafeXHTML);
- imprintDialog->contents()->addNew("
"
- "Thanks for the flag icons to flagpedia.net", Wt::TextFormat::UnsafeXHTML);
- imprintDialog->contents()->setMaximumSize(Wt::WLength(60, Wt::LengthUnit::FontEm), Wt::WLength(40, Wt::LengthUnit::FontEm));
- imprintDialog->contents()->setOverflow(Wt::Overflow::Auto);
- imprintDialog->buttonClicked().connect([=]() { imprintDialog->accept(); });
- imprintDialog->show();
- });
-}
-
-Wt::WWebWidget* App::createImageElement(Wt::Json::Object& line, const std::string& writer, Wt::WContainerWidget* outputContainer, std::string id) {
- Wt::Json::Object imageDescription = line["image"];
- auto imageLineItem = outputContainer->addNew();
- auto outputText = Wt::WString("{1}: ").arg(writer);
- imageLineItem->addNew(outputText)->setStyleClass("output-line");
- auto image = imageLineItem->addNew();
- std::string base64Data = (std::string)imageDescription["imageblobbase64"];
- std::string decodedData = Wt::Utils::base64Decode(base64Data);
- std::string imageType = imageDescription["type"].toString(); // Lese den Bildtyp
- auto imageResource = std::make_shared(
- "image/" + imageType,
- std::vector(decodedData.begin(), decodedData.end()));
- std::cout << __LINE__ << std::endl;
- image->setImageLink(Wt::WLink(imageResource));
- imageLineItem->setAttributeValue("dummy", id);
- return imageLineItem;
-}
-
-std::string App::getChatLineWriter(Wt::Json::Object &line, Wt::Json::Object conversation) {
- std::string sender = (std::string)line["sender"];
- if (sender == sessionId()) {
- return "you";
- } else if (sender == (std::string)conversation["sessionid1"]) {
- return (std::string)conversation["user1"];
- } else {
- return (std::string)conversation["user2"];
- }
-}
-
-std::string App::replaceSmileys(std::string outputText) {
- for (const auto &smiley : smileys_) {
- std::size_t pos = outputText.find(smiley.first);
- while (pos != std::string::npos) {
- outputText.replace(pos, smiley.first.length(), "" + smiley.second.code + ";");
- pos = outputText.find(smiley.first, pos + smiley.second.code.length());
- }
- }
- return outputText;
-}
-
-void App::showUnreadMessages(Wt::Json::Object data) {
- Wt::WString base = Wt::WString::tr("menu_inbox");
- Wt::WString buttonText = (int)data["data"] == 0 ? base : Wt::WString("{1} ({2})").arg(base).arg((int)data["data"]);
- auto currentText = inbox_->text();
- inbox_->setText(buttonText);
- std::string pattern{"Posteingang\\(\\s*(\\d+)\\)"};
- std::regex regex(pattern);
- std::string text = currentText.toUTF8();
- std::smatch match;
- auto doPlay{false};
- if (std::regex_search(text, match, regex)) {
- std::string numberStr = match[2].str();
- auto oldValue = std::stoi(numberStr);
- if (oldValue < (int)data["data"] && (int)data["data"] > 0) {
- doPlay = true;
- }
- } else if (text == Wt::WString::tr("menu_inbox") && buttonText != Wt::WString::tr("menu_inbox")) {
- doPlay = true;
- }
- if (doPlay) {
- messageReceived_->play();
- }
- triggerUpdate();
- if (inboxOpen_) {
- server_.sendOpenConversations(sessionId());
- }
-}
-
-void App::showOpenInbox(Wt::Json::Object data) {
- searchFields.outputContainer = nullptr;
- contentContainer_->clear();
- contentContainer_->setPadding(Wt::WLength(1, Wt::LengthUnit::FontEm), Wt::Side::Top | Wt::Side::Bottom);
- contentContainer_->setPadding(Wt::WLength(2, Wt::LengthUnit::FontEm), Wt::Side::Left | Wt::Side::Right);
- contentContainer_->setOverflow(Wt::Overflow::Auto);
- auto headline = contentContainer_->addNew("Inbox
");
- headline->setInline(false);
- auto conversationsTable = contentContainer_->addNew();
- conversationsTable->resize(Wt::WLength(15, Wt::LengthUnit::FontEm), Wt::WLength::Auto);
- for (Wt::Json::Object &user: (Wt::Json::Array)data["data"]) {
- auto row = conversationsTable->rowCount();
- auto userItem = conversationsTable->elementAt(row, 0)->addNew();
- Wt::WString partnerName = (std::string)user["name"];
- auto flag = userItem->addNew(Wt::WLink(std::make_shared("../docroot/flags/" + (std::string)user["isoCountryCode"] + ".png")));
- flag->setToolTip(country);
- flag->setStyleClass("flag-icon");
- userItem->addNew(Wt::WString("{1} ({2})").arg(partnerName).arg((int)user["age"]));
- userItem->setStyleClass(Wt::WString("userlist-item userlist-gender-{1}").arg((std::string)user["gender"]));
- userItem->setHeight(Wt::WLength(2, Wt::LengthUnit::FontEm));
- userItem->setPadding(Wt::WLength(3, Wt::LengthUnit::Pixel));
- userItem->clicked().connect([=, this]() {
- requestConversation(partnerName.toUTF8());
- });
- }
- triggerUpdate();
-}
-
-void App::updateUserinfo(Wt::Json::Object data) {
- Wt::Json::Object userData = data["data"];
- if ((std::string)userData["name"] != currentConversationWith_) {
- return;
- }
- auto containerLayout = (Wt::WVBoxLayout*)contentContainer_->layout();
- auto infoLayoutItem = containerLayout->itemAt(0);
- auto infoWidget = (Wt::WContainerWidget*)(infoLayoutItem->widget());
- auto infoWidgetLayout = (Wt::WHBoxLayout*)infoWidget->layout();
- auto infoTextWidget = dynamic_cast(infoWidgetLayout->itemAt(1)->widget());
- auto blockButton = dynamic_cast(infoWidgetLayout->itemAt(2)->widget());
- try {
- infoWidget->setStyleClass(Wt::WString("user-conversation-info userlist-gender-{1}").arg((std::string)userData["gender"]));
- if (infoTextWidget) {
- infoTextWidget->setText(Wt::WString("{1} ({2}) - {3}, {4}").arg((std::string)userData["name"])
- .arg((int)userData["age"]).arg((std::string)userData["country"]).arg(genders_[(std::string)userData["gender"]]));
- }
- blockButton->setText((bool)userData["blocked"] ? "Unblock" : "Block");
- } catch (const std::exception &e) {
- std::cout << e.what() << std::endl << Wt::Json::serialize(userData) << std::endl;
- }
- triggerUpdate();
-}
-
-std::unique_ptr App::createSmileysBar(Wt::WLineEdit *inputLine, std::shared_ptr cursorPosition) {
- auto smileyBar = std::make_unique();
- smileyBar->setHidden(true);
- for (auto &smiley: smileys_) {
- auto code = smileyPlaceholder_;
- code = code.arg(smiley.second.code);
- auto item = smileyBar->addNew(code, Wt::TextFormat::UnsafeXHTML);
- item->setToolTip(smiley.second.tooltip);
- item->clicked().connect([=]() {
- try {
- auto currentText = inputLine->text().toUTF8();
- currentText.insert(*cursorPosition, smiley.first);
- inputLine->setText(currentText);
- inputLine->setFocus();
- *cursorPosition += smiley.first.length();
- } catch (const std::exception &e) {
- std::cout << e.what() << std::endl;
- }
- });
- }
- smileyBar->setStyleClass("smiley-bar");
- return smileyBar;
-}
-
-void App::toggleSmileysBar(Wt::WContainerWidget *smileyBar) {
- smileyBar->setHidden(!smileyBar->isHidden());
-}
-
-void App::systemEvent(Wt::Json::Object broadcast) {
- if ((std::string)broadcast["related-user"] != currentConversationWith_) {
- return;
- }
- auto containerLayout = (Wt::WVBoxLayout*)contentContainer_->layout();
- auto infoLayoutItem = containerLayout->itemAt(0);
- auto infoWidget = (Wt::WContainerWidget*)(infoLayoutItem->widget());
- auto infoWidgetLayout = (Wt::WHBoxLayout*)infoWidget->layout();
- auto blockButton = dynamic_cast(infoWidgetLayout->itemAt(2)->widget());
- if (broadcast["data"] == "blocked") {
- blockButton->setText("Unblock");
- } else if (broadcast["data"] == "unblocked") {
- blockButton->setText("Block");
- }
-}
-
-
-void App::createMenu() {
- menuContainer_->clear();
- menuContainer_->setStyleClass("menu");
- addLeaveButton();
- addIdentifier();
- addSearchButton();
- addInboxButton();
- addHistoryButton();
- addLoginTimeView();
- addTimeoutView();
-}
-
-void App::addLeaveButton() {
- auto leaveButton = menuContainer_->addNew(Wt::WString::tr("menu_leave"));
- leaveButton->clicked().connect(this, &App::logout);
-}
-
-void App::logout() {
- server_.addToDisconnectList(this);
- userListContainer_->clear();
- menuContainer_->clear();
- userName = "";
- showLogin();
- inboxOpen_ = false;
- searchFields.outputContainer = nullptr;
-}
-
-void App::addHistoryButton() {
- auto history = menuContainer_->addNew(Wt::WString::tr("menu_history"));
- history->clicked().connect(this, &App::requestHistory);
-}
-
-void App::addIdentifier() {
- menuContainer_->setPositionScheme(Wt::PositionScheme::Relative);
- auto flag = menuContainer_->addNew(Wt::WLink(std::make_shared("../docroot/flags/" + isoCountryCode + ".png")));
- flag->setToolTip(country);
- flag->setStyleClass("flag-icon");
- auto identifier = menuContainer_->addNew(Wt::WString("{1} ({2}), {3}").arg(userName).arg(isoCountryCode).arg(age));
- identifier->setMargin(Wt::WLength(0.3, Wt::LengthUnit::FontEm), Wt::Side::Bottom | Wt::Side::Top);
- Wt::WCssDecorationStyle backgroundStyle;
- backgroundStyle.setBackgroundColor(Wt::StandardColor::White);
- identifier->setStyleClass("inline-block");
- identifier->setPadding(Wt::WLength(0.3, Wt::LengthUnit::FontEm), Wt::Side::Left | Wt::Side::Right);
- identifier->setDecorationStyle(backgroundStyle);
- identifier->setWidth(Wt::WLength(25, Wt::LengthUnit::FontEm));
-}
-
-void App::addSearchButton() {
- auto searchButton = menuContainer_->addNew(Wt::WString::tr("menu_search"));
- searchButton->clicked().connect(this, &App::showSearchWindow);
-}
-
-void App::addInboxButton() {
- inbox_ = menuContainer_->addNew(Wt::WString::tr("menu_inbox"));
- inbox_->clicked().connect(this, &App::openInbox);
-}
-
-void App::showSearchWindow() {
- setActivity();
- auto contentLayout = resetSearchFields();
- auto userNameField = setupNameSearchField(contentLayout);
- auto ageSearchFields = setupSearchFields(contentLayout);
- auto countryFields = setupCountryDropDown(contentLayout);
- auto gendersFields = setupGendersDropDown(contentLayout);
- searchFields.outputContainer = setupSearchButton(contentLayout);
- restoreSearchFields(searchFields.outputContainer, userNameField, ageSearchFields.first, ageSearchFields.second,
- countryFields.second, gendersFields.second, countryFields.first, gendersFields.first);
-}
-
-Wt::WVBoxLayout *App::resetSearchFields() {
- currentConversationWith_ = "";
- contentContainer_->clear();
- inboxOpen_ = false;
- auto contentLayout = contentContainer_->setLayout(std::make_unique());
- contentLayout->addWidget(std::make_unique(Wt::WString::tr("search_title"), Wt::TextFormat::UnsafeXHTML));
- return contentLayout;
-}
-
-std::pair App::setupSearchFields(Wt::WVBoxLayout *contentLayout) {
- auto minAgeEdit = addSearchItemLine(contentLayout, Wt::WString::tr("search_from_age").toUTF8());
- minAgeEdit->setRange(18, 150);
- minAgeEdit->setValue(18);
- minAgeEdit->changed().connect([=, this] { searchFields.minAge = minAgeEdit->value(); });
- auto maxAgeEdit = addSearchItemLine(contentLayout, Wt::WString::tr("search_to_age").toUTF8());
- maxAgeEdit->setRange(18, 150);
- maxAgeEdit->setValue(150);
- maxAgeEdit->changed().connect([=, this] { searchFields.maxAge = maxAgeEdit->value(); });
- return {minAgeEdit, maxAgeEdit};
-}
-
-std::pair App::setupCountryDropDown(Wt::WVBoxLayout *contentLayout) {
- auto countryOpenList = addSearchItemLine(contentLayout, Wt::WString::tr("search_country").toUTF8());
- countryOpenList->addNew(Wt::WString::tr("search_all"));
- countryOpenList->setStyleClass("selectBoxes-drop-down-trigger");
- auto countryDropDown = countryOpenList->addNew();
- countryDropDown->setStyleClass("selectBoxes-dropdown");
- countryOpenList->setToolTip(Wt::WString::tr("search_country_tooltip"));
- std::map countries = server_.countries();
- addItem("All", countryDropDown, countryOpenList, &searchFields.countries, true);
- addItem(country, countryDropDown, countryOpenList, &searchFields.countries);
- for (const auto &itemCountry: countries) {
- if (itemCountry.first.toUTF8() != country) {
- addItem(itemCountry.first.toUTF8(), countryDropDown, countryOpenList, &searchFields.countries);
- }
- }
- return {countryOpenList, countryDropDown};
-}
-
-std::pair App::setupGendersDropDown(Wt::WVBoxLayout *contentLayout) {
- auto gendersOpenList = addSearchItemLine(contentLayout, Wt::WString::tr("search_genders").toUTF8());
- gendersOpenList->addNew(Wt::WString::tr("search_all"));
- gendersOpenList->setStyleClass("selectBoxes-drop-down-trigger");
- auto gendersDropDown = gendersOpenList->addNew();
- gendersDropDown->setStyleClass("selectBoxes-dropdown");
- gendersOpenList->setToolTip(Wt::WString::tr("search_genders_tooltip"));
- addItem("All", gendersDropDown, gendersOpenList, &searchFields.gender, true);
- std::map swappedGenders;
- for (const auto& pair : genders_) {
- swappedGenders[pair.second] = pair.first;
- }
- for (const auto &itemGender: swappedGenders) {
- addItem(itemGender.first.toUTF8(), gendersDropDown, gendersOpenList, &searchFields.gender);
- }
- return {gendersOpenList, gendersDropDown};
-}
-
-
-void App::addItem(const std::string& country, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *container, std::unordered_set *saveItems, bool isSelected) {
- auto menuItem = dropDownContainer->addNew(country);
- menuItem->changed().connect([=, this]() mutable { itemChanged(menuItem, dropDownContainer, container, saveItems); });
- menuItem->setInline(false);
- if (isSelected) {
- menuItem->setChecked();
- }
-}
-
-void App::addUserItemToLayout(Wt::WVBoxLayout *layout, Wt::Json::Object userObject) {
- auto userName = (std::string)userObject["name"];
- auto line = layout->addWidget(std::make_unique());
- auto flag = line->addNew(Wt::WLink(std::make_shared("../docroot/flags/" + (std::string)userObject["isoCountryCode"] + ".png")));
- flag->setMaximumSize(Wt::WLength(60, Wt::LengthUnit::Pixel), Wt::WLength(20, Wt::LengthUnit::Pixel));
- flag->setHeight(Wt::WLength(2, Wt::LengthUnit::FontEm));
- flag->setStyleClass("flag-icon");
- flag->setToolTip(userObject["country"]);
- line->addNew(Wt::WString("{1} ({2})").arg(userName).arg((int)userObject["age"]));
- line->setStyleClass(Wt::WString("userlist-item userlist-gender-{1}").arg((std::string)userObject["gender"]));
- line->setHeight(Wt::WLength(2, Wt::LengthUnit::FontEm));
- line->setPadding(Wt::WLength(3, Wt::LengthUnit::Pixel));
- line->clicked().connect([=, this]() {
- requestConversation(userName);
- });
-
-}
-
-std::unordered_set App::gendersListToShortGendersList(std::unordered_set gendersList) {
- std::unordered_set result;
- for (const auto &gender: gendersList) {
- result.insert(genderShortOfGender(gender));
- }
- return result;
-}
-
-std::string App::genderShortOfGender(const std::string incomingGender) {
- for (const auto &genderItem: genders_) {
- if (incomingGender == genderItem.second) {
- return genderItem.first.toUTF8();
- }
- }
- return incomingGender;
-}
-
-void App::extendSearchResultIfNeeded(Wt::Json::Object broadcast) {
- if (searchFields.outputContainer == nullptr) {
- return;
- }
- auto user = (Wt::Json::Object)broadcast["data"];
- auto age = (int)user["age"];
- auto country = (std::string)user["country"];
- auto gender = (std::string)user["gender"];
- if (
- (searchFields.userName.toUTF8() == "" || ((std::string)user["name"]).find(searchFields.userName.toUTF8()) != std::string::npos)
- && (searchFields.minAge <= age)
- && (searchFields.maxAge >= age)
- && (searchFields.countries.contains("All") || searchFields.countries.contains(country) || searchFields.countries.size() == 0)
- && (searchFields.gender.contains("All") || searchFields.gender.contains(gender) || searchFields.gender.size() == 0)
- ) {
- startSearch();
- }
-}
-
-void App::removeUserFromSearch(Wt::Json::Object) {
- if (searchFields.outputContainer == nullptr) {
- return;
- }
- startSearch();
-}
-
-void App::requestHistory() {
- setActivity();
- server_.sendHistory(sessionId());
-}
-
-void App::showHistory(Wt::Json::Object broadcast) {
- try {
- contentContainer_->clear();
- auto headerWidget = contentContainer_->addNew(Wt::WString::tr("history_title"), Wt::TextFormat::UnsafeXHTML);
- headerWidget->setInline(false);
- auto listWidget = contentContainer_->addNew();
- auto dataArray = (Wt::Json::Array)broadcast["data"];
-
- if (dataArray.empty()) {
- // Keine bisherigen Unterhaltungen vorhanden
- contentContainer_->addNew(Wt::WString::tr("history_empty"));
- } else {
- for (Wt::Json::Object user: dataArray) {
- auto userName = std::make_shared((std::string)user["name"]);
- auto tableCell = listWidget->elementAt(listWidget->rowCount(), 0);
- tableCell->addNew(Wt::WString("{1} ({2})").arg(*userName).arg((int)user["age"]));
- tableCell->setStyleClass(Wt::WString("user-conversation-info userlist-item userlist-gender-{1}").arg((std::string)user["gender"]));
- tableCell->clicked().connect([=, this]() {
- requestConversation(*userName);
- });
- }
- }
- } catch(std::exception &e) {
- std::cout << e.what() << std::endl;
- }
-
- triggerUpdate();
-}
-
-void App::connectionTimedOut() {
- showLogin();
- loginTimer_->stop();
- timeoutRemainingTimer_->stop();
- menuContainer_->clear();
- userListContainer_->clear();
- triggerUpdate();
-}
-
-void App::addLoginTimeView() {
- auto loggedinTimeWidget = menuContainer_->addNew();
- loggedinTimeWidget->setStyleClass("menu-info-text");
- loginTimer_ = root()->addChild(std::make_unique());
- loginTimer_->setInterval(std::chrono::seconds(1));
- auto loggedInRefresh = [=, this]() {
- auto currentLoginSeconds = currentlyLoggedInSeconds();
- int hours = currentLoginSeconds / 3600;
- int minutes = (currentLoginSeconds % 3600) / 60;
- std::stringstream elapsedTimeStream;
- elapsedTimeStream << std::setw(2) << std::setfill('0') << hours << ":"
- << std::setw(2) << std::setfill('0') << minutes << " h";
- std::string elapsedTimeString = elapsedTimeStream.str();
- loggedinTimeWidget->setText(Wt::WString::tr("menu_in_chat_for").arg(elapsedTimeString));
- };
- loginTimer_->timeout().connect(loggedInRefresh);
- loggedInRefresh();
- loginTimer_->start();
-}
-
-void App::addTimeoutView() {
- auto timeoutRemainingWidget = menuContainer_->addNew();
- timeoutRemainingWidget->setStyleClass("menu-info-text");
- timeoutRemainingTimer_ = root()->addChild(std::make_unique());
- timeoutRemainingTimer_->setInterval(std::chrono::milliseconds(500));
- auto timeoutRemainingRefresh = [=, this]() {
- auto remainingLoginSeconds = remainingSecondsToTimeout();
- int minutes = remainingLoginSeconds / 60;
- int seconds = (remainingLoginSeconds % 60);
- std::stringstream remainingTimeStream;
- remainingTimeStream << std::setw(2) << std::setfill('0') << minutes << ":"
- << std::setw(2) << std::setfill('0') << seconds << " m";
- std::string elapsedTimeString = remainingTimeStream.str();
- timeoutRemainingWidget->setText(Wt::WString::tr("menu_timeout_in").arg(elapsedTimeString));
- };
- timeoutRemainingTimer_->timeout().connect(timeoutRemainingRefresh);
- timeoutRemainingRefresh();
- timeoutRemainingTimer_->start();
-}
-
-void App::showPartnerSites() {
- setMetaTags();
- contentContainer_->clear();
- contentContainer_->setOverflow(Wt::Overflow::Auto);
- auto linkContainer = contentContainer_->addNew();
- auto contentLayout = linkContainer->setLayout(std::make_unique());
- contentLayout->addWidget(std::make_unique("Partners
"));
- if (userName == "") {
- auto hpLink = contentLayout->addWidget(std::make_unique("Back to main page"));
- hpLink->clicked().connect(this, &App::showLogin);
- }
- rapidcsv::Document doc("../docroot/links.csv");
- for (size_t i = 0; i < doc.GetRowCount(); ++i) {
- auto url = doc.GetCell(1, i);
- auto name = doc.GetCell(0, i);
- auto link = Wt::WLink(url);
- link.setTarget(Wt::LinkTarget::NewWindow);
- contentLayout->addWidget(std::make_unique(link, name));
- }
-}
-
-void App::itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WContainerWidget *container, std::unordered_set *saveItems) {
- saveItems->clear();
- bool unselect = (item->text() == "All" && item->isChecked());
- for (auto &widgetItem: dropDownContainer->children()) {
- auto widgetCheckBox = static_cast(widgetItem);
- if (unselect && widgetCheckBox->text() != "All" && widgetCheckBox->isChecked()) {
- widgetCheckBox->setChecked(false);
- }
- if (widgetCheckBox->isChecked()) {
- saveItems->insert(widgetCheckBox->text().toUTF8());
- }
- }
- if (saveItems->size() > 1 && saveItems->find("All") != saveItems->end()) {
- saveItems->erase(saveItems->find("All"));
- static_cast(dropDownContainer->children().at(0))->setChecked(false);
- }
- if (saveItems->empty()) {
- saveItems->insert("All");
- }
- std::string result;
- for (const auto &selected: *saveItems) {
- result += (result.empty() ? "" : ", ") + selected;
- }
- auto outputWidget = (Wt::WText*)container->children().at(0);
- outputWidget->setText(result);
-}
-
-void App::restoreSearchFields(Wt::WContainerWidget *searchResultContainer, Wt::WLineEdit *userNameEdit, Wt::WSpinBox *minAgeEdit,
- Wt::WSpinBox *maxAgeEdit, Wt::WContainerWidget *countryDropDownContainer, Wt::WContainerWidget *gendersDropDownContainer,
- Wt::WContainerWidget *countryOpenList, Wt::WContainerWidget *gendersOpenList) {
- if (!searchFields.set) {
- searchFields = Search(searchResultContainer);
- } else {
- userNameEdit->setValueText(searchFields.userName);
- minAgeEdit->setValue(searchFields.minAge);
- maxAgeEdit->setValue(searchFields.maxAge);
- for (auto countryWidget: countryDropDownContainer->children()) {
- auto countryCheckBox = (Wt::WCheckBox*)countryWidget;
- countryCheckBox->setChecked(searchFields.countries.find(countryCheckBox->text().toUTF8()) != searchFields.countries.end());
- }
- itemChanged((Wt::WCheckBox*)*countryDropDownContainer->children().begin(), countryDropDownContainer, countryOpenList, &searchFields.countries);
- for (auto genderWidget: gendersDropDownContainer->children()) {
- auto genderCheckBox = (Wt::WCheckBox*)genderWidget;
- genderCheckBox->setChecked(searchFields.gender.find(genderCheckBox->text().toUTF8()) != searchFields.gender.end());
- }
- itemChanged((Wt::WCheckBox*)*gendersDropDownContainer->children().begin(), gendersDropDownContainer, gendersOpenList, &searchFields.gender);
- startSearch();
- }
-}
-
-Wt::WLineEdit *App::setupNameSearchField(Wt::WVBoxLayout *contentLayout) {
- auto userNameEdit = addSearchItemLine(contentLayout, Wt::WString::tr("search_username_includes").toUTF8());
- userNameEdit->changed().connect([=, this] { searchFields.userName = userNameEdit->text().trim(); });
- return userNameEdit;
-}
-
-Wt::WContainerWidget *App::setupSearchButton(Wt::WVBoxLayout *contentLayout) {
- auto searchButton = addSearchItemLine(contentLayout, "");
- searchButton->setText(Wt::WString::tr("search_button"));
- auto searchResultContainer = contentLayout->addWidget(std::make_unique(), 1);
- searchResultContainer->addNew(Wt::WString::tr("search_no_results"));
- searchButton->clicked().connect(this, &App::startSearch);
- return searchResultContainer;
-}
-
-void App::startSearch() {
- if (searchFields.minAge > searchFields.maxAge) {
- searchFields.outputContainer->clear();
- searchFields.outputContainer->addNew(Wt::WString::tr("search_min_age_error"));
- return;
- }
- server_.userSearch(sessionId(), searchFields.userName.toUTF8(), searchFields.minAge, searchFields.maxAge,
- searchFields.countries, gendersListToShortGendersList(searchFields.gender), userName);
-}
-
-void App::showSearch(Wt::Json::Object broadcast) {
- if (!searchFields.outputContainer) {
- return;
- }
- searchFields.outputContainer->clear();
- auto searchResult = (Wt::Json::Array)broadcast["data"];
- if (searchResult.size() == 0) {
- searchFields.outputContainer->addNew(Wt::WString::tr("search_no_results"));
- }
- auto searchListContainer = searchFields.outputContainer->addNew();
- auto searchList = searchListContainer->setLayout(std::make_unique());
- searchListContainer->setOverflow(Wt::Overflow::Auto);
- for (const Wt::Json::Object &searchItem: searchResult) {
- addUserItemToLayout(searchList, searchItem);
- }
- triggerUpdate();
-}
-
-void App::openInbox() {
- setActivity();
- currentConversationWith_ = "";
- contentContainer_->clear();
- contentContainer_->addNew("Inbox
");
- inboxOpen_ = true;
- searchFields.outputContainer = nullptr;
- server_.sendOpenConversations(sessionId());
-}
-
-void App::incomingBroadcast() {
- auto broadcasts = server_.getBroadcastsForSession(sessionId());
- for (Wt::Json::Object &broadcast: broadcasts) {
- if (broadcast["type"] == "userlist") {
- updateUserlist(broadcast["data"], (int)broadcast["count"]);
- } else if (broadcast["type"] == "logout") {
- server_.disconnect(this);
- } else if (broadcast["type"] == "messagequeue") {
- renderConversation(broadcast);
- } else if (broadcast["type"] == "unread-chats") {
- showUnreadMessages(broadcast);
- } else if (broadcast["type"] == "openconversations" && inboxOpen_) {
- showOpenInbox(broadcast);
- } else if (broadcast["type"] == "userinfo") {
- updateUserinfo(broadcast);
- } else if (broadcast["type"] == "system") {
- systemEvent(broadcast);
- } else if (broadcast["type"] == "conversation-start") {
- showConversation(broadcast);
- } else if (broadcast["type"] == "search-result") {
- showSearch(broadcast);
- } else if (broadcast["type"] == "newuser") {
- extendSearchResultIfNeeded(broadcast);
- } else if (broadcast["type"] == "userleft") {
- removeUserFromSearch(broadcast);
- } else if (broadcast["type"] == "history") {
- showHistory(broadcast);
- } else if (broadcast["type"] == "timedout") {
- connectionTimedOut();
- }
- }
-}
-
-void App::startChat() {
- createMenu();
- contentContainer_->clear();
- contentContainer_->addNew(Wt::WString::tr("introduction"), Wt::TextFormat::UnsafeXHTML);
- setLoggedIn();
-}
-
-void App::createUserListContainer(Wt::WHBoxLayout *layout) {
- userListContainer_ = layout->addWidget(std::make_unique());
- userListContainer_->setStyleClass("userlist");
-}
-
-void App::createContentContainer(Wt::WHBoxLayout *layout) {
- contentContainer_ = layout->addWidget(std::make_unique());
- contentContainer_->setStyleClass("content");
-}
-
-void App::updateLocation() {
- CURL *curl;
- curl_global_init(CURL_GLOBAL_DEFAULT);
- curl = curl_easy_init();
- try {
- if (curl) {
- std::string userIP = getUserIP();
- std::string apiUrl = buildApiUrl(userIP);
- setCurlOptions(curl, apiUrl);
- performCurlRequest(curl);
- processCurlResponse();
- curl_easy_cleanup(curl);
- }
- } catch (std::exception &e) {
- handleException(e);
- }
- curl_global_cleanup();
-}
-
-std::string App::getUserIP() {
- std::string userIP = env_.clientAddress();
- return (userIP == "127.0.0.1") ? "77.189.91.196" : userIP;
-}
-
-std::string App::buildApiUrl(const std::string &userIP) {
- return "http://ip-api.com/xml/" + userIP;
-}
-
-void App::setCurlOptions(CURL *curl, const std::string &apiUrl) {
- curl_easy_setopt(curl, CURLOPT_URL, apiUrl.c_str());
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &App::WriteCallback);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, &responseData_);
-}
-
-void App::performCurlRequest(CURL *curl) {
- CURLcode res = curl_easy_perform(curl);
- if (res != CURLE_OK) {
- throw std::runtime_error("Curl request failed");
- }
-}
-
-void App::processCurlResponse() {
- xmlDocPtr doc = xmlReadMemory(responseData_.c_str(), responseData_.size(), NULL, NULL, 0);
- if (doc != NULL) {
- parseXmlDocument(doc);
- xmlFreeDoc(doc);
- }
-}
-
-void App::parseXmlDocument(xmlDocPtr doc) {
- xmlNodePtr countryCodeNode = xmlDocGetRootElement(doc)->children;
- while (countryCodeNode != nullptr) {
- processXmlNode(countryCodeNode);
- countryCodeNode = countryCodeNode->next;
- }
-}
-
-void App::processXmlNode(xmlNodePtr node) {
- if (xmlStrEqual(node->name, BAD_CAST "countryCode")) {
- isoCountryCode = reinterpret_cast(xmlNodeGetContent(node));
- } else if (xmlStrEqual(node->name, BAD_CAST "country")) {
- country = reinterpret_cast(xmlNodeGetContent(node));
- }
-}
-
-void App::handleException(const std::exception &e) {
- std::cerr << "Error: " << e.what() << std::endl;
-}
-
-bool App::isNickAllowed(const std::string& nick) {
- std::string lowercaseNick = nick;
- std::transform(lowercaseNick.begin(), lowercaseNick.end(), lowercaseNick.begin(), ::tolower);
- return (lowercaseNick != "self") &&
- (lowercaseNick != "system") &&
- (lowercaseNick != "you") &&
- std::all_of(notAllowedNickPhrases_.begin(), notAllowedNickPhrases_.end(),
- [&](const std::string& phrase) {
- std::string lowercasePhrase = phrase;
- std::transform(lowercasePhrase.begin(), lowercasePhrase.end(), lowercasePhrase.begin(), ::tolower);
- return lowercaseNick.find(lowercasePhrase) == std::string::npos;
- });
-}
-
-template
-Class *App::addSearchItemLine(Wt::WVBoxLayout *layout, std::string label, std::unique_ptr additionalItem) {
- auto lineContainer = layout->addWidget(std::make_unique());
- lineContainer->setStyleClass("search-line");
- lineContainer->setPositionScheme(Wt::PositionScheme::Relative);
- auto lineLayout = lineContainer->setLayout(std::make_unique());
- lineContainer->setPadding(Wt::WLength("0"));
- lineContainer->setMargin(Wt::WLength("0"));
- auto labelWidget = lineLayout->addWidget(std::make_unique(label));
- labelWidget->setWidth(Wt::WLength(9, Wt::LengthUnit::FontEm));
- lineLayout->setContentsMargins(0, 0, 0, 0);
- lineLayout->setSpacing(0);
- auto input = std::make_unique();
- auto returnInput = input.get();
- lineLayout->addWidget(std::move(input), 1);
- if (additionalItem) {
- lineLayout->addWidget(std::move(additionalItem));
- lineContainer->setOverflow(Wt::Overflow::Visible);
- }
- return returnInput;
-}
diff --git a/src/app.h b/src/app.h
deleted file mode 100644
index 1f53080..0000000
--- a/src/app.h
+++ /dev/null
@@ -1,229 +0,0 @@
-#ifndef APP_H
-#define APP_H
-
-#include
-#include
-#include "broadcast.h"
-#include "curl/curl.h"
-#include
-#include
-#include