This commit is contained in:
Nerixyz 2024-11-09 12:50:11 +01:00
parent 5fcb033167
commit 77ea204be0
No known key found for this signature in database
GPG key ID: 946BA188C5609CCC
4 changed files with 44 additions and 28 deletions

View file

@ -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<TimestampElement>();
builder.emplace<TextElement>(expirationText, MessageElementFlag::Text,
MessageColor::System);
builder
.emplace<TextElement>(loginPromptText, MessageElementFlag::Text,
MessageColor::Link)
->setLink({Link::OpenAccountsPage, {}});
return builder.release();
}
std::pair<MessagePtrMut, HighlightAlert> MessageBuilder::makeIrcMessage(
/* mutable */ Channel *channel, const Communi::IrcMessage *ircMessage,
const MessageParseArgs &args, /* mutable */ QString content,

View file

@ -258,6 +258,9 @@ public:
const QVariantMap &tags,
const QTime &time);
static MessagePtrMut makeAccountExpiredMessage(
const QString &expirationText);
private:
struct TextState {
TwitchChannel *twitchChannel = nullptr;

View file

@ -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<TimestampElement>();
builder.emplace<TextElement>(expirationText, MessageElementFlag::Text,
MessageColor::System);
builder
.emplace<TextElement>(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 "))

View file

@ -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,21 +412,29 @@ 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);
}
}
})
.finally(tryFlush)
.execute();