Added message historyp
This commit is contained in:
35
src/app.cpp
35
src/app.cpp
@@ -359,7 +359,6 @@ void App::setupConversationUI(Wt::Json::Object userData) {
|
||||
Wt::WContainerWidget* App::createInfoWidget(Wt::WVBoxLayout *layout, Wt::Json::Object userData) {
|
||||
auto infoWidget = layout->addNew<Wt::WContainerWidget>();
|
||||
auto infoLayout = infoWidget->setLayout(std::make_unique<Wt::WHBoxLayout>());
|
||||
infoWidget->setStyleClass("user-conversation-info");
|
||||
infoWidget->setStyleClass(Wt::WString("user-conversation-info userlist-gender-{1}").arg((std::string)userData["gender"]));
|
||||
infoLayout->addWidget(createInfoText(userData), 1);
|
||||
auto blockButton = createBlockButton(userData);
|
||||
@@ -757,6 +756,7 @@ void App::createMenu() {
|
||||
addIdentifier();
|
||||
addSearchButton();
|
||||
addInboxButton();
|
||||
addHistoryButton();
|
||||
}
|
||||
|
||||
void App::addLeaveButton() {
|
||||
@@ -773,6 +773,11 @@ void App::logout() {
|
||||
searchFields.outputContainer = nullptr;
|
||||
}
|
||||
|
||||
void App::addHistoryButton() {
|
||||
auto history = menuContainer_->addNew<Wt::WPushButton>("History");
|
||||
history->clicked().connect(this, &App::requestHistory);
|
||||
}
|
||||
|
||||
void App::addIdentifier() {
|
||||
auto identifier = menuContainer_->addNew<Wt::WText>(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);
|
||||
@@ -930,6 +935,32 @@ void App::removeUserFromSearch(Wt::Json::Object) {
|
||||
startSearch();
|
||||
}
|
||||
|
||||
void App::requestHistory() {
|
||||
server_.sendHistory(sessionId());
|
||||
}
|
||||
|
||||
void App::showHistory(Wt::Json::Object broadcast) {
|
||||
try {
|
||||
contentContainer_->clear();
|
||||
auto headerWidget = contentContainer_->addNew<Wt::WText>("<h2>Conversations with already logged in users</h2>");
|
||||
headerWidget->setInline(false);
|
||||
auto listWidget = contentContainer_->addNew<Wt::WTable>();
|
||||
for (Wt::Json::Object user: (Wt::Json::Array)broadcast["data"]) {
|
||||
auto userName = std::make_shared<std::string>((std::string)user["name"]);
|
||||
auto tableCell = listWidget->elementAt(listWidget->rowCount(), 0);
|
||||
tableCell->addNew<Wt::WText>(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::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());
|
||||
@@ -1056,6 +1087,8 @@ void App::incomingBroadcast() {
|
||||
extendSearchResultIfNeeded(broadcast);
|
||||
} else if (broadcast["type"] == "userleft") {
|
||||
removeUserFromSearch(broadcast);
|
||||
} else if (broadcast["type"] == "history") {
|
||||
showHistory(broadcast);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +116,7 @@ private:
|
||||
void createMenu();
|
||||
void addLeaveButton();
|
||||
void logout();
|
||||
void addHistoryButton();
|
||||
void addIdentifier();
|
||||
void addSearchButton();
|
||||
void addInboxButton();
|
||||
@@ -194,6 +195,8 @@ private:
|
||||
std::string genderShortOfGender(const std::string incomingGender);
|
||||
void extendSearchResultIfNeeded(Wt::Json::Object broadcast);
|
||||
void removeUserFromSearch(Wt::Json::Object broadcast);
|
||||
void requestHistory();
|
||||
void showHistory(Wt::Json::Object broadcast);
|
||||
};
|
||||
|
||||
#endif // APP_H
|
||||
|
||||
@@ -396,6 +396,29 @@ void Broadcast::userSearch(std::string toSession, std::string nameIncludes, int
|
||||
addMessageToSessionBroadcast(toSession, broadcast);
|
||||
}
|
||||
|
||||
void Broadcast::sendHistory(std::string toSession) {
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
Wt::Json::Array filteredConversationsPartners;
|
||||
for (const auto& pair : conversations_) {
|
||||
const std::string& key = pair.first;
|
||||
if (key.rfind(toSession + "/", 0) == 0 || key.find("/" + toSession) == key.size() - toSession.length() - 1) {
|
||||
std::string partnerId;
|
||||
if (key.rfind(toSession + "/", 0) == 0) {
|
||||
partnerId = key.substr(toSession.size() + 1);
|
||||
} else {
|
||||
partnerId = key.substr(0, key.size() - toSession.size() - 1);
|
||||
}
|
||||
auto partner = userForSessionId(partnerId);
|
||||
filteredConversationsPartners.push_back(Wt::Json::Value(partner));
|
||||
}
|
||||
}
|
||||
Wt::Json::Object broadcast{
|
||||
{"type", "history"},
|
||||
{"data", filteredConversationsPartners}
|
||||
};
|
||||
addMessageToSessionBroadcast(toSession, broadcast);
|
||||
}
|
||||
|
||||
bool Broadcast::parseCountriesData() {
|
||||
std::istringstream iss(responseData_);
|
||||
std::string line;
|
||||
|
||||
@@ -84,6 +84,7 @@ public:
|
||||
void requestConversation(std::string sendToSessionId, std::string withUserName, std::string requestingUserName);
|
||||
void 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);
|
||||
void sendHistory(std::string toSession);
|
||||
protected:
|
||||
struct Connection {
|
||||
Connection(const std::string &id, Client *client, const std::function<void ()> &fct);
|
||||
|
||||
Reference in New Issue
Block a user