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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user