Add support for non-highlight channel point rewards (#1809)
This commit is contained in:
@@ -35,6 +35,7 @@ enum class MessageFlag : uint32_t {
|
||||
Debug = (1 << 18),
|
||||
Similar = (1 << 19),
|
||||
RedeemedHighlight = (1 << 20),
|
||||
RedeemedChannelPointReward = (1 << 21),
|
||||
};
|
||||
using MessageFlags = FlagsEnum<MessageFlag>;
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ struct MessageParseArgs {
|
||||
bool isSentWhisper = false;
|
||||
bool trimSubscriberUsername = false;
|
||||
bool isStaffOrBroadcaster = false;
|
||||
QString channelPointRewardId = "";
|
||||
};
|
||||
|
||||
class MessageBuilder
|
||||
|
||||
@@ -676,4 +676,43 @@ void IrcTextElement::addToContainer(MessageLayoutContainer &container,
|
||||
}
|
||||
}
|
||||
|
||||
LinebreakElement::LinebreakElement(MessageElementFlags flags)
|
||||
: MessageElement(flags)
|
||||
{
|
||||
}
|
||||
|
||||
void LinebreakElement::addToContainer(MessageLayoutContainer &container,
|
||||
MessageElementFlags flags)
|
||||
{
|
||||
if (flags.hasAny(this->getFlags()))
|
||||
{
|
||||
container.breakLine();
|
||||
}
|
||||
}
|
||||
|
||||
ScalingImageElement::ScalingImageElement(ImageSet images,
|
||||
MessageElementFlags flags)
|
||||
: MessageElement(flags)
|
||||
, images_(images)
|
||||
{
|
||||
}
|
||||
|
||||
void ScalingImageElement::addToContainer(MessageLayoutContainer &container,
|
||||
MessageElementFlags flags)
|
||||
{
|
||||
if (flags.hasAny(this->getFlags()))
|
||||
{
|
||||
const auto &image =
|
||||
this->images_.getImageOrLoaded(container.getScale());
|
||||
if (image->isEmpty())
|
||||
return;
|
||||
|
||||
auto size = QSize(image->width() * container.getScale(),
|
||||
image->height() * container.getScale());
|
||||
|
||||
container.addElement((new ImageLayoutElement(*this, image, size))
|
||||
->setLink(this->getLink()));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "messages/Link.hpp"
|
||||
#include "messages/MessageColor.hpp"
|
||||
#include "singletons/Fonts.hpp"
|
||||
#include "src/messages/ImageSet.hpp"
|
||||
|
||||
#include <QRect>
|
||||
#include <QString>
|
||||
@@ -39,6 +40,9 @@ enum class MessageElementFlag {
|
||||
BttvEmoteImage = (1 << 6),
|
||||
BttvEmoteText = (1 << 7),
|
||||
BttvEmote = BttvEmoteImage | BttvEmoteText,
|
||||
|
||||
ChannelPointReward = (1 << 8),
|
||||
|
||||
FfzEmoteImage = (1 << 10),
|
||||
FfzEmoteText = (1 << 11),
|
||||
FfzEmote = FfzEmoteImage | FfzEmoteText,
|
||||
@@ -321,4 +325,26 @@ private:
|
||||
std::vector<Word> words_;
|
||||
};
|
||||
|
||||
// Forces a linebreak
|
||||
class LinebreakElement : public MessageElement
|
||||
{
|
||||
public:
|
||||
LinebreakElement(MessageElementFlags flags);
|
||||
|
||||
void addToContainer(MessageLayoutContainer &container,
|
||||
MessageElementFlags flags) override;
|
||||
};
|
||||
|
||||
// Image element which will pick the quality of the image based on ui scale
|
||||
class ScalingImageElement : public MessageElement
|
||||
{
|
||||
public:
|
||||
ScalingImageElement(ImageSet images, MessageElementFlags flags);
|
||||
|
||||
void addToContainer(MessageLayoutContainer &container,
|
||||
MessageElementFlags flags) override;
|
||||
|
||||
private:
|
||||
ImageSet images_;
|
||||
};
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -169,7 +169,7 @@ void MessageLayout::actuallyLayout(int width, MessageElementFlags flags)
|
||||
// Painting
|
||||
void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
|
||||
Selection &selection, bool isLastReadMessage,
|
||||
bool isWindowFocused)
|
||||
bool isWindowFocused, bool isMentions)
|
||||
{
|
||||
auto app = getApp();
|
||||
QPixmap *pixmap = this->buffer_.get();
|
||||
@@ -220,6 +220,14 @@ void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
|
||||
app->themes->messages.disabled);
|
||||
}
|
||||
|
||||
if (!isMentions &&
|
||||
this->message_->flags.has(MessageFlag::RedeemedChannelPointReward))
|
||||
{
|
||||
painter.fillRect(
|
||||
0, y, this->scale_ * 4, pixmap->height(),
|
||||
*ColorProvider::instance().color(ColorType::Subscription));
|
||||
}
|
||||
|
||||
// draw selection
|
||||
if (!selection.isEmpty())
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
// Painting
|
||||
void paint(QPainter &painter, int width, int y, int messageIndex,
|
||||
Selection &selection, bool isLastReadMessage,
|
||||
bool isWindowFocused);
|
||||
bool isWindowFocused, bool isMentions);
|
||||
void invalidateBuffer();
|
||||
void deleteBuffer();
|
||||
void deleteCache();
|
||||
|
||||
Reference in New Issue
Block a user