From 1a1d3b7dc56e173d46d89fd9c05cd295bb8bcbf2 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 9 Nov 2018 09:45:13 +0100 Subject: Room join/invite, fix build for mingw --- include/dchat/Room.hpp | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'include/dchat/Room.hpp') diff --git a/include/dchat/Room.hpp b/include/dchat/Room.hpp index 5dd0e3f..a39f2f0 100644 --- a/include/dchat/Room.hpp +++ b/include/dchat/Room.hpp @@ -28,9 +28,17 @@ namespace dchat DISABLE_COPY(Room) public: Room(Rooms *rooms, std::shared_ptr id); - std::shared_ptr addUser(const odhtdb::Signature::PublicKey &userPublicKey, const odhtdb::DataView groupId); + // 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 setLocalUser(std::shared_ptr user, std::shared_ptr keyPair); void publishMessage(const std::string &msg); Rooms *rooms; @@ -38,10 +46,12 @@ namespace dchat std::shared_ptr encryptionKey; std::string name; odhtdb::Signature::MapPublicKey> userByPublicKey; + std::vector> groups; std::vector messages; std::shared_ptr localUser; // Used for local users odhtdb::Signature::MapPublicKey> publicKeyToKeyPairMap; + std::string inviteKey; void *userdata; }; @@ -70,13 +80,31 @@ namespace dchat std::string newName; }; + struct InviteUserRequest + { + std::shared_ptr room; + odhtdb::Signature::PublicKey userPublicKey; + std::string message; + }; + + struct RoomAddUserRequest + { + std::shared_ptr room; + std::shared_ptr user; + std::shared_ptr addedByUser; + uint32_t timestampSeconds; + bool loadedFromCache; + bool isLocalUser; + }; + // if connection failed then @rooms is null and errMsg contains the error using ConnectBoostrapNodeCallbackFunc = std::function rooms, const char *errMsg)>; using CreateRoomCallbackFunc = std::function room)>; - using RoomAddUserCallbackFunc = std::function room, std::shared_ptr user)>; + using RoomAddUserCallbackFunc = std::function; using RoomAddMessageCallbackFunc = std::function; using UserChangeNicknameCallbackFunc = std::function; using ChangeRoomNameCallbackFunc = std::function; + using ReceiveInviteUserCallbackFunc = std::function; struct RoomCallbackFuncs { ConnectBoostrapNodeCallbackFunc connectCallbackFunc; @@ -85,10 +113,12 @@ namespace dchat RoomAddMessageCallbackFunc addMessageCallbackFunc; UserChangeNicknameCallbackFunc userChangeNicknameCallbackFunc; ChangeRoomNameCallbackFunc changeRoomNameCallbackFunc; + ReceiveInviteUserCallbackFunc receiveInviteUserCallbackFunc; }; class Rooms { + friend Room; DISABLE_COPY(Rooms) public: // @callbackFuncs.connectCallbackFunc can't be null @@ -98,7 +128,8 @@ namespace dchat // Throws on failure void registerUser(const std::string &username, const std::string &password); // Throws on failure - void createRoom(const std::string &name); + std::shared_ptr createRoom(const std::string &name); + void requestJoinRoom(const std::string &inviteKey, const std::string &message); std::shared_ptr database; private: @@ -116,5 +147,8 @@ namespace dchat std::string currentUsername; std::string currentUserPassword; std::recursive_mutex roomModifyMutex; + + odhtdb::MapHash> waitingToJoinRoom; + std::recursive_mutex waitingToJoinRoomMutex; }; } \ No newline at end of file -- cgit v1.2.3