From 0cae593b94c4fdfe100516c7f08f75e40bc1e089 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 8 Apr 2019 21:02:51 +0200 Subject: Move room setName to its own function, escape commands --- include/dchat/Process.hpp | 8 ++++++++ include/dchat/Room.hpp | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 include/dchat/Process.hpp (limited to 'include') diff --git a/include/dchat/Process.hpp b/include/dchat/Process.hpp new file mode 100644 index 0000000..18aa2d9 --- /dev/null +++ b/include/dchat/Process.hpp @@ -0,0 +1,8 @@ +#pragma once + +#include + +namespace dchat +{ + std::string escapeCommand(const std::string &cmd); +} \ No newline at end of file diff --git a/include/dchat/Room.hpp b/include/dchat/Room.hpp index 56b60e5..6681cdc 100644 --- a/include/dchat/Room.hpp +++ b/include/dchat/Room.hpp @@ -31,16 +31,16 @@ namespace dchat Room(Rooms *rooms, std::shared_ptr id); // Throws exception on failure if we are not allowed to add the user to the group void addUser(const odhtdb::Signature::PublicKey &userPublicKey, std::shared_ptr group); - // Returns null if the user already exists in the room - std::shared_ptr addUserLocally(const odhtdb::Signature::PublicKey &userPublicKey, std::shared_ptr group); - // Returns null if the group already exists in the room - std::shared_ptr addGroupLocally(const odhtdb::DataView groupId); + // Returns null if user doesn't exist in room std::shared_ptr getUserByPublicKey(const odhtdb::Signature::PublicKey &userPublicKey); + // Returns null if group doesn't exist in room std::shared_ptr getGroupById(const odhtdb::DataView groupId); + void setAvatarUrl(const std::string &url); - void setNickname(const std::string &nickname); + void setUserNickname(const std::string &nickname); + bool setName(const std::string &name); void publishMessage(const std::string &msg); const odhtdb::Signature::MapPublicKey>& getUsers() const { return userByPublicKey; } @@ -57,6 +57,10 @@ namespace dchat // TODO: Move to private when we have proper support for groups std::vector> groups; private: + // Returns null if the user already exists in the room + std::shared_ptr addUserLocally(const odhtdb::Signature::PublicKey &userPublicKey, std::shared_ptr group); + // Returns null if the group already exists in the room + std::shared_ptr addGroupLocally(const odhtdb::DataView groupId); void setLocalUser(std::shared_ptr user, std::shared_ptr keyPair); private: odhtdb::Signature::MapPublicKey> userByPublicKey; @@ -116,6 +120,7 @@ namespace dchat uint32_t timestampSeconds; bool loadedFromCache; bool isLocalUser; + bool waitedToJoin; }; // if connection failed then @rooms is null and errMsg contains the error @@ -153,7 +158,8 @@ namespace dchat void registerUser(const std::string &username, const std::string &password); // Throws on failure std::shared_ptr createRoom(const std::string &name); - void requestJoinRoom(const std::string &inviteKey, const std::string &message); + // Throws on failure, returns true on success, returns false on expected failures (such as already being a member of the room) + bool requestJoinRoom(const std::string &inviteKey, const std::string &message); std::shared_ptr database; -- cgit v1.2.3