From 8b1d23b390b8184c028de10138a3ffeb27421e7f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 1 May 2018 14:58:16 +0200 Subject: Use new odhtdb with timestamp bug fix, fix waiting msg --- src/main.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 03f6a81..1e63d70 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -111,8 +111,9 @@ int main(int argc, char **argv) string currentUserName; string currentUserPassword; recursive_mutex channelMessageMutex; + bool waitingToJoin = false; - database.setOnCreateNodeCallback([&waitingToJoinChannels, &database, &channels, &channelMessageMutex](const odhtdb::DatabaseCreateNodeRequest &request) + database.setOnCreateNodeCallback([&waitingToJoinChannels, &database, &channels, &channelMessageMutex, &waitingToJoin](const odhtdb::DatabaseCreateNodeRequest &request) { lock_guard lock(channelMessageMutex); for(vector::iterator it = waitingToJoinChannels.begin(); it != waitingToJoinChannels.end(); ++it) @@ -127,6 +128,7 @@ int main(int argc, char **argv) User *nodeCreatorUser = new OnlineUser(request.creatorUser); channel->addUserLocally(nodeCreatorUser); + waitingToJoin = true; waitingToJoinChannels.erase(it); return; @@ -155,7 +157,7 @@ int main(int argc, char **argv) } }); - database.setOnAddUserCallback([¤tUserKeyPair, &channels, &channelMessageMutex](const odhtdb::DatabaseAddUserRequest &request) + database.setOnAddUserCallback([¤tUserKeyPair, &channels, &channelMessageMutex, &waitingToJoin](const odhtdb::DatabaseAddUserRequest &request) { lock_guard lock(channelMessageMutex); if(currentUserKeyPair && request.userToAdd->getPublicKey() == currentUserKeyPair->getPublicKey()) @@ -172,6 +174,7 @@ int main(int argc, char **argv) if(userToAdd && currentUserKeyPair && request.userToAdd->getPublicKey() == currentUserKeyPair->getPublicKey() && channel->getLocalUser()->type != User::Type::ONLINE) { channel->replaceLocalUser(new OnlineUser(request.userToAdd)); + waitingToJoin = false; return; } @@ -359,7 +362,7 @@ int main(int argc, char **argv) } }); - Command::add("jc", [¤tUserKeyPair, &database, &localNodeUsers, &channelMessageMutex](const vector &args) + Command::add("jc", [¤tUserKeyPair, &database, &localNodeUsers, &channelMessageMutex, &waitingToJoin](const vector &args) { lock_guard lock(channelMessageMutex); if(args.size() != 1) @@ -391,6 +394,7 @@ int main(int argc, char **argv) } database.seed(databaseNode); + waitingToJoin = true; // TODO: Add the channel to join to a pending join list in a file and remove from it when we have joined the channel. // The reason for doing that is so if we crash or lose internet connection before we have got `create node` request from remote peers, // then we need to start seeding again when we login. Once we have `create node` request, then it's added to local cache and when you login, @@ -447,10 +451,7 @@ int main(int argc, char **argv) sf::Event event; while (window.isOpen()) { - channelMessageMutex.lock(); Channel *currentChannel = Channel::getCurrent(); - bool waitingToJoin = currentChannel != &offlineChannel && currentChannel->getLocalUser()->type != User::Type::ONLINE; - channelMessageMutex.unlock(); while (window.pollEvent(event)) { -- cgit v1.2.3