minor code improvements

This commit is contained in:
fourtf 2018-01-28 03:48:15 +01:00
parent 431b9a8c1f
commit 99aac9eb6a
5 changed files with 16 additions and 23 deletions

View file

@ -18,7 +18,7 @@ MessagePtr MessageBuilder::getMessage()
return this->message;
}
void MessageBuilder::appendElement(MessageElement *element)
void MessageBuilder::append(MessageElement *element)
{
this->message->addElement(element);
}
@ -39,7 +39,7 @@ void MessageBuilder::setHighlight(bool value)
void MessageBuilder::appendTimestamp(const QTime &time)
{
this->appendElement(new TimestampElement(time));
this->append(new TimestampElement(time));
}
QString MessageBuilder::matchLink(const QString &string)

View file

@ -9,35 +9,29 @@
namespace chatterino {
namespace messages {
struct MessageBuilder
{
struct MessageBuilder {
public:
MessageBuilder();
MessagePtr getMessage();
void setHighlight(bool value);
void appendElement(MessageElement *element);
void append(MessageElement *element);
void appendTimestamp();
void appendTimestamp(const QTime &time);
QString matchLink(const QString &string);
// typename std::enable_if<std::is_base_of<MessageElement, T>::value, T>::type
template <class T, class... Args>
template <typename T, typename... Args,
typename _ = std::enable_if<std::is_base_of<MessageElement, T>::value>::type>
T *emplace(Args &&... args)
{
static_assert(std::is_base_of<MessageElement, T>::value, "T must extend MessageElement");
T *element = new T(std::forward<Args>(args)...);
this->appendElement(element);
this->append(element);
return element;
}
void appendTimestamp();
void appendTimestamp(const QTime &time);
QString matchLink(const QString &string);
QString originalMessage;
protected:
MessagePtr message;
};

View file

@ -7,9 +7,7 @@
namespace chatterino {
namespace messages {
struct MessageColor
{
public:
struct MessageColor {
enum Type { Custom, Text, Link, System };
MessageColor(const QColor &color);

View file

@ -45,6 +45,7 @@ private:
QString roomID;
QColor usernameColor;
QString originalMessage;
void parseMessageID();
void parseRoomID();

View file

@ -56,7 +56,7 @@ void EmotePopup::loadChannel(ChannelPtr _channel)
// TITLE
messages::MessageBuilder builder1;
builder1.appendElement(new TextElement(title, MessageElement::Text));
builder1.append(new TextElement(title, MessageElement::Text));
builder1.getMessage()->flags &= Message::Centered;
emoteChannel->addMessage(builder1.getMessage());
@ -67,7 +67,7 @@ void EmotePopup::loadChannel(ChannelPtr _channel)
builder2.getMessage()->flags &= Message::DisableCompactEmotes;
map.each([&](const QString &key, const util::EmoteData &value) {
builder2.appendElement((new EmoteElement(value, MessageElement::Flags::AlwaysShow))
builder2.append((new EmoteElement(value, MessageElement::Flags::AlwaysShow))
->setLink(Link(Link::InsertText, key)));
});
@ -96,7 +96,7 @@ void EmotePopup::loadEmojis()
// title
messages::MessageBuilder builder1;
builder1.appendElement(new TextElement("emojis", MessageElement::Text));
builder1.append(new TextElement("emojis", MessageElement::Text));
builder1.getMessage()->flags &= Message::Centered;
emojiChannel->addMessage(builder1.getMessage());
@ -106,7 +106,7 @@ void EmotePopup::loadEmojis()
builder.getMessage()->flags &= Message::DisableCompactEmotes;
emojis.each([this, &builder](const QString &key, const util::EmoteData &value) {
builder.appendElement((new EmoteElement(value, MessageElement::Flags::AlwaysShow))
builder.append((new EmoteElement(value, MessageElement::Flags::AlwaysShow))
->setLink(Link(Link::Type::InsertText, key)));
});
emojiChannel->addMessage(builder.getMessage());