diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index 00b5eedbf..0b40163c5 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -1987,6 +1987,29 @@ MessagePtr MessageBuilder::makeLowTrustUpdateMessage( return builder.release(); } +MessagePtrMut MessageBuilder::makeAccountExpiredMessage( + const QString &expirationText) +{ + auto loginPromptText = u"Try adding your account again."_s; + + MessageBuilder builder; + auto text = expirationText % ' ' % loginPromptText; + builder->messageText = text; + builder->searchText = text; + builder->flags.set(MessageFlag::System, + MessageFlag::DoNotTriggerNotification); + + builder.emplace(); + builder.emplace(expirationText, MessageElementFlag::Text, + MessageColor::System); + builder + .emplace(loginPromptText, MessageElementFlag::Text, + MessageColor::Link) + ->setLink({Link::OpenAccountsPage, {}}); + + return builder.release(); +} + std::pair MessageBuilder::makeIrcMessage( /* mutable */ Channel *channel, const Communi::IrcMessage *ircMessage, const MessageParseArgs &args, /* mutable */ QString content, diff --git a/src/messages/MessageBuilder.hpp b/src/messages/MessageBuilder.hpp index 122348b06..298cd9f8d 100644 --- a/src/messages/MessageBuilder.hpp +++ b/src/messages/MessageBuilder.hpp @@ -258,6 +258,9 @@ public: const QVariantMap &tags, const QTime &time); + static MessagePtrMut makeAccountExpiredMessage( + const QString &expirationText); + private: struct TextState { TwitchChannel *twitchChannel = nullptr; diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index 9864b3644..91762df54 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -230,29 +230,10 @@ MessagePtr parseNoticeMessage(Communi::IrcNoticeMessage *message) if (message->content().startsWith("Login auth", Qt::CaseInsensitive)) { - const auto linkColor = MessageColor(MessageColor::Link); - const auto accountsLink = Link(Link::OpenAccountsPage, QString()); const auto curUser = getApp()->getAccounts()->twitch.getCurrent(); - const auto expirationText = QString("Login expired for user \"%1\"!") - .arg(curUser->getUserName()); - const auto loginPromptText = QString("Try adding your account again."); - MessageBuilder builder; - auto text = QString("%1 %2").arg(expirationText, loginPromptText); - builder.message().messageText = text; - builder.message().searchText = text; - builder.message().flags.set(MessageFlag::System); - builder.message().flags.set(MessageFlag::DoNotTriggerNotification); - - builder.emplace(); - builder.emplace(expirationText, MessageElementFlag::Text, - MessageColor::System); - builder - .emplace(loginPromptText, MessageElementFlag::Text, - linkColor) - ->setLink(accountsLink); - - return builder.release(); + return MessageBuilder::makeAccountExpiredMessage( + u"Login expired for user \"" % curUser->getUserName() % u"\"!"); } if (message->content().startsWith("You are permanently banned ")) diff --git a/src/providers/twitch/TwitchAccountManager.cpp b/src/providers/twitch/TwitchAccountManager.cpp index f74fafa69..41a651eee 100644 --- a/src/providers/twitch/TwitchAccountManager.cpp +++ b/src/providers/twitch/TwitchAccountManager.cpp @@ -7,6 +7,7 @@ #include "common/network/NetworkResult.hpp" #include "common/Outcome.hpp" #include "common/QLogging.hpp" +#include "messages/MessageBuilder.hpp" #include "providers/twitch/api/Helix.hpp" #include "providers/twitch/TwitchAccount.hpp" #include "providers/twitch/TwitchCommon.hpp" @@ -411,20 +412,28 @@ void TwitchAccountManager::refreshAccounts(bool emitChanged) }) .onError([this, account](const auto &res) { auto json = res.parseJson(); - QString message = - u"Failed to refresh OAuth token for " % - account->getUserName() % u" error: " % res.formatError() % - u" - " % json["message"_L1].toString(u"(no message)"_s); + QString message = u"Failed to refresh OAuth token for " % + account->getUserName() % u" (" % + res.formatError() % u" - " % + json["message"_L1].toString(u"no message"_s) % + u")."; qCWarning(chatterinoTwitch) << message; if (account == this->getCurrent()) { if (res.status().value_or(0) == 400) // invalid token { - message += - QStringView(u". Consider re-adding your account."); + auto msg = + MessageBuilder::makeAccountExpiredMessage(message); + getApp()->getTwitch()->forEachChannel( + [msg](const auto &chan) { + chan->addMessage(msg, MessageContext::Original); + }); + } + else + { + getApp()->getTwitch()->addGlobalSystemMessage(message); } - getApp()->getTwitch()->addGlobalSystemMessage(message); } }) .finally(tryFlush)