From 903c45c6c8c59f9823121d00dfee9d53c5a08688 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 12:09:12 +0200 Subject: [PATCH 01/15] replace --- CONTRIBUTING.md | 2 +- mocks/include/mocks/Helix.hpp | 8 +-- mocks/include/mocks/UserData.hpp | 4 +- src/PrecompiledHeader.hpp | 2 +- src/common/Args.hpp | 7 +-- src/common/Channel.cpp | 2 +- src/common/Channel.hpp | 9 ++-- src/common/Common.hpp | 2 +- src/common/Env.cpp | 4 +- src/common/Env.hpp | 5 +- src/common/SignalVectorModel.hpp | 9 ++-- .../commands/CommandController.cpp | 10 ++-- .../commands/builtin/twitch/ChatSettings.cpp | 4 +- .../highlights/HighlightController.cpp | 48 ++++++++--------- .../highlights/HighlightController.hpp | 8 +-- src/controllers/hotkeys/HotkeyController.cpp | 6 +-- src/controllers/hotkeys/HotkeyController.hpp | 4 +- src/controllers/hotkeys/HotkeyHelpers.cpp | 5 +- src/controllers/hotkeys/HotkeyHelpers.hpp | 4 +- .../moderationactions/ModerationAction.cpp | 2 +- .../moderationactions/ModerationAction.hpp | 6 +-- src/controllers/nicknames/Nickname.hpp | 10 ++-- src/controllers/userdata/UserData.hpp | 5 +- .../userdata/UserDataController.cpp | 10 ++-- .../userdata/UserDataController.hpp | 6 +-- src/messages/Emote.hpp | 5 +- src/messages/LimitedQueue.hpp | 30 +++++------ src/messages/MessageElement.cpp | 2 +- src/messages/SharedMessageBuilder.cpp | 2 +- .../NetworkConfigurationProvider.cpp | 2 +- src/providers/bttv/BttvEmotes.cpp | 14 ++--- src/providers/bttv/BttvEmotes.hpp | 9 ++-- src/providers/chatterino/ChatterinoBadges.cpp | 4 +- src/providers/chatterino/ChatterinoBadges.hpp | 5 +- src/providers/ffz/FfzBadges.cpp | 4 +- src/providers/ffz/FfzBadges.hpp | 4 +- src/providers/ffz/FfzEmotes.cpp | 14 ++--- src/providers/ffz/FfzEmotes.hpp | 9 ++-- src/providers/seventv/SeventvBadges.cpp | 4 +- src/providers/seventv/SeventvBadges.hpp | 4 +- src/providers/seventv/SeventvEmotes.cpp | 26 ++++----- src/providers/seventv/SeventvEmotes.hpp | 10 ++-- src/providers/seventv/eventapi/Message.hpp | 11 ++-- src/providers/twitch/IrcMessageHandler.cpp | 2 +- src/providers/twitch/PubSubManager.cpp | 4 +- src/providers/twitch/PubSubManager.hpp | 4 +- src/providers/twitch/TwitchBadges.cpp | 10 ++-- src/providers/twitch/TwitchBadges.hpp | 8 +-- src/providers/twitch/TwitchChannel.cpp | 54 +++++++++---------- src/providers/twitch/TwitchChannel.hpp | 23 ++++---- src/providers/twitch/TwitchMessageBuilder.cpp | 22 ++++---- src/providers/twitch/TwitchMessageBuilder.hpp | 4 +- src/providers/twitch/api/Helix.cpp | 12 ++--- src/providers/twitch/api/Helix.hpp | 34 ++++++------ src/providers/twitch/pubsubmessages/Base.hpp | 14 ++--- .../twitch/pubsubmessages/Message.hpp | 9 ++-- src/singletons/NativeMessaging.cpp | 4 +- src/singletons/NativeMessaging.hpp | 4 +- src/singletons/Paths.cpp | 2 +- src/singletons/Paths.hpp | 5 +- src/singletons/Settings.cpp | 4 +- src/singletons/Settings.hpp | 2 +- src/singletons/WindowManager.cpp | 6 +-- src/util/Helpers.hpp | 25 +++++++++ src/util/NuulsUploader.cpp | 14 ++--- src/util/WindowsHelper.cpp | 4 +- src/util/WindowsHelper.hpp | 5 +- src/widgets/BaseWidget.cpp | 6 +-- src/widgets/BaseWidget.hpp | 9 ++-- src/widgets/BaseWindow.hpp | 2 +- src/widgets/dialogs/BadgePickerDialog.hpp | 4 +- src/widgets/dialogs/IrcConnectionEditor.hpp | 3 +- src/widgets/dialogs/ReplyThreadPopup.cpp | 6 +-- src/widgets/dialogs/UserInfoPopup.cpp | 2 +- src/widgets/helper/Button.cpp | 4 +- src/widgets/helper/Button.hpp | 7 +-- src/widgets/helper/ChannelView.cpp | 34 ++++++------ src/widgets/helper/ChannelView.hpp | 14 ++--- src/widgets/helper/SearchPopup.cpp | 2 +- tests/src/BttvLiveUpdates.cpp | 8 +-- tests/src/HighlightController.cpp | 27 +++++----- tests/src/InputCompletion.cpp | 1 - tests/src/SeventvEventAPI.cpp | 17 +++--- 83 files changed, 393 insertions(+), 369 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index af533919635..ebd54f6977d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,7 +39,7 @@ int compare(const QString &a, const QString &b); * link * ^^^ No need to repeat the obvious. */ -boost::optional matchLink(const QString &text); +std::optional matchLink(const QString &text); ``` # Code diff --git a/mocks/include/mocks/Helix.hpp b/mocks/include/mocks/Helix.hpp index 4a64bf8c4fc..1771b1e2b8e 100644 --- a/mocks/include/mocks/Helix.hpp +++ b/mocks/include/mocks/Helix.hpp @@ -269,7 +269,7 @@ class Helix : public IHelix // contains a comma MOCK_METHOD(void, updateFollowerMode, (QString broadcasterID, QString moderatorID, - boost::optional followerModeDuration, + std::optional followerModeDuration, ResultCallback successCallback, (FailureCallback failureCallback)), @@ -279,7 +279,7 @@ class Helix : public IHelix // contains a comma MOCK_METHOD(void, updateNonModeratorChatDelay, (QString broadcasterID, QString moderatorID, - boost::optional nonModeratorChatDelayDuration, + std::optional nonModeratorChatDelayDuration, ResultCallback successCallback, (FailureCallback failureCallback)), @@ -289,7 +289,7 @@ class Helix : public IHelix // contains a comma MOCK_METHOD(void, updateSlowMode, (QString broadcasterID, QString moderatorID, - boost::optional slowModeWaitTime, + std::optional slowModeWaitTime, ResultCallback successCallback, (FailureCallback failureCallback)), @@ -321,7 +321,7 @@ class Helix : public IHelix // contains a comma MOCK_METHOD(void, banUser, (QString broadcasterID, QString moderatorID, QString userID, - boost::optional duration, QString reason, + std::optional duration, QString reason, ResultCallback<> successCallback, (FailureCallback failureCallback)), (override)); // /timeout, /ban diff --git a/mocks/include/mocks/UserData.hpp b/mocks/include/mocks/UserData.hpp index df20eb82277..62159a19fcd 100644 --- a/mocks/include/mocks/UserData.hpp +++ b/mocks/include/mocks/UserData.hpp @@ -11,9 +11,9 @@ class UserDataController : public IUserDataController // Get extra data about a user // If the user does not have any extra data, return none - boost::optional getUser(const QString &userID) const override + std::optional getUser(const QString &userID) const override { - return boost::none; + return std::nullopt; } // Update or insert extra data for the user's color override diff --git a/src/PrecompiledHeader.hpp b/src/PrecompiledHeader.hpp index f430a099c32..144faf56b47 100644 --- a/src/PrecompiledHeader.hpp +++ b/src/PrecompiledHeader.hpp @@ -2,7 +2,6 @@ # include # include # include -# include # include # include # include @@ -117,6 +116,7 @@ # include # include # include +# include # include # include # include diff --git a/src/common/Args.hpp b/src/common/Args.hpp index 386f6f50da9..9fba4bdaf46 100644 --- a/src/common/Args.hpp +++ b/src/common/Args.hpp @@ -2,9 +2,10 @@ #include "common/WindowDescriptors.hpp" -#include #include +#include + namespace chatterino { /// Command line arguments passed to Chatterino. @@ -18,12 +19,12 @@ class Args bool shouldRunBrowserExtensionHost{}; // Shows a single chat. Used on windows to embed in another application. bool isFramelessEmbed{}; - boost::optional parentWindowId{}; + std::optional parentWindowId{}; // Not settings directly bool dontSaveSettings{}; bool dontLoadMainWindow{}; - boost::optional customChannelLayout; + std::optional customChannelLayout; bool verbose{}; private: diff --git a/src/common/Channel.cpp b/src/common/Channel.cpp index 8e731bf41bb..f0dc5d185c9 100644 --- a/src/common/Channel.cpp +++ b/src/common/Channel.cpp @@ -80,7 +80,7 @@ LimitedQueueSnapshot Channel::getMessageSnapshot() } void Channel::addMessage(MessagePtr message, - boost::optional overridingFlags) + std::optional overridingFlags) { auto app = getApp(); MessagePtr deleted; diff --git a/src/common/Channel.hpp b/src/common/Channel.hpp index 81347c1a8b4..7fcb5636cbb 100644 --- a/src/common/Channel.hpp +++ b/src/common/Channel.hpp @@ -4,13 +4,13 @@ #include "controllers/completion/TabCompletionModel.hpp" #include "messages/LimitedQueue.hpp" -#include #include #include #include #include #include +#include namespace chatterino { @@ -52,7 +52,7 @@ class Channel : public std::enable_shared_from_this pajlada::Signals::Signal sendReplySignal; - pajlada::Signals::Signal> + pajlada::Signals::Signal> messageAppended; pajlada::Signals::Signal &> messagesAddedAtStart; pajlada::Signals::Signal messageReplaced; @@ -75,9 +75,8 @@ class Channel : public std::enable_shared_from_this // overridingFlags can be filled in with flags that should be used instead // of the message's flags. This is useful in case a flag is specific to a // type of split - void addMessage( - MessagePtr message, - boost::optional overridingFlags = boost::none); + void addMessage(MessagePtr message, + std::optional overridingFlags = std::nullopt); void addMessagesAtStart(const std::vector &messages_); /// Inserts the given messages in order by Message::serverReceivedTime. diff --git a/src/common/Common.hpp b/src/common/Common.hpp index 353b52d7e0e..b0315a8aaf2 100644 --- a/src/common/Common.hpp +++ b/src/common/Common.hpp @@ -1,11 +1,11 @@ #pragma once -#include #include #include #include #include +#include #include namespace chatterino { diff --git a/src/common/Env.cpp b/src/common/Env.cpp index 605e4924799..174cae67bf6 100644 --- a/src/common/Env.cpp +++ b/src/common/Env.cpp @@ -44,7 +44,7 @@ namespace { return defaultValue; } - boost::optional readOptionalStringEnv(const char *envName) + std::optional readOptionalStringEnv(const char *envName) { auto envString = std::getenv(envName); if (envString != nullptr) @@ -52,7 +52,7 @@ namespace { return QString(envString); } - return boost::none; + return std::nullopt; } uint16_t readPortEnv(const char *envName, uint16_t defaultValue) diff --git a/src/common/Env.hpp b/src/common/Env.hpp index 97e5040d863..353a6af483a 100644 --- a/src/common/Env.hpp +++ b/src/common/Env.hpp @@ -1,8 +1,9 @@ #pragma once -#include #include +#include + namespace chatterino { class Env @@ -17,7 +18,7 @@ class Env const QString twitchServerHost; const uint16_t twitchServerPort; const bool twitchServerSecure; - const boost::optional proxyUrl; + const std::optional proxyUrl; }; } // namespace chatterino diff --git a/src/common/SignalVectorModel.hpp b/src/common/SignalVectorModel.hpp index b2d9819df9e..9260d29404a 100644 --- a/src/common/SignalVectorModel.hpp +++ b/src/common/SignalVectorModel.hpp @@ -2,12 +2,13 @@ #include "common/SignalVector.hpp" -#include #include #include #include #include +#include + namespace chatterino { template @@ -166,7 +167,7 @@ class SignalVectorModel : public QAbstractTableModel, assert(this->rows_[row].original); TVectorItem item = this->getItemFromRow( - this->rows_[row].items, this->rows_[row].original.get()); + this->rows_[row].items, this->rows_[row].original.value()); this->vector_->insert(item, vecRow, this); } @@ -262,7 +263,7 @@ class SignalVectorModel : public QAbstractTableModel, TVectorItem item = this->getItemFromRow(this->rows_[sourceRow].items, - this->rows_[sourceRow].original.get()); + this->rows_[sourceRow].original.value()); this->vector_->removeAt(signalVectorRow); this->vector_->insert( item, this->getVectorIndexFromModelIndex(destinationChild)); @@ -417,7 +418,7 @@ class SignalVectorModel : public QAbstractTableModel, struct Row { std::vector items; - boost::optional original; + std::optional original; bool isCustomRow; Row(std::vector _items, bool _isCustomRow = false) diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 894af5c0347..6f69cabf63e 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -114,7 +114,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words) const auto &bttvemotes = app->twitch->getBttvEmotes(); const auto &ffzemotes = app->twitch->getFfzEmotes(); auto flags = MessageElementFlags(); - auto emote = boost::optional{}; + auto emote = std::optional{}; for (int i = 2; i < words.length(); i++) { { // Twitch emote @@ -138,7 +138,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words) } if (emote) { - b.emplace(emote.get(), flags); + b.emplace(*emote, flags); continue; } } // bttv/ffz emote @@ -181,7 +181,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words) app->twitch->whispersChannel->addMessage(messagexD); - auto overrideFlags = boost::optional(messagexD->flags); + auto overrideFlags = std::optional(messagexD->flags); overrideFlags->set(MessageFlag::DoNotLog); if (getSettings()->inlineWhispers && @@ -2856,7 +2856,7 @@ void CommandController::initialize(Settings &, Paths &paths) formatBanTimeoutError](const auto &targetUser) { getHelix()->banUser( twitchChannel->roomId(), currentUser->getUserId(), - targetUser.id, boost::none, reason, + targetUser.id, std::nullopt, reason, [] { // No response for bans, they're emitted over pubsub/IRC instead }, @@ -2910,7 +2910,7 @@ void CommandController::initialize(Settings &, Paths &paths) getHelix()->banUser( twitchChannel->roomId(), currentUser->getUserId(), target, - boost::none, reason, + std::nullopt, reason, [] { // No response for bans, they're emitted over pubsub/IRC instead }, diff --git a/src/controllers/commands/builtin/twitch/ChatSettings.cpp b/src/controllers/commands/builtin/twitch/ChatSettings.cpp index ed687261561..09fd23db89c 100644 --- a/src/controllers/commands/builtin/twitch/ChatSettings.cpp +++ b/src/controllers/commands/builtin/twitch/ChatSettings.cpp @@ -289,7 +289,7 @@ QString slowOff(const CommandContext &ctx) } getHelix()->updateSlowMode(ctx.twitchChannel->roomId(), - currentUser->getUserId(), boost::none, + currentUser->getUserId(), std::nullopt, successCallback, failureCallback(ctx.channel)); return ""; @@ -367,7 +367,7 @@ QString followersOff(const CommandContext &ctx) } getHelix()->updateFollowerMode( - ctx.twitchChannel->roomId(), currentUser->getUserId(), boost::none, + ctx.twitchChannel->roomId(), currentUser->getUserId(), std::nullopt, successCallback, failureCallback(ctx.channel)); return ""; diff --git a/src/controllers/highlights/HighlightController.cpp b/src/controllers/highlights/HighlightController.cpp index 91999c82f88..6e91f706b71 100644 --- a/src/controllers/highlights/HighlightController.cpp +++ b/src/controllers/highlights/HighlightController.cpp @@ -23,7 +23,7 @@ auto highlightPhraseCheck(const HighlightPhrase &highlight) -> HighlightCheck [highlight](const auto &args, const auto &badges, const auto &senderName, const auto &originalMessage, const auto &flags, - const auto self) -> boost::optional { + const auto self) -> std::optional { (void)args; // unused (void)badges; // unused (void)senderName; // unused @@ -32,15 +32,15 @@ auto highlightPhraseCheck(const HighlightPhrase &highlight) -> HighlightCheck if (self) { // Phrase checks should ignore highlights from the user - return boost::none; + return std::nullopt; } if (!highlight.isMatch(originalMessage)) { - return boost::none; + return std::nullopt; } - boost::optional highlightSoundUrl; + std::optional highlightSoundUrl; if (highlight.hasCustomSound()) { highlightSoundUrl = highlight.getSoundUrl(); @@ -62,7 +62,7 @@ void rebuildSubscriptionHighlights(Settings &settings, auto highlightSound = settings.enableSubHighlightSound.getValue(); auto highlightAlert = settings.enableSubHighlightTaskbar.getValue(); auto highlightSoundUrlValue = settings.subHighlightSoundUrl.getValue(); - boost::optional highlightSoundUrl; + std::optional highlightSoundUrl; if (!highlightSoundUrlValue.isEmpty()) { highlightSoundUrl = highlightSoundUrlValue; @@ -73,7 +73,7 @@ void rebuildSubscriptionHighlights(Settings &settings, checks.emplace_back(HighlightCheck{ [=](const auto &args, const auto &badges, const auto &senderName, const auto &originalMessage, const auto &flags, - const auto self) -> boost::optional { + const auto self) -> std::optional { (void)badges; // unused (void)senderName; // unused (void)originalMessage; // unused @@ -82,7 +82,7 @@ void rebuildSubscriptionHighlights(Settings &settings, if (!args.isSubscriptionMessage) { - return boost::none; + return std::nullopt; } auto highlightColor = @@ -108,7 +108,7 @@ void rebuildWhisperHighlights(Settings &settings, auto highlightAlert = settings.enableWhisperHighlightTaskbar.getValue(); auto highlightSoundUrlValue = settings.whisperHighlightSoundUrl.getValue(); - boost::optional highlightSoundUrl; + std::optional highlightSoundUrl; if (!highlightSoundUrlValue.isEmpty()) { highlightSoundUrl = highlightSoundUrlValue; @@ -119,7 +119,7 @@ void rebuildWhisperHighlights(Settings &settings, checks.emplace_back(HighlightCheck{ [=](const auto &args, const auto &badges, const auto &senderName, const auto &originalMessage, const auto &flags, - const auto self) -> boost::optional { + const auto self) -> std::optional { (void)badges; // unused (void)senderName; // unused (void)originalMessage; // unused @@ -128,7 +128,7 @@ void rebuildWhisperHighlights(Settings &settings, if (!args.isReceivedWhisper) { - return boost::none; + return std::nullopt; } return HighlightResult{ @@ -151,7 +151,7 @@ void rebuildReplyThreadHighlight(Settings &settings, auto highlightAlert = settings.enableThreadHighlightTaskbar.getValue(); auto highlightSoundUrlValue = settings.threadHighlightSoundUrl.getValue(); - boost::optional highlightSoundUrl; + std::optional highlightSoundUrl; if (!highlightSoundUrlValue.isEmpty()) { highlightSoundUrl = highlightSoundUrlValue; @@ -162,7 +162,7 @@ void rebuildReplyThreadHighlight(Settings &settings, [=](const auto & /*args*/, const auto & /*badges*/, const auto & /*senderName*/, const auto & /*originalMessage*/, const auto &flags, - const auto self) -> boost::optional { + const auto self) -> std::optional { if (flags.has(MessageFlag::SubscribedThread) && !self) { return HighlightResult{ @@ -175,7 +175,7 @@ void rebuildReplyThreadHighlight(Settings &settings, }; } - return boost::none; + return std::nullopt; }}); } } @@ -219,7 +219,7 @@ void rebuildUserHighlights(Settings &settings, [showInMentions]( const auto &args, const auto &badges, const auto &senderName, const auto &originalMessage, const auto &flags, - const auto self) -> boost::optional { + const auto self) -> std::optional { (void)args; //unused (void)badges; //unused (void)senderName; //unused @@ -228,7 +228,7 @@ void rebuildUserHighlights(Settings &settings, if (!self) { - return boost::none; + return std::nullopt; } // Highlight color is provided by the ColorProvider and will be updated accordingly @@ -246,7 +246,7 @@ void rebuildUserHighlights(Settings &settings, [highlight](const auto &args, const auto &badges, const auto &senderName, const auto &originalMessage, const auto &flags, - const auto self) -> boost::optional { + const auto self) -> std::optional { (void)args; // unused (void)badges; // unused (void)originalMessage; // unused @@ -255,10 +255,10 @@ void rebuildUserHighlights(Settings &settings, if (!highlight.isMatch(senderName)) { - return boost::none; + return std::nullopt; } - boost::optional highlightSoundUrl; + std::optional highlightSoundUrl; if (highlight.hasCustomSound()) { highlightSoundUrl = highlight.getSoundUrl(); @@ -286,7 +286,7 @@ void rebuildBadgeHighlights(Settings &settings, [highlight](const auto &args, const auto &badges, const auto &senderName, const auto &originalMessage, const auto &flags, - const auto self) -> boost::optional { + const auto self) -> std::optional { (void)args; // unused (void)senderName; // unused (void)originalMessage; // unused @@ -297,7 +297,7 @@ void rebuildBadgeHighlights(Settings &settings, { if (highlight.isMatch(badge)) { - boost::optional highlightSoundUrl; + std::optional highlightSoundUrl; if (highlight.hasCustomSound()) { highlightSoundUrl = highlight.getSoundUrl(); @@ -313,7 +313,7 @@ void rebuildBadgeHighlights(Settings &settings, } } - return boost::none; + return std::nullopt; }}); } } @@ -323,7 +323,7 @@ void rebuildBadgeHighlights(Settings &settings, namespace chatterino { HighlightResult::HighlightResult(bool _alert, bool _playSound, - boost::optional _customSoundUrl, + std::optional _customSoundUrl, std::shared_ptr _color, bool _showInMentions) : alert(_alert) @@ -337,7 +337,7 @@ HighlightResult::HighlightResult(bool _alert, bool _playSound, HighlightResult HighlightResult::emptyResult() { return { - false, false, boost::none, nullptr, false, + false, false, std::nullopt, nullptr, false, }; } @@ -395,7 +395,7 @@ std::ostream &operator<<(std::ostream &os, const HighlightResult &result) os << "Alert: " << (result.alert ? "Yes" : "No") << ", " << "Play sound: " << (result.playSound ? "Yes" : "No") << " (" << (result.customSoundUrl - ? result.customSoundUrl.get().toString().toStdString() + ? result.customSoundUrl->toString().toStdString() : "") << ")" << ", " diff --git a/src/controllers/highlights/HighlightController.hpp b/src/controllers/highlights/HighlightController.hpp index 7e238d81737..9f3951ba0cc 100644 --- a/src/controllers/highlights/HighlightController.hpp +++ b/src/controllers/highlights/HighlightController.hpp @@ -4,7 +4,6 @@ #include "common/Singleton.hpp" #include "common/UniqueAccess.hpp" -#include #include #include #include @@ -12,6 +11,7 @@ #include #include +#include #include namespace chatterino { @@ -23,7 +23,7 @@ using MessageFlags = FlagsEnum; struct HighlightResult { HighlightResult(bool _alert, bool _playSound, - boost::optional _customSoundUrl, + std::optional _customSoundUrl, std::shared_ptr _color, bool _showInMentions); /** @@ -46,7 +46,7 @@ struct HighlightResult { * * May only be set if playSound is true **/ - boost::optional customSoundUrl{}; + std::optional customSoundUrl{}; /** * @brief set if highlight should set a background color @@ -76,7 +76,7 @@ struct HighlightResult { }; struct HighlightCheck { - using Checker = std::function( + using Checker = std::function( const MessageParseArgs &args, const std::vector &badges, const QString &senderName, const QString &originalMessage, const MessageFlags &messageFlags, bool self)>; diff --git a/src/controllers/hotkeys/HotkeyController.cpp b/src/controllers/hotkeys/HotkeyController.cpp index 16a1e035665..0fc85f97e79 100644 --- a/src/controllers/hotkeys/HotkeyController.cpp +++ b/src/controllers/hotkeys/HotkeyController.cpp @@ -127,7 +127,7 @@ int HotkeyController::replaceHotkey(QString oldName, return this->hotkeys_.append(newHotkey); } -boost::optional HotkeyController::hotkeyCategoryFromName( +std::optional HotkeyController::hotkeyCategoryFromName( QString categoryName) { for (const auto &[category, data] : this->categories()) @@ -189,8 +189,8 @@ QString HotkeyController::categoryName(HotkeyCategory category) const return categoryData.name; } -const std::map - &HotkeyController::categories() const +const std::map & + HotkeyController::categories() const { return this->hotkeyCategories_; } diff --git a/src/controllers/hotkeys/HotkeyController.hpp b/src/controllers/hotkeys/HotkeyController.hpp index 1ea48540033..d5e74f3fbde 100644 --- a/src/controllers/hotkeys/HotkeyController.hpp +++ b/src/controllers/hotkeys/HotkeyController.hpp @@ -4,7 +4,6 @@ #include "common/Singleton.hpp" #include "controllers/hotkeys/HotkeyCategory.hpp" -#include #include #include @@ -52,8 +51,7 @@ class HotkeyController final : public Singleton * @returns the new index in the SignalVector **/ int replaceHotkey(QString oldName, std::shared_ptr newHotkey); - boost::optional hotkeyCategoryFromName( - QString categoryName); + std::optional hotkeyCategoryFromName(QString categoryName); /** * @brief checks if the hotkey is duplicate diff --git a/src/controllers/hotkeys/HotkeyHelpers.cpp b/src/controllers/hotkeys/HotkeyHelpers.cpp index 2859ad6d2d6..7be663d6e13 100644 --- a/src/controllers/hotkeys/HotkeyHelpers.cpp +++ b/src/controllers/hotkeys/HotkeyHelpers.cpp @@ -3,9 +3,10 @@ #include "controllers/hotkeys/ActionNames.hpp" #include "controllers/hotkeys/HotkeyCategory.hpp" -#include #include +#include + namespace chatterino { std::vector parseHotkeyArguments(QString argumentString) @@ -31,7 +32,7 @@ std::vector parseHotkeyArguments(QString argumentString) return arguments; } -boost::optional findHotkeyActionDefinition( +std::optional findHotkeyActionDefinition( HotkeyCategory category, const QString &action) { auto allActions = actionNames.find(category); diff --git a/src/controllers/hotkeys/HotkeyHelpers.hpp b/src/controllers/hotkeys/HotkeyHelpers.hpp index dfbdb6f2dea..a2218472dea 100644 --- a/src/controllers/hotkeys/HotkeyHelpers.hpp +++ b/src/controllers/hotkeys/HotkeyHelpers.hpp @@ -2,15 +2,15 @@ #include "controllers/hotkeys/ActionNames.hpp" -#include #include +#include #include namespace chatterino { std::vector parseHotkeyArguments(QString argumentString); -boost::optional findHotkeyActionDefinition( +std::optional findHotkeyActionDefinition( HotkeyCategory category, const QString &action); } // namespace chatterino diff --git a/src/controllers/moderationactions/ModerationAction.cpp b/src/controllers/moderationactions/ModerationAction.cpp index de26613c2c6..3d4e371f187 100644 --- a/src/controllers/moderationactions/ModerationAction.cpp +++ b/src/controllers/moderationactions/ModerationAction.cpp @@ -136,7 +136,7 @@ bool ModerationAction::isImage() const return bool(this->image_); } -const boost::optional &ModerationAction::getImage() const +const std::optional &ModerationAction::getImage() const { assertInGuiThread(); diff --git a/src/controllers/moderationactions/ModerationAction.hpp b/src/controllers/moderationactions/ModerationAction.hpp index 2165a1d6f5a..8fa4c9be8a2 100644 --- a/src/controllers/moderationactions/ModerationAction.hpp +++ b/src/controllers/moderationactions/ModerationAction.hpp @@ -2,11 +2,11 @@ #include "util/RapidjsonHelpers.hpp" -#include #include #include #include +#include namespace chatterino { @@ -21,13 +21,13 @@ class ModerationAction bool operator==(const ModerationAction &other) const; bool isImage() const; - const boost::optional &getImage() const; + const std::optional &getImage() const; const QString &getLine1() const; const QString &getLine2() const; const QString &getAction() const; private: - mutable boost::optional image_; + mutable std::optional image_; QString line1_; QString line2_; QString action_; diff --git a/src/controllers/nicknames/Nickname.hpp b/src/controllers/nicknames/Nickname.hpp index fa8bdf6d075..7343dd393bd 100644 --- a/src/controllers/nicknames/Nickname.hpp +++ b/src/controllers/nicknames/Nickname.hpp @@ -3,12 +3,12 @@ #include "util/RapidjsonHelpers.hpp" #include "util/RapidJsonSerializeQString.hpp" -#include #include #include #include #include +#include namespace chatterino { @@ -59,18 +59,18 @@ class Nickname return this->isCaseSensitive_; } - [[nodiscard]] boost::optional match( + [[nodiscard]] std::optional match( const QString &usernameText) const { if (this->isRegex()) { if (!this->regex_.isValid()) { - return boost::none; + return std::nullopt; } if (this->name().isEmpty()) { - return boost::none; + return std::nullopt; } auto workingCopy = usernameText; @@ -90,7 +90,7 @@ class Nickname } } - return boost::none; + return std::nullopt; } private: diff --git a/src/controllers/userdata/UserData.hpp b/src/controllers/userdata/UserData.hpp index a5b460d7149..37eb79aa86c 100644 --- a/src/controllers/userdata/UserData.hpp +++ b/src/controllers/userdata/UserData.hpp @@ -3,11 +3,12 @@ #include "util/RapidjsonHelpers.hpp" #include "util/RapidJsonSerializeQString.hpp" -#include #include #include #include +#include + namespace chatterino { // UserData defines a set of data that is defined for a unique user @@ -15,7 +16,7 @@ namespace chatterino { // or a user note that should be displayed with the user // Replacement fields should be optional, where none denotes that the field should not be updated for the user struct UserData { - boost::optional color{boost::none}; + std::optional color{std::nullopt}; // TODO: User note? }; diff --git a/src/controllers/userdata/UserDataController.cpp b/src/controllers/userdata/UserDataController.cpp index 001c24b8de7..63cf7f1d95e 100644 --- a/src/controllers/userdata/UserDataController.cpp +++ b/src/controllers/userdata/UserDataController.cpp @@ -2,6 +2,7 @@ #include "singletons/Paths.hpp" #include "util/CombinePath.hpp" +#include "util/Helpers.hpp" namespace { @@ -42,15 +43,14 @@ void UserDataController::save() this->sm->save(); } -boost::optional UserDataController::getUser( - const QString &userID) const +std::optional UserDataController::getUser(const QString &userID) const { std::shared_lock lock(this->usersMutex); auto it = this->users.find(userID); if (it == this->users.end()) { - return boost::none; + return std::nullopt; } return it->second; @@ -67,8 +67,8 @@ void UserDataController::setUserColor(const QString &userID, { auto c = this->getUsers(); auto it = c.find(userID); - boost::optional finalColor = - boost::make_optional(!colorString.isEmpty(), QColor(colorString)); + std::optional finalColor = + makeConditionedOptional(!colorString.isEmpty(), QColor(colorString)); if (it == c.end()) { if (!finalColor) diff --git a/src/controllers/userdata/UserDataController.hpp b/src/controllers/userdata/UserDataController.hpp index fe9b54b2813..fba501f4c51 100644 --- a/src/controllers/userdata/UserDataController.hpp +++ b/src/controllers/userdata/UserDataController.hpp @@ -7,11 +7,11 @@ #include "util/RapidJsonSerializeQString.hpp" #include "util/serialize/Container.hpp" -#include #include #include #include +#include #include #include @@ -22,7 +22,7 @@ class IUserDataController public: virtual ~IUserDataController() = default; - virtual boost::optional getUser(const QString &userID) const = 0; + virtual std::optional getUser(const QString &userID) const = 0; virtual void setUserColor(const QString &userID, const QString &colorString) = 0; @@ -35,7 +35,7 @@ class UserDataController : public IUserDataController, public Singleton // Get extra data about a user // If the user does not have any extra data, return none - boost::optional getUser(const QString &userID) const override; + std::optional getUser(const QString &userID) const override; // Update or insert extra data for the user's color override void setUserColor(const QString &userID, diff --git a/src/messages/Emote.hpp b/src/messages/Emote.hpp index d157abbfcf5..e8c0642b16e 100644 --- a/src/messages/Emote.hpp +++ b/src/messages/Emote.hpp @@ -3,11 +3,10 @@ #include "common/Aliases.hpp" #include "messages/ImageSet.hpp" -#include - #include #include #include +#include #include namespace chatterino { @@ -24,7 +23,7 @@ struct Emote { * If this emote is aliased, this contains * the original (base) name of the emote. */ - boost::optional baseName; + std::optional baseName; // FOURTF: no solution yet, to be refactored later const QString &getCopyString() const diff --git a/src/messages/LimitedQueue.hpp b/src/messages/LimitedQueue.hpp index 8c419e184f2..62fd025278d 100644 --- a/src/messages/LimitedQueue.hpp +++ b/src/messages/LimitedQueue.hpp @@ -3,10 +3,10 @@ #include "messages/LimitedQueueSnapshot.hpp" #include -#include #include #include +#include #include #include @@ -62,13 +62,13 @@ class LimitedQueue * @param[in] index the index of the item to fetch * @return the item at the index if it's populated, or none if it's not */ - [[nodiscard]] boost::optional get(size_t index) const + [[nodiscard]] std::optional get(size_t index) const { std::shared_lock lock(this->mutex_); if (index >= this->buffer_.size()) { - return boost::none; + return std::nullopt; } return this->buffer_[index]; @@ -79,13 +79,13 @@ class LimitedQueue * * @return the item at the front of the queue if it's populated, or none the queue is empty */ - [[nodiscard]] boost::optional first() const + [[nodiscard]] std::optional first() const { std::shared_lock lock(this->mutex_); if (this->buffer_.empty()) { - return boost::none; + return std::nullopt; } return this->buffer_.front(); @@ -96,13 +96,13 @@ class LimitedQueue * * @return the item at the back of the queue if it's populated, or none the queue is empty */ - [[nodiscard]] boost::optional last() const + [[nodiscard]] std::optional last() const { std::shared_lock lock(this->mutex_); if (this->buffer_.empty()) { - return boost::none; + return std::nullopt; } return this->buffer_.back(); @@ -293,14 +293,14 @@ class LimitedQueue * * The contents of the LimitedQueue are iterated over from front to back * until the first element that satisfies `pred(item)`. If no item - * satisfies the predicate, or if the queue is empty, then boost::none + * satisfies the predicate, or if the queue is empty, then std::nullopt * is returned. * * @param[in] pred predicate that will be applied to items - * @return the first item found or boost::none + * @return the first item found or std::nullopt */ template - [[nodiscard]] boost::optional find(Predicate pred) const + [[nodiscard]] std::optional find(Predicate pred) const { std::shared_lock lock(this->mutex_); @@ -312,7 +312,7 @@ class LimitedQueue } } - return boost::none; + return std::nullopt; } /** @@ -320,14 +320,14 @@ class LimitedQueue * * The contents of the LimitedQueue are iterated over from back to front * until the first element that satisfies `pred(item)`. If no item - * satisfies the predicate, or if the queue is empty, then boost::none + * satisfies the predicate, or if the queue is empty, then std::nullopt * is returned. * * @param[in] pred predicate that will be applied to items - * @return the first item found or boost::none + * @return the first item found or std::nullopt */ template - [[nodiscard]] boost::optional rfind(Predicate pred) const + [[nodiscard]] std::optional rfind(Predicate pred) const { std::shared_lock lock(this->mutex_); @@ -339,7 +339,7 @@ class LimitedQueue } } - return boost::none; + return std::nullopt; } private: diff --git a/src/messages/MessageElement.cpp b/src/messages/MessageElement.cpp index 55503d27bca..638b893f4af 100644 --- a/src/messages/MessageElement.cpp +++ b/src/messages/MessageElement.cpp @@ -788,7 +788,7 @@ void TwitchModerationElement::addToContainer(MessageLayoutContainer &container, if (auto image = action.getImage()) { container.addElement( - (new ImageLayoutElement(*this, image.get(), size)) + (new ImageLayoutElement(*this, *image, size)) ->setLink(Link(Link::UserAction, action.getAction()))); } else diff --git a/src/messages/SharedMessageBuilder.cpp b/src/messages/SharedMessageBuilder.cpp index b54147c3048..bedeb5cdf41 100644 --- a/src/messages/SharedMessageBuilder.cpp +++ b/src/messages/SharedMessageBuilder.cpp @@ -175,7 +175,7 @@ void SharedMessageBuilder::parseHighlights() if (highlightResult.customSoundUrl) { - this->highlightSoundUrl_ = highlightResult.customSoundUrl.get(); + this->highlightSoundUrl_ = *highlightResult.customSoundUrl; } else { diff --git a/src/providers/NetworkConfigurationProvider.cpp b/src/providers/NetworkConfigurationProvider.cpp index 57291ac2519..dca88e8a6cd 100644 --- a/src/providers/NetworkConfigurationProvider.cpp +++ b/src/providers/NetworkConfigurationProvider.cpp @@ -69,7 +69,7 @@ void NetworkConfigurationProvider::applyFromEnv(const Env &env) { if (env.proxyUrl) { - applyProxy(env.proxyUrl.get()); + applyProxy(*env.proxyUrl); } } diff --git a/src/providers/bttv/BttvEmotes.cpp b/src/providers/bttv/BttvEmotes.cpp index 42bf51cba0c..fa2cdc3166e 100644 --- a/src/providers/bttv/BttvEmotes.cpp +++ b/src/providers/bttv/BttvEmotes.cpp @@ -179,13 +179,13 @@ std::shared_ptr BttvEmotes::emotes() const return this->global_.get(); } -boost::optional BttvEmotes::emote(const EmoteName &name) const +std::optional BttvEmotes::emote(const EmoteName &name) const { auto emotes = this->global_.get(); auto it = emotes->find(name); if (it == emotes->end()) - return boost::none; + return std::nullopt; return it->second; } @@ -291,7 +291,7 @@ EmotePtr BttvEmotes::addEmote( return emote; } -boost::optional> BttvEmotes::updateEmote( +std::optional> BttvEmotes::updateEmote( const QString &channelDisplayName, Atomic> &channelEmoteMap, const BttvLiveUpdateEmoteUpdateAddMessage &message) @@ -305,7 +305,7 @@ boost::optional> BttvEmotes::updateEmote( { // We already copied the map at this point and are now discarding the copy. // This is fine, because this case should be really rare. - return boost::none; + return std::nullopt; } auto oldEmotePtr = it->second; // copy the existing emote, to not change the original one @@ -316,7 +316,7 @@ boost::optional> BttvEmotes::updateEmote( if (!updateChannelEmote(emote, channelDisplayName, message.jsonEmote)) { // The emote wasn't actually updated - return boost::none; + return std::nullopt; } auto name = emote.name; @@ -327,7 +327,7 @@ boost::optional> BttvEmotes::updateEmote( return std::make_pair(oldEmotePtr, emotePtr); } -boost::optional BttvEmotes::removeEmote( +std::optional BttvEmotes::removeEmote( Atomic> &channelEmoteMap, const BttvLiveUpdateEmoteRemoveMessage &message) { @@ -338,7 +338,7 @@ boost::optional BttvEmotes::removeEmote( { // We already copied the map at this point and are now discarding the copy. // This is fine, because this case should be really rare. - return boost::none; + return std::nullopt; } auto emote = it->second; updatedMap.erase(it); diff --git a/src/providers/bttv/BttvEmotes.hpp b/src/providers/bttv/BttvEmotes.hpp index bbdcacccbca..e8258d88162 100644 --- a/src/providers/bttv/BttvEmotes.hpp +++ b/src/providers/bttv/BttvEmotes.hpp @@ -3,9 +3,8 @@ #include "common/Aliases.hpp" #include "common/Atomic.hpp" -#include - #include +#include namespace chatterino { @@ -27,7 +26,7 @@ class BttvEmotes final BttvEmotes(); std::shared_ptr emotes() const; - boost::optional emote(const EmoteName &name) const; + std::optional emote(const EmoteName &name) const; void loadEmotes(); void setEmotes(std::shared_ptr emotes); static void loadChannel(std::weak_ptr channel, @@ -55,7 +54,7 @@ class BttvEmotes final * * @return pair if any emote was updated. */ - static boost::optional> updateEmote( + static std::optional> updateEmote( const QString &channelDisplayName, Atomic> &channelEmoteMap, const BttvLiveUpdateEmoteUpdateAddMessage &message); @@ -67,7 +66,7 @@ class BttvEmotes final * * @return The removed emote if any emote was removed. */ - static boost::optional removeEmote( + static std::optional removeEmote( Atomic> &channelEmoteMap, const BttvLiveUpdateEmoteRemoveMessage &message); diff --git a/src/providers/chatterino/ChatterinoBadges.cpp b/src/providers/chatterino/ChatterinoBadges.cpp index f0ccec3af0c..9ea1abeafe9 100644 --- a/src/providers/chatterino/ChatterinoBadges.cpp +++ b/src/providers/chatterino/ChatterinoBadges.cpp @@ -21,7 +21,7 @@ ChatterinoBadges::ChatterinoBadges() { } -boost::optional ChatterinoBadges::getBadge(const UserId &id) +std::optional ChatterinoBadges::getBadge(const UserId &id) { std::shared_lock lock(this->mutex_); @@ -30,7 +30,7 @@ boost::optional ChatterinoBadges::getBadge(const UserId &id) { return emotes[it->second]; } - return boost::none; + return std::nullopt; } void ChatterinoBadges::loadChatterinoBadges() diff --git a/src/providers/chatterino/ChatterinoBadges.hpp b/src/providers/chatterino/ChatterinoBadges.hpp index 179c55a4501..0d6598e5cc6 100644 --- a/src/providers/chatterino/ChatterinoBadges.hpp +++ b/src/providers/chatterino/ChatterinoBadges.hpp @@ -4,9 +4,8 @@ #include "common/Singleton.hpp" #include "util/QStringHash.hpp" -#include - #include +#include #include #include #include @@ -22,7 +21,7 @@ class ChatterinoBadges : public Singleton virtual void initialize(Settings &settings, Paths &paths) override; ChatterinoBadges(); - boost::optional getBadge(const UserId &id); + std::optional getBadge(const UserId &id); private: void loadChatterinoBadges(); diff --git a/src/providers/ffz/FfzBadges.cpp b/src/providers/ffz/FfzBadges.cpp index ebeaabf16ad..a70007ac253 100644 --- a/src/providers/ffz/FfzBadges.cpp +++ b/src/providers/ffz/FfzBadges.cpp @@ -43,7 +43,7 @@ std::vector FfzBadges::getUserBadges(const UserId &id) return badges; } -boost::optional FfzBadges::getBadge(const int badgeID) +std::optional FfzBadges::getBadge(const int badgeID) { auto it = this->badges.find(badgeID); if (it != this->badges.end()) @@ -51,7 +51,7 @@ boost::optional FfzBadges::getBadge(const int badgeID) return it->second; } - return boost::none; + return std::nullopt; } void FfzBadges::load() diff --git a/src/providers/ffz/FfzBadges.hpp b/src/providers/ffz/FfzBadges.hpp index c0cc80c681d..33852a5b962 100644 --- a/src/providers/ffz/FfzBadges.hpp +++ b/src/providers/ffz/FfzBadges.hpp @@ -4,10 +4,10 @@ #include "common/Singleton.hpp" #include "util/QStringHash.hpp" -#include #include #include +#include #include #include #include @@ -32,7 +32,7 @@ class FfzBadges : public Singleton std::vector getUserBadges(const UserId &id); private: - boost::optional getBadge(int badgeID); + std::optional getBadge(int badgeID); void load(); diff --git a/src/providers/ffz/FfzEmotes.cpp b/src/providers/ffz/FfzEmotes.cpp index 0a28cc51b6e..6595a3678b6 100644 --- a/src/providers/ffz/FfzEmotes.cpp +++ b/src/providers/ffz/FfzEmotes.cpp @@ -119,10 +119,10 @@ namespace { return emotes; } - boost::optional parseAuthorityBadge(const QJsonObject &badgeUrls, - const QString &tooltip) + std::optional parseAuthorityBadge(const QJsonObject &badgeUrls, + const QString &tooltip) { - boost::optional authorityBadge; + std::optional authorityBadge; if (!badgeUrls.isEmpty()) { @@ -173,7 +173,7 @@ std::shared_ptr FfzEmotes::emotes() const return this->global_.get(); } -boost::optional FfzEmotes::emote(const EmoteName &name) const +std::optional FfzEmotes::emote(const EmoteName &name) const { auto emotes = this->global_.get(); auto it = emotes->find(name); @@ -181,7 +181,7 @@ boost::optional FfzEmotes::emote(const EmoteName &name) const { return it->second; } - return boost::none; + return std::nullopt; } void FfzEmotes::loadEmotes() @@ -214,8 +214,8 @@ void FfzEmotes::setEmotes(std::shared_ptr emotes) void FfzEmotes::loadChannel( std::weak_ptr channel, const QString &channelID, std::function emoteCallback, - std::function)> modBadgeCallback, - std::function)> vipBadgeCallback, + std::function)> modBadgeCallback, + std::function)> vipBadgeCallback, bool manualRefresh) { qCDebug(chatterinoFfzemotes) diff --git a/src/providers/ffz/FfzEmotes.hpp b/src/providers/ffz/FfzEmotes.hpp index e2865fcb58d..3b4d1f8af4b 100644 --- a/src/providers/ffz/FfzEmotes.hpp +++ b/src/providers/ffz/FfzEmotes.hpp @@ -3,9 +3,8 @@ #include "common/Aliases.hpp" #include "common/Atomic.hpp" -#include - #include +#include namespace chatterino { @@ -20,14 +19,14 @@ class FfzEmotes final FfzEmotes(); std::shared_ptr emotes() const; - boost::optional emote(const EmoteName &name) const; + std::optional emote(const EmoteName &name) const; void loadEmotes(); void setEmotes(std::shared_ptr emotes); static void loadChannel( std::weak_ptr channel, const QString &channelId, std::function emoteCallback, - std::function)> modBadgeCallback, - std::function)> vipBadgeCallback, + std::function)> modBadgeCallback, + std::function)> vipBadgeCallback, bool manualRefresh); private: diff --git a/src/providers/seventv/SeventvBadges.cpp b/src/providers/seventv/SeventvBadges.cpp index e54682baa75..3ee36735c78 100644 --- a/src/providers/seventv/SeventvBadges.cpp +++ b/src/providers/seventv/SeventvBadges.cpp @@ -13,7 +13,7 @@ namespace chatterino { -boost::optional SeventvBadges::getBadge(const UserId &id) const +std::optional SeventvBadges::getBadge(const UserId &id) const { std::shared_lock lock(this->mutex_); @@ -22,7 +22,7 @@ boost::optional SeventvBadges::getBadge(const UserId &id) const { return it->second; } - return boost::none; + return std::nullopt; } void SeventvBadges::assignBadgeToUser(const QString &badgeID, diff --git a/src/providers/seventv/SeventvBadges.hpp b/src/providers/seventv/SeventvBadges.hpp index a6ed981ee87..72552891612 100644 --- a/src/providers/seventv/SeventvBadges.hpp +++ b/src/providers/seventv/SeventvBadges.hpp @@ -4,10 +4,10 @@ #include "common/Singleton.hpp" #include "util/QStringHash.hpp" -#include #include #include +#include #include #include @@ -20,7 +20,7 @@ class SeventvBadges : public Singleton { public: // Return the badge, if any, that is assigned to the user - boost::optional getBadge(const UserId &id) const; + std::optional getBadge(const UserId &id) const; // Assign the given badge to the user void assignBadgeToUser(const QString &badgeID, const UserId &userID); diff --git a/src/providers/seventv/SeventvEmotes.cpp b/src/providers/seventv/SeventvEmotes.cpp index 31d0724fa58..4004d9edbb8 100644 --- a/src/providers/seventv/SeventvEmotes.cpp +++ b/src/providers/seventv/SeventvEmotes.cpp @@ -11,6 +11,7 @@ #include "providers/seventv/SeventvAPI.hpp" #include "providers/twitch/TwitchChannel.hpp" #include "singletons/Settings.hpp" +#include "util/Helpers.hpp" #include #include @@ -109,7 +110,7 @@ CreateEmoteResult createEmote(const QJsonObject &activeEmote, auto emote = Emote({emoteName, imageSet, tooltip, Url{EMOTE_LINK_FORMAT.arg(emoteId.string)}, zeroWidth, emoteId, - author, boost::make_optional(aliasedName, baseEmoteName)}); + author, makeConditionedOptional(aliasedName, baseEmoteName)}); return {emote, emoteId, emoteName, !emote.images.getImage1()->isEmpty()}; } @@ -162,7 +163,7 @@ EmotePtr createUpdatedEmote(const EmotePtr &oldEmote, bool toNonAliased = oldEmote->baseName.has_value() && dispatch.emoteName == oldEmote->baseName->string; - auto baseName = oldEmote->baseName.get_value_or(oldEmote->name); + auto baseName = oldEmote->baseName.value_or(oldEmote->name); auto emote = std::make_shared(Emote( {EmoteName{dispatch.emoteName}, oldEmote->images, toNonAliased @@ -170,7 +171,7 @@ EmotePtr createUpdatedEmote(const EmotePtr &oldEmote, : createAliasedTooltip(dispatch.emoteName, baseName.string, oldEmote->author.string, false), oldEmote->homePage, oldEmote->zeroWidth, oldEmote->id, - oldEmote->author, boost::make_optional(!toNonAliased, baseName)})); + oldEmote->author, makeConditionedOptional(!toNonAliased, baseName)})); return emote; } @@ -191,15 +192,14 @@ std::shared_ptr SeventvEmotes::globalEmotes() const return this->global_.get(); } -boost::optional SeventvEmotes::globalEmote( - const EmoteName &name) const +std::optional SeventvEmotes::globalEmote(const EmoteName &name) const { auto emotes = this->global_.get(); auto it = emotes->find(name); if (it == emotes->end()) { - return boost::none; + return std::nullopt; } return it->second; } @@ -328,7 +328,7 @@ void SeventvEmotes::loadChannelEmotes( }); } -boost::optional SeventvEmotes::addEmote( +std::optional SeventvEmotes::addEmote( Atomic> &map, const EmoteAddDispatch &dispatch) { @@ -336,7 +336,7 @@ boost::optional SeventvEmotes::addEmote( auto emoteData = dispatch.emoteJson["data"].toObject(); if (emoteData.empty() || !checkEmoteVisibility(emoteData)) { - return boost::none; + return std::nullopt; } // This copies the map. @@ -347,7 +347,7 @@ boost::optional SeventvEmotes::addEmote( // Incoming emote didn't contain any images, abort qCDebug(chatterinoSeventv) << "Emote without images:" << dispatch.emoteJson; - return boost::none; + return std::nullopt; } auto emote = std::make_shared(std::move(result.emote)); updatedMap[result.name] = emote; @@ -356,7 +356,7 @@ boost::optional SeventvEmotes::addEmote( return emote; } -boost::optional SeventvEmotes::updateEmote( +std::optional SeventvEmotes::updateEmote( Atomic> &map, const EmoteUpdateDispatch &dispatch) { @@ -364,7 +364,7 @@ boost::optional SeventvEmotes::updateEmote( auto oldEmote = oldMap->findEmote(dispatch.emoteName, dispatch.emoteID); if (oldEmote == oldMap->end()) { - return boost::none; + return std::nullopt; } // This copies the map. @@ -378,7 +378,7 @@ boost::optional SeventvEmotes::updateEmote( return emote; } -boost::optional SeventvEmotes::removeEmote( +std::optional SeventvEmotes::removeEmote( Atomic> &map, const EmoteRemoveDispatch &dispatch) { @@ -389,7 +389,7 @@ boost::optional SeventvEmotes::removeEmote( { // We already copied the map at this point and are now discarding the copy. // This is fine, because this case should be really rare. - return boost::none; + return std::nullopt; } auto emote = it->second; updatedMap.erase(it); diff --git a/src/providers/seventv/SeventvEmotes.hpp b/src/providers/seventv/SeventvEmotes.hpp index e8a59f13bfd..0ba2641e443 100644 --- a/src/providers/seventv/SeventvEmotes.hpp +++ b/src/providers/seventv/SeventvEmotes.hpp @@ -1,6 +1,5 @@ #pragma once -#include "boost/optional.hpp" #include "common/Aliases.hpp" #include "common/Atomic.hpp" #include "common/FlagsEnum.hpp" @@ -8,6 +7,7 @@ #include #include +#include namespace chatterino { @@ -89,7 +89,7 @@ class SeventvEmotes final SeventvEmotes(); std::shared_ptr globalEmotes() const; - boost::optional globalEmote(const EmoteName &name) const; + std::optional globalEmote(const EmoteName &name) const; void loadGlobalEmotes(); void setGlobalEmotes(std::shared_ptr emotes); static void loadChannelEmotes( @@ -104,7 +104,7 @@ class SeventvEmotes final * * @return The added emote if an emote was added. */ - static boost::optional addEmote( + static std::optional addEmote( Atomic> &map, const seventv::eventapi::EmoteAddDispatch &dispatch); @@ -115,7 +115,7 @@ class SeventvEmotes final * * @return The updated emote if any emote was updated. */ - static boost::optional updateEmote( + static std::optional updateEmote( Atomic> &map, const seventv::eventapi::EmoteUpdateDispatch &dispatch); @@ -126,7 +126,7 @@ class SeventvEmotes final * * @return The removed emote if any emote was removed. */ - static boost::optional removeEmote( + static std::optional removeEmote( Atomic> &map, const seventv::eventapi::EmoteRemoveDispatch &dispatch); diff --git a/src/providers/seventv/eventapi/Message.hpp b/src/providers/seventv/eventapi/Message.hpp index 1b857f9eaa7..5dbc848b756 100644 --- a/src/providers/seventv/eventapi/Message.hpp +++ b/src/providers/seventv/eventapi/Message.hpp @@ -2,12 +2,13 @@ #include "providers/seventv/eventapi/Subscription.hpp" -#include #include #include #include #include +#include + namespace chatterino::seventv::eventapi { struct Message { @@ -18,22 +19,22 @@ struct Message { Message(QJsonObject _json); template - boost::optional toInner(); + std::optional toInner(); }; template -boost::optional Message::toInner() +std::optional Message::toInner() { return InnerClass{this->data}; } -static boost::optional parseBaseMessage(const QString &blob) +static std::optional parseBaseMessage(const QString &blob) { QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8())); if (jsonDoc.isNull()) { - return boost::none; + return std::nullopt; } return Message(jsonDoc.object()); diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index 754ac74b850..38c15f289a3 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -914,7 +914,7 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message) c->addMessage(_message); - auto overrideFlags = boost::optional(_message->flags); + auto overrideFlags = std::optional(_message->flags); overrideFlags->set(MessageFlag::DoNotTriggerNotification); overrideFlags->set(MessageFlag::DoNotLog); diff --git a/src/providers/twitch/PubSubManager.cpp b/src/providers/twitch/PubSubManager.cpp index 4094200f697..cc240d01d45 100644 --- a/src/providers/twitch/PubSubManager.cpp +++ b/src/providers/twitch/PubSubManager.cpp @@ -727,14 +727,14 @@ void PubSub::registerNonce(QString nonce, NonceInfo info) this->nonces_[nonce] = std::move(info); } -boost::optional PubSub::findNonceInfo(QString nonce) +std::optional PubSub::findNonceInfo(QString nonce) { // TODO: This should also DELETE the nonceinfo from the map auto it = this->nonces_.find(nonce); if (it == this->nonces_.end()) { - return boost::none; + return std::nullopt; } return it->second; diff --git a/src/providers/twitch/PubSubManager.hpp b/src/providers/twitch/PubSubManager.hpp index 40f6a44e90f..f300bb5d338 100644 --- a/src/providers/twitch/PubSubManager.hpp +++ b/src/providers/twitch/PubSubManager.hpp @@ -5,7 +5,6 @@ #include "util/ExponentialBackoff.hpp" #include "util/QStringHash.hpp" -#include #include #include #include @@ -15,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -188,7 +188,7 @@ class PubSub void registerNonce(QString nonce, NonceInfo nonceInfo); // Find client associated with a nonce - boost::optional findNonceInfo(QString nonce); + std::optional findNonceInfo(QString nonce); std::unordered_map nonces_; diff --git a/src/providers/twitch/TwitchBadges.cpp b/src/providers/twitch/TwitchBadges.cpp index daf782f2918..1637077e47c 100644 --- a/src/providers/twitch/TwitchBadges.cpp +++ b/src/providers/twitch/TwitchBadges.cpp @@ -149,8 +149,8 @@ void TwitchBadges::loaded() } } -boost::optional TwitchBadges::badge(const QString &set, - const QString &version) const +std::optional TwitchBadges::badge(const QString &set, + const QString &version) const { auto badgeSets = this->badgeSets_.access(); auto it = badgeSets->find(set); @@ -162,10 +162,10 @@ boost::optional TwitchBadges::badge(const QString &set, return it2->second; } } - return boost::none; + return std::nullopt; } -boost::optional TwitchBadges::badge(const QString &set) const +std::optional TwitchBadges::badge(const QString &set) const { auto badgeSets = this->badgeSets_.access(); auto it = badgeSets->find(set); @@ -176,7 +176,7 @@ boost::optional TwitchBadges::badge(const QString &set) const return it->second.begin()->second; } } - return boost::none; + return std::nullopt; } void TwitchBadges::getBadgeIcon(const QString &name, BadgeIconCallback callback) diff --git a/src/providers/twitch/TwitchBadges.hpp b/src/providers/twitch/TwitchBadges.hpp index 42b2494db52..4ca4c42b699 100644 --- a/src/providers/twitch/TwitchBadges.hpp +++ b/src/providers/twitch/TwitchBadges.hpp @@ -3,7 +3,6 @@ #include "common/UniqueAccess.hpp" #include "util/QStringHash.hpp" -#include #include #include #include @@ -11,6 +10,7 @@ #include #include +#include #include #include #include @@ -35,10 +35,10 @@ class TwitchBadges static TwitchBadges *instance(); // Get badge from name and version - boost::optional badge(const QString &set, - const QString &version) const; + std::optional badge(const QString &set, + const QString &version) const; // Get first matching badge with name, regardless of version - boost::optional badge(const QString &set) const; + std::optional badge(const QString &set) const; void getBadgeIcon(const QString &name, BadgeIconCallback callback); void getBadgeIcon(const DisplayBadge &badge, BadgeIconCallback callback); diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 7de6f33337b..ea9c90e3d4e 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -35,6 +35,7 @@ #include "singletons/Settings.hpp" #include "singletons/Toasts.hpp" #include "singletons/WindowManager.hpp" +#include "util/Helpers.hpp" #include "util/PostToThread.hpp" #include "util/QStringHash.hpp" #include "widgets/Window.hpp" @@ -396,14 +397,14 @@ bool TwitchChannel::isChannelPointRewardKnown(const QString &rewardId) return it != pointRewards->end(); } -boost::optional TwitchChannel::channelPointReward( +std::optional TwitchChannel::channelPointReward( const QString &rewardId) const { auto rewards = this->channelPointRewards_.accessConst(); auto it = rewards->find(rewardId); if (it == rewards->end()) - return boost::none; + return std::nullopt; return it->second; } @@ -751,35 +752,34 @@ SharedAccessGuard return this->streamStatus_.accessConst(); } -boost::optional TwitchChannel::bttvEmote(const EmoteName &name) const +std::optional TwitchChannel::bttvEmote(const EmoteName &name) const { auto emotes = this->bttvEmotes_.get(); auto it = emotes->find(name); if (it == emotes->end()) - return boost::none; + return std::nullopt; return it->second; } -boost::optional TwitchChannel::ffzEmote(const EmoteName &name) const +std::optional TwitchChannel::ffzEmote(const EmoteName &name) const { auto emotes = this->ffzEmotes_.get(); auto it = emotes->find(name); if (it == emotes->end()) - return boost::none; + return std::nullopt; return it->second; } -boost::optional TwitchChannel::seventvEmote( - const EmoteName &name) const +std::optional TwitchChannel::seventvEmote(const EmoteName &name) const { auto emotes = this->seventvEmotes_.get(); auto it = emotes->find(name); if (it == emotes->end()) { - return boost::none; + return std::nullopt; } return it->second; } @@ -865,7 +865,7 @@ void TwitchChannel::removeBttvEmote( } this->addOrReplaceLiveUpdatesAddRemove(false, "BTTV", QString() /*actor*/, - removed.get()->name.string); + (*removed)->name.string); } void TwitchChannel::addSeventvEmote( @@ -904,7 +904,7 @@ void TwitchChannel::removeSeventvEmote( } this->addOrReplaceLiveUpdatesAddRemove(false, "7TV", dispatch.actorName, - removed.get()->name.string); + (*removed)->name.string); } void TwitchChannel::updateSeventvUser( @@ -955,13 +955,13 @@ void TwitchChannel::updateSeventvData(const QString &newUserID, return; } - boost::optional oldUserID = boost::make_optional( + std::optional oldUserID = makeConditionedOptional( !this->seventvUserID_.isEmpty() && this->seventvUserID_ != newUserID, this->seventvUserID_); - boost::optional oldEmoteSetID = - boost::make_optional(!this->seventvEmoteSetID_.isEmpty() && - this->seventvEmoteSetID_ != newEmoteSetID, - this->seventvEmoteSetID_); + std::optional oldEmoteSetID = + makeConditionedOptional(!this->seventvEmoteSetID_.isEmpty() && + this->seventvEmoteSetID_ != newEmoteSetID, + this->seventvEmoteSetID_); this->seventvUserID_ = newUserID; this->seventvEmoteSetID_ = newEmoteSetID; @@ -974,8 +974,8 @@ void TwitchChannel::updateSeventvData(const QString &newUserID, if (oldUserID || oldEmoteSetID) { getApp()->twitch->dropSeventvChannel( - oldUserID.get_value_or(QString()), - oldEmoteSetID.get_value_or(QString())); + oldUserID.value_or(QString()), + oldEmoteSetID.value_or(QString())); } } }); @@ -1251,8 +1251,8 @@ void TwitchChannel::addReplyThread(const std::shared_ptr &thread) this->threads_[thread->rootId()] = thread; } -const std::unordered_map> - &TwitchChannel::threads() const +const std::unordered_map> & + TwitchChannel::threads() const { return this->threads_; } @@ -1538,8 +1538,8 @@ void TwitchChannel::createClip() }); } -boost::optional TwitchChannel::twitchBadge( - const QString &set, const QString &version) const +std::optional TwitchChannel::twitchBadge(const QString &set, + const QString &version) const { auto badgeSets = this->badgeSets_.access(); auto it = badgeSets->find(set); @@ -1551,20 +1551,20 @@ boost::optional TwitchChannel::twitchBadge( return it2->second; } } - return boost::none; + return std::nullopt; } -boost::optional TwitchChannel::ffzCustomModBadge() const +std::optional TwitchChannel::ffzCustomModBadge() const { return this->ffzCustomModBadge_.get(); } -boost::optional TwitchChannel::ffzCustomVipBadge() const +std::optional TwitchChannel::ffzCustomVipBadge() const { return this->ffzCustomVipBadge_.get(); } -boost::optional TwitchChannel::cheerEmote(const QString &string) +std::optional TwitchChannel::cheerEmote(const QString &string) { auto sets = this->cheerEmoteSets_.access(); for (const auto &set : *sets) @@ -1590,7 +1590,7 @@ boost::optional TwitchChannel::cheerEmote(const QString &string) } } } - return boost::none; + return std::nullopt; } void TwitchChannel::updateSevenTVActivity() diff --git a/src/providers/twitch/TwitchChannel.hpp b/src/providers/twitch/TwitchChannel.hpp index a06299e23ee..c411c367d01 100644 --- a/src/providers/twitch/TwitchChannel.hpp +++ b/src/providers/twitch/TwitchChannel.hpp @@ -9,7 +9,6 @@ #include "providers/twitch/TwitchEmotes.hpp" #include "util/QStringHash.hpp" -#include #include #include #include @@ -134,9 +133,9 @@ class TwitchChannel : public Channel, public ChannelChatters SharedAccessGuard accessStreamStatus() const; // Emotes - boost::optional bttvEmote(const EmoteName &name) const; - boost::optional ffzEmote(const EmoteName &name) const; - boost::optional seventvEmote(const EmoteName &name) const; + std::optional bttvEmote(const EmoteName &name) const; + std::optional ffzEmote(const EmoteName &name) const; + std::optional seventvEmote(const EmoteName &name) const; std::shared_ptr bttvEmotes() const; std::shared_ptr ffzEmotes() const; std::shared_ptr seventvEmotes() const; @@ -172,13 +171,13 @@ class TwitchChannel : public Channel, public ChannelChatters const QString &newEmoteSetID); // Badges - boost::optional ffzCustomModBadge() const; - boost::optional ffzCustomVipBadge() const; - boost::optional twitchBadge(const QString &set, - const QString &version) const; + std::optional ffzCustomModBadge() const; + std::optional ffzCustomVipBadge() const; + std::optional twitchBadge(const QString &set, + const QString &version) const; // Cheers - boost::optional cheerEmote(const QString &string); + std::optional cheerEmote(const QString &string); // Replies /** @@ -217,7 +216,7 @@ class TwitchChannel : public Channel, public ChannelChatters channelPointRewardAdded; void addChannelPointReward(const ChannelPointReward &reward); bool isChannelPointRewardKnown(const QString &rewardId); - boost::optional channelPointReward( + std::optional channelPointReward( const QString &rewardId) const; // Live status @@ -342,8 +341,8 @@ class TwitchChannel : public Channel, public ChannelChatters Atomic> bttvEmotes_; Atomic> ffzEmotes_; Atomic> seventvEmotes_; - Atomic> ffzCustomModBadge_; - Atomic> ffzCustomVipBadge_; + Atomic> ffzCustomModBadge_; + Atomic> ffzCustomVipBadge_; private: // Badges diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index ae58d917860..bd1791512c1 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -229,7 +229,7 @@ MessagePtr TwitchMessageBuilder::build() if (reward) { this->appendChannelPointRewardMessage( - reward.get(), this, this->channel->isMod(), + *reward, this, this->channel->isMod(), this->channel->isBroadcaster()); } } @@ -1069,7 +1069,7 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) const auto &globalSeventvEmotes = app->twitch->getSeventvEmotes(); auto flags = MessageElementFlags(); - auto emote = boost::optional{}; + auto emote = std::optional{}; bool zeroWidth = false; // Emote order: @@ -1124,8 +1124,7 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) auto baseEmoteElement = this->releaseBack(); std::vector layers = { - {baseEmote, baseEmoteElement->getFlags()}, - {emote.get(), flags}}; + {baseEmote, baseEmoteElement->getFlags()}, {*emote, flags}}; this->emplace( std::move(layers), baseEmoteElement->getFlags() | flags, this->textColor_); @@ -1135,7 +1134,7 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) auto asLayered = dynamic_cast(&this->back()); if (asLayered) { - asLayered->addEmoteLayer({emote.get(), flags}); + asLayered->addEmoteLayer({*emote, flags}); asLayered->addFlags(flags); return Success; } @@ -1143,15 +1142,14 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) // No emote to merge with, just show as regular emote } - this->emplace(emote.get(), flags, this->textColor_); + this->emplace(*emote, flags, this->textColor_); return Success; } return Failure; } -boost::optional TwitchMessageBuilder::getTwitchBadge( - const Badge &badge) +std::optional TwitchMessageBuilder::getTwitchBadge(const Badge &badge) { if (auto channelBadge = this->twitchChannel->twitchBadge(badge.key_, badge.value_)) @@ -1165,7 +1163,7 @@ boost::optional TwitchMessageBuilder::getTwitchBadge( return globalBadge; } - return boost::none; + return std::nullopt; } std::unordered_map TwitchMessageBuilder::parseBadgeInfoTag( @@ -1248,7 +1246,7 @@ void TwitchMessageBuilder::appendTwitchBadges() if (auto customModBadge = this->twitchChannel->ffzCustomModBadge()) { this->emplace( - customModBadge.get(), + *customModBadge, MessageElementFlag::BadgeChannelAuthority) ->setTooltip((*customModBadge)->tooltip.string); // early out, since we have to add a custom badge element here @@ -1260,7 +1258,7 @@ void TwitchMessageBuilder::appendTwitchBadges() if (auto customVipBadge = this->twitchChannel->ffzCustomVipBadge()) { this->emplace( - customVipBadge.get(), + *customVipBadge, MessageElementFlag::BadgeChannelAuthority) ->setTooltip((*customVipBadge)->tooltip.string); // early out, since we have to add a custom badge element here @@ -1302,7 +1300,7 @@ void TwitchMessageBuilder::appendTwitchBadges() } } - this->emplace(badgeEmote.get(), badge.flag_) + this->emplace(*badgeEmote, badge.flag_) ->setTooltip(tooltip); } diff --git a/src/providers/twitch/TwitchMessageBuilder.hpp b/src/providers/twitch/TwitchMessageBuilder.hpp index 645dc3aafa8..afd337fdd87 100644 --- a/src/providers/twitch/TwitchMessageBuilder.hpp +++ b/src/providers/twitch/TwitchMessageBuilder.hpp @@ -4,11 +4,11 @@ #include "common/Outcome.hpp" #include "messages/SharedMessageBuilder.hpp" -#include #include #include #include +#include #include namespace chatterino { @@ -108,7 +108,7 @@ class TwitchMessageBuilder : public SharedMessageBuilder void runIgnoreReplaces(std::vector &twitchEmotes); - boost::optional getTwitchBadge(const Badge &badge); + std::optional getTwitchBadge(const Badge &badge); Outcome tryAppendEmote(const EmoteName &name) override; void addWords(const QStringList &words, diff --git a/src/providers/twitch/api/Helix.cpp b/src/providers/twitch/api/Helix.cpp index 48f3ac2564a..810e02e8755 100644 --- a/src/providers/twitch/api/Helix.cpp +++ b/src/providers/twitch/api/Helix.cpp @@ -1741,7 +1741,7 @@ void Helix::updateEmoteMode( void Helix::updateFollowerMode( QString broadcasterID, QString moderatorID, - boost::optional followerModeDuration, + std::optional followerModeDuration, ResultCallback successCallback, FailureCallback failureCallback) { @@ -1758,7 +1758,7 @@ void Helix::updateFollowerMode( void Helix::updateNonModeratorChatDelay( QString broadcasterID, QString moderatorID, - boost::optional nonModeratorChatDelayDuration, + std::optional nonModeratorChatDelayDuration, ResultCallback successCallback, FailureCallback failureCallback) { @@ -1777,7 +1777,7 @@ void Helix::updateNonModeratorChatDelay( void Helix::updateSlowMode( QString broadcasterID, QString moderatorID, - boost::optional slowModeWaitTime, + std::optional slowModeWaitTime, ResultCallback successCallback, FailureCallback failureCallback) { @@ -2138,7 +2138,7 @@ void Helix::fetchModerators( // Ban/timeout a user // https://dev.twitch.tv/docs/api/reference#ban-user void Helix::banUser(QString broadcasterID, QString moderatorID, QString userID, - boost::optional duration, QString reason, + std::optional duration, QString reason, ResultCallback<> successCallback, FailureCallback failureCallback) { @@ -2890,14 +2890,14 @@ NetworkRequest Helix::makeRequest(const QString &url, const QUrlQuery &urlQuery, { qCDebug(chatterinoTwitch) << "Helix::makeRequest called without a client ID set BabyRage"; - // return boost::none; + // return std::nullopt; } if (this->oauthToken.isEmpty()) { qCDebug(chatterinoTwitch) << "Helix::makeRequest called without an oauth token set BabyRage"; - // return boost::none; + // return std::nullopt; } const QString baseUrl("https://api.twitch.tv/helix/"); diff --git a/src/providers/twitch/api/Helix.hpp b/src/providers/twitch/api/Helix.hpp index 05e203a8a73..35cde366910 100644 --- a/src/providers/twitch/api/Helix.hpp +++ b/src/providers/twitch/api/Helix.hpp @@ -3,9 +3,9 @@ #include "common/Aliases.hpp" #include "common/NetworkRequest.hpp" #include "providers/twitch/TwitchEmotes.hpp" +#include "util/Helpers.hpp" #include "util/QStringHash.hpp" -#include #include #include #include @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -277,24 +278,23 @@ struct HelixChannelEmote { struct HelixChatSettings { const QString broadcasterId; const bool emoteMode; - // boost::none if disabled - const boost::optional followerModeDuration; // time in minutes - const boost::optional - nonModeratorChatDelayDuration; // time in seconds - const boost::optional slowModeWaitTime; // time in seconds + // std::nullopt if disabled + const std::optional followerModeDuration; // time in minutes + const std::optional nonModeratorChatDelayDuration; // time in seconds + const std::optional slowModeWaitTime; // time in seconds const bool subscriberMode; const bool uniqueChatMode; explicit HelixChatSettings(QJsonObject jsonObject) : broadcasterId(jsonObject.value("broadcaster_id").toString()) , emoteMode(jsonObject.value("emote_mode").toBool()) - , followerModeDuration(boost::make_optional( + , followerModeDuration(makeConditionedOptional( jsonObject.value("follower_mode").toBool(), jsonObject.value("follower_mode_duration").toInt())) - , nonModeratorChatDelayDuration(boost::make_optional( + , nonModeratorChatDelayDuration(makeConditionedOptional( jsonObject.value("non_moderator_chat_delay").toBool(), jsonObject.value("non_moderator_chat_delay_duration").toInt())) - , slowModeWaitTime(boost::make_optional( + , slowModeWaitTime(makeConditionedOptional( jsonObject.value("slow_mode").toBool(), jsonObject.value("slow_mode_wait_time").toInt())) , subscriberMode(jsonObject.value("subscriber_mode").toBool()) @@ -908,7 +908,7 @@ class IHelix // https://dev.twitch.tv/docs/api/reference#update-chat-settings virtual void updateFollowerMode( QString broadcasterID, QString moderatorID, - boost::optional followerModeDuration, + std::optional followerModeDuration, ResultCallback successCallback, FailureCallback failureCallback) = 0; @@ -917,7 +917,7 @@ class IHelix // https://dev.twitch.tv/docs/api/reference#update-chat-settings virtual void updateNonModeratorChatDelay( QString broadcasterID, QString moderatorID, - boost::optional nonModeratorChatDelayDuration, + std::optional nonModeratorChatDelayDuration, ResultCallback successCallback, FailureCallback failureCallback) = 0; @@ -926,7 +926,7 @@ class IHelix // https://dev.twitch.tv/docs/api/reference#update-chat-settings virtual void updateSlowMode( QString broadcasterID, QString moderatorID, - boost::optional slowModeWaitTime, + std::optional slowModeWaitTime, ResultCallback successCallback, FailureCallback failureCallback) = 0; @@ -951,7 +951,7 @@ class IHelix // https://dev.twitch.tv/docs/api/reference#ban-user virtual void banUser( QString broadcasterID, QString moderatorID, QString userID, - boost::optional duration, QString reason, + std::optional duration, QString reason, ResultCallback<> successCallback, FailureCallback failureCallback) = 0; @@ -1224,7 +1224,7 @@ class Helix final : public IHelix // https://dev.twitch.tv/docs/api/reference#update-chat-settings void updateFollowerMode( QString broadcasterID, QString moderatorID, - boost::optional followerModeDuration, + std::optional followerModeDuration, ResultCallback successCallback, FailureCallback failureCallback) final; @@ -1233,7 +1233,7 @@ class Helix final : public IHelix // https://dev.twitch.tv/docs/api/reference#update-chat-settings void updateNonModeratorChatDelay( QString broadcasterID, QString moderatorID, - boost::optional nonModeratorChatDelayDuration, + std::optional nonModeratorChatDelayDuration, ResultCallback successCallback, FailureCallback failureCallback) final; @@ -1241,7 +1241,7 @@ class Helix final : public IHelix // Updates the slow mode using // https://dev.twitch.tv/docs/api/reference#update-chat-settings void updateSlowMode(QString broadcasterID, QString moderatorID, - boost::optional slowModeWaitTime, + std::optional slowModeWaitTime, ResultCallback successCallback, FailureCallback failureCallback) final; @@ -1266,7 +1266,7 @@ class Helix final : public IHelix // https://dev.twitch.tv/docs/api/reference#ban-user void banUser( QString broadcasterID, QString moderatorID, QString userID, - boost::optional duration, QString reason, + std::optional duration, QString reason, ResultCallback<> successCallback, FailureCallback failureCallback) final; diff --git a/src/providers/twitch/pubsubmessages/Base.hpp b/src/providers/twitch/pubsubmessages/Base.hpp index c6d817718f4..ce190ee065d 100644 --- a/src/providers/twitch/pubsubmessages/Base.hpp +++ b/src/providers/twitch/pubsubmessages/Base.hpp @@ -1,11 +1,12 @@ #pragma once -#include #include #include #include #include +#include + namespace chatterino { struct PubSubMessage { @@ -27,16 +28,16 @@ struct PubSubMessage { PubSubMessage(QJsonObject _object); template - boost::optional toInner(); + std::optional toInner(); }; template -boost::optional PubSubMessage::toInner() +std::optional PubSubMessage::toInner() { auto dataValue = this->object.value("data"); if (!dataValue.isObject()) { - return boost::none; + return std::nullopt; } auto data = dataValue.toObject(); @@ -44,14 +45,13 @@ boost::optional PubSubMessage::toInner() return InnerClass{this->nonce, data}; } -static boost::optional parsePubSubBaseMessage( - const QString &blob) +static std::optional parsePubSubBaseMessage(const QString &blob) { QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8())); if (jsonDoc.isNull()) { - return boost::none; + return std::nullopt; } return PubSubMessage(jsonDoc.object()); diff --git a/src/providers/twitch/pubsubmessages/Message.hpp b/src/providers/twitch/pubsubmessages/Message.hpp index 2f061d0b9c8..e854929f936 100644 --- a/src/providers/twitch/pubsubmessages/Message.hpp +++ b/src/providers/twitch/pubsubmessages/Message.hpp @@ -2,11 +2,12 @@ #include "common/QLogging.hpp" -#include #include #include #include +#include + namespace chatterino { struct PubSubMessageMessage { @@ -42,15 +43,15 @@ struct PubSubMessageMessage { } template - boost::optional toInner() const; + std::optional toInner() const; }; template -boost::optional PubSubMessageMessage::toInner() const +std::optional PubSubMessageMessage::toInner() const { if (this->messageObject.empty()) { - return boost::none; + return std::nullopt; } return InnerClass{this->messageObject}; diff --git a/src/singletons/NativeMessaging.cpp b/src/singletons/NativeMessaging.cpp index a7165c1f766..d2fb7b29d6e 100644 --- a/src/singletons/NativeMessaging.cpp +++ b/src/singletons/NativeMessaging.cpp @@ -312,9 +312,9 @@ void NativeMessagingServer::syncChannels(const QJsonArray &twitchChannels) this->channelWarmer_ = std::move(updated); } -Atomic> &nmIpcError() +Atomic> &nmIpcError() { - static Atomic> x; + static Atomic> x; return x; } diff --git a/src/singletons/NativeMessaging.hpp b/src/singletons/NativeMessaging.hpp index 4ed46ad0dad..1186315da4f 100644 --- a/src/singletons/NativeMessaging.hpp +++ b/src/singletons/NativeMessaging.hpp @@ -2,10 +2,10 @@ #include "common/Atomic.hpp" -#include #include #include +#include #include namespace chatterino { @@ -19,7 +19,7 @@ using ChannelPtr = std::shared_ptr; void registerNmHost(Paths &paths); std::string &getNmQueueName(Paths &paths); -Atomic> &nmIpcError(); +Atomic> &nmIpcError(); namespace nm::client { diff --git a/src/singletons/Paths.cpp b/src/singletons/Paths.cpp index f2fa553357a..bcf2a6eeaba 100644 --- a/src/singletons/Paths.cpp +++ b/src/singletons/Paths.cpp @@ -83,7 +83,7 @@ void Paths::initCheckPortable() void Paths::initRootDirectory() { - assert(this->portable_.is_initialized()); + assert(this->portable_.has_value()); // Root path = %APPDATA%/Chatterino or the folder that the executable // resides in diff --git a/src/singletons/Paths.hpp b/src/singletons/Paths.hpp index d7f00e19ef1..fa9a84a72d1 100644 --- a/src/singletons/Paths.hpp +++ b/src/singletons/Paths.hpp @@ -1,8 +1,9 @@ #pragma once -#include #include +#include + namespace chatterino { class Paths @@ -51,7 +52,7 @@ class Paths void initRootDirectory(); void initSubDirectories(); - boost::optional portable_; + std::optional portable_; // Directory for cache files. Same as /Misc QString cacheDirectory_; diff --git a/src/singletons/Settings.cpp b/src/singletons/Settings.cpp index a56db4ffa16..8caa53c81a0 100644 --- a/src/singletons/Settings.cpp +++ b/src/singletons/Settings.cpp @@ -87,7 +87,7 @@ bool Settings::isMutedChannel(const QString &channelName) return false; } -boost::optional Settings::matchNickname(const QString &usernameText) +std::optional Settings::matchNickname(const QString &usernameText) { auto nicknames = this->nicknames.readOnly(); @@ -99,7 +99,7 @@ boost::optional Settings::matchNickname(const QString &usernameText) } } - return boost::none; + return std::nullopt; } void Settings::mute(const QString &channelName) diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index 27d2b8cbc9b..2f953594801 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -593,7 +593,7 @@ class Settings bool isBlacklistedUser(const QString &username); bool isMutedChannel(const QString &channelName); bool toggleMutedChannel(const QString &channelName); - boost::optional matchNickname(const QString &username); + std::optional matchNickname(const QString &username); private: void mute(const QString &channelName); diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index 0565184fe13..43188682290 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -24,7 +24,6 @@ #include "widgets/splits/SplitContainer.hpp" #include "widgets/Window.hpp" -#include #include #include #include @@ -34,13 +33,14 @@ #include #include +#include namespace chatterino { namespace { - boost::optional &shouldMoveOutOfBoundsWindow() + std::optional &shouldMoveOutOfBoundsWindow() { - static boost::optional x; + static std::optional x; return x; } diff --git a/src/util/Helpers.hpp b/src/util/Helpers.hpp index f066f7a93b6..51154db5d1e 100644 --- a/src/util/Helpers.hpp +++ b/src/util/Helpers.hpp @@ -6,6 +6,7 @@ #include #include +#include #include namespace chatterino { @@ -155,4 +156,28 @@ std::vector splitListIntoBatches(const T &list, int batchSize = 100) bool compareEmoteStrings(const QString &a, const QString &b); +template +constexpr std::optional makeConditionedOptional(bool condition, + const T &value) +{ + if (condition) + { + return value; + } + + return std::nullopt; +} + +template +constexpr std::optional> makeConditionedOptional(bool condition, + T &&value) +{ + if (condition) + { + return std::optional>(std::forward(value)); + } + + return std::nullopt; +} + } // namespace chatterino diff --git a/src/util/NuulsUploader.cpp b/src/util/NuulsUploader.cpp index 8627ef8fddd..ca3be77b6e8 100644 --- a/src/util/NuulsUploader.cpp +++ b/src/util/NuulsUploader.cpp @@ -23,7 +23,7 @@ namespace { -boost::optional convertToPng(QImage image) +std::optional convertToPng(QImage image) { QByteArray imageData; QBuffer buf(&imageData); @@ -31,11 +31,11 @@ boost::optional convertToPng(QImage image) bool success = image.save(&buf, "png"); if (success) { - return boost::optional(imageData); + return std::optional(imageData); } else { - return boost::optional(boost::none); + return std::optional(std::nullopt); } } } // namespace @@ -271,10 +271,10 @@ void upload(const QMimeData *source, ChannelPtr channel, return; } - boost::optional imageData = convertToPng(img); + std::optional imageData = convertToPng(img); if (imageData) { - RawImageData data = {imageData.get(), "png", localPath}; + RawImageData data = {*imageData, "png", localPath}; uploadQueue.push(data); } else @@ -340,10 +340,10 @@ void upload(const QMimeData *source, ChannelPtr channel, else { // not PNG, try loading it into QImage and save it to a PNG. QImage image = qvariant_cast(source->imageData()); - boost::optional imageData = convertToPng(image); + std::optional imageData = convertToPng(image); if (imageData) { - uploadImageToNuuls({imageData.get(), "png", ""}, channel, + uploadImageToNuuls({*imageData, "png", ""}, channel, outputTextEdit); } else diff --git a/src/util/WindowsHelper.cpp b/src/util/WindowsHelper.cpp index 00b31db37e5..6584604db23 100644 --- a/src/util/WindowsHelper.cpp +++ b/src/util/WindowsHelper.cpp @@ -22,7 +22,7 @@ using GetDpiForMonitor_ = HRESULT(CALLBACK *)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *); // TODO: This should be changed to `GetDpiForWindow`. -boost::optional getWindowDpi(HWND hwnd) +std::optional getWindowDpi(HWND hwnd) { static HINSTANCE shcore = LoadLibrary(L"Shcore.dll"); if (shcore != nullptr) @@ -41,7 +41,7 @@ boost::optional getWindowDpi(HWND hwnd) } } - return boost::none; + return std::nullopt; } void flushClipboard() diff --git a/src/util/WindowsHelper.hpp b/src/util/WindowsHelper.hpp index ff569265fd7..af719996b75 100644 --- a/src/util/WindowsHelper.hpp +++ b/src/util/WindowsHelper.hpp @@ -2,15 +2,16 @@ #ifdef USEWINSDK -# include # include # include +# include + namespace chatterino { enum class AssociationQueryType { Protocol, FileExtension }; -boost::optional getWindowDpi(HWND hwnd); +std::optional getWindowDpi(HWND hwnd); void flushClipboard(); bool isRegisteredForStartup(); diff --git a/src/widgets/BaseWidget.cpp b/src/widgets/BaseWidget.cpp index 5be0e8c2619..fb0ae41c589 100644 --- a/src/widgets/BaseWidget.cpp +++ b/src/widgets/BaseWidget.cpp @@ -42,7 +42,7 @@ float BaseWidget::scale() const { if (this->overrideScale_) { - return this->overrideScale_.get(); + return *this->overrideScale_; } else if (auto baseWidget = dynamic_cast(this->window())) { @@ -65,13 +65,13 @@ void BaseWidget::setScale(float value) this->setScaleIndependantSize(this->scaleIndependantSize()); } -void BaseWidget::setOverrideScale(boost::optional value) +void BaseWidget::setOverrideScale(std::optional value) { this->overrideScale_ = value; this->setScale(this->scale()); } -boost::optional BaseWidget::overrideScale() const +std::optional BaseWidget::overrideScale() const { return this->overrideScale_; } diff --git a/src/widgets/BaseWidget.hpp b/src/widgets/BaseWidget.hpp index 8aee5881fdc..ed31283fd95 100644 --- a/src/widgets/BaseWidget.hpp +++ b/src/widgets/BaseWidget.hpp @@ -1,11 +1,12 @@ #pragma once -#include #include #include #include #include +#include + namespace chatterino { class Theme; @@ -22,8 +23,8 @@ class BaseWidget : public QWidget virtual float scale() const; pajlada::Signals::Signal scaleChanged; - boost::optional overrideScale() const; - void setOverrideScale(boost::optional); + std::optional overrideScale() const; + void setOverrideScale(std::optional); QSize scaleIndependantSize() const; int scaleIndependantWidth() const; @@ -56,7 +57,7 @@ class BaseWidget : public QWidget private: float scale_{1.f}; - boost::optional overrideScale_; + std::optional overrideScale_; QSize scaleIndependantSize_; std::vector widgets_; diff --git a/src/widgets/BaseWindow.hpp b/src/widgets/BaseWindow.hpp index 864e8f9bf9c..cc6fbe71319 100644 --- a/src/widgets/BaseWindow.hpp +++ b/src/widgets/BaseWindow.hpp @@ -95,7 +95,7 @@ class BaseWindow : public BaseWidget void updateScale(); - boost::optional overrideBackgroundColor_; + std::optional overrideBackgroundColor_; private: void init(); diff --git a/src/widgets/dialogs/BadgePickerDialog.hpp b/src/widgets/dialogs/BadgePickerDialog.hpp index 8e5f266bb27..b7d791ee7da 100644 --- a/src/widgets/dialogs/BadgePickerDialog.hpp +++ b/src/widgets/dialogs/BadgePickerDialog.hpp @@ -2,11 +2,11 @@ #include "util/DisplayBadge.hpp" -#include #include #include #include +#include namespace chatterino { @@ -14,7 +14,7 @@ class BadgePickerDialog : public QDialog, public std::enable_shared_from_this { using QIconPtr = std::shared_ptr; - using BadgeOpt = boost::optional; + using BadgeOpt = std::optional; public: BadgePickerDialog(QList badges, QWidget *parent = nullptr); diff --git a/src/widgets/dialogs/IrcConnectionEditor.hpp b/src/widgets/dialogs/IrcConnectionEditor.hpp index 9cad20af535..1bad5c5ad10 100644 --- a/src/widgets/dialogs/IrcConnectionEditor.hpp +++ b/src/widgets/dialogs/IrcConnectionEditor.hpp @@ -3,9 +3,10 @@ #include "providers/irc/Irc2.hpp" #include "widgets/BaseWindow.hpp" -#include #include +#include + namespace Ui { class IrcConnectionEditor; } diff --git a/src/widgets/dialogs/ReplyThreadPopup.cpp b/src/widgets/dialogs/ReplyThreadPopup.cpp index 8026c7ef9bb..9b01f29fcdf 100644 --- a/src/widgets/dialogs/ReplyThreadPopup.cpp +++ b/src/widgets/dialogs/ReplyThreadPopup.cpp @@ -239,7 +239,7 @@ void ReplyThreadPopup::addMessagesFromThread() this->ui_.threadView->setSourceChannel(sourceChannel); auto overrideFlags = - boost::optional(this->thread_->root()->flags); + std::optional(this->thread_->root()->flags); overrideFlags->set(MessageFlag::DoNotLog); this->virtualChannel_->addMessage(this->thread_->root(), overrideFlags); @@ -247,7 +247,7 @@ void ReplyThreadPopup::addMessagesFromThread() { if (auto msg = msgRef.lock()) { - auto overrideFlags = boost::optional(msg->flags); + auto overrideFlags = std::optional(msg->flags); overrideFlags->set(MessageFlag::DoNotLog); this->virtualChannel_->addMessage(msg, overrideFlags); @@ -261,7 +261,7 @@ void ReplyThreadPopup::addMessagesFromThread() if (message->replyThread == this->thread_) { auto overrideFlags = - boost::optional(message->flags); + std::optional(message->flags); overrideFlags->set(MessageFlag::DoNotLog); // same reply thread, add message diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index a34b00bf63d..77beea3e89f 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -110,7 +110,7 @@ namespace { { MessagePtr message = snapshot[i]; - auto overrideFlags = boost::optional(message->flags); + auto overrideFlags = std::optional(message->flags); overrideFlags->set(MessageFlag::DoNotLog); if (checkMessageUserName(userName, message)) diff --git a/src/widgets/helper/Button.cpp b/src/widgets/helper/Button.cpp index b4caa299f77..a6fa3ba6f9c 100644 --- a/src/widgets/helper/Button.cpp +++ b/src/widgets/helper/Button.cpp @@ -36,7 +36,7 @@ Button::Button(BaseWidget *parent) this->setMouseTracking(true); } -void Button::setMouseEffectColor(boost::optional color) +void Button::setMouseEffectColor(std::optional color) { this->mouseEffectColor_ = std::move(color); } @@ -185,7 +185,7 @@ void Button::fancyPaint(QPainter &painter) if (this->mouseEffectColor_) { - c = this->mouseEffectColor_.get(); + c = *this->mouseEffectColor_; } else { diff --git a/src/widgets/helper/Button.hpp b/src/widgets/helper/Button.hpp index 1bc763a9f4f..06910499954 100644 --- a/src/widgets/helper/Button.hpp +++ b/src/widgets/helper/Button.hpp @@ -2,7 +2,6 @@ #include "widgets/BaseWidget.hpp" -#include #include #include #include @@ -10,6 +9,8 @@ #include #include +#include + namespace chatterino { class Button : public BaseWidget @@ -31,7 +32,7 @@ class Button : public BaseWidget Button(BaseWidget *parent = nullptr); - void setMouseEffectColor(boost::optional color); + void setMouseEffectColor(std::optional color); void setPixmap(const QPixmap &pixmap_); const QPixmap &getPixmap() const; @@ -94,7 +95,7 @@ class Button : public BaseWidget double hoverMultiplier_{0.0}; QTimer effectTimer_{}; std::vector clickEffects_{}; - boost::optional mouseEffectColor_{}; + std::optional mouseEffectColor_{}; std::unique_ptr menu_{}; }; diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 3d1924e8617..2d91cf4778b 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -291,13 +291,12 @@ bool ChannelView::paused() const return this->pausable() && !this->pauses_.empty(); } -void ChannelView::pause(PauseReason reason, boost::optional msecs) +void ChannelView::pause(PauseReason reason, std::optional msecs) { if (msecs) { /// Msecs has a value - auto timePoint = - SteadyClock::now() + std::chrono::milliseconds(msecs.get()); + auto timePoint = SteadyClock::now() + std::chrono::milliseconds(*msecs); auto it = this->pauses_.find(reason); if (it == this->pauses_.end()) @@ -308,7 +307,7 @@ void ChannelView::pause(PauseReason reason, boost::optional msecs) else { /// If the new time point is newer then we override. - if (it->second && it->second.get() < timePoint) + if (it->second && it->second.value() < timePoint) it->second = timePoint; } } @@ -316,7 +315,7 @@ void ChannelView::pause(PauseReason reason, boost::optional msecs) { /// Msecs is none -> pause is infinite. /// We just override the value. - this->pauses_[reason] = boost::none; + this->pauses_[reason] = std::nullopt; } this->updatePauses(); @@ -339,7 +338,7 @@ void ChannelView::updatePauses() this->unpaused(); /// No pauses so we can stop the timer - this->pauseEnd_ = boost::none; + this->pauseEnd_ = std::nullopt; this->pauseTimer_.stop(); this->scrollBar_->offsetMaximum(this->pauseScrollMaximumOffset_); @@ -355,7 +354,7 @@ void ChannelView::updatePauses() })) { /// Some of the pauses are infinite - this->pauseEnd_ = boost::none; + this->pauseEnd_ = std::nullopt; this->pauseTimer_.stop(); } else @@ -366,7 +365,7 @@ void ChannelView::updatePauses() [](auto &&a, auto &&b) { return a.second > b.second; }) - ->second.get(); + ->second.value(); if (pauseEnd != this->pauseEnd_) { @@ -645,13 +644,12 @@ bool ChannelView::getEnableScrollingToBottom() const return this->enableScrollingToBottom_; } -void ChannelView::setOverrideFlags(boost::optional value) +void ChannelView::setOverrideFlags(std::optional value) { this->overrideFlags_ = std::move(value); } -const boost::optional &ChannelView::getOverrideFlags() - const +const std::optional &ChannelView::getOverrideFlags() const { return this->overrideFlags_; } @@ -697,7 +695,7 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel) this->channelConnections_.managedConnect( underlyingChannel->messageAppended, [this](MessagePtr &message, - boost::optional overridingFlags) { + std::optional overridingFlags) { if (this->shouldIncludeMessage(message)) { if (this->channel_->lastDate_ != QDate::currentDate()) @@ -713,12 +711,12 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel) // logging will be handled. Prevent duplications. if (overridingFlags) { - overridingFlags.get().set(MessageFlag::DoNotLog); + overridingFlags->set(MessageFlag::DoNotLog); } else { overridingFlags = MessageFlags(message->flags); - overridingFlags.get().set(MessageFlag::DoNotLog); + overridingFlags->set(MessageFlag::DoNotLog); } this->channel_->addMessage(message, overridingFlags); @@ -764,7 +762,7 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel) this->channelConnections_.managedConnect( this->channel_->messageAppended, [this](MessagePtr &message, - boost::optional overridingFlags) { + std::optional overridingFlags) { this->messageAppended(message, std::move(overridingFlags)); }); @@ -880,12 +878,12 @@ bool ChannelView::hasSourceChannel() const } void ChannelView::messageAppended(MessagePtr &message, - boost::optional overridingFlags) + std::optional overridingFlags) { auto *messageFlags = &message->flags; if (overridingFlags) { - messageFlags = overridingFlags.get_ptr(); + messageFlags = &*overridingFlags; } auto messageRef = std::make_shared(message); @@ -1109,7 +1107,7 @@ MessageElementFlags ChannelView::getFlags() const if (this->overrideFlags_) { - return this->overrideFlags_.get(); + return *this->overrideFlags_; } MessageElementFlags flags = app->windows->getWordFlags(); diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 1fb4c39418e..a728920cb1a 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -93,8 +93,8 @@ class ChannelView final : public BaseWidget void setEnableScrollingToBottom(bool); bool getEnableScrollingToBottom() const; - void setOverrideFlags(boost::optional value); - const boost::optional &getOverrideFlags() const; + void setOverrideFlags(std::optional value); + const std::optional &getOverrideFlags() const; void updateLastReadMessage(); /** @@ -112,7 +112,7 @@ class ChannelView final : public BaseWidget bool pausable() const; void setPausable(bool value); bool paused() const; - void pause(PauseReason reason, boost::optional msecs = boost::none); + void pause(PauseReason reason, std::optional msecs = std::nullopt); void unpause(PauseReason reason); MessageElementFlags getFlags() const; @@ -195,7 +195,7 @@ class ChannelView final : public BaseWidget void initializeSignals(); void messageAppended(MessagePtr &message, - boost::optional overridingFlags); + std::optional overridingFlags); void messageAddedAtStart(std::vector &messages); void messageRemoveFromStart(MessagePtr &message); void messageReplaced(size_t index, MessagePtr &replacement); @@ -265,15 +265,15 @@ class ChannelView final : public BaseWidget bool pausable_ = false; QTimer pauseTimer_; - std::unordered_map> + std::unordered_map> pauses_; - boost::optional pauseEnd_; + std::optional pauseEnd_; int pauseScrollMinimumOffset_ = 0; int pauseScrollMaximumOffset_ = 0; // Keeps track how many message indices we need to offset the selection when we resume scrolling uint32_t pauseSelectionOffset_ = 0; - boost::optional overrideFlags_; + std::optional overrideFlags_; MessageLayoutPtr lastReadMessage_; ThreadGuard snapshotGuard_; diff --git a/src/widgets/helper/SearchPopup.cpp b/src/widgets/helper/SearchPopup.cpp index 6f0f551199b..f768bdd1e67 100644 --- a/src/widgets/helper/SearchPopup.cpp +++ b/src/widgets/helper/SearchPopup.cpp @@ -52,7 +52,7 @@ ChannelPtr SearchPopup::filter(const QString &text, const QString &channelName, // If all predicates match, add the message to the channel if (accept) { - auto overrideFlags = boost::optional(message->flags); + auto overrideFlags = std::optional(message->flags); overrideFlags->set(MessageFlag::DoNotLog); channel->addMessage(message, overrideFlags); diff --git a/tests/src/BttvLiveUpdates.cpp b/tests/src/BttvLiveUpdates.cpp index 5fbe9f58103..580f2e61f96 100644 --- a/tests/src/BttvLiveUpdates.cpp +++ b/tests/src/BttvLiveUpdates.cpp @@ -1,9 +1,9 @@ #include "providers/bttv/BttvLiveUpdates.hpp" -#include #include #include +#include #include using namespace chatterino; @@ -18,9 +18,9 @@ TEST(BttvLiveUpdates, AllEvents) chatterino::BttvLiveUpdates liveUpdates(host); liveUpdates.start(); - boost::optional addMessage; - boost::optional updateMessage; - boost::optional removeMessage; + std::optional addMessage; + std::optional updateMessage; + std::optional removeMessage; std::ignore = liveUpdates.signals_.emoteAdded.connect([&](const auto &m) { addMessage = m; diff --git a/tests/src/HighlightController.cpp b/tests/src/HighlightController.cpp index a682a1419e3..a45bbf98c02 100644 --- a/tests/src/HighlightController.cpp +++ b/tests/src/HighlightController.cpp @@ -11,7 +11,6 @@ #include "singletons/Paths.hpp" #include "singletons/Settings.hpp" -#include #include #include #include @@ -268,7 +267,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured) { false, // alert false, // playsound - boost::none, // custom sound url + std::nullopt, // custom sound url std::make_shared("#7fffffff"), // color false, }, @@ -307,7 +306,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured) { true, // alert false, // playsound - boost::none, // custom sound url + std::nullopt, // custom sound url std::make_shared("#7fe8b7eb"), // color false, //showInMentions }, @@ -332,7 +331,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured) { true, // alert false, // playsound - boost::none, // custom sound url + std::nullopt, // custom sound url std::make_shared("#7fffffff"), // color false, //showInMentions }, @@ -358,7 +357,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured) { false, // alert false, // playsound - boost::none, // custom sound url + std::nullopt, // custom sound url std::make_shared("#7fe8b7ec"), // color true, // showInMentions }, @@ -379,7 +378,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured) { true, // alert false, // playsound - boost::none, // custom sound url + std::nullopt, // custom sound url std::make_shared("#7ff19900"), // color true, // showInMentions }, @@ -399,7 +398,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured) { true, // alert true, // playsound - boost::none, // custom sound url + std::nullopt, // custom sound url std::make_shared("#7f7f3f49"), // color true, // showInMentions }, @@ -420,7 +419,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured) { false, // alert false, // playsound - boost::none, // custom sound url + std::nullopt, // custom sound url std::make_shared("#6fffffff"), // color false, }, @@ -442,9 +441,9 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured) .state = true, // state .result = { - false, // alert - false, // playsound - boost::none, // custom sound url + false, // alert + false, // playsound + std::nullopt, // custom sound url std::make_shared( HighlightPhrase:: FALLBACK_HIGHLIGHT_COLOR), // color @@ -468,9 +467,9 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured) .state = true, // state .result = { - true, // alert - true, // playsound - boost::none, // custom sound url + true, // alert + true, // playsound + std::nullopt, // custom sound url std::make_shared("#7f7f3f49"), // color true, // showInMentions }, diff --git a/tests/src/InputCompletion.cpp b/tests/src/InputCompletion.cpp index aadfc46377c..b31aef64582 100644 --- a/tests/src/InputCompletion.cpp +++ b/tests/src/InputCompletion.cpp @@ -13,7 +13,6 @@ #include "singletons/Settings.hpp" #include "widgets/splits/InputCompletionPopup.hpp" -#include #include #include #include diff --git a/tests/src/SeventvEventAPI.cpp b/tests/src/SeventvEventAPI.cpp index cbdadfb618c..780f90bac10 100644 --- a/tests/src/SeventvEventAPI.cpp +++ b/tests/src/SeventvEventAPI.cpp @@ -4,10 +4,11 @@ #include "providers/seventv/eventapi/Dispatch.hpp" #include "providers/seventv/eventapi/Message.hpp" -#include #include #include +#include + using namespace chatterino; using namespace chatterino::seventv::eventapi; using namespace std::chrono_literals; @@ -22,10 +23,10 @@ TEST(SeventvEventAPI, AllEvents) SeventvEventAPI eventAPI(host, std::chrono::milliseconds(1000)); eventAPI.start(); - boost::optional addDispatch; - boost::optional updateDispatch; - boost::optional removeDispatch; - boost::optional userDispatch; + std::optional addDispatch; + std::optional updateDispatch; + std::optional removeDispatch; + std::optional userDispatch; eventAPI.signals_.emoteAdded.connect([&](const auto &d) { addDispatch = d; @@ -67,9 +68,9 @@ TEST(SeventvEventAPI, AllEvents) ASSERT_EQ(rem.emoteID, QString("621d13967cc2d4e1953838ed")); ASSERT_EQ(userDispatch.has_value(), false); - addDispatch = boost::none; - updateDispatch = boost::none; - removeDispatch = boost::none; + addDispatch = std::nullopt; + updateDispatch = std::nullopt; + removeDispatch = std::nullopt; eventAPI.subscribeUser(TARGET_USER_ID, ""); std::this_thread::sleep_for(50ms); From a20e52bea36ace4614c336ec3c1f39292e125fb5 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 12:09:29 +0200 Subject: [PATCH 02/15] refactor --- src/common/SignalVectorModel.hpp | 6 ++++-- src/providers/bttv/BttvEmotes.cpp | 10 ++++++++++ src/providers/twitch/TwitchMessageBuilder.cpp | 7 ++++--- src/util/NuulsUploader.cpp | 18 +++++++++--------- src/widgets/BaseWidget.cpp | 9 ++++----- src/widgets/helper/ChannelView.cpp | 2 ++ 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/common/SignalVectorModel.hpp b/src/common/SignalVectorModel.hpp index 9260d29404a..c44a167af8f 100644 --- a/src/common/SignalVectorModel.hpp +++ b/src/common/SignalVectorModel.hpp @@ -128,7 +128,8 @@ class SignalVectorModel : public QAbstractTableModel, QVariant data(const QModelIndex &index, int role) const override { - int row = index.row(), column = index.column(); + int row = index.row(); + int column = index.column(); if (row < 0 || column < 0 || row >= this->rows_.size() || column >= this->columnCount_) { @@ -141,7 +142,8 @@ class SignalVectorModel : public QAbstractTableModel, bool setData(const QModelIndex &index, const QVariant &value, int role) override { - int row = index.row(), column = index.column(); + int row = index.row(); + int column = index.column(); if (row < 0 || column < 0 || row >= this->rows_.size() || column >= this->columnCount_) { diff --git a/src/providers/bttv/BttvEmotes.cpp b/src/providers/bttv/BttvEmotes.cpp index fa2cdc3166e..80af67403f7 100644 --- a/src/providers/bttv/BttvEmotes.cpp +++ b/src/providers/bttv/BttvEmotes.cpp @@ -185,7 +185,10 @@ std::optional BttvEmotes::emote(const EmoteName &name) const auto it = emotes->find(name); if (it == emotes->end()) + { return std::nullopt; + } + return it->second; } @@ -203,8 +206,10 @@ void BttvEmotes::loadEmotes() auto emotes = this->global_.get(); auto pair = parseGlobalEmotes(result.parseJsonArray(), *emotes); if (pair.first) + { this->setEmotes( std::make_shared(std::move(pair.second))); + } return pair.first; }) .execute(); @@ -251,13 +256,18 @@ void BttvEmotes::loadChannel(std::weak_ptr channel, .onError([channelId, channel, manualRefresh](auto result) { auto shared = channel.lock(); if (!shared) + { return; + } + if (result.status() == 404) { // User does not have any BTTV emotes if (manualRefresh) + { shared->addMessage( makeSystemMessage(CHANNEL_HAS_NO_EMOTES)); + } } else { diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index bd1791512c1..a0654d1933e 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -228,7 +228,7 @@ MessagePtr TwitchMessageBuilder::build() this->args.channelPointRewardId); if (reward) { - this->appendChannelPointRewardMessage( + TwitchMessageBuilder::appendChannelPointRewardMessage( *reward, this, this->channel->isMod(), this->channel->isBroadcaster()); } @@ -1115,7 +1115,7 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) !this->isEmpty()) { // Attempt to merge current zero-width emote into any previous emotes - auto asEmote = dynamic_cast(&this->back()); + auto *asEmote = dynamic_cast(&this->back()); if (asEmote) { // Make sure to access asEmote before taking ownership when releasing @@ -1131,7 +1131,8 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) return Success; } - auto asLayered = dynamic_cast(&this->back()); + auto *asLayered = + dynamic_cast(&this->back()); if (asLayered) { asLayered->addEmoteLayer({*emote, flags}); diff --git a/src/util/NuulsUploader.cpp b/src/util/NuulsUploader.cpp index ca3be77b6e8..a614c91bf2c 100644 --- a/src/util/NuulsUploader.cpp +++ b/src/util/NuulsUploader.cpp @@ -23,7 +23,7 @@ namespace { -std::optional convertToPng(QImage image) +std::optional convertToPng(const QImage &image) { QByteArray imageData; QBuffer buf(&imageData); @@ -31,16 +31,16 @@ std::optional convertToPng(QImage image) bool success = image.save(&buf, "png"); if (success) { - return std::optional(imageData); - } - else - { - return std::optional(std::nullopt); + return imageData; } + + return std::nullopt; } + } // namespace namespace chatterino { + // These variables are only used from the main thread. static auto uploadMutex = QMutex(); static std::queue uploadQueue; @@ -271,7 +271,7 @@ void upload(const QMimeData *source, ChannelPtr channel, return; } - std::optional imageData = convertToPng(img); + auto imageData = convertToPng(img); if (imageData) { RawImageData data = {*imageData, "png", localPath}; @@ -339,8 +339,8 @@ void upload(const QMimeData *source, ChannelPtr channel, else { // not PNG, try loading it into QImage and save it to a PNG. - QImage image = qvariant_cast(source->imageData()); - std::optional imageData = convertToPng(image); + auto image = qvariant_cast(source->imageData()); + auto imageData = convertToPng(image); if (imageData) { uploadImageToNuuls({*imageData, "png", ""}, channel, diff --git a/src/widgets/BaseWidget.cpp b/src/widgets/BaseWidget.cpp index fb0ae41c589..9b818aa2f3b 100644 --- a/src/widgets/BaseWidget.cpp +++ b/src/widgets/BaseWidget.cpp @@ -44,14 +44,13 @@ float BaseWidget::scale() const { return *this->overrideScale_; } - else if (auto baseWidget = dynamic_cast(this->window())) + + if (auto *baseWidget = dynamic_cast(this->window())) { return baseWidget->scale_; } - else - { - return 1.f; - } + + return 1.F; } void BaseWidget::setScale(float value) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 2d91cf4778b..882124a8389 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -308,7 +308,9 @@ void ChannelView::pause(PauseReason reason, std::optional msecs) { /// If the new time point is newer then we override. if (it->second && it->second.value() < timePoint) + { it->second = timePoint; + } } } else From 080687831d5aaac875bc1bb5661f974706d92072 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 12:52:49 +0200 Subject: [PATCH 03/15] feat: tools/clang-format-all now reformats benchmarks & mocks --- tools/clang-format-all.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/clang-format-all.sh b/tools/clang-format-all.sh index dc300e330fb..7e1e94eb504 100755 --- a/tools/clang-format-all.sh +++ b/tools/clang-format-all.sh @@ -5,4 +5,6 @@ echo if [[ $REPLY =~ ^[Yy]$ ]]; then find src/ \( -iname "*.hpp" -o -iname "*.cpp" \) -exec clang-format -i {} \; find tests/src/ \( -iname "*.hpp" -o -iname "*.cpp" \) -exec clang-format -i {} \; + find benchmarks/src/ \( -iname "*.hpp" -o -iname "*.cpp" \) -exec clang-format -i {} \; + find mocks/include/ \( -iname "*.hpp" -o -iname "*.cpp" \) -exec clang-format -i {} \; fi From 5d90a35c209667352d0afdbb48f604b0d745d111 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 13:05:03 +0200 Subject: [PATCH 04/15] undo bad format --- src/controllers/hotkeys/HotkeyController.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/hotkeys/HotkeyController.cpp b/src/controllers/hotkeys/HotkeyController.cpp index 0fc85f97e79..9c2297071e0 100644 --- a/src/controllers/hotkeys/HotkeyController.cpp +++ b/src/controllers/hotkeys/HotkeyController.cpp @@ -189,8 +189,8 @@ QString HotkeyController::categoryName(HotkeyCategory category) const return categoryData.name; } -const std::map & - HotkeyController::categories() const +const std::map + &HotkeyController::categories() const { return this->hotkeyCategories_; } From 819254a4df82688a612056807c11ecee56dfe94d Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 13:08:29 +0200 Subject: [PATCH 05/15] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f862b26aeda..bc47ac40344 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ - Dev: Add a compile-time flag `CHATTERINO_UPDATER` which can be turned off to disable update checks. (#4854) - Dev: Add a compile-time flag `USE_SYSTEM_MINIAUDIO` which can be turned on to use the system miniaudio. (#4867) - Dev: Update vcpkg to use Qt6. (#4872) +- Dev: Replace `boost::optional` with `std::optional`. (#4877) ## 2.4.6 From 5cbea5798b8d66bc1d0090190616f18725b35802 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 13:09:39 +0200 Subject: [PATCH 06/15] undo bad formatting --- src/providers/twitch/TwitchChannel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index ea9c90e3d4e..61a1cceebbb 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -1251,8 +1251,8 @@ void TwitchChannel::addReplyThread(const std::shared_ptr &thread) this->threads_[thread->rootId()] = thread; } -const std::unordered_map> & - TwitchChannel::threads() const +const std::unordered_map> + &TwitchChannel::threads() const { return this->threads_; } From 74b322451c3cc0d73445e9943e0da01b5a6967b5 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 13:24:18 +0200 Subject: [PATCH 07/15] fix windows compilation --- src/widgets/AttachedWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/AttachedWindow.cpp b/src/widgets/AttachedWindow.cpp index acb00263bfe..a3fb20c858c 100644 --- a/src/widgets/AttachedWindow.cpp +++ b/src/widgets/AttachedWindow.cpp @@ -273,7 +273,7 @@ void AttachedWindow::updateWindowRect(void *_attachedPtr) float scale = 1.f; if (auto dpi = getWindowDpi(attached)) { - scale = dpi.get() / 96.f; + scale = *dpi / 96.f; for (auto w : this->ui_.split->findChildren()) { From d77ec34c39f8aef0bfb3aa2c0747c0506db85e3c Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 15:23:00 +0200 Subject: [PATCH 08/15] Fix windows compile --- src/widgets/BaseWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/BaseWindow.cpp b/src/widgets/BaseWindow.cpp index 33fd49952e8..ad12fe185b3 100644 --- a/src/widgets/BaseWindow.cpp +++ b/src/widgets/BaseWindow.cpp @@ -728,7 +728,7 @@ bool BaseWindow::handleSHOWWINDOW(MSG *msg) if (auto dpi = getWindowDpi(msg->hwnd)) { - float currentScale = (float)dpi.get() / 96.F; + float currentScale = (float)dpi.value() / 96.F; if (currentScale != this->nativeScale_) { this->nativeScale_ = currentScale; From 57bf62823945dc8c9b2a82fac2e40f2e9f2d9fbc Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 15:32:32 +0200 Subject: [PATCH 09/15] refactor: Help clang-tidy know we only use the previous time point if there's a value --- src/widgets/helper/ChannelView.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 882124a8389..31272e601eb 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -307,9 +307,11 @@ void ChannelView::pause(PauseReason reason, std::optional msecs) else { /// If the new time point is newer then we override. - if (it->second && it->second.value() < timePoint) + auto &previousTimePoint = it->second; + if (previousTimePoint.has_value() && + previousTimePoint.value() < timePoint) { - it->second = timePoint; + previousTimePoint = timePoint; } } } From f3f507c52cd457591a0f55f1a01425c95b1e1a3c Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 15:34:21 +0200 Subject: [PATCH 10/15] reformat: Make TwitchMessageBuilder::getTwitchBadge const --- src/providers/twitch/TwitchMessageBuilder.cpp | 3 ++- src/providers/twitch/TwitchMessageBuilder.hpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index a0654d1933e..70e35112b22 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -1150,7 +1150,8 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name) return Failure; } -std::optional TwitchMessageBuilder::getTwitchBadge(const Badge &badge) +std::optional TwitchMessageBuilder::getTwitchBadge( + const Badge &badge) const { if (auto channelBadge = this->twitchChannel->twitchBadge(badge.key_, badge.value_)) diff --git a/src/providers/twitch/TwitchMessageBuilder.hpp b/src/providers/twitch/TwitchMessageBuilder.hpp index afd337fdd87..8430bb6aba3 100644 --- a/src/providers/twitch/TwitchMessageBuilder.hpp +++ b/src/providers/twitch/TwitchMessageBuilder.hpp @@ -108,7 +108,7 @@ class TwitchMessageBuilder : public SharedMessageBuilder void runIgnoreReplaces(std::vector &twitchEmotes); - std::optional getTwitchBadge(const Badge &badge); + std::optional getTwitchBadge(const Badge &badge) const; Outcome tryAppendEmote(const EmoteName &name) override; void addWords(const QStringList &words, From 2e9a351ab696b640038a5bc71c16a17aab970f08 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 15:35:40 +0200 Subject: [PATCH 11/15] refactor: use queue emplace when adding an image to the nuuls image queue --- src/util/NuulsUploader.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/util/NuulsUploader.cpp b/src/util/NuulsUploader.cpp index a614c91bf2c..78961220034 100644 --- a/src/util/NuulsUploader.cpp +++ b/src/util/NuulsUploader.cpp @@ -274,8 +274,7 @@ void upload(const QMimeData *source, ChannelPtr channel, auto imageData = convertToPng(img); if (imageData) { - RawImageData data = {*imageData, "png", localPath}; - uploadQueue.push(data); + uploadQueue.emplace(*imageData, "png", localPath); } else { From bdac357ea163966ceb578d4102bc9d21548f7598 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 15:37:19 +0200 Subject: [PATCH 12/15] refactor: TwitchChannel, make the optionals const --- src/providers/twitch/TwitchChannel.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 61a1cceebbb..f3a9f7009c6 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -955,10 +955,10 @@ void TwitchChannel::updateSeventvData(const QString &newUserID, return; } - std::optional oldUserID = makeConditionedOptional( + const auto oldUserID = makeConditionedOptional( !this->seventvUserID_.isEmpty() && this->seventvUserID_ != newUserID, this->seventvUserID_); - std::optional oldEmoteSetID = + const auto oldEmoteSetID = makeConditionedOptional(!this->seventvEmoteSetID_.isEmpty() && this->seventvEmoteSetID_ != newEmoteSetID, this->seventvEmoteSetID_); From a60e65d048ad34507dac2ffdb1efc399df83fb8c Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 15:38:30 +0200 Subject: [PATCH 13/15] fix windows compile --- src/widgets/FramelessEmbedWindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/FramelessEmbedWindow.cpp b/src/widgets/FramelessEmbedWindow.cpp index c710e6e34e6..d9e5479d880 100644 --- a/src/widgets/FramelessEmbedWindow.cpp +++ b/src/widgets/FramelessEmbedWindow.cpp @@ -70,7 +70,7 @@ void FramelessEmbedWindow::showEvent(QShowEvent *) } if (auto parentHwnd = - reinterpret_cast(getArgs().parentWindowId.get())) + reinterpret_cast(getArgs().parentWindowId.value())) { auto handle = reinterpret_cast(this->winId()); if (!::SetParent(handle, parentHwnd)) From 84a32077854131edb6ee328734582c0c4a1e4370 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 15:41:15 +0200 Subject: [PATCH 14/15] reformat --- src/messages/SharedMessageBuilder.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/messages/SharedMessageBuilder.cpp b/src/messages/SharedMessageBuilder.cpp index bedeb5cdf41..9f8f3bec8ba 100644 --- a/src/messages/SharedMessageBuilder.cpp +++ b/src/messages/SharedMessageBuilder.cpp @@ -277,4 +277,5 @@ QString SharedMessageBuilder::stylizeUsername(const QString &username, return usernameText; } + } // namespace chatterino From 2ba7d23d3568ae7f315adf76695d160a7330e621 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 8 Oct 2023 16:02:15 +0200 Subject: [PATCH 15/15] Revert "refactor: use queue emplace when adding an image to the nuuls image" This reverts commit 2e9a351ab696b640038a5bc71c16a17aab970f08. --- src/util/NuulsUploader.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/util/NuulsUploader.cpp b/src/util/NuulsUploader.cpp index 78961220034..a614c91bf2c 100644 --- a/src/util/NuulsUploader.cpp +++ b/src/util/NuulsUploader.cpp @@ -274,7 +274,8 @@ void upload(const QMimeData *source, ChannelPtr channel, auto imageData = convertToPng(img); if (imageData) { - uploadQueue.emplace(*imageData, "png", localPath); + RawImageData data = {*imageData, "png", localPath}; + uploadQueue.push(data); } else {