From 983be4253f2ea3827d78db97afcc666664ae75ed Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 7 Apr 2019 17:15:42 +0200 Subject: Update cache signature, update odhtdb --- include/dchat/Cache.hpp | 8 ++++++-- include/dchat/Gif.hpp | 2 +- include/dchat/Room.hpp | 9 ++++++++- include/dchat/WebPagePreview.hpp | 5 +---- 4 files changed, 16 insertions(+), 8 deletions(-) (limited to 'include/dchat') diff --git a/include/dchat/Cache.hpp b/include/dchat/Cache.hpp index 8d3f28e..71bd785 100644 --- a/include/dchat/Cache.hpp +++ b/include/dchat/Cache.hpp @@ -1,7 +1,6 @@ #pragma once #include "types.hpp" -#include "WebPagePreview.hpp" #include "StringView.hpp" #include "utils.hpp" #include @@ -63,6 +62,7 @@ namespace dchat // Returned gif should be allocated with @new using CreateGifFunc = std::function; using CreateStaticImageFunc = std::function; + using CreateWebPagePreviewFunc = std::function; class Cache { @@ -70,13 +70,16 @@ namespace dchat public: // @createGifFunc can't be null // @createStaticImageFunc can't be null - Cache(CreateGifFunc createGifFunc, CreateStaticImageFunc createStaticImageFunc); + // @createWebPagePreviewFunc can't be null + Cache(CreateGifFunc createGifFunc, CreateStaticImageFunc createStaticImageFunc, CreateWebPagePreviewFunc createWebPagePreviewFunc); ~Cache(); // Get cached content or download it. // Default download file limit is 12MB // Returns ContentByUrlResult describing texture status. const ContentByUrlResult getContentByUrl(const std::string &url, int downloadLimitBytes = 12582912); + private: + ContentByUrlResult loadImageFromFile(const boost::filesystem::path &filepath, bool loadFromCache); private: struct ImageDownloadInfo { @@ -93,5 +96,6 @@ namespace dchat std::unordered_map contentUrlCache; CreateGifFunc createGifFunc; CreateStaticImageFunc createStaticImageFunc; + CreateWebPagePreviewFunc createWebPagePreviewFunc; }; } diff --git a/include/dchat/Gif.hpp b/include/dchat/Gif.hpp index c870d1c..b7d2efb 100644 --- a/include/dchat/Gif.hpp +++ b/include/dchat/Gif.hpp @@ -35,7 +35,7 @@ namespace dchat static bool isDataGif(const StringView &data); protected: // Return false if texture creation failed - virtual bool createTexture(int width, int height) = 0; + virtual bool createTexture() = 0; // Size of texture data is same as the size that the texture was created with (also same size returned by @getSize function) virtual void updateTexture(void *textureData) = 0; private: diff --git a/include/dchat/Room.hpp b/include/dchat/Room.hpp index 6980bfc..56b60e5 100644 --- a/include/dchat/Room.hpp +++ b/include/dchat/Room.hpp @@ -39,11 +39,13 @@ namespace dchat 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 setAvatarUrl(const std::string &url); void setNickname(const std::string &nickname); void publishMessage(const std::string &msg); + const odhtdb::Signature::MapPublicKey>& getUsers() const { return userByPublicKey; } + const std::vector>& getMessages() const { return messages; } + Rooms *rooms; std::shared_ptr id; std::shared_ptr encryptionKey; @@ -54,6 +56,8 @@ namespace dchat // TODO: Move to private when we have proper support for groups std::vector> groups; + private: + void setLocalUser(std::shared_ptr user, std::shared_ptr keyPair); private: odhtdb::Signature::MapPublicKey> userByPublicKey; // Used for local users @@ -152,6 +156,9 @@ namespace dchat void requestJoinRoom(const std::string &inviteKey, const std::string &message); std::shared_ptr database; + + const odhtdb::MapHash>& getRooms() const { return roomById; } + bool isLoggedIn() const { return loggedIn; } private: Rooms(const char *address, u16 port, RoomCallbackFuncs callbackFuncs); void createNodeCallbackFunc(const odhtdb::DatabaseCreateNodeRequest &request); diff --git a/include/dchat/WebPagePreview.hpp b/include/dchat/WebPagePreview.hpp index df75419..8be497a 100644 --- a/include/dchat/WebPagePreview.hpp +++ b/include/dchat/WebPagePreview.hpp @@ -1,13 +1,10 @@ #pragma once -#include - namespace dchat { class WebPagePreview { public: - std::string title; - std::string description; + virtual ~WebPagePreview() {} }; } -- cgit v1.2.3