Replace boost::optional with std::optional (#4877)

This commit is contained in:
pajlada 2023-10-08 18:50:48 +02:00 committed by GitHub
parent fe4d6121a2
commit fec45889a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
88 changed files with 428 additions and 383 deletions

View file

@ -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 `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: 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: Update vcpkg to use Qt6. (#4872)
- Dev: Replace `boost::optional` with `std::optional`. (#4877)
## 2.4.6 ## 2.4.6

View file

@ -39,7 +39,7 @@ int compare(const QString &a, const QString &b);
* link * link
* ^^^ No need to repeat the obvious. * ^^^ No need to repeat the obvious.
*/ */
boost::optional<QRegularExpressionMatch> matchLink(const QString &text); std::optional<QRegularExpressionMatch> matchLink(const QString &text);
``` ```
# Code # Code

View file

@ -269,7 +269,7 @@ public:
// contains a comma // contains a comma
MOCK_METHOD(void, updateFollowerMode, MOCK_METHOD(void, updateFollowerMode,
(QString broadcasterID, QString moderatorID, (QString broadcasterID, QString moderatorID,
boost::optional<int> followerModeDuration, std::optional<int> followerModeDuration,
ResultCallback<HelixChatSettings> successCallback, ResultCallback<HelixChatSettings> successCallback,
(FailureCallback<HelixUpdateChatSettingsError, QString> (FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback)), failureCallback)),
@ -279,7 +279,7 @@ public:
// contains a comma // contains a comma
MOCK_METHOD(void, updateNonModeratorChatDelay, MOCK_METHOD(void, updateNonModeratorChatDelay,
(QString broadcasterID, QString moderatorID, (QString broadcasterID, QString moderatorID,
boost::optional<int> nonModeratorChatDelayDuration, std::optional<int> nonModeratorChatDelayDuration,
ResultCallback<HelixChatSettings> successCallback, ResultCallback<HelixChatSettings> successCallback,
(FailureCallback<HelixUpdateChatSettingsError, QString> (FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback)), failureCallback)),
@ -289,7 +289,7 @@ public:
// contains a comma // contains a comma
MOCK_METHOD(void, updateSlowMode, MOCK_METHOD(void, updateSlowMode,
(QString broadcasterID, QString moderatorID, (QString broadcasterID, QString moderatorID,
boost::optional<int> slowModeWaitTime, std::optional<int> slowModeWaitTime,
ResultCallback<HelixChatSettings> successCallback, ResultCallback<HelixChatSettings> successCallback,
(FailureCallback<HelixUpdateChatSettingsError, QString> (FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback)), failureCallback)),
@ -321,7 +321,7 @@ public:
// contains a comma // contains a comma
MOCK_METHOD(void, banUser, MOCK_METHOD(void, banUser,
(QString broadcasterID, QString moderatorID, QString userID, (QString broadcasterID, QString moderatorID, QString userID,
boost::optional<int> duration, QString reason, std::optional<int> duration, QString reason,
ResultCallback<> successCallback, ResultCallback<> successCallback,
(FailureCallback<HelixBanUserError, QString> failureCallback)), (FailureCallback<HelixBanUserError, QString> failureCallback)),
(override)); // /timeout, /ban (override)); // /timeout, /ban

View file

@ -11,9 +11,9 @@ public:
// Get extra data about a user // Get extra data about a user
// If the user does not have any extra data, return none // If the user does not have any extra data, return none
boost::optional<UserData> getUser(const QString &userID) const override std::optional<UserData> getUser(const QString &userID) const override
{ {
return boost::none; return std::nullopt;
} }
// Update or insert extra data for the user's color override // Update or insert extra data for the user's color override

View file

@ -2,7 +2,6 @@
# include <boost/circular_buffer.hpp> # include <boost/circular_buffer.hpp>
# include <boost/current_function.hpp> # include <boost/current_function.hpp>
# include <boost/foreach.hpp> # include <boost/foreach.hpp>
# include <boost/optional.hpp>
# include <boost/signals2.hpp> # include <boost/signals2.hpp>
# include <IrcCommand> # include <IrcCommand>
# include <IrcConnection> # include <IrcConnection>
@ -117,6 +116,7 @@
# include <map> # include <map>
# include <memory> # include <memory>
# include <mutex> # include <mutex>
# include <optional>
# include <random> # include <random>
# include <set> # include <set>
# include <string> # include <string>

View file

@ -2,9 +2,10 @@
#include "common/WindowDescriptors.hpp" #include "common/WindowDescriptors.hpp"
#include <boost/optional.hpp>
#include <QApplication> #include <QApplication>
#include <optional>
namespace chatterino { namespace chatterino {
/// Command line arguments passed to Chatterino. /// Command line arguments passed to Chatterino.
@ -18,12 +19,12 @@ public:
bool shouldRunBrowserExtensionHost{}; bool shouldRunBrowserExtensionHost{};
// Shows a single chat. Used on windows to embed in another application. // Shows a single chat. Used on windows to embed in another application.
bool isFramelessEmbed{}; bool isFramelessEmbed{};
boost::optional<unsigned long long> parentWindowId{}; std::optional<unsigned long long> parentWindowId{};
// Not settings directly // Not settings directly
bool dontSaveSettings{}; bool dontSaveSettings{};
bool dontLoadMainWindow{}; bool dontLoadMainWindow{};
boost::optional<WindowLayout> customChannelLayout; std::optional<WindowLayout> customChannelLayout;
bool verbose{}; bool verbose{};
private: private:

View file

@ -80,7 +80,7 @@ LimitedQueueSnapshot<MessagePtr> Channel::getMessageSnapshot()
} }
void Channel::addMessage(MessagePtr message, void Channel::addMessage(MessagePtr message,
boost::optional<MessageFlags> overridingFlags) std::optional<MessageFlags> overridingFlags)
{ {
auto app = getApp(); auto app = getApp();
MessagePtr deleted; MessagePtr deleted;

View file

@ -4,13 +4,13 @@
#include "controllers/completion/TabCompletionModel.hpp" #include "controllers/completion/TabCompletionModel.hpp"
#include "messages/LimitedQueue.hpp" #include "messages/LimitedQueue.hpp"
#include <boost/optional.hpp>
#include <pajlada/signals/signal.hpp> #include <pajlada/signals/signal.hpp>
#include <QDate> #include <QDate>
#include <QString> #include <QString>
#include <QTimer> #include <QTimer>
#include <memory> #include <memory>
#include <optional>
namespace chatterino { namespace chatterino {
@ -52,7 +52,7 @@ public:
pajlada::Signals::Signal<const QString &, const QString &, const QString &, pajlada::Signals::Signal<const QString &, const QString &, const QString &,
bool &> bool &>
sendReplySignal; sendReplySignal;
pajlada::Signals::Signal<MessagePtr &, boost::optional<MessageFlags>> pajlada::Signals::Signal<MessagePtr &, std::optional<MessageFlags>>
messageAppended; messageAppended;
pajlada::Signals::Signal<std::vector<MessagePtr> &> messagesAddedAtStart; pajlada::Signals::Signal<std::vector<MessagePtr> &> messagesAddedAtStart;
pajlada::Signals::Signal<size_t, MessagePtr &> messageReplaced; pajlada::Signals::Signal<size_t, MessagePtr &> messageReplaced;
@ -75,9 +75,8 @@ public:
// overridingFlags can be filled in with flags that should be used instead // 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 // of the message's flags. This is useful in case a flag is specific to a
// type of split // type of split
void addMessage( void addMessage(MessagePtr message,
MessagePtr message, std::optional<MessageFlags> overridingFlags = std::nullopt);
boost::optional<MessageFlags> overridingFlags = boost::none);
void addMessagesAtStart(const std::vector<MessagePtr> &messages_); void addMessagesAtStart(const std::vector<MessagePtr> &messages_);
/// Inserts the given messages in order by Message::serverReceivedTime. /// Inserts the given messages in order by Message::serverReceivedTime.

View file

@ -1,11 +1,11 @@
#pragma once #pragma once
#include <boost/optional.hpp>
#include <boost/preprocessor.hpp> #include <boost/preprocessor.hpp>
#include <QString> #include <QString>
#include <QWidget> #include <QWidget>
#include <memory> #include <memory>
#include <optional>
#include <string> #include <string>
namespace chatterino { namespace chatterino {

View file

@ -44,7 +44,7 @@ namespace {
return defaultValue; return defaultValue;
} }
boost::optional<QString> readOptionalStringEnv(const char *envName) std::optional<QString> readOptionalStringEnv(const char *envName)
{ {
auto envString = std::getenv(envName); auto envString = std::getenv(envName);
if (envString != nullptr) if (envString != nullptr)
@ -52,7 +52,7 @@ namespace {
return QString(envString); return QString(envString);
} }
return boost::none; return std::nullopt;
} }
uint16_t readPortEnv(const char *envName, uint16_t defaultValue) uint16_t readPortEnv(const char *envName, uint16_t defaultValue)

View file

@ -1,8 +1,9 @@
#pragma once #pragma once
#include <boost/optional.hpp>
#include <QString> #include <QString>
#include <optional>
namespace chatterino { namespace chatterino {
class Env class Env
@ -17,7 +18,7 @@ public:
const QString twitchServerHost; const QString twitchServerHost;
const uint16_t twitchServerPort; const uint16_t twitchServerPort;
const bool twitchServerSecure; const bool twitchServerSecure;
const boost::optional<QString> proxyUrl; const std::optional<QString> proxyUrl;
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -2,12 +2,13 @@
#include "common/SignalVector.hpp" #include "common/SignalVector.hpp"
#include <boost/optional.hpp>
#include <pajlada/signals/signalholder.hpp> #include <pajlada/signals/signalholder.hpp>
#include <QAbstractTableModel> #include <QAbstractTableModel>
#include <QMimeData> #include <QMimeData>
#include <QStandardItem> #include <QStandardItem>
#include <optional>
namespace chatterino { namespace chatterino {
template <typename T> template <typename T>
@ -127,7 +128,8 @@ public:
QVariant data(const QModelIndex &index, int role) const override 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() || if (row < 0 || column < 0 || row >= this->rows_.size() ||
column >= this->columnCount_) column >= this->columnCount_)
{ {
@ -140,7 +142,8 @@ public:
bool setData(const QModelIndex &index, const QVariant &value, bool setData(const QModelIndex &index, const QVariant &value,
int role) override 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() || if (row < 0 || column < 0 || row >= this->rows_.size() ||
column >= this->columnCount_) column >= this->columnCount_)
{ {
@ -166,7 +169,7 @@ public:
assert(this->rows_[row].original); assert(this->rows_[row].original);
TVectorItem item = this->getItemFromRow( 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); this->vector_->insert(item, vecRow, this);
} }
@ -262,7 +265,7 @@ public:
TVectorItem item = TVectorItem item =
this->getItemFromRow(this->rows_[sourceRow].items, this->getItemFromRow(this->rows_[sourceRow].items,
this->rows_[sourceRow].original.get()); this->rows_[sourceRow].original.value());
this->vector_->removeAt(signalVectorRow); this->vector_->removeAt(signalVectorRow);
this->vector_->insert( this->vector_->insert(
item, this->getVectorIndexFromModelIndex(destinationChild)); item, this->getVectorIndexFromModelIndex(destinationChild));
@ -417,7 +420,7 @@ protected:
struct Row { struct Row {
std::vector<QStandardItem *> items; std::vector<QStandardItem *> items;
boost::optional<TVectorItem> original; std::optional<TVectorItem> original;
bool isCustomRow; bool isCustomRow;
Row(std::vector<QStandardItem *> _items, bool _isCustomRow = false) Row(std::vector<QStandardItem *> _items, bool _isCustomRow = false)

View file

@ -114,7 +114,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
const auto &bttvemotes = app->twitch->getBttvEmotes(); const auto &bttvemotes = app->twitch->getBttvEmotes();
const auto &ffzemotes = app->twitch->getFfzEmotes(); const auto &ffzemotes = app->twitch->getFfzEmotes();
auto flags = MessageElementFlags(); auto flags = MessageElementFlags();
auto emote = boost::optional<EmotePtr>{}; auto emote = std::optional<EmotePtr>{};
for (int i = 2; i < words.length(); i++) for (int i = 2; i < words.length(); i++)
{ {
{ // Twitch emote { // Twitch emote
@ -138,7 +138,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
} }
if (emote) if (emote)
{ {
b.emplace<EmoteElement>(emote.get(), flags); b.emplace<EmoteElement>(*emote, flags);
continue; continue;
} }
} // bttv/ffz emote } // bttv/ffz emote
@ -181,7 +181,7 @@ bool appendWhisperMessageWordsLocally(const QStringList &words)
app->twitch->whispersChannel->addMessage(messagexD); app->twitch->whispersChannel->addMessage(messagexD);
auto overrideFlags = boost::optional<MessageFlags>(messagexD->flags); auto overrideFlags = std::optional<MessageFlags>(messagexD->flags);
overrideFlags->set(MessageFlag::DoNotLog); overrideFlags->set(MessageFlag::DoNotLog);
if (getSettings()->inlineWhispers && if (getSettings()->inlineWhispers &&
@ -2856,7 +2856,7 @@ void CommandController::initialize(Settings &, Paths &paths)
formatBanTimeoutError](const auto &targetUser) { formatBanTimeoutError](const auto &targetUser) {
getHelix()->banUser( getHelix()->banUser(
twitchChannel->roomId(), currentUser->getUserId(), 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 // No response for bans, they're emitted over pubsub/IRC instead
}, },
@ -2910,7 +2910,7 @@ void CommandController::initialize(Settings &, Paths &paths)
getHelix()->banUser( getHelix()->banUser(
twitchChannel->roomId(), currentUser->getUserId(), target, twitchChannel->roomId(), currentUser->getUserId(), target,
boost::none, reason, std::nullopt, reason,
[] { [] {
// No response for bans, they're emitted over pubsub/IRC instead // No response for bans, they're emitted over pubsub/IRC instead
}, },

View file

@ -289,7 +289,7 @@ QString slowOff(const CommandContext &ctx)
} }
getHelix()->updateSlowMode(ctx.twitchChannel->roomId(), getHelix()->updateSlowMode(ctx.twitchChannel->roomId(),
currentUser->getUserId(), boost::none, currentUser->getUserId(), std::nullopt,
successCallback, failureCallback(ctx.channel)); successCallback, failureCallback(ctx.channel));
return ""; return "";
@ -367,7 +367,7 @@ QString followersOff(const CommandContext &ctx)
} }
getHelix()->updateFollowerMode( getHelix()->updateFollowerMode(
ctx.twitchChannel->roomId(), currentUser->getUserId(), boost::none, ctx.twitchChannel->roomId(), currentUser->getUserId(), std::nullopt,
successCallback, failureCallback(ctx.channel)); successCallback, failureCallback(ctx.channel));
return ""; return "";

View file

@ -23,7 +23,7 @@ auto highlightPhraseCheck(const HighlightPhrase &highlight) -> HighlightCheck
[highlight](const auto &args, const auto &badges, [highlight](const auto &args, const auto &badges,
const auto &senderName, const auto &originalMessage, const auto &senderName, const auto &originalMessage,
const auto &flags, const auto &flags,
const auto self) -> boost::optional<HighlightResult> { const auto self) -> std::optional<HighlightResult> {
(void)args; // unused (void)args; // unused
(void)badges; // unused (void)badges; // unused
(void)senderName; // unused (void)senderName; // unused
@ -32,15 +32,15 @@ auto highlightPhraseCheck(const HighlightPhrase &highlight) -> HighlightCheck
if (self) if (self)
{ {
// Phrase checks should ignore highlights from the user // Phrase checks should ignore highlights from the user
return boost::none; return std::nullopt;
} }
if (!highlight.isMatch(originalMessage)) if (!highlight.isMatch(originalMessage))
{ {
return boost::none; return std::nullopt;
} }
boost::optional<QUrl> highlightSoundUrl; std::optional<QUrl> highlightSoundUrl;
if (highlight.hasCustomSound()) if (highlight.hasCustomSound())
{ {
highlightSoundUrl = highlight.getSoundUrl(); highlightSoundUrl = highlight.getSoundUrl();
@ -62,7 +62,7 @@ void rebuildSubscriptionHighlights(Settings &settings,
auto highlightSound = settings.enableSubHighlightSound.getValue(); auto highlightSound = settings.enableSubHighlightSound.getValue();
auto highlightAlert = settings.enableSubHighlightTaskbar.getValue(); auto highlightAlert = settings.enableSubHighlightTaskbar.getValue();
auto highlightSoundUrlValue = settings.subHighlightSoundUrl.getValue(); auto highlightSoundUrlValue = settings.subHighlightSoundUrl.getValue();
boost::optional<QUrl> highlightSoundUrl; std::optional<QUrl> highlightSoundUrl;
if (!highlightSoundUrlValue.isEmpty()) if (!highlightSoundUrlValue.isEmpty())
{ {
highlightSoundUrl = highlightSoundUrlValue; highlightSoundUrl = highlightSoundUrlValue;
@ -73,7 +73,7 @@ void rebuildSubscriptionHighlights(Settings &settings,
checks.emplace_back(HighlightCheck{ checks.emplace_back(HighlightCheck{
[=](const auto &args, const auto &badges, const auto &senderName, [=](const auto &args, const auto &badges, const auto &senderName,
const auto &originalMessage, const auto &flags, const auto &originalMessage, const auto &flags,
const auto self) -> boost::optional<HighlightResult> { const auto self) -> std::optional<HighlightResult> {
(void)badges; // unused (void)badges; // unused
(void)senderName; // unused (void)senderName; // unused
(void)originalMessage; // unused (void)originalMessage; // unused
@ -82,7 +82,7 @@ void rebuildSubscriptionHighlights(Settings &settings,
if (!args.isSubscriptionMessage) if (!args.isSubscriptionMessage)
{ {
return boost::none; return std::nullopt;
} }
auto highlightColor = auto highlightColor =
@ -108,7 +108,7 @@ void rebuildWhisperHighlights(Settings &settings,
auto highlightAlert = settings.enableWhisperHighlightTaskbar.getValue(); auto highlightAlert = settings.enableWhisperHighlightTaskbar.getValue();
auto highlightSoundUrlValue = auto highlightSoundUrlValue =
settings.whisperHighlightSoundUrl.getValue(); settings.whisperHighlightSoundUrl.getValue();
boost::optional<QUrl> highlightSoundUrl; std::optional<QUrl> highlightSoundUrl;
if (!highlightSoundUrlValue.isEmpty()) if (!highlightSoundUrlValue.isEmpty())
{ {
highlightSoundUrl = highlightSoundUrlValue; highlightSoundUrl = highlightSoundUrlValue;
@ -119,7 +119,7 @@ void rebuildWhisperHighlights(Settings &settings,
checks.emplace_back(HighlightCheck{ checks.emplace_back(HighlightCheck{
[=](const auto &args, const auto &badges, const auto &senderName, [=](const auto &args, const auto &badges, const auto &senderName,
const auto &originalMessage, const auto &flags, const auto &originalMessage, const auto &flags,
const auto self) -> boost::optional<HighlightResult> { const auto self) -> std::optional<HighlightResult> {
(void)badges; // unused (void)badges; // unused
(void)senderName; // unused (void)senderName; // unused
(void)originalMessage; // unused (void)originalMessage; // unused
@ -128,7 +128,7 @@ void rebuildWhisperHighlights(Settings &settings,
if (!args.isReceivedWhisper) if (!args.isReceivedWhisper)
{ {
return boost::none; return std::nullopt;
} }
return HighlightResult{ return HighlightResult{
@ -151,7 +151,7 @@ void rebuildReplyThreadHighlight(Settings &settings,
auto highlightAlert = settings.enableThreadHighlightTaskbar.getValue(); auto highlightAlert = settings.enableThreadHighlightTaskbar.getValue();
auto highlightSoundUrlValue = auto highlightSoundUrlValue =
settings.threadHighlightSoundUrl.getValue(); settings.threadHighlightSoundUrl.getValue();
boost::optional<QUrl> highlightSoundUrl; std::optional<QUrl> highlightSoundUrl;
if (!highlightSoundUrlValue.isEmpty()) if (!highlightSoundUrlValue.isEmpty())
{ {
highlightSoundUrl = highlightSoundUrlValue; highlightSoundUrl = highlightSoundUrlValue;
@ -162,7 +162,7 @@ void rebuildReplyThreadHighlight(Settings &settings,
[=](const auto & /*args*/, const auto & /*badges*/, [=](const auto & /*args*/, const auto & /*badges*/,
const auto & /*senderName*/, const auto & /*originalMessage*/, const auto & /*senderName*/, const auto & /*originalMessage*/,
const auto &flags, const auto &flags,
const auto self) -> boost::optional<HighlightResult> { const auto self) -> std::optional<HighlightResult> {
if (flags.has(MessageFlag::SubscribedThread) && !self) if (flags.has(MessageFlag::SubscribedThread) && !self)
{ {
return HighlightResult{ 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]( [showInMentions](
const auto &args, const auto &badges, const auto &senderName, const auto &args, const auto &badges, const auto &senderName,
const auto &originalMessage, const auto &flags, const auto &originalMessage, const auto &flags,
const auto self) -> boost::optional<HighlightResult> { const auto self) -> std::optional<HighlightResult> {
(void)args; //unused (void)args; //unused
(void)badges; //unused (void)badges; //unused
(void)senderName; //unused (void)senderName; //unused
@ -228,7 +228,7 @@ void rebuildUserHighlights(Settings &settings,
if (!self) if (!self)
{ {
return boost::none; return std::nullopt;
} }
// Highlight color is provided by the ColorProvider and will be updated accordingly // 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, [highlight](const auto &args, const auto &badges,
const auto &senderName, const auto &originalMessage, const auto &senderName, const auto &originalMessage,
const auto &flags, const auto &flags,
const auto self) -> boost::optional<HighlightResult> { const auto self) -> std::optional<HighlightResult> {
(void)args; // unused (void)args; // unused
(void)badges; // unused (void)badges; // unused
(void)originalMessage; // unused (void)originalMessage; // unused
@ -255,10 +255,10 @@ void rebuildUserHighlights(Settings &settings,
if (!highlight.isMatch(senderName)) if (!highlight.isMatch(senderName))
{ {
return boost::none; return std::nullopt;
} }
boost::optional<QUrl> highlightSoundUrl; std::optional<QUrl> highlightSoundUrl;
if (highlight.hasCustomSound()) if (highlight.hasCustomSound())
{ {
highlightSoundUrl = highlight.getSoundUrl(); highlightSoundUrl = highlight.getSoundUrl();
@ -286,7 +286,7 @@ void rebuildBadgeHighlights(Settings &settings,
[highlight](const auto &args, const auto &badges, [highlight](const auto &args, const auto &badges,
const auto &senderName, const auto &originalMessage, const auto &senderName, const auto &originalMessage,
const auto &flags, const auto &flags,
const auto self) -> boost::optional<HighlightResult> { const auto self) -> std::optional<HighlightResult> {
(void)args; // unused (void)args; // unused
(void)senderName; // unused (void)senderName; // unused
(void)originalMessage; // unused (void)originalMessage; // unused
@ -297,7 +297,7 @@ void rebuildBadgeHighlights(Settings &settings,
{ {
if (highlight.isMatch(badge)) if (highlight.isMatch(badge))
{ {
boost::optional<QUrl> highlightSoundUrl; std::optional<QUrl> highlightSoundUrl;
if (highlight.hasCustomSound()) if (highlight.hasCustomSound())
{ {
highlightSoundUrl = highlight.getSoundUrl(); 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 { namespace chatterino {
HighlightResult::HighlightResult(bool _alert, bool _playSound, HighlightResult::HighlightResult(bool _alert, bool _playSound,
boost::optional<QUrl> _customSoundUrl, std::optional<QUrl> _customSoundUrl,
std::shared_ptr<QColor> _color, std::shared_ptr<QColor> _color,
bool _showInMentions) bool _showInMentions)
: alert(_alert) : alert(_alert)
@ -337,7 +337,7 @@ HighlightResult::HighlightResult(bool _alert, bool _playSound,
HighlightResult HighlightResult::emptyResult() HighlightResult HighlightResult::emptyResult()
{ {
return { 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") << ", " os << "Alert: " << (result.alert ? "Yes" : "No") << ", "
<< "Play sound: " << (result.playSound ? "Yes" : "No") << " (" << "Play sound: " << (result.playSound ? "Yes" : "No") << " ("
<< (result.customSoundUrl << (result.customSoundUrl
? result.customSoundUrl.get().toString().toStdString() ? result.customSoundUrl->toString().toStdString()
: "") : "")
<< ")" << ")"
<< ", " << ", "

View file

@ -4,7 +4,6 @@
#include "common/Singleton.hpp" #include "common/Singleton.hpp"
#include "common/UniqueAccess.hpp" #include "common/UniqueAccess.hpp"
#include <boost/optional.hpp>
#include <pajlada/settings.hpp> #include <pajlada/settings.hpp>
#include <pajlada/settings/settinglistener.hpp> #include <pajlada/settings/settinglistener.hpp>
#include <QColor> #include <QColor>
@ -12,6 +11,7 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <optional>
#include <utility> #include <utility>
namespace chatterino { namespace chatterino {
@ -23,7 +23,7 @@ using MessageFlags = FlagsEnum<MessageFlag>;
struct HighlightResult { struct HighlightResult {
HighlightResult(bool _alert, bool _playSound, HighlightResult(bool _alert, bool _playSound,
boost::optional<QUrl> _customSoundUrl, std::optional<QUrl> _customSoundUrl,
std::shared_ptr<QColor> _color, bool _showInMentions); std::shared_ptr<QColor> _color, bool _showInMentions);
/** /**
@ -46,7 +46,7 @@ struct HighlightResult {
* *
* May only be set if playSound is true * May only be set if playSound is true
**/ **/
boost::optional<QUrl> customSoundUrl{}; std::optional<QUrl> customSoundUrl{};
/** /**
* @brief set if highlight should set a background color * @brief set if highlight should set a background color
@ -76,7 +76,7 @@ struct HighlightResult {
}; };
struct HighlightCheck { struct HighlightCheck {
using Checker = std::function<boost::optional<HighlightResult>( using Checker = std::function<std::optional<HighlightResult>(
const MessageParseArgs &args, const std::vector<Badge> &badges, const MessageParseArgs &args, const std::vector<Badge> &badges,
const QString &senderName, const QString &originalMessage, const QString &senderName, const QString &originalMessage,
const MessageFlags &messageFlags, bool self)>; const MessageFlags &messageFlags, bool self)>;

View file

@ -127,7 +127,7 @@ int HotkeyController::replaceHotkey(QString oldName,
return this->hotkeys_.append(newHotkey); return this->hotkeys_.append(newHotkey);
} }
boost::optional<HotkeyCategory> HotkeyController::hotkeyCategoryFromName( std::optional<HotkeyCategory> HotkeyController::hotkeyCategoryFromName(
QString categoryName) QString categoryName)
{ {
for (const auto &[category, data] : this->categories()) for (const auto &[category, data] : this->categories())

View file

@ -4,7 +4,6 @@
#include "common/Singleton.hpp" #include "common/Singleton.hpp"
#include "controllers/hotkeys/HotkeyCategory.hpp" #include "controllers/hotkeys/HotkeyCategory.hpp"
#include <boost/optional.hpp>
#include <pajlada/signals/signal.hpp> #include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp> #include <pajlada/signals/signalholder.hpp>
@ -52,8 +51,7 @@ public:
* @returns the new index in the SignalVector * @returns the new index in the SignalVector
**/ **/
int replaceHotkey(QString oldName, std::shared_ptr<Hotkey> newHotkey); int replaceHotkey(QString oldName, std::shared_ptr<Hotkey> newHotkey);
boost::optional<HotkeyCategory> hotkeyCategoryFromName( std::optional<HotkeyCategory> hotkeyCategoryFromName(QString categoryName);
QString categoryName);
/** /**
* @brief checks if the hotkey is duplicate * @brief checks if the hotkey is duplicate

View file

@ -3,9 +3,10 @@
#include "controllers/hotkeys/ActionNames.hpp" #include "controllers/hotkeys/ActionNames.hpp"
#include "controllers/hotkeys/HotkeyCategory.hpp" #include "controllers/hotkeys/HotkeyCategory.hpp"
#include <boost/optional/optional.hpp>
#include <QStringList> #include <QStringList>
#include <optional>
namespace chatterino { namespace chatterino {
std::vector<QString> parseHotkeyArguments(QString argumentString) std::vector<QString> parseHotkeyArguments(QString argumentString)
@ -31,7 +32,7 @@ std::vector<QString> parseHotkeyArguments(QString argumentString)
return arguments; return arguments;
} }
boost::optional<ActionDefinition> findHotkeyActionDefinition( std::optional<ActionDefinition> findHotkeyActionDefinition(
HotkeyCategory category, const QString &action) HotkeyCategory category, const QString &action)
{ {
auto allActions = actionNames.find(category); auto allActions = actionNames.find(category);

View file

@ -2,15 +2,15 @@
#include "controllers/hotkeys/ActionNames.hpp" #include "controllers/hotkeys/ActionNames.hpp"
#include <boost/optional/optional.hpp>
#include <QString> #include <QString>
#include <optional>
#include <vector> #include <vector>
namespace chatterino { namespace chatterino {
std::vector<QString> parseHotkeyArguments(QString argumentString); std::vector<QString> parseHotkeyArguments(QString argumentString);
boost::optional<ActionDefinition> findHotkeyActionDefinition( std::optional<ActionDefinition> findHotkeyActionDefinition(
HotkeyCategory category, const QString &action); HotkeyCategory category, const QString &action);
} // namespace chatterino } // namespace chatterino

View file

@ -136,7 +136,7 @@ bool ModerationAction::isImage() const
return bool(this->image_); return bool(this->image_);
} }
const boost::optional<ImagePtr> &ModerationAction::getImage() const const std::optional<ImagePtr> &ModerationAction::getImage() const
{ {
assertInGuiThread(); assertInGuiThread();

View file

@ -2,11 +2,11 @@
#include "util/RapidjsonHelpers.hpp" #include "util/RapidjsonHelpers.hpp"
#include <boost/optional.hpp>
#include <pajlada/serialize.hpp> #include <pajlada/serialize.hpp>
#include <QString> #include <QString>
#include <memory> #include <memory>
#include <optional>
namespace chatterino { namespace chatterino {
@ -21,13 +21,13 @@ public:
bool operator==(const ModerationAction &other) const; bool operator==(const ModerationAction &other) const;
bool isImage() const; bool isImage() const;
const boost::optional<ImagePtr> &getImage() const; const std::optional<ImagePtr> &getImage() const;
const QString &getLine1() const; const QString &getLine1() const;
const QString &getLine2() const; const QString &getLine2() const;
const QString &getAction() const; const QString &getAction() const;
private: private:
mutable boost::optional<ImagePtr> image_; mutable std::optional<ImagePtr> image_;
QString line1_; QString line1_;
QString line2_; QString line2_;
QString action_; QString action_;

View file

@ -3,12 +3,12 @@
#include "util/RapidjsonHelpers.hpp" #include "util/RapidjsonHelpers.hpp"
#include "util/RapidJsonSerializeQString.hpp" #include "util/RapidJsonSerializeQString.hpp"
#include <boost/optional.hpp>
#include <pajlada/serialize.hpp> #include <pajlada/serialize.hpp>
#include <QRegularExpression> #include <QRegularExpression>
#include <QString> #include <QString>
#include <memory> #include <memory>
#include <optional>
namespace chatterino { namespace chatterino {
@ -59,18 +59,18 @@ public:
return this->isCaseSensitive_; return this->isCaseSensitive_;
} }
[[nodiscard]] boost::optional<QString> match( [[nodiscard]] std::optional<QString> match(
const QString &usernameText) const const QString &usernameText) const
{ {
if (this->isRegex()) if (this->isRegex())
{ {
if (!this->regex_.isValid()) if (!this->regex_.isValid())
{ {
return boost::none; return std::nullopt;
} }
if (this->name().isEmpty()) if (this->name().isEmpty())
{ {
return boost::none; return std::nullopt;
} }
auto workingCopy = usernameText; auto workingCopy = usernameText;
@ -90,7 +90,7 @@ public:
} }
} }
return boost::none; return std::nullopt;
} }
private: private:

View file

@ -3,11 +3,12 @@
#include "util/RapidjsonHelpers.hpp" #include "util/RapidjsonHelpers.hpp"
#include "util/RapidJsonSerializeQString.hpp" #include "util/RapidJsonSerializeQString.hpp"
#include <boost/optional.hpp>
#include <pajlada/serialize.hpp> #include <pajlada/serialize.hpp>
#include <QColor> #include <QColor>
#include <QString> #include <QString>
#include <optional>
namespace chatterino { namespace chatterino {
// UserData defines a set of data that is defined for a unique user // 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 // 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 // Replacement fields should be optional, where none denotes that the field should not be updated for the user
struct UserData { struct UserData {
boost::optional<QColor> color{boost::none}; std::optional<QColor> color{std::nullopt};
// TODO: User note? // TODO: User note?
}; };

View file

@ -2,6 +2,7 @@
#include "singletons/Paths.hpp" #include "singletons/Paths.hpp"
#include "util/CombinePath.hpp" #include "util/CombinePath.hpp"
#include "util/Helpers.hpp"
namespace { namespace {
@ -42,15 +43,14 @@ void UserDataController::save()
this->sm->save(); this->sm->save();
} }
boost::optional<UserData> UserDataController::getUser( std::optional<UserData> UserDataController::getUser(const QString &userID) const
const QString &userID) const
{ {
std::shared_lock lock(this->usersMutex); std::shared_lock lock(this->usersMutex);
auto it = this->users.find(userID); auto it = this->users.find(userID);
if (it == this->users.end()) if (it == this->users.end())
{ {
return boost::none; return std::nullopt;
} }
return it->second; return it->second;
@ -67,8 +67,8 @@ void UserDataController::setUserColor(const QString &userID,
{ {
auto c = this->getUsers(); auto c = this->getUsers();
auto it = c.find(userID); auto it = c.find(userID);
boost::optional<QColor> finalColor = std::optional<QColor> finalColor =
boost::make_optional(!colorString.isEmpty(), QColor(colorString)); makeConditionedOptional(!colorString.isEmpty(), QColor(colorString));
if (it == c.end()) if (it == c.end())
{ {
if (!finalColor) if (!finalColor)

View file

@ -7,11 +7,11 @@
#include "util/RapidJsonSerializeQString.hpp" #include "util/RapidJsonSerializeQString.hpp"
#include "util/serialize/Container.hpp" #include "util/serialize/Container.hpp"
#include <boost/optional.hpp>
#include <pajlada/settings.hpp> #include <pajlada/settings.hpp>
#include <QColor> #include <QColor>
#include <QString> #include <QString>
#include <optional>
#include <shared_mutex> #include <shared_mutex>
#include <unordered_map> #include <unordered_map>
@ -22,7 +22,7 @@ class IUserDataController
public: public:
virtual ~IUserDataController() = default; virtual ~IUserDataController() = default;
virtual boost::optional<UserData> getUser(const QString &userID) const = 0; virtual std::optional<UserData> getUser(const QString &userID) const = 0;
virtual void setUserColor(const QString &userID, virtual void setUserColor(const QString &userID,
const QString &colorString) = 0; const QString &colorString) = 0;
@ -35,7 +35,7 @@ public:
// Get extra data about a user // Get extra data about a user
// If the user does not have any extra data, return none // If the user does not have any extra data, return none
boost::optional<UserData> getUser(const QString &userID) const override; std::optional<UserData> getUser(const QString &userID) const override;
// Update or insert extra data for the user's color override // Update or insert extra data for the user's color override
void setUserColor(const QString &userID, void setUserColor(const QString &userID,

View file

@ -3,11 +3,10 @@
#include "common/Aliases.hpp" #include "common/Aliases.hpp"
#include "messages/ImageSet.hpp" #include "messages/ImageSet.hpp"
#include <boost/optional.hpp>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <optional>
#include <unordered_map> #include <unordered_map>
namespace chatterino { namespace chatterino {
@ -24,7 +23,7 @@ struct Emote {
* If this emote is aliased, this contains * If this emote is aliased, this contains
* the original (base) name of the emote. * the original (base) name of the emote.
*/ */
boost::optional<EmoteName> baseName; std::optional<EmoteName> baseName;
// FOURTF: no solution yet, to be refactored later // FOURTF: no solution yet, to be refactored later
const QString &getCopyString() const const QString &getCopyString() const

View file

@ -3,10 +3,10 @@
#include "messages/LimitedQueueSnapshot.hpp" #include "messages/LimitedQueueSnapshot.hpp"
#include <boost/circular_buffer.hpp> #include <boost/circular_buffer.hpp>
#include <boost/optional.hpp>
#include <cassert> #include <cassert>
#include <mutex> #include <mutex>
#include <optional>
#include <shared_mutex> #include <shared_mutex>
#include <vector> #include <vector>
@ -62,13 +62,13 @@ public:
* @param[in] index the index of the item to fetch * @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 * @return the item at the index if it's populated, or none if it's not
*/ */
[[nodiscard]] boost::optional<T> get(size_t index) const [[nodiscard]] std::optional<T> get(size_t index) const
{ {
std::shared_lock lock(this->mutex_); std::shared_lock lock(this->mutex_);
if (index >= this->buffer_.size()) if (index >= this->buffer_.size())
{ {
return boost::none; return std::nullopt;
} }
return this->buffer_[index]; return this->buffer_[index];
@ -79,13 +79,13 @@ public:
* *
* @return the item at the front of the queue if it's populated, or none the queue is empty * @return the item at the front of the queue if it's populated, or none the queue is empty
*/ */
[[nodiscard]] boost::optional<T> first() const [[nodiscard]] std::optional<T> first() const
{ {
std::shared_lock lock(this->mutex_); std::shared_lock lock(this->mutex_);
if (this->buffer_.empty()) if (this->buffer_.empty())
{ {
return boost::none; return std::nullopt;
} }
return this->buffer_.front(); return this->buffer_.front();
@ -96,13 +96,13 @@ public:
* *
* @return the item at the back of the queue if it's populated, or none the queue is empty * @return the item at the back of the queue if it's populated, or none the queue is empty
*/ */
[[nodiscard]] boost::optional<T> last() const [[nodiscard]] std::optional<T> last() const
{ {
std::shared_lock lock(this->mutex_); std::shared_lock lock(this->mutex_);
if (this->buffer_.empty()) if (this->buffer_.empty())
{ {
return boost::none; return std::nullopt;
} }
return this->buffer_.back(); return this->buffer_.back();
@ -293,14 +293,14 @@ public:
* *
* The contents of the LimitedQueue are iterated over from front to back * The contents of the LimitedQueue are iterated over from front to back
* until the first element that satisfies `pred(item)`. If no item * 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. * is returned.
* *
* @param[in] pred predicate that will be applied to items * @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 <typename Predicate> template <typename Predicate>
[[nodiscard]] boost::optional<T> find(Predicate pred) const [[nodiscard]] std::optional<T> find(Predicate pred) const
{ {
std::shared_lock lock(this->mutex_); std::shared_lock lock(this->mutex_);
@ -312,7 +312,7 @@ public:
} }
} }
return boost::none; return std::nullopt;
} }
/** /**
@ -320,14 +320,14 @@ public:
* *
* The contents of the LimitedQueue are iterated over from back to front * The contents of the LimitedQueue are iterated over from back to front
* until the first element that satisfies `pred(item)`. If no item * 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. * is returned.
* *
* @param[in] pred predicate that will be applied to items * @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 <typename Predicate> template <typename Predicate>
[[nodiscard]] boost::optional<T> rfind(Predicate pred) const [[nodiscard]] std::optional<T> rfind(Predicate pred) const
{ {
std::shared_lock lock(this->mutex_); std::shared_lock lock(this->mutex_);
@ -339,7 +339,7 @@ public:
} }
} }
return boost::none; return std::nullopt;
} }
private: private:

View file

@ -788,7 +788,7 @@ void TwitchModerationElement::addToContainer(MessageLayoutContainer &container,
if (auto image = action.getImage()) if (auto image = action.getImage())
{ {
container.addElement( container.addElement(
(new ImageLayoutElement(*this, image.get(), size)) (new ImageLayoutElement(*this, *image, size))
->setLink(Link(Link::UserAction, action.getAction()))); ->setLink(Link(Link::UserAction, action.getAction())));
} }
else else

View file

@ -175,7 +175,7 @@ void SharedMessageBuilder::parseHighlights()
if (highlightResult.customSoundUrl) if (highlightResult.customSoundUrl)
{ {
this->highlightSoundUrl_ = highlightResult.customSoundUrl.get(); this->highlightSoundUrl_ = *highlightResult.customSoundUrl;
} }
else else
{ {
@ -277,4 +277,5 @@ QString SharedMessageBuilder::stylizeUsername(const QString &username,
return usernameText; return usernameText;
} }
} // namespace chatterino } // namespace chatterino

View file

@ -69,7 +69,7 @@ void NetworkConfigurationProvider::applyFromEnv(const Env &env)
{ {
if (env.proxyUrl) if (env.proxyUrl)
{ {
applyProxy(env.proxyUrl.get()); applyProxy(*env.proxyUrl);
} }
} }

View file

@ -179,13 +179,16 @@ std::shared_ptr<const EmoteMap> BttvEmotes::emotes() const
return this->global_.get(); return this->global_.get();
} }
boost::optional<EmotePtr> BttvEmotes::emote(const EmoteName &name) const std::optional<EmotePtr> BttvEmotes::emote(const EmoteName &name) const
{ {
auto emotes = this->global_.get(); auto emotes = this->global_.get();
auto it = emotes->find(name); auto it = emotes->find(name);
if (it == emotes->end()) if (it == emotes->end())
return boost::none; {
return std::nullopt;
}
return it->second; return it->second;
} }
@ -203,8 +206,10 @@ void BttvEmotes::loadEmotes()
auto emotes = this->global_.get(); auto emotes = this->global_.get();
auto pair = parseGlobalEmotes(result.parseJsonArray(), *emotes); auto pair = parseGlobalEmotes(result.parseJsonArray(), *emotes);
if (pair.first) if (pair.first)
{
this->setEmotes( this->setEmotes(
std::make_shared<EmoteMap>(std::move(pair.second))); std::make_shared<EmoteMap>(std::move(pair.second)));
}
return pair.first; return pair.first;
}) })
.execute(); .execute();
@ -251,13 +256,18 @@ void BttvEmotes::loadChannel(std::weak_ptr<Channel> channel,
.onError([channelId, channel, manualRefresh](auto result) { .onError([channelId, channel, manualRefresh](auto result) {
auto shared = channel.lock(); auto shared = channel.lock();
if (!shared) if (!shared)
{
return; return;
}
if (result.status() == 404) if (result.status() == 404)
{ {
// User does not have any BTTV emotes // User does not have any BTTV emotes
if (manualRefresh) if (manualRefresh)
{
shared->addMessage( shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES)); makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
}
} }
else else
{ {
@ -291,7 +301,7 @@ EmotePtr BttvEmotes::addEmote(
return emote; return emote;
} }
boost::optional<std::pair<EmotePtr, EmotePtr>> BttvEmotes::updateEmote( std::optional<std::pair<EmotePtr, EmotePtr>> BttvEmotes::updateEmote(
const QString &channelDisplayName, const QString &channelDisplayName,
Atomic<std::shared_ptr<const EmoteMap>> &channelEmoteMap, Atomic<std::shared_ptr<const EmoteMap>> &channelEmoteMap,
const BttvLiveUpdateEmoteUpdateAddMessage &message) const BttvLiveUpdateEmoteUpdateAddMessage &message)
@ -305,7 +315,7 @@ boost::optional<std::pair<EmotePtr, EmotePtr>> BttvEmotes::updateEmote(
{ {
// We already copied the map at this point and are now discarding the copy. // We already copied the map at this point and are now discarding the copy.
// This is fine, because this case should be really rare. // This is fine, because this case should be really rare.
return boost::none; return std::nullopt;
} }
auto oldEmotePtr = it->second; auto oldEmotePtr = it->second;
// copy the existing emote, to not change the original one // copy the existing emote, to not change the original one
@ -316,7 +326,7 @@ boost::optional<std::pair<EmotePtr, EmotePtr>> BttvEmotes::updateEmote(
if (!updateChannelEmote(emote, channelDisplayName, message.jsonEmote)) if (!updateChannelEmote(emote, channelDisplayName, message.jsonEmote))
{ {
// The emote wasn't actually updated // The emote wasn't actually updated
return boost::none; return std::nullopt;
} }
auto name = emote.name; auto name = emote.name;
@ -327,7 +337,7 @@ boost::optional<std::pair<EmotePtr, EmotePtr>> BttvEmotes::updateEmote(
return std::make_pair(oldEmotePtr, emotePtr); return std::make_pair(oldEmotePtr, emotePtr);
} }
boost::optional<EmotePtr> BttvEmotes::removeEmote( std::optional<EmotePtr> BttvEmotes::removeEmote(
Atomic<std::shared_ptr<const EmoteMap>> &channelEmoteMap, Atomic<std::shared_ptr<const EmoteMap>> &channelEmoteMap,
const BttvLiveUpdateEmoteRemoveMessage &message) const BttvLiveUpdateEmoteRemoveMessage &message)
{ {
@ -338,7 +348,7 @@ boost::optional<EmotePtr> BttvEmotes::removeEmote(
{ {
// We already copied the map at this point and are now discarding the copy. // We already copied the map at this point and are now discarding the copy.
// This is fine, because this case should be really rare. // This is fine, because this case should be really rare.
return boost::none; return std::nullopt;
} }
auto emote = it->second; auto emote = it->second;
updatedMap.erase(it); updatedMap.erase(it);

View file

@ -3,9 +3,8 @@
#include "common/Aliases.hpp" #include "common/Aliases.hpp"
#include "common/Atomic.hpp" #include "common/Atomic.hpp"
#include <boost/optional.hpp>
#include <memory> #include <memory>
#include <optional>
namespace chatterino { namespace chatterino {
@ -27,7 +26,7 @@ public:
BttvEmotes(); BttvEmotes();
std::shared_ptr<const EmoteMap> emotes() const; std::shared_ptr<const EmoteMap> emotes() const;
boost::optional<EmotePtr> emote(const EmoteName &name) const; std::optional<EmotePtr> emote(const EmoteName &name) const;
void loadEmotes(); void loadEmotes();
void setEmotes(std::shared_ptr<const EmoteMap> emotes); void setEmotes(std::shared_ptr<const EmoteMap> emotes);
static void loadChannel(std::weak_ptr<Channel> channel, static void loadChannel(std::weak_ptr<Channel> channel,
@ -55,7 +54,7 @@ public:
* *
* @return pair<old emote, new emote> if any emote was updated. * @return pair<old emote, new emote> if any emote was updated.
*/ */
static boost::optional<std::pair<EmotePtr, EmotePtr>> updateEmote( static std::optional<std::pair<EmotePtr, EmotePtr>> updateEmote(
const QString &channelDisplayName, const QString &channelDisplayName,
Atomic<std::shared_ptr<const EmoteMap>> &channelEmoteMap, Atomic<std::shared_ptr<const EmoteMap>> &channelEmoteMap,
const BttvLiveUpdateEmoteUpdateAddMessage &message); const BttvLiveUpdateEmoteUpdateAddMessage &message);
@ -67,7 +66,7 @@ public:
* *
* @return The removed emote if any emote was removed. * @return The removed emote if any emote was removed.
*/ */
static boost::optional<EmotePtr> removeEmote( static std::optional<EmotePtr> removeEmote(
Atomic<std::shared_ptr<const EmoteMap>> &channelEmoteMap, Atomic<std::shared_ptr<const EmoteMap>> &channelEmoteMap,
const BttvLiveUpdateEmoteRemoveMessage &message); const BttvLiveUpdateEmoteRemoveMessage &message);

View file

@ -21,7 +21,7 @@ ChatterinoBadges::ChatterinoBadges()
{ {
} }
boost::optional<EmotePtr> ChatterinoBadges::getBadge(const UserId &id) std::optional<EmotePtr> ChatterinoBadges::getBadge(const UserId &id)
{ {
std::shared_lock lock(this->mutex_); std::shared_lock lock(this->mutex_);
@ -30,7 +30,7 @@ boost::optional<EmotePtr> ChatterinoBadges::getBadge(const UserId &id)
{ {
return emotes[it->second]; return emotes[it->second];
} }
return boost::none; return std::nullopt;
} }
void ChatterinoBadges::loadChatterinoBadges() void ChatterinoBadges::loadChatterinoBadges()

View file

@ -4,9 +4,8 @@
#include "common/Singleton.hpp" #include "common/Singleton.hpp"
#include "util/QStringHash.hpp" #include "util/QStringHash.hpp"
#include <boost/optional.hpp>
#include <memory> #include <memory>
#include <optional>
#include <shared_mutex> #include <shared_mutex>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
@ -22,7 +21,7 @@ public:
virtual void initialize(Settings &settings, Paths &paths) override; virtual void initialize(Settings &settings, Paths &paths) override;
ChatterinoBadges(); ChatterinoBadges();
boost::optional<EmotePtr> getBadge(const UserId &id); std::optional<EmotePtr> getBadge(const UserId &id);
private: private:
void loadChatterinoBadges(); void loadChatterinoBadges();

View file

@ -43,7 +43,7 @@ std::vector<FfzBadges::Badge> FfzBadges::getUserBadges(const UserId &id)
return badges; return badges;
} }
boost::optional<FfzBadges::Badge> FfzBadges::getBadge(const int badgeID) std::optional<FfzBadges::Badge> FfzBadges::getBadge(const int badgeID)
{ {
auto it = this->badges.find(badgeID); auto it = this->badges.find(badgeID);
if (it != this->badges.end()) if (it != this->badges.end())
@ -51,7 +51,7 @@ boost::optional<FfzBadges::Badge> FfzBadges::getBadge(const int badgeID)
return it->second; return it->second;
} }
return boost::none; return std::nullopt;
} }
void FfzBadges::load() void FfzBadges::load()

View file

@ -4,10 +4,10 @@
#include "common/Singleton.hpp" #include "common/Singleton.hpp"
#include "util/QStringHash.hpp" #include "util/QStringHash.hpp"
#include <boost/optional.hpp>
#include <QColor> #include <QColor>
#include <memory> #include <memory>
#include <optional>
#include <set> #include <set>
#include <shared_mutex> #include <shared_mutex>
#include <unordered_map> #include <unordered_map>
@ -32,7 +32,7 @@ public:
std::vector<Badge> getUserBadges(const UserId &id); std::vector<Badge> getUserBadges(const UserId &id);
private: private:
boost::optional<Badge> getBadge(int badgeID); std::optional<Badge> getBadge(int badgeID);
void load(); void load();

View file

@ -119,10 +119,10 @@ namespace {
return emotes; return emotes;
} }
boost::optional<EmotePtr> parseAuthorityBadge(const QJsonObject &badgeUrls, std::optional<EmotePtr> parseAuthorityBadge(const QJsonObject &badgeUrls,
const QString &tooltip) const QString &tooltip)
{ {
boost::optional<EmotePtr> authorityBadge; std::optional<EmotePtr> authorityBadge;
if (!badgeUrls.isEmpty()) if (!badgeUrls.isEmpty())
{ {
@ -173,7 +173,7 @@ std::shared_ptr<const EmoteMap> FfzEmotes::emotes() const
return this->global_.get(); return this->global_.get();
} }
boost::optional<EmotePtr> FfzEmotes::emote(const EmoteName &name) const std::optional<EmotePtr> FfzEmotes::emote(const EmoteName &name) const
{ {
auto emotes = this->global_.get(); auto emotes = this->global_.get();
auto it = emotes->find(name); auto it = emotes->find(name);
@ -181,7 +181,7 @@ boost::optional<EmotePtr> FfzEmotes::emote(const EmoteName &name) const
{ {
return it->second; return it->second;
} }
return boost::none; return std::nullopt;
} }
void FfzEmotes::loadEmotes() void FfzEmotes::loadEmotes()
@ -214,8 +214,8 @@ void FfzEmotes::setEmotes(std::shared_ptr<const EmoteMap> emotes)
void FfzEmotes::loadChannel( void FfzEmotes::loadChannel(
std::weak_ptr<Channel> channel, const QString &channelID, std::weak_ptr<Channel> channel, const QString &channelID,
std::function<void(EmoteMap &&)> emoteCallback, std::function<void(EmoteMap &&)> emoteCallback,
std::function<void(boost::optional<EmotePtr>)> modBadgeCallback, std::function<void(std::optional<EmotePtr>)> modBadgeCallback,
std::function<void(boost::optional<EmotePtr>)> vipBadgeCallback, std::function<void(std::optional<EmotePtr>)> vipBadgeCallback,
bool manualRefresh) bool manualRefresh)
{ {
qCDebug(chatterinoFfzemotes) qCDebug(chatterinoFfzemotes)

View file

@ -3,9 +3,8 @@
#include "common/Aliases.hpp" #include "common/Aliases.hpp"
#include "common/Atomic.hpp" #include "common/Atomic.hpp"
#include <boost/optional.hpp>
#include <memory> #include <memory>
#include <optional>
namespace chatterino { namespace chatterino {
@ -20,14 +19,14 @@ public:
FfzEmotes(); FfzEmotes();
std::shared_ptr<const EmoteMap> emotes() const; std::shared_ptr<const EmoteMap> emotes() const;
boost::optional<EmotePtr> emote(const EmoteName &name) const; std::optional<EmotePtr> emote(const EmoteName &name) const;
void loadEmotes(); void loadEmotes();
void setEmotes(std::shared_ptr<const EmoteMap> emotes); void setEmotes(std::shared_ptr<const EmoteMap> emotes);
static void loadChannel( static void loadChannel(
std::weak_ptr<Channel> channel, const QString &channelId, std::weak_ptr<Channel> channel, const QString &channelId,
std::function<void(EmoteMap &&)> emoteCallback, std::function<void(EmoteMap &&)> emoteCallback,
std::function<void(boost::optional<EmotePtr>)> modBadgeCallback, std::function<void(std::optional<EmotePtr>)> modBadgeCallback,
std::function<void(boost::optional<EmotePtr>)> vipBadgeCallback, std::function<void(std::optional<EmotePtr>)> vipBadgeCallback,
bool manualRefresh); bool manualRefresh);
private: private:

View file

@ -13,7 +13,7 @@
namespace chatterino { namespace chatterino {
boost::optional<EmotePtr> SeventvBadges::getBadge(const UserId &id) const std::optional<EmotePtr> SeventvBadges::getBadge(const UserId &id) const
{ {
std::shared_lock lock(this->mutex_); std::shared_lock lock(this->mutex_);
@ -22,7 +22,7 @@ boost::optional<EmotePtr> SeventvBadges::getBadge(const UserId &id) const
{ {
return it->second; return it->second;
} }
return boost::none; return std::nullopt;
} }
void SeventvBadges::assignBadgeToUser(const QString &badgeID, void SeventvBadges::assignBadgeToUser(const QString &badgeID,

View file

@ -4,10 +4,10 @@
#include "common/Singleton.hpp" #include "common/Singleton.hpp"
#include "util/QStringHash.hpp" #include "util/QStringHash.hpp"
#include <boost/optional.hpp>
#include <QJsonObject> #include <QJsonObject>
#include <memory> #include <memory>
#include <optional>
#include <shared_mutex> #include <shared_mutex>
#include <unordered_map> #include <unordered_map>
@ -20,7 +20,7 @@ class SeventvBadges : public Singleton
{ {
public: public:
// Return the badge, if any, that is assigned to the user // Return the badge, if any, that is assigned to the user
boost::optional<EmotePtr> getBadge(const UserId &id) const; std::optional<EmotePtr> getBadge(const UserId &id) const;
// Assign the given badge to the user // Assign the given badge to the user
void assignBadgeToUser(const QString &badgeID, const UserId &userID); void assignBadgeToUser(const QString &badgeID, const UserId &userID);

View file

@ -11,6 +11,7 @@
#include "providers/seventv/SeventvAPI.hpp" #include "providers/seventv/SeventvAPI.hpp"
#include "providers/twitch/TwitchChannel.hpp" #include "providers/twitch/TwitchChannel.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "util/Helpers.hpp"
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
@ -109,7 +110,7 @@ CreateEmoteResult createEmote(const QJsonObject &activeEmote,
auto emote = auto emote =
Emote({emoteName, imageSet, tooltip, Emote({emoteName, imageSet, tooltip,
Url{EMOTE_LINK_FORMAT.arg(emoteId.string)}, zeroWidth, emoteId, 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()}; return {emote, emoteId, emoteName, !emote.images.getImage1()->isEmpty()};
} }
@ -162,7 +163,7 @@ EmotePtr createUpdatedEmote(const EmotePtr &oldEmote,
bool toNonAliased = oldEmote->baseName.has_value() && bool toNonAliased = oldEmote->baseName.has_value() &&
dispatch.emoteName == oldEmote->baseName->string; 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<const Emote>(Emote( auto emote = std::make_shared<const Emote>(Emote(
{EmoteName{dispatch.emoteName}, oldEmote->images, {EmoteName{dispatch.emoteName}, oldEmote->images,
toNonAliased toNonAliased
@ -170,7 +171,7 @@ EmotePtr createUpdatedEmote(const EmotePtr &oldEmote,
: createAliasedTooltip(dispatch.emoteName, baseName.string, : createAliasedTooltip(dispatch.emoteName, baseName.string,
oldEmote->author.string, false), oldEmote->author.string, false),
oldEmote->homePage, oldEmote->zeroWidth, oldEmote->id, oldEmote->homePage, oldEmote->zeroWidth, oldEmote->id,
oldEmote->author, boost::make_optional(!toNonAliased, baseName)})); oldEmote->author, makeConditionedOptional(!toNonAliased, baseName)}));
return emote; return emote;
} }
@ -191,15 +192,14 @@ std::shared_ptr<const EmoteMap> SeventvEmotes::globalEmotes() const
return this->global_.get(); return this->global_.get();
} }
boost::optional<EmotePtr> SeventvEmotes::globalEmote( std::optional<EmotePtr> SeventvEmotes::globalEmote(const EmoteName &name) const
const EmoteName &name) const
{ {
auto emotes = this->global_.get(); auto emotes = this->global_.get();
auto it = emotes->find(name); auto it = emotes->find(name);
if (it == emotes->end()) if (it == emotes->end())
{ {
return boost::none; return std::nullopt;
} }
return it->second; return it->second;
} }
@ -328,7 +328,7 @@ void SeventvEmotes::loadChannelEmotes(
}); });
} }
boost::optional<EmotePtr> SeventvEmotes::addEmote( std::optional<EmotePtr> SeventvEmotes::addEmote(
Atomic<std::shared_ptr<const EmoteMap>> &map, Atomic<std::shared_ptr<const EmoteMap>> &map,
const EmoteAddDispatch &dispatch) const EmoteAddDispatch &dispatch)
{ {
@ -336,7 +336,7 @@ boost::optional<EmotePtr> SeventvEmotes::addEmote(
auto emoteData = dispatch.emoteJson["data"].toObject(); auto emoteData = dispatch.emoteJson["data"].toObject();
if (emoteData.empty() || !checkEmoteVisibility(emoteData)) if (emoteData.empty() || !checkEmoteVisibility(emoteData))
{ {
return boost::none; return std::nullopt;
} }
// This copies the map. // This copies the map.
@ -347,7 +347,7 @@ boost::optional<EmotePtr> SeventvEmotes::addEmote(
// Incoming emote didn't contain any images, abort // Incoming emote didn't contain any images, abort
qCDebug(chatterinoSeventv) qCDebug(chatterinoSeventv)
<< "Emote without images:" << dispatch.emoteJson; << "Emote without images:" << dispatch.emoteJson;
return boost::none; return std::nullopt;
} }
auto emote = std::make_shared<const Emote>(std::move(result.emote)); auto emote = std::make_shared<const Emote>(std::move(result.emote));
updatedMap[result.name] = emote; updatedMap[result.name] = emote;
@ -356,7 +356,7 @@ boost::optional<EmotePtr> SeventvEmotes::addEmote(
return emote; return emote;
} }
boost::optional<EmotePtr> SeventvEmotes::updateEmote( std::optional<EmotePtr> SeventvEmotes::updateEmote(
Atomic<std::shared_ptr<const EmoteMap>> &map, Atomic<std::shared_ptr<const EmoteMap>> &map,
const EmoteUpdateDispatch &dispatch) const EmoteUpdateDispatch &dispatch)
{ {
@ -364,7 +364,7 @@ boost::optional<EmotePtr> SeventvEmotes::updateEmote(
auto oldEmote = oldMap->findEmote(dispatch.emoteName, dispatch.emoteID); auto oldEmote = oldMap->findEmote(dispatch.emoteName, dispatch.emoteID);
if (oldEmote == oldMap->end()) if (oldEmote == oldMap->end())
{ {
return boost::none; return std::nullopt;
} }
// This copies the map. // This copies the map.
@ -378,7 +378,7 @@ boost::optional<EmotePtr> SeventvEmotes::updateEmote(
return emote; return emote;
} }
boost::optional<EmotePtr> SeventvEmotes::removeEmote( std::optional<EmotePtr> SeventvEmotes::removeEmote(
Atomic<std::shared_ptr<const EmoteMap>> &map, Atomic<std::shared_ptr<const EmoteMap>> &map,
const EmoteRemoveDispatch &dispatch) const EmoteRemoveDispatch &dispatch)
{ {
@ -389,7 +389,7 @@ boost::optional<EmotePtr> SeventvEmotes::removeEmote(
{ {
// We already copied the map at this point and are now discarding the copy. // We already copied the map at this point and are now discarding the copy.
// This is fine, because this case should be really rare. // This is fine, because this case should be really rare.
return boost::none; return std::nullopt;
} }
auto emote = it->second; auto emote = it->second;
updatedMap.erase(it); updatedMap.erase(it);

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "boost/optional.hpp"
#include "common/Aliases.hpp" #include "common/Aliases.hpp"
#include "common/Atomic.hpp" #include "common/Atomic.hpp"
#include "common/FlagsEnum.hpp" #include "common/FlagsEnum.hpp"
@ -8,6 +7,7 @@
#include <QJsonObject> #include <QJsonObject>
#include <memory> #include <memory>
#include <optional>
namespace chatterino { namespace chatterino {
@ -89,7 +89,7 @@ public:
SeventvEmotes(); SeventvEmotes();
std::shared_ptr<const EmoteMap> globalEmotes() const; std::shared_ptr<const EmoteMap> globalEmotes() const;
boost::optional<EmotePtr> globalEmote(const EmoteName &name) const; std::optional<EmotePtr> globalEmote(const EmoteName &name) const;
void loadGlobalEmotes(); void loadGlobalEmotes();
void setGlobalEmotes(std::shared_ptr<const EmoteMap> emotes); void setGlobalEmotes(std::shared_ptr<const EmoteMap> emotes);
static void loadChannelEmotes( static void loadChannelEmotes(
@ -104,7 +104,7 @@ public:
* *
* @return The added emote if an emote was added. * @return The added emote if an emote was added.
*/ */
static boost::optional<EmotePtr> addEmote( static std::optional<EmotePtr> addEmote(
Atomic<std::shared_ptr<const EmoteMap>> &map, Atomic<std::shared_ptr<const EmoteMap>> &map,
const seventv::eventapi::EmoteAddDispatch &dispatch); const seventv::eventapi::EmoteAddDispatch &dispatch);
@ -115,7 +115,7 @@ public:
* *
* @return The updated emote if any emote was updated. * @return The updated emote if any emote was updated.
*/ */
static boost::optional<EmotePtr> updateEmote( static std::optional<EmotePtr> updateEmote(
Atomic<std::shared_ptr<const EmoteMap>> &map, Atomic<std::shared_ptr<const EmoteMap>> &map,
const seventv::eventapi::EmoteUpdateDispatch &dispatch); const seventv::eventapi::EmoteUpdateDispatch &dispatch);
@ -126,7 +126,7 @@ public:
* *
* @return The removed emote if any emote was removed. * @return The removed emote if any emote was removed.
*/ */
static boost::optional<EmotePtr> removeEmote( static std::optional<EmotePtr> removeEmote(
Atomic<std::shared_ptr<const EmoteMap>> &map, Atomic<std::shared_ptr<const EmoteMap>> &map,
const seventv::eventapi::EmoteRemoveDispatch &dispatch); const seventv::eventapi::EmoteRemoveDispatch &dispatch);

View file

@ -2,12 +2,13 @@
#include "providers/seventv/eventapi/Subscription.hpp" #include "providers/seventv/eventapi/Subscription.hpp"
#include <boost/optional.hpp>
#include <magic_enum.hpp> #include <magic_enum.hpp>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QString> #include <QString>
#include <optional>
namespace chatterino::seventv::eventapi { namespace chatterino::seventv::eventapi {
struct Message { struct Message {
@ -18,22 +19,22 @@ struct Message {
Message(QJsonObject _json); Message(QJsonObject _json);
template <class InnerClass> template <class InnerClass>
boost::optional<InnerClass> toInner(); std::optional<InnerClass> toInner();
}; };
template <class InnerClass> template <class InnerClass>
boost::optional<InnerClass> Message::toInner() std::optional<InnerClass> Message::toInner()
{ {
return InnerClass{this->data}; return InnerClass{this->data};
} }
static boost::optional<Message> parseBaseMessage(const QString &blob) static std::optional<Message> parseBaseMessage(const QString &blob)
{ {
QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8())); QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8()));
if (jsonDoc.isNull()) if (jsonDoc.isNull())
{ {
return boost::none; return std::nullopt;
} }
return Message(jsonDoc.object()); return Message(jsonDoc.object());

View file

@ -914,7 +914,7 @@ void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *message)
c->addMessage(_message); c->addMessage(_message);
auto overrideFlags = boost::optional<MessageFlags>(_message->flags); auto overrideFlags = std::optional<MessageFlags>(_message->flags);
overrideFlags->set(MessageFlag::DoNotTriggerNotification); overrideFlags->set(MessageFlag::DoNotTriggerNotification);
overrideFlags->set(MessageFlag::DoNotLog); overrideFlags->set(MessageFlag::DoNotLog);

View file

@ -727,14 +727,14 @@ void PubSub::registerNonce(QString nonce, NonceInfo info)
this->nonces_[nonce] = std::move(info); this->nonces_[nonce] = std::move(info);
} }
boost::optional<PubSub::NonceInfo> PubSub::findNonceInfo(QString nonce) std::optional<PubSub::NonceInfo> PubSub::findNonceInfo(QString nonce)
{ {
// TODO: This should also DELETE the nonceinfo from the map // TODO: This should also DELETE the nonceinfo from the map
auto it = this->nonces_.find(nonce); auto it = this->nonces_.find(nonce);
if (it == this->nonces_.end()) if (it == this->nonces_.end())
{ {
return boost::none; return std::nullopt;
} }
return it->second; return it->second;

View file

@ -5,7 +5,6 @@
#include "util/ExponentialBackoff.hpp" #include "util/ExponentialBackoff.hpp"
#include "util/QStringHash.hpp" #include "util/QStringHash.hpp"
#include <boost/optional.hpp>
#include <pajlada/signals/signal.hpp> #include <pajlada/signals/signal.hpp>
#include <QJsonObject> #include <QJsonObject>
#include <QString> #include <QString>
@ -15,6 +14,7 @@
#include <chrono> #include <chrono>
#include <map> #include <map>
#include <memory> #include <memory>
#include <optional>
#include <thread> #include <thread>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
@ -188,7 +188,7 @@ private:
void registerNonce(QString nonce, NonceInfo nonceInfo); void registerNonce(QString nonce, NonceInfo nonceInfo);
// Find client associated with a nonce // Find client associated with a nonce
boost::optional<NonceInfo> findNonceInfo(QString nonce); std::optional<NonceInfo> findNonceInfo(QString nonce);
std::unordered_map<QString, NonceInfo> nonces_; std::unordered_map<QString, NonceInfo> nonces_;

View file

@ -149,8 +149,8 @@ void TwitchBadges::loaded()
} }
} }
boost::optional<EmotePtr> TwitchBadges::badge(const QString &set, std::optional<EmotePtr> TwitchBadges::badge(const QString &set,
const QString &version) const const QString &version) const
{ {
auto badgeSets = this->badgeSets_.access(); auto badgeSets = this->badgeSets_.access();
auto it = badgeSets->find(set); auto it = badgeSets->find(set);
@ -162,10 +162,10 @@ boost::optional<EmotePtr> TwitchBadges::badge(const QString &set,
return it2->second; return it2->second;
} }
} }
return boost::none; return std::nullopt;
} }
boost::optional<EmotePtr> TwitchBadges::badge(const QString &set) const std::optional<EmotePtr> TwitchBadges::badge(const QString &set) const
{ {
auto badgeSets = this->badgeSets_.access(); auto badgeSets = this->badgeSets_.access();
auto it = badgeSets->find(set); auto it = badgeSets->find(set);
@ -176,7 +176,7 @@ boost::optional<EmotePtr> TwitchBadges::badge(const QString &set) const
return it->second.begin()->second; return it->second.begin()->second;
} }
} }
return boost::none; return std::nullopt;
} }
void TwitchBadges::getBadgeIcon(const QString &name, BadgeIconCallback callback) void TwitchBadges::getBadgeIcon(const QString &name, BadgeIconCallback callback)

View file

@ -3,7 +3,6 @@
#include "common/UniqueAccess.hpp" #include "common/UniqueAccess.hpp"
#include "util/QStringHash.hpp" #include "util/QStringHash.hpp"
#include <boost/optional.hpp>
#include <pajlada/signals/signal.hpp> #include <pajlada/signals/signal.hpp>
#include <QIcon> #include <QIcon>
#include <QJsonObject> #include <QJsonObject>
@ -11,6 +10,7 @@
#include <QString> #include <QString>
#include <memory> #include <memory>
#include <optional>
#include <queue> #include <queue>
#include <shared_mutex> #include <shared_mutex>
#include <unordered_map> #include <unordered_map>
@ -35,10 +35,10 @@ public:
static TwitchBadges *instance(); static TwitchBadges *instance();
// Get badge from name and version // Get badge from name and version
boost::optional<EmotePtr> badge(const QString &set, std::optional<EmotePtr> badge(const QString &set,
const QString &version) const; const QString &version) const;
// Get first matching badge with name, regardless of version // Get first matching badge with name, regardless of version
boost::optional<EmotePtr> badge(const QString &set) const; std::optional<EmotePtr> badge(const QString &set) const;
void getBadgeIcon(const QString &name, BadgeIconCallback callback); void getBadgeIcon(const QString &name, BadgeIconCallback callback);
void getBadgeIcon(const DisplayBadge &badge, BadgeIconCallback callback); void getBadgeIcon(const DisplayBadge &badge, BadgeIconCallback callback);

View file

@ -35,6 +35,7 @@
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "singletons/Toasts.hpp" #include "singletons/Toasts.hpp"
#include "singletons/WindowManager.hpp" #include "singletons/WindowManager.hpp"
#include "util/Helpers.hpp"
#include "util/PostToThread.hpp" #include "util/PostToThread.hpp"
#include "util/QStringHash.hpp" #include "util/QStringHash.hpp"
#include "widgets/Window.hpp" #include "widgets/Window.hpp"
@ -396,14 +397,14 @@ bool TwitchChannel::isChannelPointRewardKnown(const QString &rewardId)
return it != pointRewards->end(); return it != pointRewards->end();
} }
boost::optional<ChannelPointReward> TwitchChannel::channelPointReward( std::optional<ChannelPointReward> TwitchChannel::channelPointReward(
const QString &rewardId) const const QString &rewardId) const
{ {
auto rewards = this->channelPointRewards_.accessConst(); auto rewards = this->channelPointRewards_.accessConst();
auto it = rewards->find(rewardId); auto it = rewards->find(rewardId);
if (it == rewards->end()) if (it == rewards->end())
return boost::none; return std::nullopt;
return it->second; return it->second;
} }
@ -751,35 +752,34 @@ SharedAccessGuard<const TwitchChannel::StreamStatus>
return this->streamStatus_.accessConst(); return this->streamStatus_.accessConst();
} }
boost::optional<EmotePtr> TwitchChannel::bttvEmote(const EmoteName &name) const std::optional<EmotePtr> TwitchChannel::bttvEmote(const EmoteName &name) const
{ {
auto emotes = this->bttvEmotes_.get(); auto emotes = this->bttvEmotes_.get();
auto it = emotes->find(name); auto it = emotes->find(name);
if (it == emotes->end()) if (it == emotes->end())
return boost::none; return std::nullopt;
return it->second; return it->second;
} }
boost::optional<EmotePtr> TwitchChannel::ffzEmote(const EmoteName &name) const std::optional<EmotePtr> TwitchChannel::ffzEmote(const EmoteName &name) const
{ {
auto emotes = this->ffzEmotes_.get(); auto emotes = this->ffzEmotes_.get();
auto it = emotes->find(name); auto it = emotes->find(name);
if (it == emotes->end()) if (it == emotes->end())
return boost::none; return std::nullopt;
return it->second; return it->second;
} }
boost::optional<EmotePtr> TwitchChannel::seventvEmote( std::optional<EmotePtr> TwitchChannel::seventvEmote(const EmoteName &name) const
const EmoteName &name) const
{ {
auto emotes = this->seventvEmotes_.get(); auto emotes = this->seventvEmotes_.get();
auto it = emotes->find(name); auto it = emotes->find(name);
if (it == emotes->end()) if (it == emotes->end())
{ {
return boost::none; return std::nullopt;
} }
return it->second; return it->second;
} }
@ -865,7 +865,7 @@ void TwitchChannel::removeBttvEmote(
} }
this->addOrReplaceLiveUpdatesAddRemove(false, "BTTV", QString() /*actor*/, this->addOrReplaceLiveUpdatesAddRemove(false, "BTTV", QString() /*actor*/,
removed.get()->name.string); (*removed)->name.string);
} }
void TwitchChannel::addSeventvEmote( void TwitchChannel::addSeventvEmote(
@ -904,7 +904,7 @@ void TwitchChannel::removeSeventvEmote(
} }
this->addOrReplaceLiveUpdatesAddRemove(false, "7TV", dispatch.actorName, this->addOrReplaceLiveUpdatesAddRemove(false, "7TV", dispatch.actorName,
removed.get()->name.string); (*removed)->name.string);
} }
void TwitchChannel::updateSeventvUser( void TwitchChannel::updateSeventvUser(
@ -955,13 +955,13 @@ void TwitchChannel::updateSeventvData(const QString &newUserID,
return; return;
} }
boost::optional<QString> oldUserID = boost::make_optional( const auto oldUserID = makeConditionedOptional(
!this->seventvUserID_.isEmpty() && this->seventvUserID_ != newUserID, !this->seventvUserID_.isEmpty() && this->seventvUserID_ != newUserID,
this->seventvUserID_); this->seventvUserID_);
boost::optional<QString> oldEmoteSetID = const auto oldEmoteSetID =
boost::make_optional(!this->seventvEmoteSetID_.isEmpty() && makeConditionedOptional(!this->seventvEmoteSetID_.isEmpty() &&
this->seventvEmoteSetID_ != newEmoteSetID, this->seventvEmoteSetID_ != newEmoteSetID,
this->seventvEmoteSetID_); this->seventvEmoteSetID_);
this->seventvUserID_ = newUserID; this->seventvUserID_ = newUserID;
this->seventvEmoteSetID_ = newEmoteSetID; this->seventvEmoteSetID_ = newEmoteSetID;
@ -974,8 +974,8 @@ void TwitchChannel::updateSeventvData(const QString &newUserID,
if (oldUserID || oldEmoteSetID) if (oldUserID || oldEmoteSetID)
{ {
getApp()->twitch->dropSeventvChannel( getApp()->twitch->dropSeventvChannel(
oldUserID.get_value_or(QString()), oldUserID.value_or(QString()),
oldEmoteSetID.get_value_or(QString())); oldEmoteSetID.value_or(QString()));
} }
} }
}); });
@ -1538,8 +1538,8 @@ void TwitchChannel::createClip()
}); });
} }
boost::optional<EmotePtr> TwitchChannel::twitchBadge( std::optional<EmotePtr> TwitchChannel::twitchBadge(const QString &set,
const QString &set, const QString &version) const const QString &version) const
{ {
auto badgeSets = this->badgeSets_.access(); auto badgeSets = this->badgeSets_.access();
auto it = badgeSets->find(set); auto it = badgeSets->find(set);
@ -1551,20 +1551,20 @@ boost::optional<EmotePtr> TwitchChannel::twitchBadge(
return it2->second; return it2->second;
} }
} }
return boost::none; return std::nullopt;
} }
boost::optional<EmotePtr> TwitchChannel::ffzCustomModBadge() const std::optional<EmotePtr> TwitchChannel::ffzCustomModBadge() const
{ {
return this->ffzCustomModBadge_.get(); return this->ffzCustomModBadge_.get();
} }
boost::optional<EmotePtr> TwitchChannel::ffzCustomVipBadge() const std::optional<EmotePtr> TwitchChannel::ffzCustomVipBadge() const
{ {
return this->ffzCustomVipBadge_.get(); return this->ffzCustomVipBadge_.get();
} }
boost::optional<CheerEmote> TwitchChannel::cheerEmote(const QString &string) std::optional<CheerEmote> TwitchChannel::cheerEmote(const QString &string)
{ {
auto sets = this->cheerEmoteSets_.access(); auto sets = this->cheerEmoteSets_.access();
for (const auto &set : *sets) for (const auto &set : *sets)
@ -1590,7 +1590,7 @@ boost::optional<CheerEmote> TwitchChannel::cheerEmote(const QString &string)
} }
} }
} }
return boost::none; return std::nullopt;
} }
void TwitchChannel::updateSevenTVActivity() void TwitchChannel::updateSevenTVActivity()

View file

@ -9,7 +9,6 @@
#include "providers/twitch/TwitchEmotes.hpp" #include "providers/twitch/TwitchEmotes.hpp"
#include "util/QStringHash.hpp" #include "util/QStringHash.hpp"
#include <boost/optional.hpp>
#include <boost/signals2.hpp> #include <boost/signals2.hpp>
#include <pajlada/signals/signalholder.hpp> #include <pajlada/signals/signalholder.hpp>
#include <QColor> #include <QColor>
@ -134,9 +133,9 @@ public:
SharedAccessGuard<const StreamStatus> accessStreamStatus() const; SharedAccessGuard<const StreamStatus> accessStreamStatus() const;
// Emotes // Emotes
boost::optional<EmotePtr> bttvEmote(const EmoteName &name) const; std::optional<EmotePtr> bttvEmote(const EmoteName &name) const;
boost::optional<EmotePtr> ffzEmote(const EmoteName &name) const; std::optional<EmotePtr> ffzEmote(const EmoteName &name) const;
boost::optional<EmotePtr> seventvEmote(const EmoteName &name) const; std::optional<EmotePtr> seventvEmote(const EmoteName &name) const;
std::shared_ptr<const EmoteMap> bttvEmotes() const; std::shared_ptr<const EmoteMap> bttvEmotes() const;
std::shared_ptr<const EmoteMap> ffzEmotes() const; std::shared_ptr<const EmoteMap> ffzEmotes() const;
std::shared_ptr<const EmoteMap> seventvEmotes() const; std::shared_ptr<const EmoteMap> seventvEmotes() const;
@ -172,13 +171,13 @@ public:
const QString &newEmoteSetID); const QString &newEmoteSetID);
// Badges // Badges
boost::optional<EmotePtr> ffzCustomModBadge() const; std::optional<EmotePtr> ffzCustomModBadge() const;
boost::optional<EmotePtr> ffzCustomVipBadge() const; std::optional<EmotePtr> ffzCustomVipBadge() const;
boost::optional<EmotePtr> twitchBadge(const QString &set, std::optional<EmotePtr> twitchBadge(const QString &set,
const QString &version) const; const QString &version) const;
// Cheers // Cheers
boost::optional<CheerEmote> cheerEmote(const QString &string); std::optional<CheerEmote> cheerEmote(const QString &string);
// Replies // Replies
/** /**
@ -217,7 +216,7 @@ public:
channelPointRewardAdded; channelPointRewardAdded;
void addChannelPointReward(const ChannelPointReward &reward); void addChannelPointReward(const ChannelPointReward &reward);
bool isChannelPointRewardKnown(const QString &rewardId); bool isChannelPointRewardKnown(const QString &rewardId);
boost::optional<ChannelPointReward> channelPointReward( std::optional<ChannelPointReward> channelPointReward(
const QString &rewardId) const; const QString &rewardId) const;
// Live status // Live status
@ -342,8 +341,8 @@ protected:
Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_; Atomic<std::shared_ptr<const EmoteMap>> bttvEmotes_;
Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_; Atomic<std::shared_ptr<const EmoteMap>> ffzEmotes_;
Atomic<std::shared_ptr<const EmoteMap>> seventvEmotes_; Atomic<std::shared_ptr<const EmoteMap>> seventvEmotes_;
Atomic<boost::optional<EmotePtr>> ffzCustomModBadge_; Atomic<std::optional<EmotePtr>> ffzCustomModBadge_;
Atomic<boost::optional<EmotePtr>> ffzCustomVipBadge_; Atomic<std::optional<EmotePtr>> ffzCustomVipBadge_;
private: private:
// Badges // Badges

View file

@ -228,8 +228,8 @@ MessagePtr TwitchMessageBuilder::build()
this->args.channelPointRewardId); this->args.channelPointRewardId);
if (reward) if (reward)
{ {
this->appendChannelPointRewardMessage( TwitchMessageBuilder::appendChannelPointRewardMessage(
reward.get(), this, this->channel->isMod(), *reward, this, this->channel->isMod(),
this->channel->isBroadcaster()); this->channel->isBroadcaster());
} }
} }
@ -1069,7 +1069,7 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
const auto &globalSeventvEmotes = app->twitch->getSeventvEmotes(); const auto &globalSeventvEmotes = app->twitch->getSeventvEmotes();
auto flags = MessageElementFlags(); auto flags = MessageElementFlags();
auto emote = boost::optional<EmotePtr>{}; auto emote = std::optional<EmotePtr>{};
bool zeroWidth = false; bool zeroWidth = false;
// Emote order: // Emote order:
@ -1115,7 +1115,7 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
!this->isEmpty()) !this->isEmpty())
{ {
// Attempt to merge current zero-width emote into any previous emotes // Attempt to merge current zero-width emote into any previous emotes
auto asEmote = dynamic_cast<EmoteElement *>(&this->back()); auto *asEmote = dynamic_cast<EmoteElement *>(&this->back());
if (asEmote) if (asEmote)
{ {
// Make sure to access asEmote before taking ownership when releasing // Make sure to access asEmote before taking ownership when releasing
@ -1124,18 +1124,18 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
auto baseEmoteElement = this->releaseBack(); auto baseEmoteElement = this->releaseBack();
std::vector<LayeredEmoteElement::Emote> layers = { std::vector<LayeredEmoteElement::Emote> layers = {
{baseEmote, baseEmoteElement->getFlags()}, {baseEmote, baseEmoteElement->getFlags()}, {*emote, flags}};
{emote.get(), flags}};
this->emplace<LayeredEmoteElement>( this->emplace<LayeredEmoteElement>(
std::move(layers), baseEmoteElement->getFlags() | flags, std::move(layers), baseEmoteElement->getFlags() | flags,
this->textColor_); this->textColor_);
return Success; return Success;
} }
auto asLayered = dynamic_cast<LayeredEmoteElement *>(&this->back()); auto *asLayered =
dynamic_cast<LayeredEmoteElement *>(&this->back());
if (asLayered) if (asLayered)
{ {
asLayered->addEmoteLayer({emote.get(), flags}); asLayered->addEmoteLayer({*emote, flags});
asLayered->addFlags(flags); asLayered->addFlags(flags);
return Success; return Success;
} }
@ -1143,15 +1143,15 @@ Outcome TwitchMessageBuilder::tryAppendEmote(const EmoteName &name)
// No emote to merge with, just show as regular emote // No emote to merge with, just show as regular emote
} }
this->emplace<EmoteElement>(emote.get(), flags, this->textColor_); this->emplace<EmoteElement>(*emote, flags, this->textColor_);
return Success; return Success;
} }
return Failure; return Failure;
} }
boost::optional<EmotePtr> TwitchMessageBuilder::getTwitchBadge( std::optional<EmotePtr> TwitchMessageBuilder::getTwitchBadge(
const Badge &badge) const Badge &badge) const
{ {
if (auto channelBadge = if (auto channelBadge =
this->twitchChannel->twitchBadge(badge.key_, badge.value_)) this->twitchChannel->twitchBadge(badge.key_, badge.value_))
@ -1165,7 +1165,7 @@ boost::optional<EmotePtr> TwitchMessageBuilder::getTwitchBadge(
return globalBadge; return globalBadge;
} }
return boost::none; return std::nullopt;
} }
std::unordered_map<QString, QString> TwitchMessageBuilder::parseBadgeInfoTag( std::unordered_map<QString, QString> TwitchMessageBuilder::parseBadgeInfoTag(
@ -1248,7 +1248,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
if (auto customModBadge = this->twitchChannel->ffzCustomModBadge()) if (auto customModBadge = this->twitchChannel->ffzCustomModBadge())
{ {
this->emplace<ModBadgeElement>( this->emplace<ModBadgeElement>(
customModBadge.get(), *customModBadge,
MessageElementFlag::BadgeChannelAuthority) MessageElementFlag::BadgeChannelAuthority)
->setTooltip((*customModBadge)->tooltip.string); ->setTooltip((*customModBadge)->tooltip.string);
// early out, since we have to add a custom badge element here // early out, since we have to add a custom badge element here
@ -1260,7 +1260,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
if (auto customVipBadge = this->twitchChannel->ffzCustomVipBadge()) if (auto customVipBadge = this->twitchChannel->ffzCustomVipBadge())
{ {
this->emplace<VipBadgeElement>( this->emplace<VipBadgeElement>(
customVipBadge.get(), *customVipBadge,
MessageElementFlag::BadgeChannelAuthority) MessageElementFlag::BadgeChannelAuthority)
->setTooltip((*customVipBadge)->tooltip.string); ->setTooltip((*customVipBadge)->tooltip.string);
// early out, since we have to add a custom badge element here // early out, since we have to add a custom badge element here
@ -1302,7 +1302,7 @@ void TwitchMessageBuilder::appendTwitchBadges()
} }
} }
this->emplace<BadgeElement>(badgeEmote.get(), badge.flag_) this->emplace<BadgeElement>(*badgeEmote, badge.flag_)
->setTooltip(tooltip); ->setTooltip(tooltip);
} }

View file

@ -4,11 +4,11 @@
#include "common/Outcome.hpp" #include "common/Outcome.hpp"
#include "messages/SharedMessageBuilder.hpp" #include "messages/SharedMessageBuilder.hpp"
#include <boost/optional.hpp>
#include <IrcMessage> #include <IrcMessage>
#include <QString> #include <QString>
#include <QVariant> #include <QVariant>
#include <optional>
#include <unordered_map> #include <unordered_map>
namespace chatterino { namespace chatterino {
@ -108,7 +108,7 @@ private:
void runIgnoreReplaces(std::vector<TwitchEmoteOccurrence> &twitchEmotes); void runIgnoreReplaces(std::vector<TwitchEmoteOccurrence> &twitchEmotes);
boost::optional<EmotePtr> getTwitchBadge(const Badge &badge); std::optional<EmotePtr> getTwitchBadge(const Badge &badge) const;
Outcome tryAppendEmote(const EmoteName &name) override; Outcome tryAppendEmote(const EmoteName &name) override;
void addWords(const QStringList &words, void addWords(const QStringList &words,

View file

@ -1741,7 +1741,7 @@ void Helix::updateEmoteMode(
void Helix::updateFollowerMode( void Helix::updateFollowerMode(
QString broadcasterID, QString moderatorID, QString broadcasterID, QString moderatorID,
boost::optional<int> followerModeDuration, std::optional<int> followerModeDuration,
ResultCallback<HelixChatSettings> successCallback, ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback) FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback)
{ {
@ -1758,7 +1758,7 @@ void Helix::updateFollowerMode(
void Helix::updateNonModeratorChatDelay( void Helix::updateNonModeratorChatDelay(
QString broadcasterID, QString moderatorID, QString broadcasterID, QString moderatorID,
boost::optional<int> nonModeratorChatDelayDuration, std::optional<int> nonModeratorChatDelayDuration,
ResultCallback<HelixChatSettings> successCallback, ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback) FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback)
{ {
@ -1777,7 +1777,7 @@ void Helix::updateNonModeratorChatDelay(
void Helix::updateSlowMode( void Helix::updateSlowMode(
QString broadcasterID, QString moderatorID, QString broadcasterID, QString moderatorID,
boost::optional<int> slowModeWaitTime, std::optional<int> slowModeWaitTime,
ResultCallback<HelixChatSettings> successCallback, ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback) FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback)
{ {
@ -2138,7 +2138,7 @@ void Helix::fetchModerators(
// Ban/timeout a user // Ban/timeout a user
// https://dev.twitch.tv/docs/api/reference#ban-user // https://dev.twitch.tv/docs/api/reference#ban-user
void Helix::banUser(QString broadcasterID, QString moderatorID, QString userID, void Helix::banUser(QString broadcasterID, QString moderatorID, QString userID,
boost::optional<int> duration, QString reason, std::optional<int> duration, QString reason,
ResultCallback<> successCallback, ResultCallback<> successCallback,
FailureCallback<HelixBanUserError, QString> failureCallback) FailureCallback<HelixBanUserError, QString> failureCallback)
{ {
@ -2890,14 +2890,14 @@ NetworkRequest Helix::makeRequest(const QString &url, const QUrlQuery &urlQuery,
{ {
qCDebug(chatterinoTwitch) qCDebug(chatterinoTwitch)
<< "Helix::makeRequest called without a client ID set BabyRage"; << "Helix::makeRequest called without a client ID set BabyRage";
// return boost::none; // return std::nullopt;
} }
if (this->oauthToken.isEmpty()) if (this->oauthToken.isEmpty())
{ {
qCDebug(chatterinoTwitch) qCDebug(chatterinoTwitch)
<< "Helix::makeRequest called without an oauth token set BabyRage"; << "Helix::makeRequest called without an oauth token set BabyRage";
// return boost::none; // return std::nullopt;
} }
const QString baseUrl("https://api.twitch.tv/helix/"); const QString baseUrl("https://api.twitch.tv/helix/");

View file

@ -3,9 +3,9 @@
#include "common/Aliases.hpp" #include "common/Aliases.hpp"
#include "common/NetworkRequest.hpp" #include "common/NetworkRequest.hpp"
#include "providers/twitch/TwitchEmotes.hpp" #include "providers/twitch/TwitchEmotes.hpp"
#include "util/Helpers.hpp"
#include "util/QStringHash.hpp" #include "util/QStringHash.hpp"
#include <boost/optional.hpp>
#include <QDateTime> #include <QDateTime>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonObject> #include <QJsonObject>
@ -15,6 +15,7 @@
#include <QUrlQuery> #include <QUrlQuery>
#include <functional> #include <functional>
#include <optional>
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
@ -277,24 +278,23 @@ struct HelixChannelEmote {
struct HelixChatSettings { struct HelixChatSettings {
const QString broadcasterId; const QString broadcasterId;
const bool emoteMode; const bool emoteMode;
// boost::none if disabled // std::nullopt if disabled
const boost::optional<int> followerModeDuration; // time in minutes const std::optional<int> followerModeDuration; // time in minutes
const boost::optional<int> const std::optional<int> nonModeratorChatDelayDuration; // time in seconds
nonModeratorChatDelayDuration; // time in seconds const std::optional<int> slowModeWaitTime; // time in seconds
const boost::optional<int> slowModeWaitTime; // time in seconds
const bool subscriberMode; const bool subscriberMode;
const bool uniqueChatMode; const bool uniqueChatMode;
explicit HelixChatSettings(QJsonObject jsonObject) explicit HelixChatSettings(QJsonObject jsonObject)
: broadcasterId(jsonObject.value("broadcaster_id").toString()) : broadcasterId(jsonObject.value("broadcaster_id").toString())
, emoteMode(jsonObject.value("emote_mode").toBool()) , emoteMode(jsonObject.value("emote_mode").toBool())
, followerModeDuration(boost::make_optional( , followerModeDuration(makeConditionedOptional(
jsonObject.value("follower_mode").toBool(), jsonObject.value("follower_mode").toBool(),
jsonObject.value("follower_mode_duration").toInt())) 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").toBool(),
jsonObject.value("non_moderator_chat_delay_duration").toInt())) jsonObject.value("non_moderator_chat_delay_duration").toInt()))
, slowModeWaitTime(boost::make_optional( , slowModeWaitTime(makeConditionedOptional(
jsonObject.value("slow_mode").toBool(), jsonObject.value("slow_mode").toBool(),
jsonObject.value("slow_mode_wait_time").toInt())) jsonObject.value("slow_mode_wait_time").toInt()))
, subscriberMode(jsonObject.value("subscriber_mode").toBool()) , subscriberMode(jsonObject.value("subscriber_mode").toBool())
@ -908,7 +908,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#update-chat-settings // https://dev.twitch.tv/docs/api/reference#update-chat-settings
virtual void updateFollowerMode( virtual void updateFollowerMode(
QString broadcasterID, QString moderatorID, QString broadcasterID, QString moderatorID,
boost::optional<int> followerModeDuration, std::optional<int> followerModeDuration,
ResultCallback<HelixChatSettings> successCallback, ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback) = 0; failureCallback) = 0;
@ -917,7 +917,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#update-chat-settings // https://dev.twitch.tv/docs/api/reference#update-chat-settings
virtual void updateNonModeratorChatDelay( virtual void updateNonModeratorChatDelay(
QString broadcasterID, QString moderatorID, QString broadcasterID, QString moderatorID,
boost::optional<int> nonModeratorChatDelayDuration, std::optional<int> nonModeratorChatDelayDuration,
ResultCallback<HelixChatSettings> successCallback, ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback) = 0; failureCallback) = 0;
@ -926,7 +926,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#update-chat-settings // https://dev.twitch.tv/docs/api/reference#update-chat-settings
virtual void updateSlowMode( virtual void updateSlowMode(
QString broadcasterID, QString moderatorID, QString broadcasterID, QString moderatorID,
boost::optional<int> slowModeWaitTime, std::optional<int> slowModeWaitTime,
ResultCallback<HelixChatSettings> successCallback, ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback) = 0; failureCallback) = 0;
@ -951,7 +951,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#ban-user // https://dev.twitch.tv/docs/api/reference#ban-user
virtual void banUser( virtual void banUser(
QString broadcasterID, QString moderatorID, QString userID, QString broadcasterID, QString moderatorID, QString userID,
boost::optional<int> duration, QString reason, std::optional<int> duration, QString reason,
ResultCallback<> successCallback, ResultCallback<> successCallback,
FailureCallback<HelixBanUserError, QString> failureCallback) = 0; FailureCallback<HelixBanUserError, QString> failureCallback) = 0;
@ -1224,7 +1224,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#update-chat-settings // https://dev.twitch.tv/docs/api/reference#update-chat-settings
void updateFollowerMode( void updateFollowerMode(
QString broadcasterID, QString moderatorID, QString broadcasterID, QString moderatorID,
boost::optional<int> followerModeDuration, std::optional<int> followerModeDuration,
ResultCallback<HelixChatSettings> successCallback, ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback) FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback)
final; final;
@ -1233,7 +1233,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#update-chat-settings // https://dev.twitch.tv/docs/api/reference#update-chat-settings
void updateNonModeratorChatDelay( void updateNonModeratorChatDelay(
QString broadcasterID, QString moderatorID, QString broadcasterID, QString moderatorID,
boost::optional<int> nonModeratorChatDelayDuration, std::optional<int> nonModeratorChatDelayDuration,
ResultCallback<HelixChatSettings> successCallback, ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback) FailureCallback<HelixUpdateChatSettingsError, QString> failureCallback)
final; final;
@ -1241,7 +1241,7 @@ public:
// Updates the slow mode using // Updates the slow mode using
// https://dev.twitch.tv/docs/api/reference#update-chat-settings // https://dev.twitch.tv/docs/api/reference#update-chat-settings
void updateSlowMode(QString broadcasterID, QString moderatorID, void updateSlowMode(QString broadcasterID, QString moderatorID,
boost::optional<int> slowModeWaitTime, std::optional<int> slowModeWaitTime,
ResultCallback<HelixChatSettings> successCallback, ResultCallback<HelixChatSettings> successCallback,
FailureCallback<HelixUpdateChatSettingsError, QString> FailureCallback<HelixUpdateChatSettingsError, QString>
failureCallback) final; failureCallback) final;
@ -1266,7 +1266,7 @@ public:
// https://dev.twitch.tv/docs/api/reference#ban-user // https://dev.twitch.tv/docs/api/reference#ban-user
void banUser( void banUser(
QString broadcasterID, QString moderatorID, QString userID, QString broadcasterID, QString moderatorID, QString userID,
boost::optional<int> duration, QString reason, std::optional<int> duration, QString reason,
ResultCallback<> successCallback, ResultCallback<> successCallback,
FailureCallback<HelixBanUserError, QString> failureCallback) final; FailureCallback<HelixBanUserError, QString> failureCallback) final;

View file

@ -1,11 +1,12 @@
#pragma once #pragma once
#include <boost/optional.hpp>
#include <magic_enum.hpp> #include <magic_enum.hpp>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QString> #include <QString>
#include <optional>
namespace chatterino { namespace chatterino {
struct PubSubMessage { struct PubSubMessage {
@ -27,16 +28,16 @@ struct PubSubMessage {
PubSubMessage(QJsonObject _object); PubSubMessage(QJsonObject _object);
template <class InnerClass> template <class InnerClass>
boost::optional<InnerClass> toInner(); std::optional<InnerClass> toInner();
}; };
template <class InnerClass> template <class InnerClass>
boost::optional<InnerClass> PubSubMessage::toInner() std::optional<InnerClass> PubSubMessage::toInner()
{ {
auto dataValue = this->object.value("data"); auto dataValue = this->object.value("data");
if (!dataValue.isObject()) if (!dataValue.isObject())
{ {
return boost::none; return std::nullopt;
} }
auto data = dataValue.toObject(); auto data = dataValue.toObject();
@ -44,14 +45,13 @@ boost::optional<InnerClass> PubSubMessage::toInner()
return InnerClass{this->nonce, data}; return InnerClass{this->nonce, data};
} }
static boost::optional<PubSubMessage> parsePubSubBaseMessage( static std::optional<PubSubMessage> parsePubSubBaseMessage(const QString &blob)
const QString &blob)
{ {
QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8())); QJsonDocument jsonDoc(QJsonDocument::fromJson(blob.toUtf8()));
if (jsonDoc.isNull()) if (jsonDoc.isNull())
{ {
return boost::none; return std::nullopt;
} }
return PubSubMessage(jsonDoc.object()); return PubSubMessage(jsonDoc.object());

View file

@ -2,11 +2,12 @@
#include "common/QLogging.hpp" #include "common/QLogging.hpp"
#include <boost/optional.hpp>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QString> #include <QString>
#include <optional>
namespace chatterino { namespace chatterino {
struct PubSubMessageMessage { struct PubSubMessageMessage {
@ -42,15 +43,15 @@ struct PubSubMessageMessage {
} }
template <class InnerClass> template <class InnerClass>
boost::optional<InnerClass> toInner() const; std::optional<InnerClass> toInner() const;
}; };
template <class InnerClass> template <class InnerClass>
boost::optional<InnerClass> PubSubMessageMessage::toInner() const std::optional<InnerClass> PubSubMessageMessage::toInner() const
{ {
if (this->messageObject.empty()) if (this->messageObject.empty())
{ {
return boost::none; return std::nullopt;
} }
return InnerClass{this->messageObject}; return InnerClass{this->messageObject};

View file

@ -312,9 +312,9 @@ void NativeMessagingServer::syncChannels(const QJsonArray &twitchChannels)
this->channelWarmer_ = std::move(updated); this->channelWarmer_ = std::move(updated);
} }
Atomic<boost::optional<QString>> &nmIpcError() Atomic<std::optional<QString>> &nmIpcError()
{ {
static Atomic<boost::optional<QString>> x; static Atomic<std::optional<QString>> x;
return x; return x;
} }

View file

@ -2,10 +2,10 @@
#include "common/Atomic.hpp" #include "common/Atomic.hpp"
#include <boost/optional.hpp>
#include <QString> #include <QString>
#include <QThread> #include <QThread>
#include <optional>
#include <vector> #include <vector>
namespace chatterino { namespace chatterino {
@ -19,7 +19,7 @@ using ChannelPtr = std::shared_ptr<Channel>;
void registerNmHost(Paths &paths); void registerNmHost(Paths &paths);
std::string &getNmQueueName(Paths &paths); std::string &getNmQueueName(Paths &paths);
Atomic<boost::optional<QString>> &nmIpcError(); Atomic<std::optional<QString>> &nmIpcError();
namespace nm::client { namespace nm::client {

View file

@ -83,7 +83,7 @@ void Paths::initCheckPortable()
void Paths::initRootDirectory() void Paths::initRootDirectory()
{ {
assert(this->portable_.is_initialized()); assert(this->portable_.has_value());
// Root path = %APPDATA%/Chatterino or the folder that the executable // Root path = %APPDATA%/Chatterino or the folder that the executable
// resides in // resides in

View file

@ -1,8 +1,9 @@
#pragma once #pragma once
#include <boost/optional.hpp>
#include <QString> #include <QString>
#include <optional>
namespace chatterino { namespace chatterino {
class Paths class Paths
@ -51,7 +52,7 @@ private:
void initRootDirectory(); void initRootDirectory();
void initSubDirectories(); void initSubDirectories();
boost::optional<bool> portable_; std::optional<bool> portable_;
// Directory for cache files. Same as <appDataDirectory>/Misc // Directory for cache files. Same as <appDataDirectory>/Misc
QString cacheDirectory_; QString cacheDirectory_;

View file

@ -87,7 +87,7 @@ bool Settings::isMutedChannel(const QString &channelName)
return false; return false;
} }
boost::optional<QString> Settings::matchNickname(const QString &usernameText) std::optional<QString> Settings::matchNickname(const QString &usernameText)
{ {
auto nicknames = this->nicknames.readOnly(); auto nicknames = this->nicknames.readOnly();
@ -99,7 +99,7 @@ boost::optional<QString> Settings::matchNickname(const QString &usernameText)
} }
} }
return boost::none; return std::nullopt;
} }
void Settings::mute(const QString &channelName) void Settings::mute(const QString &channelName)

View file

@ -593,7 +593,7 @@ public:
bool isBlacklistedUser(const QString &username); bool isBlacklistedUser(const QString &username);
bool isMutedChannel(const QString &channelName); bool isMutedChannel(const QString &channelName);
bool toggleMutedChannel(const QString &channelName); bool toggleMutedChannel(const QString &channelName);
boost::optional<QString> matchNickname(const QString &username); std::optional<QString> matchNickname(const QString &username);
private: private:
void mute(const QString &channelName); void mute(const QString &channelName);

View file

@ -24,7 +24,6 @@
#include "widgets/splits/SplitContainer.hpp" #include "widgets/splits/SplitContainer.hpp"
#include "widgets/Window.hpp" #include "widgets/Window.hpp"
#include <boost/optional.hpp>
#include <QDebug> #include <QDebug>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
@ -34,13 +33,14 @@
#include <QScreen> #include <QScreen>
#include <chrono> #include <chrono>
#include <optional>
namespace chatterino { namespace chatterino {
namespace { namespace {
boost::optional<bool> &shouldMoveOutOfBoundsWindow() std::optional<bool> &shouldMoveOutOfBoundsWindow()
{ {
static boost::optional<bool> x; static std::optional<bool> x;
return x; return x;
} }

View file

@ -6,6 +6,7 @@
#include <QStringRef> #include <QStringRef>
#include <cmath> #include <cmath>
#include <optional>
#include <vector> #include <vector>
namespace chatterino { namespace chatterino {
@ -155,4 +156,28 @@ std::vector<T> splitListIntoBatches(const T &list, int batchSize = 100)
bool compareEmoteStrings(const QString &a, const QString &b); bool compareEmoteStrings(const QString &a, const QString &b);
template <class T>
constexpr std::optional<T> makeConditionedOptional(bool condition,
const T &value)
{
if (condition)
{
return value;
}
return std::nullopt;
}
template <class T>
constexpr std::optional<std::decay_t<T>> makeConditionedOptional(bool condition,
T &&value)
{
if (condition)
{
return std::optional<std::decay_t<T>>(std::forward<T>(value));
}
return std::nullopt;
}
} // namespace chatterino } // namespace chatterino

View file

@ -23,7 +23,7 @@
namespace { namespace {
boost::optional<QByteArray> convertToPng(QImage image) std::optional<QByteArray> convertToPng(const QImage &image)
{ {
QByteArray imageData; QByteArray imageData;
QBuffer buf(&imageData); QBuffer buf(&imageData);
@ -31,16 +31,16 @@ boost::optional<QByteArray> convertToPng(QImage image)
bool success = image.save(&buf, "png"); bool success = image.save(&buf, "png");
if (success) if (success)
{ {
return boost::optional<QByteArray>(imageData); return imageData;
}
else
{
return boost::optional<QByteArray>(boost::none);
} }
return std::nullopt;
} }
} // namespace } // namespace
namespace chatterino { namespace chatterino {
// These variables are only used from the main thread. // These variables are only used from the main thread.
static auto uploadMutex = QMutex(); static auto uploadMutex = QMutex();
static std::queue<RawImageData> uploadQueue; static std::queue<RawImageData> uploadQueue;
@ -271,10 +271,10 @@ void upload(const QMimeData *source, ChannelPtr channel,
return; return;
} }
boost::optional<QByteArray> imageData = convertToPng(img); auto imageData = convertToPng(img);
if (imageData) if (imageData)
{ {
RawImageData data = {imageData.get(), "png", localPath}; RawImageData data = {*imageData, "png", localPath};
uploadQueue.push(data); uploadQueue.push(data);
} }
else else
@ -339,11 +339,11 @@ void upload(const QMimeData *source, ChannelPtr channel,
else else
{ // not PNG, try loading it into QImage and save it to a PNG. { // not PNG, try loading it into QImage and save it to a PNG.
QImage image = qvariant_cast<QImage>(source->imageData()); auto image = qvariant_cast<QImage>(source->imageData());
boost::optional<QByteArray> imageData = convertToPng(image); auto imageData = convertToPng(image);
if (imageData) if (imageData)
{ {
uploadImageToNuuls({imageData.get(), "png", ""}, channel, uploadImageToNuuls({*imageData, "png", ""}, channel,
outputTextEdit); outputTextEdit);
} }
else else

View file

@ -22,7 +22,7 @@ using GetDpiForMonitor_ = HRESULT(CALLBACK *)(HMONITOR, MONITOR_DPI_TYPE,
UINT *, UINT *); UINT *, UINT *);
// TODO: This should be changed to `GetDpiForWindow`. // TODO: This should be changed to `GetDpiForWindow`.
boost::optional<UINT> getWindowDpi(HWND hwnd) std::optional<UINT> getWindowDpi(HWND hwnd)
{ {
static HINSTANCE shcore = LoadLibrary(L"Shcore.dll"); static HINSTANCE shcore = LoadLibrary(L"Shcore.dll");
if (shcore != nullptr) if (shcore != nullptr)
@ -41,7 +41,7 @@ boost::optional<UINT> getWindowDpi(HWND hwnd)
} }
} }
return boost::none; return std::nullopt;
} }
void flushClipboard() void flushClipboard()

View file

@ -2,15 +2,16 @@
#ifdef USEWINSDK #ifdef USEWINSDK
# include <boost/optional.hpp>
# include <QString> # include <QString>
# include <Windows.h> # include <Windows.h>
# include <optional>
namespace chatterino { namespace chatterino {
enum class AssociationQueryType { Protocol, FileExtension }; enum class AssociationQueryType { Protocol, FileExtension };
boost::optional<UINT> getWindowDpi(HWND hwnd); std::optional<UINT> getWindowDpi(HWND hwnd);
void flushClipboard(); void flushClipboard();
bool isRegisteredForStartup(); bool isRegisteredForStartup();

View file

@ -273,7 +273,7 @@ void AttachedWindow::updateWindowRect(void *_attachedPtr)
float scale = 1.f; float scale = 1.f;
if (auto dpi = getWindowDpi(attached)) if (auto dpi = getWindowDpi(attached))
{ {
scale = dpi.get() / 96.f; scale = *dpi / 96.f;
for (auto w : this->ui_.split->findChildren<BaseWidget *>()) for (auto w : this->ui_.split->findChildren<BaseWidget *>())
{ {

View file

@ -42,16 +42,15 @@ float BaseWidget::scale() const
{ {
if (this->overrideScale_) if (this->overrideScale_)
{ {
return this->overrideScale_.get(); return *this->overrideScale_;
} }
else if (auto baseWidget = dynamic_cast<BaseWidget *>(this->window()))
if (auto *baseWidget = dynamic_cast<BaseWidget *>(this->window()))
{ {
return baseWidget->scale_; return baseWidget->scale_;
} }
else
{ return 1.F;
return 1.f;
}
} }
void BaseWidget::setScale(float value) void BaseWidget::setScale(float value)
@ -65,13 +64,13 @@ void BaseWidget::setScale(float value)
this->setScaleIndependantSize(this->scaleIndependantSize()); this->setScaleIndependantSize(this->scaleIndependantSize());
} }
void BaseWidget::setOverrideScale(boost::optional<float> value) void BaseWidget::setOverrideScale(std::optional<float> value)
{ {
this->overrideScale_ = value; this->overrideScale_ = value;
this->setScale(this->scale()); this->setScale(this->scale());
} }
boost::optional<float> BaseWidget::overrideScale() const std::optional<float> BaseWidget::overrideScale() const
{ {
return this->overrideScale_; return this->overrideScale_;
} }

View file

@ -1,11 +1,12 @@
#pragma once #pragma once
#include <boost/optional.hpp>
#include <pajlada/signals/signal.hpp> #include <pajlada/signals/signal.hpp>
#include <pajlada/signals/signalholder.hpp> #include <pajlada/signals/signalholder.hpp>
#include <QShortcut> #include <QShortcut>
#include <QWidget> #include <QWidget>
#include <optional>
namespace chatterino { namespace chatterino {
class Theme; class Theme;
@ -22,8 +23,8 @@ public:
virtual float scale() const; virtual float scale() const;
pajlada::Signals::Signal<float> scaleChanged; pajlada::Signals::Signal<float> scaleChanged;
boost::optional<float> overrideScale() const; std::optional<float> overrideScale() const;
void setOverrideScale(boost::optional<float>); void setOverrideScale(std::optional<float>);
QSize scaleIndependantSize() const; QSize scaleIndependantSize() const;
int scaleIndependantWidth() const; int scaleIndependantWidth() const;
@ -56,7 +57,7 @@ protected:
private: private:
float scale_{1.f}; float scale_{1.f};
boost::optional<float> overrideScale_; std::optional<float> overrideScale_;
QSize scaleIndependantSize_; QSize scaleIndependantSize_;
std::vector<BaseWidget *> widgets_; std::vector<BaseWidget *> widgets_;

View file

@ -728,7 +728,7 @@ bool BaseWindow::handleSHOWWINDOW(MSG *msg)
if (auto dpi = getWindowDpi(msg->hwnd)) if (auto dpi = getWindowDpi(msg->hwnd))
{ {
float currentScale = (float)dpi.get() / 96.F; float currentScale = (float)dpi.value() / 96.F;
if (currentScale != this->nativeScale_) if (currentScale != this->nativeScale_)
{ {
this->nativeScale_ = currentScale; this->nativeScale_ = currentScale;

View file

@ -95,7 +95,7 @@ protected:
void updateScale(); void updateScale();
boost::optional<QColor> overrideBackgroundColor_; std::optional<QColor> overrideBackgroundColor_;
private: private:
void init(); void init();

View file

@ -70,7 +70,7 @@ void FramelessEmbedWindow::showEvent(QShowEvent *)
} }
if (auto parentHwnd = if (auto parentHwnd =
reinterpret_cast<HWND>(getArgs().parentWindowId.get())) reinterpret_cast<HWND>(getArgs().parentWindowId.value()))
{ {
auto handle = reinterpret_cast<HWND>(this->winId()); auto handle = reinterpret_cast<HWND>(this->winId());
if (!::SetParent(handle, parentHwnd)) if (!::SetParent(handle, parentHwnd))

View file

@ -2,11 +2,11 @@
#include "util/DisplayBadge.hpp" #include "util/DisplayBadge.hpp"
#include <boost/optional.hpp>
#include <QComboBox> #include <QComboBox>
#include <QDialog> #include <QDialog>
#include <memory> #include <memory>
#include <optional>
namespace chatterino { namespace chatterino {
@ -14,7 +14,7 @@ class BadgePickerDialog : public QDialog,
public std::enable_shared_from_this<BadgePickerDialog> public std::enable_shared_from_this<BadgePickerDialog>
{ {
using QIconPtr = std::shared_ptr<QIcon>; using QIconPtr = std::shared_ptr<QIcon>;
using BadgeOpt = boost::optional<DisplayBadge>; using BadgeOpt = std::optional<DisplayBadge>;
public: public:
BadgePickerDialog(QList<DisplayBadge> badges, QWidget *parent = nullptr); BadgePickerDialog(QList<DisplayBadge> badges, QWidget *parent = nullptr);

View file

@ -3,9 +3,10 @@
#include "providers/irc/Irc2.hpp" #include "providers/irc/Irc2.hpp"
#include "widgets/BaseWindow.hpp" #include "widgets/BaseWindow.hpp"
#include <boost/optional.hpp>
#include <QDialog> #include <QDialog>
#include <optional>
namespace Ui { namespace Ui {
class IrcConnectionEditor; class IrcConnectionEditor;
} }

View file

@ -239,7 +239,7 @@ void ReplyThreadPopup::addMessagesFromThread()
this->ui_.threadView->setSourceChannel(sourceChannel); this->ui_.threadView->setSourceChannel(sourceChannel);
auto overrideFlags = auto overrideFlags =
boost::optional<MessageFlags>(this->thread_->root()->flags); std::optional<MessageFlags>(this->thread_->root()->flags);
overrideFlags->set(MessageFlag::DoNotLog); overrideFlags->set(MessageFlag::DoNotLog);
this->virtualChannel_->addMessage(this->thread_->root(), overrideFlags); this->virtualChannel_->addMessage(this->thread_->root(), overrideFlags);
@ -247,7 +247,7 @@ void ReplyThreadPopup::addMessagesFromThread()
{ {
if (auto msg = msgRef.lock()) if (auto msg = msgRef.lock())
{ {
auto overrideFlags = boost::optional<MessageFlags>(msg->flags); auto overrideFlags = std::optional<MessageFlags>(msg->flags);
overrideFlags->set(MessageFlag::DoNotLog); overrideFlags->set(MessageFlag::DoNotLog);
this->virtualChannel_->addMessage(msg, overrideFlags); this->virtualChannel_->addMessage(msg, overrideFlags);
@ -261,7 +261,7 @@ void ReplyThreadPopup::addMessagesFromThread()
if (message->replyThread == this->thread_) if (message->replyThread == this->thread_)
{ {
auto overrideFlags = auto overrideFlags =
boost::optional<MessageFlags>(message->flags); std::optional<MessageFlags>(message->flags);
overrideFlags->set(MessageFlag::DoNotLog); overrideFlags->set(MessageFlag::DoNotLog);
// same reply thread, add message // same reply thread, add message

View file

@ -110,7 +110,7 @@ namespace {
{ {
MessagePtr message = snapshot[i]; MessagePtr message = snapshot[i];
auto overrideFlags = boost::optional<MessageFlags>(message->flags); auto overrideFlags = std::optional<MessageFlags>(message->flags);
overrideFlags->set(MessageFlag::DoNotLog); overrideFlags->set(MessageFlag::DoNotLog);
if (checkMessageUserName(userName, message)) if (checkMessageUserName(userName, message))

View file

@ -36,7 +36,7 @@ Button::Button(BaseWidget *parent)
this->setMouseTracking(true); this->setMouseTracking(true);
} }
void Button::setMouseEffectColor(boost::optional<QColor> color) void Button::setMouseEffectColor(std::optional<QColor> color)
{ {
this->mouseEffectColor_ = std::move(color); this->mouseEffectColor_ = std::move(color);
} }
@ -185,7 +185,7 @@ void Button::fancyPaint(QPainter &painter)
if (this->mouseEffectColor_) if (this->mouseEffectColor_)
{ {
c = this->mouseEffectColor_.get(); c = *this->mouseEffectColor_;
} }
else else
{ {

View file

@ -2,7 +2,6 @@
#include "widgets/BaseWidget.hpp" #include "widgets/BaseWidget.hpp"
#include <boost/optional.hpp>
#include <QMenu> #include <QMenu>
#include <QMouseEvent> #include <QMouseEvent>
#include <QPainter> #include <QPainter>
@ -10,6 +9,8 @@
#include <QTimer> #include <QTimer>
#include <QWidget> #include <QWidget>
#include <optional>
namespace chatterino { namespace chatterino {
class Button : public BaseWidget class Button : public BaseWidget
@ -31,7 +32,7 @@ public:
Button(BaseWidget *parent = nullptr); Button(BaseWidget *parent = nullptr);
void setMouseEffectColor(boost::optional<QColor> color); void setMouseEffectColor(std::optional<QColor> color);
void setPixmap(const QPixmap &pixmap_); void setPixmap(const QPixmap &pixmap_);
const QPixmap &getPixmap() const; const QPixmap &getPixmap() const;
@ -94,7 +95,7 @@ private:
double hoverMultiplier_{0.0}; double hoverMultiplier_{0.0};
QTimer effectTimer_{}; QTimer effectTimer_{};
std::vector<ClickEffect> clickEffects_{}; std::vector<ClickEffect> clickEffects_{};
boost::optional<QColor> mouseEffectColor_{}; std::optional<QColor> mouseEffectColor_{};
std::unique_ptr<QMenu> menu_{}; std::unique_ptr<QMenu> menu_{};
}; };

View file

@ -291,13 +291,12 @@ bool ChannelView::paused() const
return this->pausable() && !this->pauses_.empty(); return this->pausable() && !this->pauses_.empty();
} }
void ChannelView::pause(PauseReason reason, boost::optional<uint> msecs) void ChannelView::pause(PauseReason reason, std::optional<uint> msecs)
{ {
if (msecs) if (msecs)
{ {
/// Msecs has a value /// Msecs has a value
auto timePoint = auto timePoint = SteadyClock::now() + std::chrono::milliseconds(*msecs);
SteadyClock::now() + std::chrono::milliseconds(msecs.get());
auto it = this->pauses_.find(reason); auto it = this->pauses_.find(reason);
if (it == this->pauses_.end()) if (it == this->pauses_.end())
@ -308,15 +307,19 @@ void ChannelView::pause(PauseReason reason, boost::optional<uint> msecs)
else else
{ {
/// If the new time point is newer then we override. /// If the new time point is newer then we override.
if (it->second && it->second.get() < timePoint) auto &previousTimePoint = it->second;
it->second = timePoint; if (previousTimePoint.has_value() &&
previousTimePoint.value() < timePoint)
{
previousTimePoint = timePoint;
}
} }
} }
else else
{ {
/// Msecs is none -> pause is infinite. /// Msecs is none -> pause is infinite.
/// We just override the value. /// We just override the value.
this->pauses_[reason] = boost::none; this->pauses_[reason] = std::nullopt;
} }
this->updatePauses(); this->updatePauses();
@ -339,7 +342,7 @@ void ChannelView::updatePauses()
this->unpaused(); this->unpaused();
/// No pauses so we can stop the timer /// No pauses so we can stop the timer
this->pauseEnd_ = boost::none; this->pauseEnd_ = std::nullopt;
this->pauseTimer_.stop(); this->pauseTimer_.stop();
this->scrollBar_->offsetMaximum(this->pauseScrollMaximumOffset_); this->scrollBar_->offsetMaximum(this->pauseScrollMaximumOffset_);
@ -355,7 +358,7 @@ void ChannelView::updatePauses()
})) }))
{ {
/// Some of the pauses are infinite /// Some of the pauses are infinite
this->pauseEnd_ = boost::none; this->pauseEnd_ = std::nullopt;
this->pauseTimer_.stop(); this->pauseTimer_.stop();
} }
else else
@ -366,7 +369,7 @@ void ChannelView::updatePauses()
[](auto &&a, auto &&b) { [](auto &&a, auto &&b) {
return a.second > b.second; return a.second > b.second;
}) })
->second.get(); ->second.value();
if (pauseEnd != this->pauseEnd_) if (pauseEnd != this->pauseEnd_)
{ {
@ -645,13 +648,12 @@ bool ChannelView::getEnableScrollingToBottom() const
return this->enableScrollingToBottom_; return this->enableScrollingToBottom_;
} }
void ChannelView::setOverrideFlags(boost::optional<MessageElementFlags> value) void ChannelView::setOverrideFlags(std::optional<MessageElementFlags> value)
{ {
this->overrideFlags_ = std::move(value); this->overrideFlags_ = std::move(value);
} }
const boost::optional<MessageElementFlags> &ChannelView::getOverrideFlags() const std::optional<MessageElementFlags> &ChannelView::getOverrideFlags() const
const
{ {
return this->overrideFlags_; return this->overrideFlags_;
} }
@ -697,7 +699,7 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel)
this->channelConnections_.managedConnect( this->channelConnections_.managedConnect(
underlyingChannel->messageAppended, underlyingChannel->messageAppended,
[this](MessagePtr &message, [this](MessagePtr &message,
boost::optional<MessageFlags> overridingFlags) { std::optional<MessageFlags> overridingFlags) {
if (this->shouldIncludeMessage(message)) if (this->shouldIncludeMessage(message))
{ {
if (this->channel_->lastDate_ != QDate::currentDate()) if (this->channel_->lastDate_ != QDate::currentDate())
@ -713,12 +715,12 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel)
// logging will be handled. Prevent duplications. // logging will be handled. Prevent duplications.
if (overridingFlags) if (overridingFlags)
{ {
overridingFlags.get().set(MessageFlag::DoNotLog); overridingFlags->set(MessageFlag::DoNotLog);
} }
else else
{ {
overridingFlags = MessageFlags(message->flags); overridingFlags = MessageFlags(message->flags);
overridingFlags.get().set(MessageFlag::DoNotLog); overridingFlags->set(MessageFlag::DoNotLog);
} }
this->channel_->addMessage(message, overridingFlags); this->channel_->addMessage(message, overridingFlags);
@ -764,7 +766,7 @@ void ChannelView::setChannel(ChannelPtr underlyingChannel)
this->channelConnections_.managedConnect( this->channelConnections_.managedConnect(
this->channel_->messageAppended, this->channel_->messageAppended,
[this](MessagePtr &message, [this](MessagePtr &message,
boost::optional<MessageFlags> overridingFlags) { std::optional<MessageFlags> overridingFlags) {
this->messageAppended(message, std::move(overridingFlags)); this->messageAppended(message, std::move(overridingFlags));
}); });
@ -880,12 +882,12 @@ bool ChannelView::hasSourceChannel() const
} }
void ChannelView::messageAppended(MessagePtr &message, void ChannelView::messageAppended(MessagePtr &message,
boost::optional<MessageFlags> overridingFlags) std::optional<MessageFlags> overridingFlags)
{ {
auto *messageFlags = &message->flags; auto *messageFlags = &message->flags;
if (overridingFlags) if (overridingFlags)
{ {
messageFlags = overridingFlags.get_ptr(); messageFlags = &*overridingFlags;
} }
auto messageRef = std::make_shared<MessageLayout>(message); auto messageRef = std::make_shared<MessageLayout>(message);
@ -1109,7 +1111,7 @@ MessageElementFlags ChannelView::getFlags() const
if (this->overrideFlags_) if (this->overrideFlags_)
{ {
return this->overrideFlags_.get(); return *this->overrideFlags_;
} }
MessageElementFlags flags = app->windows->getWordFlags(); MessageElementFlags flags = app->windows->getWordFlags();

View file

@ -93,8 +93,8 @@ public:
void setEnableScrollingToBottom(bool); void setEnableScrollingToBottom(bool);
bool getEnableScrollingToBottom() const; bool getEnableScrollingToBottom() const;
void setOverrideFlags(boost::optional<MessageElementFlags> value); void setOverrideFlags(std::optional<MessageElementFlags> value);
const boost::optional<MessageElementFlags> &getOverrideFlags() const; const std::optional<MessageElementFlags> &getOverrideFlags() const;
void updateLastReadMessage(); void updateLastReadMessage();
/** /**
@ -112,7 +112,7 @@ public:
bool pausable() const; bool pausable() const;
void setPausable(bool value); void setPausable(bool value);
bool paused() const; bool paused() const;
void pause(PauseReason reason, boost::optional<uint> msecs = boost::none); void pause(PauseReason reason, std::optional<uint> msecs = std::nullopt);
void unpause(PauseReason reason); void unpause(PauseReason reason);
MessageElementFlags getFlags() const; MessageElementFlags getFlags() const;
@ -195,7 +195,7 @@ private:
void initializeSignals(); void initializeSignals();
void messageAppended(MessagePtr &message, void messageAppended(MessagePtr &message,
boost::optional<MessageFlags> overridingFlags); std::optional<MessageFlags> overridingFlags);
void messageAddedAtStart(std::vector<MessagePtr> &messages); void messageAddedAtStart(std::vector<MessagePtr> &messages);
void messageRemoveFromStart(MessagePtr &message); void messageRemoveFromStart(MessagePtr &message);
void messageReplaced(size_t index, MessagePtr &replacement); void messageReplaced(size_t index, MessagePtr &replacement);
@ -265,15 +265,15 @@ private:
bool pausable_ = false; bool pausable_ = false;
QTimer pauseTimer_; QTimer pauseTimer_;
std::unordered_map<PauseReason, boost::optional<SteadyClock::time_point>> std::unordered_map<PauseReason, std::optional<SteadyClock::time_point>>
pauses_; pauses_;
boost::optional<SteadyClock::time_point> pauseEnd_; std::optional<SteadyClock::time_point> pauseEnd_;
int pauseScrollMinimumOffset_ = 0; int pauseScrollMinimumOffset_ = 0;
int pauseScrollMaximumOffset_ = 0; int pauseScrollMaximumOffset_ = 0;
// Keeps track how many message indices we need to offset the selection when we resume scrolling // Keeps track how many message indices we need to offset the selection when we resume scrolling
uint32_t pauseSelectionOffset_ = 0; uint32_t pauseSelectionOffset_ = 0;
boost::optional<MessageElementFlags> overrideFlags_; std::optional<MessageElementFlags> overrideFlags_;
MessageLayoutPtr lastReadMessage_; MessageLayoutPtr lastReadMessage_;
ThreadGuard snapshotGuard_; ThreadGuard snapshotGuard_;

View file

@ -52,7 +52,7 @@ ChannelPtr SearchPopup::filter(const QString &text, const QString &channelName,
// If all predicates match, add the message to the channel // If all predicates match, add the message to the channel
if (accept) if (accept)
{ {
auto overrideFlags = boost::optional<MessageFlags>(message->flags); auto overrideFlags = std::optional<MessageFlags>(message->flags);
overrideFlags->set(MessageFlag::DoNotLog); overrideFlags->set(MessageFlag::DoNotLog);
channel->addMessage(message, overrideFlags); channel->addMessage(message, overrideFlags);

View file

@ -1,9 +1,9 @@
#include "providers/bttv/BttvLiveUpdates.hpp" #include "providers/bttv/BttvLiveUpdates.hpp"
#include <boost/optional.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <QString> #include <QString>
#include <optional>
#include <tuple> #include <tuple>
using namespace chatterino; using namespace chatterino;
@ -18,9 +18,9 @@ TEST(BttvLiveUpdates, AllEvents)
chatterino::BttvLiveUpdates liveUpdates(host); chatterino::BttvLiveUpdates liveUpdates(host);
liveUpdates.start(); liveUpdates.start();
boost::optional<BttvLiveUpdateEmoteUpdateAddMessage> addMessage; std::optional<BttvLiveUpdateEmoteUpdateAddMessage> addMessage;
boost::optional<BttvLiveUpdateEmoteUpdateAddMessage> updateMessage; std::optional<BttvLiveUpdateEmoteUpdateAddMessage> updateMessage;
boost::optional<BttvLiveUpdateEmoteRemoveMessage> removeMessage; std::optional<BttvLiveUpdateEmoteRemoveMessage> removeMessage;
std::ignore = liveUpdates.signals_.emoteAdded.connect([&](const auto &m) { std::ignore = liveUpdates.signals_.emoteAdded.connect([&](const auto &m) {
addMessage = m; addMessage = m;

View file

@ -11,7 +11,6 @@
#include "singletons/Paths.hpp" #include "singletons/Paths.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include <boost/optional/optional_io.hpp>
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <QDebug> #include <QDebug>
@ -268,7 +267,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured)
{ {
false, // alert false, // alert
false, // playsound false, // playsound
boost::none, // custom sound url std::nullopt, // custom sound url
std::make_shared<QColor>("#7fffffff"), // color std::make_shared<QColor>("#7fffffff"), // color
false, false,
}, },
@ -307,7 +306,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured)
{ {
true, // alert true, // alert
false, // playsound false, // playsound
boost::none, // custom sound url std::nullopt, // custom sound url
std::make_shared<QColor>("#7fe8b7eb"), // color std::make_shared<QColor>("#7fe8b7eb"), // color
false, //showInMentions false, //showInMentions
}, },
@ -332,7 +331,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured)
{ {
true, // alert true, // alert
false, // playsound false, // playsound
boost::none, // custom sound url std::nullopt, // custom sound url
std::make_shared<QColor>("#7fffffff"), // color std::make_shared<QColor>("#7fffffff"), // color
false, //showInMentions false, //showInMentions
}, },
@ -358,7 +357,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured)
{ {
false, // alert false, // alert
false, // playsound false, // playsound
boost::none, // custom sound url std::nullopt, // custom sound url
std::make_shared<QColor>("#7fe8b7ec"), // color std::make_shared<QColor>("#7fe8b7ec"), // color
true, // showInMentions true, // showInMentions
}, },
@ -379,7 +378,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured)
{ {
true, // alert true, // alert
false, // playsound false, // playsound
boost::none, // custom sound url std::nullopt, // custom sound url
std::make_shared<QColor>("#7ff19900"), // color std::make_shared<QColor>("#7ff19900"), // color
true, // showInMentions true, // showInMentions
}, },
@ -399,7 +398,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured)
{ {
true, // alert true, // alert
true, // playsound true, // playsound
boost::none, // custom sound url std::nullopt, // custom sound url
std::make_shared<QColor>("#7f7f3f49"), // color std::make_shared<QColor>("#7f7f3f49"), // color
true, // showInMentions true, // showInMentions
}, },
@ -420,7 +419,7 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured)
{ {
false, // alert false, // alert
false, // playsound false, // playsound
boost::none, // custom sound url std::nullopt, // custom sound url
std::make_shared<QColor>("#6fffffff"), // color std::make_shared<QColor>("#6fffffff"), // color
false, false,
}, },
@ -442,9 +441,9 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured)
.state = true, // state .state = true, // state
.result = .result =
{ {
false, // alert false, // alert
false, // playsound false, // playsound
boost::none, // custom sound url std::nullopt, // custom sound url
std::make_shared<QColor>( std::make_shared<QColor>(
HighlightPhrase:: HighlightPhrase::
FALLBACK_HIGHLIGHT_COLOR), // color FALLBACK_HIGHLIGHT_COLOR), // color
@ -468,9 +467,9 @@ TEST_F(HighlightControllerTest, LoggedInAndConfigured)
.state = true, // state .state = true, // state
.result = .result =
{ {
true, // alert true, // alert
true, // playsound true, // playsound
boost::none, // custom sound url std::nullopt, // custom sound url
std::make_shared<QColor>("#7f7f3f49"), // color std::make_shared<QColor>("#7f7f3f49"), // color
true, // showInMentions true, // showInMentions
}, },

View file

@ -13,7 +13,6 @@
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "widgets/splits/InputCompletionPopup.hpp" #include "widgets/splits/InputCompletionPopup.hpp"
#include <boost/optional/optional_io.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>

View file

@ -4,10 +4,11 @@
#include "providers/seventv/eventapi/Dispatch.hpp" #include "providers/seventv/eventapi/Dispatch.hpp"
#include "providers/seventv/eventapi/Message.hpp" #include "providers/seventv/eventapi/Message.hpp"
#include <boost/optional.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <QString> #include <QString>
#include <optional>
using namespace chatterino; using namespace chatterino;
using namespace chatterino::seventv::eventapi; using namespace chatterino::seventv::eventapi;
using namespace std::chrono_literals; using namespace std::chrono_literals;
@ -22,10 +23,10 @@ TEST(SeventvEventAPI, AllEvents)
SeventvEventAPI eventAPI(host, std::chrono::milliseconds(1000)); SeventvEventAPI eventAPI(host, std::chrono::milliseconds(1000));
eventAPI.start(); eventAPI.start();
boost::optional<EmoteAddDispatch> addDispatch; std::optional<EmoteAddDispatch> addDispatch;
boost::optional<EmoteUpdateDispatch> updateDispatch; std::optional<EmoteUpdateDispatch> updateDispatch;
boost::optional<EmoteRemoveDispatch> removeDispatch; std::optional<EmoteRemoveDispatch> removeDispatch;
boost::optional<UserConnectionUpdateDispatch> userDispatch; std::optional<UserConnectionUpdateDispatch> userDispatch;
eventAPI.signals_.emoteAdded.connect([&](const auto &d) { eventAPI.signals_.emoteAdded.connect([&](const auto &d) {
addDispatch = d; addDispatch = d;
@ -67,9 +68,9 @@ TEST(SeventvEventAPI, AllEvents)
ASSERT_EQ(rem.emoteID, QString("621d13967cc2d4e1953838ed")); ASSERT_EQ(rem.emoteID, QString("621d13967cc2d4e1953838ed"));
ASSERT_EQ(userDispatch.has_value(), false); ASSERT_EQ(userDispatch.has_value(), false);
addDispatch = boost::none; addDispatch = std::nullopt;
updateDispatch = boost::none; updateDispatch = std::nullopt;
removeDispatch = boost::none; removeDispatch = std::nullopt;
eventAPI.subscribeUser(TARGET_USER_ID, ""); eventAPI.subscribeUser(TARGET_USER_ID, "");
std::this_thread::sleep_for(50ms); std::this_thread::sleep_for(50ms);

View file

@ -5,4 +5,6 @@ echo
if [[ $REPLY =~ ^[Yy]$ ]]; then if [[ $REPLY =~ ^[Yy]$ ]]; then
find src/ \( -iname "*.hpp" -o -iname "*.cpp" \) -exec clang-format -i {} \; find src/ \( -iname "*.hpp" -o -iname "*.cpp" \) -exec clang-format -i {} \;
find tests/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 fi