Refactored the Image Uploader feature. (#4971)
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "controllers/accounts/AccountController.hpp"
|
||||
#include "messages/Image.hpp"
|
||||
#include "messages/Message.hpp"
|
||||
#include "messages/MessageColor.hpp"
|
||||
#include "messages/MessageElement.hpp"
|
||||
#include "providers/LinkResolver.hpp"
|
||||
#include "providers/twitch/PubSubActions.hpp"
|
||||
@@ -660,6 +661,58 @@ MessageBuilder::MessageBuilder(LiveUpdatesUpdateEmoteSetMessageTag /*unused*/,
|
||||
this->message().flags.set(MessageFlag::DoNotTriggerNotification);
|
||||
}
|
||||
|
||||
MessageBuilder::MessageBuilder(ImageUploaderResultTag /*unused*/,
|
||||
const QString &imageLink,
|
||||
const QString &deletionLink,
|
||||
size_t imagesStillQueued, size_t secondsLeft)
|
||||
: MessageBuilder()
|
||||
{
|
||||
this->message().flags.set(MessageFlag::System);
|
||||
this->message().flags.set(MessageFlag::DoNotTriggerNotification);
|
||||
|
||||
this->emplace<TimestampElement>();
|
||||
|
||||
using MEF = MessageElementFlag;
|
||||
auto addText = [this](QString text, MessageElementFlags mefs = MEF::Text,
|
||||
MessageColor color =
|
||||
MessageColor::System) -> TextElement * {
|
||||
this->message().searchText += text;
|
||||
this->message().messageText += text;
|
||||
return this->emplace<TextElement>(text, mefs, color);
|
||||
};
|
||||
|
||||
addText("Your image has been uploaded to");
|
||||
|
||||
// ASSUMPTION: the user gave this uploader configuration to the program
|
||||
// therefore they trust that the host is not wrong/malicious. This doesn't obey getSettings()->lowercaseDomains.
|
||||
// This also ensures that the LinkResolver doesn't get these links.
|
||||
addText(imageLink, {MEF::OriginalLink, MEF::LowercaseLink},
|
||||
MessageColor::Link)
|
||||
->setLink({Link::Url, imageLink})
|
||||
->setTrailingSpace(false);
|
||||
|
||||
if (!deletionLink.isEmpty())
|
||||
{
|
||||
addText("(Deletion link:");
|
||||
addText(deletionLink, {MEF::OriginalLink, MEF::LowercaseLink},
|
||||
MessageColor::Link)
|
||||
->setLink({Link::Url, deletionLink})
|
||||
->setTrailingSpace(false);
|
||||
addText(")")->setTrailingSpace(false);
|
||||
}
|
||||
addText(".");
|
||||
|
||||
if (imagesStillQueued == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
addText(QString("%1 left. Please wait until all of them are uploaded. "
|
||||
"About %2 seconds left.")
|
||||
.arg(imagesStillQueued)
|
||||
.arg(secondsLeft));
|
||||
}
|
||||
|
||||
Message *MessageBuilder::operator->()
|
||||
{
|
||||
return this->message_.get();
|
||||
|
||||
@@ -37,6 +37,9 @@ struct LiveUpdatesAddEmoteMessageTag {
|
||||
};
|
||||
struct LiveUpdatesUpdateEmoteSetMessageTag {
|
||||
};
|
||||
struct ImageUploaderResultTag {
|
||||
};
|
||||
|
||||
const SystemMessageTag systemMessage{};
|
||||
const TimeoutMessageTag timeoutMessage{};
|
||||
const LiveUpdatesUpdateEmoteMessageTag liveUpdatesUpdateEmoteMessage{};
|
||||
@@ -44,6 +47,10 @@ const LiveUpdatesRemoveEmoteMessageTag liveUpdatesRemoveEmoteMessage{};
|
||||
const LiveUpdatesAddEmoteMessageTag liveUpdatesAddEmoteMessage{};
|
||||
const LiveUpdatesUpdateEmoteSetMessageTag liveUpdatesUpdateEmoteSetMessage{};
|
||||
|
||||
// This signifies that you want to construct a message containing the result of
|
||||
// a successful image upload.
|
||||
const ImageUploaderResultTag imageUploaderResultMessage{};
|
||||
|
||||
MessagePtr makeSystemMessage(const QString &text);
|
||||
MessagePtr makeSystemMessage(const QString &text, const QTime &time);
|
||||
std::pair<MessagePtr, MessagePtr> makeAutomodMessage(
|
||||
@@ -88,6 +95,16 @@ public:
|
||||
MessageBuilder(LiveUpdatesUpdateEmoteSetMessageTag, const QString &platform,
|
||||
const QString &actor, const QString &emoteSetName);
|
||||
|
||||
/**
|
||||
* "Your image has been uploaded to %1[ (Deletion link: %2)]."
|
||||
* or "Your image has been uploaded to %1 %2. %3 left. "
|
||||
* "Please wait until all of them are uploaded. "
|
||||
* "About %4 seconds left."
|
||||
*/
|
||||
MessageBuilder(ImageUploaderResultTag, const QString &imageLink,
|
||||
const QString &deletionLink, size_t imagesStillQueued = 0,
|
||||
size_t secondsLeft = 0);
|
||||
|
||||
virtual ~MessageBuilder() = default;
|
||||
|
||||
Message *operator->();
|
||||
|
||||
Reference in New Issue
Block a user