diff options
m--------- | depends/odhtdb | 0 | ||||
-rw-r--r-- | src/main.cpp | 13 |
2 files changed, 7 insertions, 6 deletions
diff --git a/depends/odhtdb b/depends/odhtdb -Subproject 8da5ba7f057978b224868028679cbda9e11089a +Subproject b0cc417bc9289fdd5c98028136e37c6a6ee6294 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<recursive_mutex> lock(channelMessageMutex); for(vector<odhtdb::DatabaseNode>::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<recursive_mutex> 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<string> &args) + Command::add("jc", [¤tUserKeyPair, &database, &localNodeUsers, &channelMessageMutex, &waitingToJoin](const vector<string> &args) { lock_guard<recursive_mutex> 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)) { |