From 6778e3b87cc9a6f5d195a2c80e5b499e3d94558b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 27 Jan 2019 02:09:50 +0100 Subject: Add binds to emoji parsing, refactor --- include/dchat/Cache.hpp | 13 +------------ include/dchat/IncomingMessage.hpp | 22 ++++++++++++++++++++++ include/dchat/MessageComposer.hpp | 32 -------------------------------- include/dchat/OutgoingMessage.hpp | 33 +++++++++++++++++++++++++++++++++ include/dchat/Range.hpp | 15 +++++++++++++++ include/dchat/Storage.hpp | 24 ++++++++++++++++++++++++ 6 files changed, 95 insertions(+), 44 deletions(-) create mode 100644 include/dchat/IncomingMessage.hpp delete mode 100644 include/dchat/MessageComposer.hpp create mode 100644 include/dchat/OutgoingMessage.hpp create mode 100644 include/dchat/Range.hpp create mode 100644 include/dchat/Storage.hpp (limited to 'include') 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; // @fileContent contains data allocated with new[], deallocate it with delete[] fileContent.data; // Returned gif should be allocated with @new using CreateGifFunc = std::function; using CreateStaticImageFunc = std::function; - + 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 &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 + +namespace dchat +{ + struct IncomingMessagePart + { + enum class Type + { + TEXT, + EMOJI + }; + + Type type; + Range textRange; + }; + + void parseIncomingMessage(const char *text, usize size, std::function 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 - -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 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 +#include +#include + +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; + + void parseOutgoingMessage(const char *text, usize size, const EmojiBindMap &emojiBindMap, std::function 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 +#include +#include +#include + +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; + + // @callbackFunc can't be nullptr + void loadBindsFromFile(LoadBindsCallbackFunc callbackFunc); + void replaceBindsInFile(const std::unordered_map &binds); +} \ No newline at end of file -- cgit v1.2.3