diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-11-09 09:45:13 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-11-09 09:45:15 +0100 |
commit | 1a1d3b7dc56e173d46d89fd9c05cd295bb8bcbf2 (patch) | |
tree | 0ad31527301790b0d63317a17194e91e1b494919 /include/dchat | |
parent | 8d5f778bced78b1ecaae7b5a301f9da5e7d9af2d (diff) |
Room join/invite, fix build for mingw
Diffstat (limited to 'include/dchat')
-rw-r--r-- | include/dchat/FileUtil.hpp | 2 | ||||
-rw-r--r-- | include/dchat/Group.hpp | 15 | ||||
-rw-r--r-- | include/dchat/Room.hpp | 40 | ||||
-rw-r--r-- | include/dchat/User.hpp | 4 |
4 files changed, 57 insertions, 4 deletions
diff --git a/include/dchat/FileUtil.hpp b/include/dchat/FileUtil.hpp index 097b607..6a7ff00 100644 --- a/include/dchat/FileUtil.hpp +++ b/include/dchat/FileUtil.hpp @@ -13,7 +13,7 @@ namespace dchat }; // Throws FileException on error. - // Returned value is allocated with malloc and should be free'd by caller. + // Returned value is allocated with `new[]` and should be `delete`[]d by caller. StringView getFileContent(const boost::filesystem::path &filepath); // Throws FileException on error diff --git a/include/dchat/Group.hpp b/include/dchat/Group.hpp new file mode 100644 index 0000000..8b47923 --- /dev/null +++ b/include/dchat/Group.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include "types.hpp" +#include <odhtdb/Group.hpp> +#include <string> + +namespace dchat +{ + class Group + { + public: + u8 id[odhtdb::GROUP_ID_LENGTH]; + std::string name; + }; +}
\ No newline at end of file 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<odhtdb::Hash> id); - std::shared_ptr<User> 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> group); + // Returns null if the user already exists in the room + std::shared_ptr<User> addUserLocally(const odhtdb::Signature::PublicKey &userPublicKey, std::shared_ptr<Group> group); + // Returns null if the group already exists in the room + std::shared_ptr<Group> addGroupLocally(const odhtdb::DataView groupId); // Returns null if user doesn't exist in room std::shared_ptr<User> getUserByPublicKey(const odhtdb::Signature::PublicKey &userPublicKey); + // Returns null if group doesn't exist in room + std::shared_ptr<Group> getGroupById(const odhtdb::DataView groupId); + void setLocalUser(std::shared_ptr<User> user, std::shared_ptr<odhtdb::Signature::KeyPair> keyPair); void publishMessage(const std::string &msg); Rooms *rooms; @@ -38,10 +46,12 @@ namespace dchat std::shared_ptr<odhtdb::OwnedByteArray> encryptionKey; std::string name; odhtdb::Signature::MapPublicKey<std::shared_ptr<User>> userByPublicKey; + std::vector<std::shared_ptr<Group>> groups; std::vector<RoomMessage> messages; std::shared_ptr<User> localUser; // Used for local users odhtdb::Signature::MapPublicKey<std::shared_ptr<odhtdb::Signature::KeyPair>> publicKeyToKeyPairMap; + std::string inviteKey; void *userdata; }; @@ -70,13 +80,31 @@ namespace dchat std::string newName; }; + struct InviteUserRequest + { + std::shared_ptr<Room> room; + odhtdb::Signature::PublicKey userPublicKey; + std::string message; + }; + + struct RoomAddUserRequest + { + std::shared_ptr<Room> room; + std::shared_ptr<User> user; + std::shared_ptr<User> addedByUser; + uint32_t timestampSeconds; + bool loadedFromCache; + bool isLocalUser; + }; + // if connection failed then @rooms is null and errMsg contains the error using ConnectBoostrapNodeCallbackFunc = std::function<void(std::shared_ptr<Rooms> rooms, const char *errMsg)>; using CreateRoomCallbackFunc = std::function<void(std::shared_ptr<Room> room)>; - using RoomAddUserCallbackFunc = std::function<void(std::shared_ptr<Room> room, std::shared_ptr<User> user)>; + using RoomAddUserCallbackFunc = std::function<void(const RoomAddUserRequest &request)>; using RoomAddMessageCallbackFunc = std::function<void(const RoomAddMessageRequest &request)>; using UserChangeNicknameCallbackFunc = std::function<void(const UserChangeNicknameRequest &request)>; using ChangeRoomNameCallbackFunc = std::function<void(const RoomChangeNameRequest &request)>; + using ReceiveInviteUserCallbackFunc = std::function<void(const InviteUserRequest &request)>; 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<Room> createRoom(const std::string &name); + void requestJoinRoom(const std::string &inviteKey, const std::string &message); std::shared_ptr<odhtdb::Database> database; private: @@ -116,5 +147,8 @@ namespace dchat std::string currentUsername; std::string currentUserPassword; std::recursive_mutex roomModifyMutex; + + odhtdb::MapHash<std::shared_ptr<odhtdb::Signature::KeyPair>> waitingToJoinRoom; + std::recursive_mutex waitingToJoinRoomMutex; }; }
\ No newline at end of file diff --git a/include/dchat/User.hpp b/include/dchat/User.hpp index 4021c78..245197f 100644 --- a/include/dchat/User.hpp +++ b/include/dchat/User.hpp @@ -1,7 +1,10 @@ #pragma once +#include "Group.hpp" #include <string> +#include <vector> #include <odhtdb/Signature.hpp> +#include <memory> namespace dchat { @@ -11,6 +14,7 @@ namespace dchat User(const odhtdb::Signature::PublicKey &_publicKey) : publicKey(_publicKey), userdata(nullptr) {} const odhtdb::Signature::PublicKey publicKey; std::string nickname; + std::vector<std::shared_ptr<Group>> groups; void *userdata; }; }
\ No newline at end of file |