mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
minor code improvements
This commit is contained in:
parent
431b9a8c1f
commit
99aac9eb6a
|
@ -18,7 +18,7 @@ MessagePtr MessageBuilder::getMessage()
|
||||||
return this->message;
|
return this->message;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageBuilder::appendElement(MessageElement *element)
|
void MessageBuilder::append(MessageElement *element)
|
||||||
{
|
{
|
||||||
this->message->addElement(element);
|
this->message->addElement(element);
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ void MessageBuilder::setHighlight(bool value)
|
||||||
|
|
||||||
void MessageBuilder::appendTimestamp(const QTime &time)
|
void MessageBuilder::appendTimestamp(const QTime &time)
|
||||||
{
|
{
|
||||||
this->appendElement(new TimestampElement(time));
|
this->append(new TimestampElement(time));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString MessageBuilder::matchLink(const QString &string)
|
QString MessageBuilder::matchLink(const QString &string)
|
||||||
|
|
|
@ -9,35 +9,29 @@
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace messages {
|
namespace messages {
|
||||||
|
|
||||||
struct MessageBuilder
|
struct MessageBuilder {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
MessageBuilder();
|
MessageBuilder();
|
||||||
|
|
||||||
MessagePtr getMessage();
|
MessagePtr getMessage();
|
||||||
|
|
||||||
void setHighlight(bool value);
|
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 <typename T, typename... Args,
|
||||||
|
typename _ = std::enable_if<std::is_base_of<MessageElement, T>::value>::type>
|
||||||
template <class T, class... Args>
|
|
||||||
T *emplace(Args &&... args)
|
T *emplace(Args &&... args)
|
||||||
{
|
{
|
||||||
static_assert(std::is_base_of<MessageElement, T>::value, "T must extend MessageElement");
|
static_assert(std::is_base_of<MessageElement, T>::value, "T must extend MessageElement");
|
||||||
|
|
||||||
T *element = new T(std::forward<Args>(args)...);
|
T *element = new T(std::forward<Args>(args)...);
|
||||||
this->appendElement(element);
|
this->append(element);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
void appendTimestamp();
|
|
||||||
void appendTimestamp(const QTime &time);
|
|
||||||
|
|
||||||
QString matchLink(const QString &string);
|
|
||||||
|
|
||||||
QString originalMessage;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MessagePtr message;
|
MessagePtr message;
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,9 +7,7 @@
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace messages {
|
namespace messages {
|
||||||
|
|
||||||
struct MessageColor
|
struct MessageColor {
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum Type { Custom, Text, Link, System };
|
enum Type { Custom, Text, Link, System };
|
||||||
|
|
||||||
MessageColor(const QColor &color);
|
MessageColor(const QColor &color);
|
||||||
|
|
|
@ -45,6 +45,7 @@ private:
|
||||||
QString roomID;
|
QString roomID;
|
||||||
|
|
||||||
QColor usernameColor;
|
QColor usernameColor;
|
||||||
|
QString originalMessage;
|
||||||
|
|
||||||
void parseMessageID();
|
void parseMessageID();
|
||||||
void parseRoomID();
|
void parseRoomID();
|
||||||
|
|
|
@ -56,7 +56,7 @@ void EmotePopup::loadChannel(ChannelPtr _channel)
|
||||||
// TITLE
|
// TITLE
|
||||||
messages::MessageBuilder builder1;
|
messages::MessageBuilder builder1;
|
||||||
|
|
||||||
builder1.appendElement(new TextElement(title, MessageElement::Text));
|
builder1.append(new TextElement(title, MessageElement::Text));
|
||||||
|
|
||||||
builder1.getMessage()->flags &= Message::Centered;
|
builder1.getMessage()->flags &= Message::Centered;
|
||||||
emoteChannel->addMessage(builder1.getMessage());
|
emoteChannel->addMessage(builder1.getMessage());
|
||||||
|
@ -67,7 +67,7 @@ void EmotePopup::loadChannel(ChannelPtr _channel)
|
||||||
builder2.getMessage()->flags &= Message::DisableCompactEmotes;
|
builder2.getMessage()->flags &= Message::DisableCompactEmotes;
|
||||||
|
|
||||||
map.each([&](const QString &key, const util::EmoteData &value) {
|
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)));
|
->setLink(Link(Link::InsertText, key)));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ void EmotePopup::loadEmojis()
|
||||||
// title
|
// title
|
||||||
messages::MessageBuilder builder1;
|
messages::MessageBuilder builder1;
|
||||||
|
|
||||||
builder1.appendElement(new TextElement("emojis", MessageElement::Text));
|
builder1.append(new TextElement("emojis", MessageElement::Text));
|
||||||
builder1.getMessage()->flags &= Message::Centered;
|
builder1.getMessage()->flags &= Message::Centered;
|
||||||
emojiChannel->addMessage(builder1.getMessage());
|
emojiChannel->addMessage(builder1.getMessage());
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ void EmotePopup::loadEmojis()
|
||||||
builder.getMessage()->flags &= Message::DisableCompactEmotes;
|
builder.getMessage()->flags &= Message::DisableCompactEmotes;
|
||||||
|
|
||||||
emojis.each([this, &builder](const QString &key, const util::EmoteData &value) {
|
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)));
|
->setLink(Link(Link::Type::InsertText, key)));
|
||||||
});
|
});
|
||||||
emojiChannel->addMessage(builder.getMessage());
|
emojiChannel->addMessage(builder.getMessage());
|
||||||
|
|
Loading…
Reference in a new issue