refactor: add Channel::addSystemMessage function (#5500)

This commit is contained in:
pajlada
2024-07-07 22:03:05 +02:00
committed by GitHub
parent 4535823ca8
commit 354079c74c
47 changed files with 443 additions and 588 deletions
+6 -8
View File
@@ -248,13 +248,12 @@ void BttvEmotes::loadChannel(std::weak_ptr<Channel> channel,
{
if (hasEmotes)
{
shared->addMessage(makeSystemMessage(
"BetterTTV channel emotes reloaded."));
shared->addSystemMessage(
"BetterTTV channel emotes reloaded.");
}
else
{
shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
shared->addSystemMessage(CHANNEL_HAS_NO_EMOTES);
}
}
})
@@ -270,8 +269,7 @@ void BttvEmotes::loadChannel(std::weak_ptr<Channel> channel,
// User does not have any BTTV emotes
if (manualRefresh)
{
shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
shared->addSystemMessage(CHANNEL_HAS_NO_EMOTES);
}
}
else
@@ -281,10 +279,10 @@ void BttvEmotes::loadChannel(std::weak_ptr<Channel> channel,
qCWarning(chatterinoBttv)
<< "Error fetching BTTV emotes for channel" << channelId
<< ", error" << errorString;
shared->addMessage(makeSystemMessage(
shared->addSystemMessage(
QStringLiteral("Failed to fetch BetterTTV channel "
"emotes. (Error: %1)")
.arg(errorString)));
.arg(errorString));
}
})
.execute();
+6 -8
View File
@@ -287,13 +287,12 @@ void FfzEmotes::loadChannel(
{
if (hasEmotes)
{
shared->addMessage(makeSystemMessage(
"FrankerFaceZ channel emotes reloaded."));
shared->addSystemMessage(
"FrankerFaceZ channel emotes reloaded.");
}
else
{
shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
shared->addSystemMessage(CHANNEL_HAS_NO_EMOTES);
}
}
})
@@ -309,8 +308,7 @@ void FfzEmotes::loadChannel(
// User does not have any FFZ emotes
if (manualRefresh)
{
shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
shared->addSystemMessage(CHANNEL_HAS_NO_EMOTES);
}
}
else
@@ -319,10 +317,10 @@ void FfzEmotes::loadChannel(
auto errorString = result.formatError();
qCWarning(LOG) << "Error fetching FFZ emotes for channel"
<< channelID << ", error" << errorString;
shared->addMessage(makeSystemMessage(
shared->addSystemMessage(
QStringLiteral("Failed to fetch FrankerFaceZ channel "
"emotes. (Error: %1)")
.arg(errorString)));
.arg(errorString));
}
})
.execute();
+3 -2
View File
@@ -1,5 +1,6 @@
#include "IrcChannel2.hpp"
#include "common/Channel.hpp"
#include "debug/AssertInGuiThread.hpp"
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
@@ -28,7 +29,7 @@ void IrcChannel::sendMessage(const QString &message)
if (message.startsWith("/"))
{
int index = message.indexOf(' ', 1);
auto index = message.indexOf(' ', 1);
QString command = message.mid(1, index - 1);
QString params = index == -1 ? "" : message.mid(index + 1);
@@ -73,7 +74,7 @@ void IrcChannel::sendMessage(const QString &message)
}
else
{
this->addMessage(makeSystemMessage("You are not connected."));
this->addSystemMessage("You are not connected.");
}
}
}
+3 -3
View File
@@ -27,7 +27,7 @@ Outcome invokeIrcCommand(const QString &commandName, const QString &allParams,
if (auto it = staticMessages.find(cmd); it != staticMessages.end())
{
channel.addMessage(makeSystemMessage(it->second));
channel.addSystemMessage(it->second);
return Success;
}
@@ -57,8 +57,8 @@ Outcome invokeIrcCommand(const QString &commandName, const QString &allParams,
{
if (params.size() < 2)
{
channel.addMessage(
makeSystemMessage("Usage: /kick <channel> <client> [message]"));
channel.addSystemMessage(
"Usage: /kick <channel> <client> [message]");
return Failure;
}
const auto &channelParam = params[0];
+4 -4
View File
@@ -84,10 +84,10 @@ void IrcServer::initializeConnectionSignals(IrcConnection *connection,
{
if (auto shared = weak.lock())
{
shared->addMessage(makeSystemMessage(
shared->addSystemMessage(
QStringLiteral("Socket error: ") +
QAbstractSocket::staticMetaObject.enumerator(index)
.valueToKey(error)));
.valueToKey(error));
}
}
});
@@ -270,7 +270,7 @@ void IrcServer::readConnectionMessageReceived(Communi::IrcMessage *message)
{
if (message->nick() == this->data_->nick)
{
shared->addMessage(makeSystemMessage("joined"));
shared->addSystemMessage("joined");
}
else
{
@@ -295,7 +295,7 @@ void IrcServer::readConnectionMessageReceived(Communi::IrcMessage *message)
{
if (message->nick() == this->data_->nick)
{
shared->addMessage(makeSystemMessage("parted"));
shared->addSystemMessage("parted");
}
else
{
+4 -4
View File
@@ -68,9 +68,9 @@ void load(
if (errorCode == "channel_not_joined" &&
!messages.empty())
{
shared->addMessage(makeSystemMessage(
shared->addSystemMessage(
"Message history service recovering, there may "
"be gaps in the message history."));
"be gaps in the message history.");
}
}
@@ -87,10 +87,10 @@ void load(
qCDebug(LOG) << "Failed to load recent messages for"
<< shared->getName();
shared->addMessage(makeSystemMessage(
shared->addSystemMessage(
QStringLiteral(
"Message history service unavailable (Error: %1)")
.arg(result.formatError())));
.arg(result.formatError()));
onError();
})
+5 -8
View File
@@ -289,13 +289,11 @@ void SeventvEmotes::loadChannelEmotes(
{
if (hasEmotes)
{
shared->addMessage(
makeSystemMessage("7TV channel emotes reloaded."));
shared->addSystemMessage("7TV channel emotes reloaded.");
}
else
{
shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
shared->addSystemMessage(CHANNEL_HAS_NO_EMOTES);
}
}
},
@@ -312,8 +310,7 @@ void SeventvEmotes::loadChannelEmotes(
<< result.parseJson();
if (manualRefresh)
{
shared->addMessage(
makeSystemMessage(CHANNEL_HAS_NO_EMOTES));
shared->addSystemMessage(CHANNEL_HAS_NO_EMOTES);
}
}
else
@@ -323,10 +320,10 @@ void SeventvEmotes::loadChannelEmotes(
qCWarning(chatterinoSeventv)
<< "Error fetching 7TV emotes for channel" << channelId
<< ", error" << errorString;
shared->addMessage(makeSystemMessage(
shared->addSystemMessage(
QStringLiteral("Failed to fetch 7TV channel "
"emotes. (Error: %1)")
.arg(errorString)));
.arg(errorString));
}
});
}
+6 -5
View File
@@ -1,6 +1,7 @@
#include "providers/twitch/IrcMessageHandler.hpp"
#include "Application.hpp"
#include "common/Channel.hpp"
#include "common/Common.hpp"
#include "common/Literals.hpp"
#include "common/QLogging.hpp"
@@ -1136,15 +1137,15 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
QString tags = message->tags().value("msg-id").toString();
if (tags == "usage_delete")
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
"Usage: /delete <msg-id> - Deletes the specified message. "
"Can't take more than one argument."));
"Can't take more than one argument.");
}
else if (tags == "bad_delete_message_error")
{
channel->addMessage(makeSystemMessage(
channel->addSystemMessage(
"There was a problem deleting the message. "
"It might be from another channel or too old to delete."));
"It might be from another channel or too old to delete.");
}
else if (tags == "host_on" || tags == "host_target_went_offline")
{
@@ -1218,7 +1219,7 @@ void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
if (message->nick() ==
getIApp()->getAccounts()->twitch.getCurrent()->getUserName())
{
twitchChannel->addMessage(makeSystemMessage("joined channel"));
twitchChannel->addSystemMessage("joined channel");
twitchChannel->joined.invoke();
}
else if (getSettings()->showJoins.getValue())
+4 -4
View File
@@ -362,8 +362,8 @@ void TwitchAccount::loadUserstateEmotes(std::weak_ptr<Channel> weakChannel)
if (auto channel = weakChannel.lock(); channel != nullptr)
{
channel->addMessage(makeSystemMessage(
"Twitch subscriber emotes reloaded."));
channel->addSystemMessage(
"Twitch subscriber emotes reloaded.");
}
},
[] {
@@ -427,7 +427,7 @@ void TwitchAccount::autoModAllow(const QString msgID, ChannelPtr channel)
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
}
@@ -473,7 +473,7 @@ void TwitchAccount::autoModDeny(const QString msgID, ChannelPtr channel)
break;
}
channel->addMessage(makeSystemMessage(errorMessage));
channel->addSystemMessage(errorMessage);
});
}
+7 -8
View File
@@ -2,7 +2,6 @@
#include "Application.hpp"
#include "common/Common.hpp"
#include "common/Env.hpp"
#include "common/network/NetworkRequest.hpp"
#include "common/network/NetworkResult.hpp"
#include "common/QLogging.hpp"
@@ -217,7 +216,7 @@ TwitchChannel::TwitchChannel(const QString &name)
// debugging
#if 0
for (int i = 0; i < 1000; i++) {
this->addMessage(makeSystemMessage("asef"));
this->addSystemMessage("asef");
}
#endif
}
@@ -1012,9 +1011,9 @@ void TwitchChannel::updateSeventvUser(
if (auto shared = weak.lock())
{
this->seventvEmotes_.set(EMPTY_EMOTE_MAP);
this->addMessage(makeSystemMessage(
this->addSystemMessage(
QString("Failed updating 7TV emote set (%1).")
.arg(reason)));
.arg(reason));
}
});
});
@@ -1512,7 +1511,7 @@ void TwitchChannel::refreshBadges()
break;
}
this->addMessage(makeSystemMessage(errorMessage));
this->addSystemMessage(errorMessage);
});
}
@@ -1600,8 +1599,8 @@ void TwitchChannel::createClip()
{
if (!this->isLive())
{
this->addMessage(makeSystemMessage(
"Cannot create clip while the channel is offline!"));
this->addSystemMessage(
"Cannot create clip while the channel is offline!");
return;
}
@@ -1616,7 +1615,7 @@ void TwitchChannel::createClip()
return;
}
this->addMessage(makeSystemMessage("Creating clip..."));
this->addSystemMessage("Creating clip...");
this->isClipCreationInProgress = true;
getHelix()->createClip(
+15 -22
View File
@@ -42,8 +42,8 @@ void sendHelixMessage(const std::shared_ptr<TwitchChannel> &channel,
auto broadcasterID = channel->roomId();
if (broadcasterID.isEmpty())
{
channel->addMessage(makeSystemMessage(
"Sending messages in this channel isn't possible."));
channel->addSystemMessage(
"Sending messages in this channel isn't possible.");
return;
}
@@ -67,14 +67,14 @@ void sendHelixMessage(const std::shared_ptr<TwitchChannel> &channel,
return;
}
auto errorMessage = [&] {
if (res.dropReason)
{
return makeSystemMessage(res.dropReason->message);
}
return makeSystemMessage("Your message was not sent.");
}();
chan->addMessage(errorMessage);
if (res.dropReason)
{
chan->addSystemMessage(res.dropReason->message);
}
else
{
chan->addSystemMessage("Your message was not sent.");
}
},
[weak = std::weak_ptr(channel)](auto error, auto message) {
auto chan = weak.lock();
@@ -112,7 +112,7 @@ void sendHelixMessage(const std::shared_ptr<TwitchChannel> &channel,
return "Unknown error: " + message;
}
}();
chan->addMessage(makeSystemMessage(errorMessage));
chan->addSystemMessage(errorMessage);
});
}
@@ -390,14 +390,13 @@ std::shared_ptr<Channel> TwitchIrcServer::getCustomChannel(
{
for (auto i = 0; i < 1000; i++)
{
channel->addMessage(makeSystemMessage(QString::number(i + 1)));
channel->addSystemMessage(QString::number(i + 1));
}
}
auto *timer = new QTimer;
QObject::connect(timer, &QTimer::timeout, [channel] {
channel->addMessage(
makeSystemMessage(QTime::currentTime().toString()));
channel->addSystemMessage(QTime::currentTime().toString());
});
timer->start(msBetweenMessages);
return timer;
@@ -562,10 +561,7 @@ bool TwitchIrcServer::prepareToSend(
{
if (this->lastErrorTimeSpeed_ + 30s < now)
{
auto errorMessage =
makeSystemMessage("You are sending messages too quickly.");
channel->addMessage(errorMessage);
channel->addSystemMessage("You are sending messages too quickly.");
this->lastErrorTimeSpeed_ = now;
}
@@ -583,10 +579,7 @@ bool TwitchIrcServer::prepareToSend(
{
if (this->lastErrorTimeAmount_ + 30s < now)
{
auto errorMessage =
makeSystemMessage("You are sending too many messages.");
channel->addMessage(errorMessage);
channel->addSystemMessage("You are sending too many messages.");
this->lastErrorTimeAmount_ = now;
}