diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-01-27 02:09:50 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:38:23 +0200 |
commit | 6778e3b87cc9a6f5d195a2c80e5b499e3d94558b (patch) | |
tree | d37e25d48168465bdf0fb29559fe6e186a15e1d7 /include/dchat | |
parent | 2446736bc775b22cf5aaae88c2c69c9504e5eb17 (diff) |
Add binds to emoji parsing, refactor
Diffstat (limited to 'include/dchat')
-rw-r--r-- | include/dchat/Cache.hpp | 13 | ||||
-rw-r--r-- | include/dchat/IncomingMessage.hpp | 22 | ||||
-rw-r--r-- | include/dchat/MessageComposer.hpp | 32 | ||||
-rw-r--r-- | include/dchat/OutgoingMessage.hpp | 33 | ||||
-rw-r--r-- | include/dchat/Range.hpp | 15 | ||||
-rw-r--r-- | include/dchat/Storage.hpp | 24 |
6 files changed, 95 insertions, 44 deletions
diff --git a/include/dchat/Cache.hpp b/include/dchat/Cache.hpp index 4d37b54..8d3f28e 100644 --- a/include/dchat/Cache.hpp +++ b/include/dchat/Cache.hpp @@ -59,12 +59,11 @@ namespace dchat i64 lastAccessed; }; - using LoadBindsCallbackFunc = std::function<void(const std::string &key, const std::string &value)>; // @fileContent contains data allocated with new[], deallocate it with delete[] fileContent.data; // Returned gif should be allocated with @new using CreateGifFunc = std::function<Gif*(StringView fileContent)>; using CreateStaticImageFunc = std::function<StaticImage*(const boost::filesystem::path &filepath)>; - + class Cache { DISABLE_COPY(Cache) @@ -74,16 +73,6 @@ namespace dchat Cache(CreateGifFunc createGifFunc, CreateStaticImageFunc createStaticImageFunc); ~Cache(); - // Creates directory if it doesn't exist (recursively). Throws boost exception on failure - static boost::filesystem::path getDchatDir(); - - // Creates directory if it doesn't exist (recursively). Throws boost exception on failure - static boost::filesystem::path getImagesDir(); - - // @callbackFunc can't be nullptr - static void loadBindsFromFile(LoadBindsCallbackFunc callbackFunc); - static void replaceBindsInFile(const std::unordered_map<std::string, std::string> &binds); - // Get cached content or download it. // Default download file limit is 12MB // Returns ContentByUrlResult describing texture status. diff --git a/include/dchat/IncomingMessage.hpp b/include/dchat/IncomingMessage.hpp new file mode 100644 index 0000000..b20e4d1 --- /dev/null +++ b/include/dchat/IncomingMessage.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "types.hpp" +#include "Range.hpp" +#include <functional> + +namespace dchat +{ + struct IncomingMessagePart + { + enum class Type + { + TEXT, + EMOJI + }; + + Type type; + Range textRange; + }; + + void parseIncomingMessage(const char *text, usize size, std::function<void(IncomingMessagePart)> callbackFunc); +}
\ No newline at end of file diff --git a/include/dchat/MessageComposer.hpp b/include/dchat/MessageComposer.hpp deleted file mode 100644 index b4b55c2..0000000 --- a/include/dchat/MessageComposer.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "types.hpp" -#include <functional> - -namespace dchat -{ - struct Range - { - int start; - int end; - - int length() const - { - return end - start; - } - }; - - struct MessagePart - { - enum class Type - { - TEXT, - EMOJI - }; - - Type type; - Range textRange; - }; - - void compose(const char *text, usize size, std::function<void(MessagePart)> callbackFunc); -}
\ No newline at end of file diff --git a/include/dchat/OutgoingMessage.hpp b/include/dchat/OutgoingMessage.hpp new file mode 100644 index 0000000..c3e8e84 --- /dev/null +++ b/include/dchat/OutgoingMessage.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include "types.hpp" +#include "Range.hpp" +#include <functional> +#include <unordered_map> +#include <string> + +namespace dchat +{ + struct OutgoingMessagePart + { + enum class Type + { + TEXT, + EMOJI + }; + + Type type; + union + { + Range textRange; + const std::string *emoji; + }; + + OutgoingMessagePart(Type _type, Range _textRange) : type(_type), textRange(_textRange) {} + OutgoingMessagePart(Type _type, const std::string *_emoji) : type(_type), emoji(_emoji) {} + }; + + using EmojiBindMap = std::unordered_map<std::string, std::string>; + + void parseOutgoingMessage(const char *text, usize size, const EmojiBindMap &emojiBindMap, std::function<void(OutgoingMessagePart)> callbackFunc); +}
\ No newline at end of file diff --git a/include/dchat/Range.hpp b/include/dchat/Range.hpp new file mode 100644 index 0000000..a3a9581 --- /dev/null +++ b/include/dchat/Range.hpp @@ -0,0 +1,15 @@ +#pragma once + +namespace dchat +{ + struct Range + { + int start; + int end; + + int length() const + { + return end - start; + } + }; +}
\ No newline at end of file diff --git a/include/dchat/Storage.hpp b/include/dchat/Storage.hpp new file mode 100644 index 0000000..4f3dfa2 --- /dev/null +++ b/include/dchat/Storage.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include <functional> +#include <string> +#include <unordered_map> +#include <boost/filesystem/path.hpp> + +namespace dchat +{ + // Throws runtime exception on failure + boost::filesystem::path getHomeDir(); + + // Creates directory if it doesn't exist (recursively). Throws boost exception on failure + boost::filesystem::path getDchatDir(); + + // Creates directory if it doesn't exist (recursively). Throws boost exception on failure + boost::filesystem::path getImagesDir(); + + using LoadBindsCallbackFunc = std::function<void(const std::string &key, const std::string &value)>; + + // @callbackFunc can't be nullptr + void loadBindsFromFile(LoadBindsCallbackFunc callbackFunc); + void replaceBindsInFile(const std::unordered_map<std::string, std::string> &binds); +}
\ No newline at end of file |