Implemented search, fixed logout
This commit is contained in:
42
src/app.cpp
42
src/app.cpp
@@ -347,6 +347,7 @@ bool App::shouldShowConversation(Wt::Json::Object userData) {
|
||||
|
||||
void App::setupConversationUI(Wt::Json::Object userData) {
|
||||
inboxOpen_ = false;
|
||||
searchFields.outputContainer = nullptr;
|
||||
contentContainer_->clear();
|
||||
auto layout = contentContainer_->setLayout(std::make_unique<Wt::WVBoxLayout>());
|
||||
createInfoWidget(layout, userData);
|
||||
@@ -653,7 +654,6 @@ void App::showUnreadMessages(Wt::Json::Object data) {
|
||||
} else if (text == "Inbox" && buttonText != "Inbox") {
|
||||
doPlay = true;
|
||||
}
|
||||
std::cout << text << "/" << buttonText << ":" << doPlay << std::endl;
|
||||
if (doPlay) {
|
||||
messageReceived_->play();
|
||||
}
|
||||
@@ -664,6 +664,7 @@ void App::showUnreadMessages(Wt::Json::Object data) {
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -765,6 +766,7 @@ void App::logout() {
|
||||
menuContainer_->clear();
|
||||
showLogin();
|
||||
inboxOpen_ = false;
|
||||
searchFields.outputContainer = nullptr;
|
||||
}
|
||||
|
||||
void App::addIdentifier() {
|
||||
@@ -794,8 +796,8 @@ void App::showSearchWindow() {
|
||||
auto ageSearchFields = setupSearchFields(contentLayout);
|
||||
auto countryFields = setupCountryDropDown(contentLayout);
|
||||
auto gendersFields = setupGendersDropDown(contentLayout);
|
||||
auto searchResultContainer = setupSearchButton(contentLayout);
|
||||
restoreSearchFields(searchResultContainer, userNameField, ageSearchFields.first, ageSearchFields.second,
|
||||
searchFields.outputContainer = setupSearchButton(contentLayout);
|
||||
restoreSearchFields(searchFields.outputContainer, userNameField, ageSearchFields.first, ageSearchFields.second,
|
||||
countryFields.second, gendersFields.second, countryFields.first, gendersFields.first);
|
||||
}
|
||||
|
||||
@@ -898,6 +900,32 @@ std::string App::genderShortOfGender(const std::string incomingGender) {
|
||||
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::itemChanged(Wt::WCheckBox *item, Wt::WContainerWidget *dropDownContainer, Wt::WPushButton *openButton, std::unordered_set<std::string> *saveItems) {
|
||||
saveItems->clear();
|
||||
bool unselect = (item->text() == "All" && item->isChecked());
|
||||
@@ -973,6 +1001,9 @@ void App::startSearch() {
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -992,6 +1023,7 @@ void App::openInbox() {
|
||||
contentContainer_->clear();
|
||||
contentContainer_->addNew<Wt::WText>("<h2>Inbox</h2>");
|
||||
inboxOpen_ = true;
|
||||
searchFields.outputContainer = nullptr;
|
||||
server_.sendOpenConversations(sessionId());
|
||||
}
|
||||
|
||||
@@ -1016,6 +1048,10 @@ void App::incomingBroadcast() {
|
||||
showConversation(broadcast);
|
||||
} else if (broadcast["type"] == "search-result") {
|
||||
showSearch(broadcast);
|
||||
} else if (broadcast["type"] == "newuser") {
|
||||
extendSearchResultIfNeeded(broadcast);
|
||||
} else if (broadcast["type"] == "userleft") {
|
||||
removeUserFromSearch(broadcast);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,10 +45,11 @@ private:
|
||||
{";)", Smiley("1F609", "Twinkle")},
|
||||
{":p", Smiley("1F60B", "Tongue")},
|
||||
{";p", Smiley("1F61C", "Twinkle tongue")},
|
||||
{"O)", Smiley("1F607", "Angel")},
|
||||
{":'(", Smiley("1F622", "Cry")}
|
||||
};
|
||||
struct Search {
|
||||
Wt::WContainerWidget *outputContainer;
|
||||
Wt::WContainerWidget *outputContainer = nullptr;
|
||||
Wt::WString userName{""};
|
||||
int minAge{18};
|
||||
int maxAge{150};
|
||||
@@ -180,6 +181,8 @@ private:
|
||||
void addUserItemToLayout(Wt::WVBoxLayout *layout, Wt::Json::Object userObject);
|
||||
std::unordered_set<std::string> gendersListToShortGendersList(std::unordered_set<std::string> gendersList);
|
||||
std::string genderShortOfGender(const std::string incomingGender);
|
||||
void extendSearchResultIfNeeded(Wt::Json::Object broadcast);
|
||||
void removeUserFromSearch(Wt::Json::Object broadcast);
|
||||
};
|
||||
|
||||
#endif // APP_H
|
||||
|
||||
@@ -24,9 +24,14 @@ Broadcast::~Broadcast() {
|
||||
|
||||
void Broadcast::connect(Client *client, const std::function<void ()> &fct) {
|
||||
connections_.push_back(std::make_unique<Connection>(Wt::WApplication::instance()->sessionId(), client, fct));
|
||||
auto broadcast = createUserList();
|
||||
auto userlistBroadcast = createUserList();
|
||||
auto newUserBroadcast = Wt::Json::Object{
|
||||
{"type", "newuser"},
|
||||
{"data", client->json()}
|
||||
};
|
||||
for (auto &connection: connections_) {
|
||||
connection->addBroadcast(broadcast);
|
||||
connection->addBroadcast(userlistBroadcast);
|
||||
connection->addBroadcast(newUserBroadcast);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +42,14 @@ void Broadcast::disconnect(Client *client) {
|
||||
connections_.erase(connections_.begin() + i);
|
||||
}
|
||||
}
|
||||
auto broadcast = createUserList();
|
||||
Wt::Json::Object leftBroadcast{
|
||||
{"type", "userleft"},
|
||||
{"data", Wt::Json::Value(client->userName)}
|
||||
};
|
||||
auto userlistBroadcast = createUserList();
|
||||
for (auto &connection: connections_) {
|
||||
connection->addBroadcast(broadcast);
|
||||
connection->addBroadcast(userlistBroadcast);
|
||||
connection->addBroadcast(leftBroadcast);
|
||||
}
|
||||
auto sessionId = sessionIdForUserName(client->userName);
|
||||
for (auto it = conversations_.begin(); it != conversations_.end();) {
|
||||
@@ -368,7 +378,6 @@ void Broadcast::requestConversation(std::string sendToSessionId, std::string wit
|
||||
void Broadcast::userSearch(std::string toSession, std::string nameIncludes, int minAge, int maxAge, std::unordered_set<std::string> countries, std::unordered_set<std::string> genders, std::string excludeName) {
|
||||
Wt::Json::Array searchResult;
|
||||
for (const auto &user: connections_) {
|
||||
std::cout << user->gender() << std::endl;
|
||||
if (
|
||||
(nameIncludes == "" || user->userName().find(nameIncludes) != std::string::npos)
|
||||
&& (minAge <= user->age())
|
||||
|
||||
Reference in New Issue
Block a user