diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-04-22 05:58:44 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-04-22 05:59:18 +0200 |
commit | 1e0e68f9cda51c881b32a54d9eece71c1428f7ac (patch) | |
tree | b8faa1d971c245e3fcf046aa1d2daa1fa601e0f9 /src/Message.cpp | |
parent | 424b02609fa34175a4e2aadb95e68b3c9c8dc93c (diff) |
Add video and gif support
Gif streams from url.
Todo: Add play controls to video
Diffstat (limited to 'src/Message.cpp')
-rw-r--r-- | src/Message.cpp | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/src/Message.cpp b/src/Message.cpp index 2740c11..19630b3 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -1,4 +1,5 @@ #include "../include/Message.hpp" +#include "../include/StringView.hpp" using namespace std; @@ -18,18 +19,49 @@ namespace dchat } } - void Message::addText(const string &text) + void Message::addText(const string &text, bool newLine) { - messageParts.push_back(new MessagePartText(text)); + messageParts.push_back(new MessagePartText(text, newLine)); } - void Message::addImage(const string &url) + void Message::addEmoji(const string &url, bool newLine) { - messageParts.push_back(new MessagePartEmoji(url)); + messageParts.push_back(new MessagePartEmoji(url, newLine)); } vector<MessagePart*>& Message::getParts() { return messageParts; } + + StringView getNextNewLine(const StringView &str) + { + for(usize i = 0; i < str.size; ++i) + { + if(str[i] == '\n') + return StringView(str.data, i); + } + return StringView(); + } + + Message* Message::buildFromString(User *user, const std::string &str) + { + Message *message = new Message(user); + usize strOffset = 0; + while(strOffset < str.size()) + { + usize foundIndex = str.find('\n', strOffset); + usize lineEnd = foundIndex; + if(foundIndex == string::npos) + lineEnd = str.size(); + + message->addText(str.substr(strOffset, lineEnd - strOffset), foundIndex != string::npos); + + if(foundIndex == string::npos) + break; + else + strOffset = lineEnd + 1; + } + return message; + } } |