aboutsummaryrefslogtreecommitdiff
path: root/include/dchat
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-04-07 17:15:42 +0200
committerdec05eba <dec05eba@protonmail.com>2020-08-18 23:38:23 +0200
commit983be4253f2ea3827d78db97afcc666664ae75ed (patch)
tree058174a46ebe3eac15467f0c9f2d0ca58cecdb2d /include/dchat
parent18c27df9d7efe087c9196b46a47867af9a111b3e (diff)
Update cache signature, update odhtdb
Diffstat (limited to 'include/dchat')
-rw-r--r--include/dchat/Cache.hpp8
-rw-r--r--include/dchat/Gif.hpp2
-rw-r--r--include/dchat/Room.hpp9
-rw-r--r--include/dchat/WebPagePreview.hpp5
4 files changed, 16 insertions, 8 deletions
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 <boost/filesystem/path.hpp>
@@ -63,6 +62,7 @@ namespace dchat
// Returned gif should be allocated with @new
using CreateGifFunc = std::function<Gif*(StringView fileContent)>;
using CreateStaticImageFunc = std::function<StaticImage*(const boost::filesystem::path &filepath)>;
+ using CreateWebPagePreviewFunc = std::function<WebPagePreview*(const std::string &title, const std::string &description)>;
class Cache
{
@@ -70,7 +70,8 @@ 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.
@@ -78,6 +79,8 @@ namespace dchat
// 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
{
TinyProcessLib::Process *process;
@@ -93,5 +96,6 @@ namespace dchat
std::unordered_map<std::string, ContentByUrlResult> 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<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 setAvatarUrl(const std::string &url);
void setNickname(const std::string &nickname);
void publishMessage(const std::string &msg);
+ const odhtdb::Signature::MapPublicKey<std::shared_ptr<User>>& getUsers() const { return userByPublicKey; }
+ const std::vector<std::shared_ptr<RoomMessage>>& getMessages() const { return messages; }
+
Rooms *rooms;
std::shared_ptr<odhtdb::Hash> id;
std::shared_ptr<odhtdb::OwnedByteArray> encryptionKey;
@@ -55,6 +57,8 @@ namespace dchat
// TODO: Move to private when we have proper support for groups
std::vector<std::shared_ptr<Group>> groups;
private:
+ void setLocalUser(std::shared_ptr<User> user, std::shared_ptr<odhtdb::Signature::KeyPair> keyPair);
+ private:
odhtdb::Signature::MapPublicKey<std::shared_ptr<User>> userByPublicKey;
// Used for local users
odhtdb::Signature::MapPublicKey<std::shared_ptr<odhtdb::Signature::KeyPair>> publicKeyToKeyPairMap;
@@ -152,6 +156,9 @@ namespace dchat
void requestJoinRoom(const std::string &inviteKey, const std::string &message);
std::shared_ptr<odhtdb::Database> database;
+
+ const odhtdb::MapHash<std::shared_ptr<Room>>& 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 <string>
-
namespace dchat
{
class WebPagePreview
{
public:
- std::string title;
- std::string description;
+ virtual ~WebPagePreview() {}
};
}