2023-08-13 12:00:52 +02:00
|
|
|
#include "providers/twitch/IrcMessageHandler.hpp"
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "Application.hpp"
|
2023-11-08 18:14:48 +01:00
|
|
|
#include "common/Common.hpp"
|
2023-07-30 18:54:42 +02:00
|
|
|
#include "common/Literals.hpp"
|
2020-11-21 16:20:10 +01:00
|
|
|
#include "common/QLogging.hpp"
|
2019-09-18 13:03:16 +02:00
|
|
|
#include "controllers/accounts/AccountController.hpp"
|
2023-08-05 14:45:43 +02:00
|
|
|
#include "controllers/ignores/IgnoreController.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "messages/LimitedQueue.hpp"
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "messages/Link.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "messages/Message.hpp"
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "messages/MessageBuilder.hpp"
|
|
|
|
#include "messages/MessageColor.hpp"
|
|
|
|
#include "messages/MessageElement.hpp"
|
|
|
|
#include "messages/MessageThread.hpp"
|
|
|
|
#include "providers/twitch/ChannelPointReward.hpp"
|
2022-12-18 15:36:39 +01:00
|
|
|
#include "providers/twitch/TwitchAccount.hpp"
|
2019-09-18 13:03:16 +02:00
|
|
|
#include "providers/twitch/TwitchAccountManager.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "providers/twitch/TwitchChannel.hpp"
|
|
|
|
#include "providers/twitch/TwitchHelpers.hpp"
|
2019-09-18 13:03:16 +02:00
|
|
|
#include "providers/twitch/TwitchIrcServer.hpp"
|
2022-12-31 15:41:01 +01:00
|
|
|
#include "providers/twitch/TwitchMessageBuilder.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Resources.hpp"
|
2018-08-11 22:23:06 +02:00
|
|
|
#include "singletons/Settings.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "singletons/WindowManager.hpp"
|
2023-08-13 12:00:52 +02:00
|
|
|
#include "util/ChannelHelpers.hpp"
|
2021-01-31 13:55:44 +01:00
|
|
|
#include "util/FormatTime.hpp"
|
2021-04-11 14:17:21 +02:00
|
|
|
#include "util/Helpers.hpp"
|
2018-06-26 14:09:39 +02:00
|
|
|
#include "util/IrcHelpers.hpp"
|
2022-10-22 12:04:51 +02:00
|
|
|
#include "util/StreamerMode.hpp"
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-06-04 12:23:23 +02:00
|
|
|
#include <IrcMessage>
|
2023-07-30 18:54:42 +02:00
|
|
|
#include <QLocale>
|
|
|
|
#include <QStringBuilder>
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2022-07-31 12:45:25 +02:00
|
|
|
#include <memory>
|
2018-06-24 17:33:22 +02:00
|
|
|
#include <unordered_set>
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
using namespace chatterino::literals;
|
|
|
|
|
2020-12-12 14:19:51 +01:00
|
|
|
namespace {
|
2023-10-31 17:47:56 +01:00
|
|
|
|
2020-12-12 14:19:51 +01:00
|
|
|
using namespace chatterino;
|
2021-05-01 17:42:51 +02:00
|
|
|
|
|
|
|
// Message types below are the ones that might contain special user's message on USERNOTICE
|
2023-10-31 17:47:56 +01:00
|
|
|
const QSet<QString> SPECIAL_MESSAGE_TYPES{
|
2023-12-16 12:48:32 +01:00
|
|
|
"sub", //
|
|
|
|
"subgift", //
|
|
|
|
"resub", // resub messages
|
|
|
|
"bitsbadgetier", // bits badge upgrade
|
|
|
|
"ritual", // new viewer ritual
|
|
|
|
"announcement", // new mod announcement thing
|
|
|
|
"viewermilestone", // watch streak, but other categories possible in future
|
2021-05-01 17:42:51 +02:00
|
|
|
};
|
|
|
|
|
2020-12-12 14:19:51 +01:00
|
|
|
MessagePtr generateBannedMessage(bool confirmedBan)
|
|
|
|
{
|
|
|
|
const auto linkColor = MessageColor(MessageColor::Link);
|
|
|
|
const auto accountsLink = Link(Link::Reconnect, QString());
|
|
|
|
const auto bannedText =
|
|
|
|
confirmedBan
|
|
|
|
? QString("You were banned from this channel!")
|
|
|
|
: QString(
|
|
|
|
"Your connection to this channel was unexpectedly dropped.");
|
|
|
|
|
|
|
|
const auto reconnectPromptText =
|
|
|
|
confirmedBan
|
|
|
|
? QString(
|
|
|
|
"If you believe you have been unbanned, try reconnecting.")
|
|
|
|
: QString("Try reconnecting.");
|
|
|
|
|
|
|
|
MessageBuilder builder;
|
2021-07-11 12:19:35 +02:00
|
|
|
auto text = QString("%1 %2").arg(bannedText, reconnectPromptText);
|
|
|
|
builder.message().messageText = text;
|
|
|
|
builder.message().searchText = text;
|
2020-12-12 14:19:51 +01:00
|
|
|
builder.message().flags.set(MessageFlag::System);
|
|
|
|
|
|
|
|
builder.emplace<TimestampElement>();
|
|
|
|
builder.emplace<TextElement>(bannedText, MessageElementFlag::Text,
|
|
|
|
MessageColor::System);
|
|
|
|
builder
|
|
|
|
.emplace<TextElement>(reconnectPromptText, MessageElementFlag::Text,
|
|
|
|
linkColor)
|
|
|
|
->setLink(accountsLink);
|
|
|
|
|
|
|
|
return builder.release();
|
|
|
|
}
|
|
|
|
|
2022-10-08 16:25:32 +02:00
|
|
|
int stripLeadingReplyMention(const QVariantMap &tags, QString &content)
|
|
|
|
{
|
|
|
|
if (!getSettings()->stripReplyMention)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2022-12-07 22:02:54 +01:00
|
|
|
if (getSettings()->hideReplyContext)
|
|
|
|
{
|
|
|
|
// Never strip reply mentions if reply contexts are hidden
|
|
|
|
return 0;
|
|
|
|
}
|
2022-10-08 16:25:32 +02:00
|
|
|
|
|
|
|
if (const auto it = tags.find("reply-parent-display-name");
|
|
|
|
it != tags.end())
|
|
|
|
{
|
|
|
|
auto displayName = it.value().toString();
|
2022-10-12 11:59:52 +02:00
|
|
|
|
|
|
|
if (content.length() <= 1 + displayName.length())
|
|
|
|
{
|
|
|
|
// The reply contains no content
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-10-08 16:25:32 +02:00
|
|
|
if (content.startsWith('@') &&
|
|
|
|
content.at(1 + displayName.length()) == ' ' &&
|
|
|
|
content.indexOf(displayName, 1) == 1)
|
|
|
|
{
|
|
|
|
int messageOffset = 1 + displayName.length() + 1;
|
|
|
|
content.remove(0, messageOffset);
|
|
|
|
return messageOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateReplyParticipatedStatus(const QVariantMap &tags,
|
|
|
|
const QString &senderLogin,
|
|
|
|
TwitchMessageBuilder &builder,
|
|
|
|
std::shared_ptr<MessageThread> &thread,
|
|
|
|
bool isNew)
|
|
|
|
{
|
|
|
|
const auto ¤tLogin =
|
|
|
|
getApp()->accounts->twitch.getCurrent()->getUserName();
|
2023-06-17 17:41:52 +02:00
|
|
|
|
|
|
|
if (thread->subscribed())
|
|
|
|
{
|
|
|
|
builder.message().flags.set(MessageFlag::SubscribedThread);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thread->unsubscribed())
|
2022-10-08 16:25:32 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-17 17:41:52 +02:00
|
|
|
if (getSettings()->autoSubToParticipatedThreads)
|
2022-10-08 16:25:32 +02:00
|
|
|
{
|
2023-06-17 17:41:52 +02:00
|
|
|
if (isNew)
|
2022-10-08 16:25:32 +02:00
|
|
|
{
|
2023-06-17 17:41:52 +02:00
|
|
|
if (const auto it = tags.find("reply-parent-user-login");
|
|
|
|
it != tags.end())
|
2022-10-08 16:25:32 +02:00
|
|
|
{
|
2023-06-17 17:41:52 +02:00
|
|
|
auto name = it.value().toString();
|
|
|
|
if (name == currentLogin)
|
|
|
|
{
|
|
|
|
thread->markSubscribed();
|
|
|
|
builder.message().flags.set(MessageFlag::SubscribedThread);
|
|
|
|
return; // already marked as participated
|
|
|
|
}
|
2022-10-08 16:25:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-17 17:41:52 +02:00
|
|
|
if (senderLogin == currentLogin)
|
|
|
|
{
|
|
|
|
thread->markSubscribed();
|
|
|
|
// don't set the highlight here
|
|
|
|
}
|
2022-10-08 16:25:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-30 18:54:42 +02:00
|
|
|
ChannelPtr channelOrEmptyByTarget(const QString &target,
|
|
|
|
TwitchIrcServer &server)
|
|
|
|
{
|
|
|
|
QString channelName;
|
|
|
|
if (!trimChannelName(target, channelName))
|
|
|
|
{
|
|
|
|
return Channel::getEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
return server.getChannelOrEmpty(channelName);
|
|
|
|
}
|
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
float relativeSimilarity(const QString &str1, const QString &str2)
|
2020-02-02 14:31:37 +01:00
|
|
|
{
|
|
|
|
// Longest Common Substring Problem
|
|
|
|
std::vector<std::vector<int>> tree(str1.size(),
|
|
|
|
std::vector<int>(str2.size(), 0));
|
|
|
|
int z = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < str1.size(); ++i)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < str2.size(); ++j)
|
|
|
|
{
|
|
|
|
if (str1[i] == str2[j])
|
|
|
|
{
|
|
|
|
if (i == 0 || j == 0)
|
|
|
|
{
|
|
|
|
tree[i][j] = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tree[i][j] = tree[i - 1][j - 1] + 1;
|
|
|
|
}
|
|
|
|
if (tree[i][j] > z)
|
|
|
|
{
|
|
|
|
z = tree[i][j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tree[i][j] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-19 21:05:40 +02:00
|
|
|
// ensure that no div by 0
|
2023-10-31 17:47:56 +01:00
|
|
|
if (z == 0)
|
2020-02-02 14:31:37 +01:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
return 0.F;
|
2020-02-02 14:31:37 +01:00
|
|
|
}
|
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
auto div = std::max<int>(1, std::max(str1.size(), str2.size()));
|
2020-02-02 14:31:37 +01:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
return float(z) / float(div);
|
2020-02-02 14:31:37 +01:00
|
|
|
}
|
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
QMap<QString, QString> parseBadges(const QString &badgesString)
|
2019-04-13 15:26:47 +02:00
|
|
|
{
|
|
|
|
QMap<QString, QString> badges;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
for (const auto &badgeData : badgesString.split(','))
|
2019-04-13 15:26:47 +02:00
|
|
|
{
|
|
|
|
auto parts = badgeData.split('/');
|
|
|
|
if (parts.length() != 2)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-04-13 15:26:47 +02:00
|
|
|
badges.insert(parts[0], parts[1]);
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-04-13 15:26:47 +02:00
|
|
|
return badges;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
void populateReply(TwitchChannel *channel, Communi::IrcMessage *message,
|
|
|
|
const std::vector<MessagePtr> &otherLoaded,
|
|
|
|
TwitchMessageBuilder &builder)
|
2022-07-31 12:45:25 +02:00
|
|
|
{
|
|
|
|
const auto &tags = message->tags();
|
2023-11-05 17:25:26 +01:00
|
|
|
if (const auto it = tags.find("reply-thread-parent-msg-id");
|
|
|
|
it != tags.end())
|
2022-07-31 12:45:25 +02:00
|
|
|
{
|
|
|
|
const QString replyID = it.value().toString();
|
2023-10-31 17:47:56 +01:00
|
|
|
auto threadIt = channel->threads().find(replyID);
|
2023-11-05 17:25:26 +01:00
|
|
|
std::shared_ptr<MessageThread> rootThread;
|
2023-10-31 17:47:56 +01:00
|
|
|
if (threadIt != channel->threads().end())
|
2022-07-31 12:45:25 +02:00
|
|
|
{
|
2022-10-08 16:25:32 +02:00
|
|
|
auto owned = threadIt->second.lock();
|
2022-07-31 12:45:25 +02:00
|
|
|
if (owned)
|
|
|
|
{
|
|
|
|
// Thread already exists (has a reply)
|
2022-10-08 16:25:32 +02:00
|
|
|
updateReplyParticipatedStatus(tags, message->nick(), builder,
|
|
|
|
owned, false);
|
2022-07-31 12:45:25 +02:00
|
|
|
builder.setThread(owned);
|
2023-11-05 17:25:26 +01:00
|
|
|
rootThread = owned;
|
2022-07-31 12:45:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-05 17:25:26 +01:00
|
|
|
if (!rootThread)
|
2022-07-31 12:45:25 +02:00
|
|
|
{
|
2023-11-05 17:25:26 +01:00
|
|
|
MessagePtr foundMessage;
|
|
|
|
|
|
|
|
// Thread does not yet exist, find root reply and create thread.
|
|
|
|
// Linear search is justified by the infrequent use of replies
|
|
|
|
for (const auto &otherMsg : otherLoaded)
|
2022-07-31 12:45:25 +02:00
|
|
|
{
|
2023-11-05 17:25:26 +01:00
|
|
|
if (otherMsg->id == replyID)
|
|
|
|
{
|
|
|
|
// Found root reply message
|
|
|
|
foundMessage = otherMsg;
|
|
|
|
break;
|
|
|
|
}
|
2022-07-31 12:45:25 +02:00
|
|
|
}
|
2022-08-06 18:18:34 +02:00
|
|
|
|
2023-11-05 17:25:26 +01:00
|
|
|
if (!foundMessage)
|
|
|
|
{
|
|
|
|
// We didn't find the reply root message in the otherLoaded messages
|
|
|
|
// which are typically the already-parsed recent messages from the
|
|
|
|
// Recent Messages API. We could have a really old message that
|
|
|
|
// still exists being replied to, so check for that here.
|
|
|
|
foundMessage = channel->findMessage(replyID);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foundMessage)
|
|
|
|
{
|
|
|
|
std::shared_ptr<MessageThread> newThread =
|
|
|
|
std::make_shared<MessageThread>(foundMessage);
|
|
|
|
updateReplyParticipatedStatus(tags, message->nick(), builder,
|
|
|
|
newThread, true);
|
|
|
|
|
|
|
|
builder.setThread(newThread);
|
|
|
|
rootThread = newThread;
|
|
|
|
// Store weak reference to thread in channel
|
|
|
|
channel->addReplyThread(newThread);
|
|
|
|
}
|
2022-08-06 18:18:34 +02:00
|
|
|
}
|
|
|
|
|
2023-11-05 17:25:26 +01:00
|
|
|
if (const auto parentIt = tags.find("reply-parent-msg-id");
|
|
|
|
parentIt != tags.end())
|
2022-08-06 18:18:34 +02:00
|
|
|
{
|
2023-11-05 17:25:26 +01:00
|
|
|
const QString parentID = parentIt.value().toString();
|
|
|
|
if (replyID == parentID)
|
|
|
|
{
|
|
|
|
if (rootThread)
|
|
|
|
{
|
|
|
|
builder.setParent(rootThread->root());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto parentThreadIt = channel->threads().find(parentID);
|
|
|
|
if (parentThreadIt != channel->threads().end())
|
|
|
|
{
|
|
|
|
auto thread = parentThreadIt->second.lock();
|
|
|
|
if (thread)
|
|
|
|
{
|
|
|
|
builder.setParent(thread->root());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto parent = channel->findMessage(parentID);
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
builder.setParent(parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-06 18:18:34 +02:00
|
|
|
}
|
2022-07-31 12:45:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
std::optional<ClearChatMessage> parseClearChatMessage(
|
|
|
|
Communi::IrcMessage *message)
|
2018-06-04 12:23:23 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
// check parameter count
|
|
|
|
if (message->parameters().length() < 1)
|
2018-06-04 12:23:23 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
return std::nullopt;
|
2018-06-04 12:23:23 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
// check if the chat has been cleared by a moderator
|
|
|
|
if (message->parameters().length() == 1)
|
2018-06-04 12:23:23 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
return ClearChatMessage{
|
|
|
|
.message =
|
|
|
|
makeSystemMessage("Chat has been cleared by a moderator.",
|
|
|
|
calculateMessageTime(message).time()),
|
|
|
|
.disableAllMessages = true,
|
|
|
|
};
|
2018-06-04 12:23:23 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
// get username, duration and message of the timed out user
|
|
|
|
QString username = message->parameter(1);
|
|
|
|
QString durationInSeconds;
|
|
|
|
QVariant v = message->tag("ban-duration");
|
|
|
|
if (v.isValid())
|
2018-06-22 23:19:52 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
durationInSeconds = v.toString();
|
2018-06-22 23:19:52 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
auto timeoutMsg =
|
|
|
|
MessageBuilder(timeoutMessage, username, durationInSeconds, false,
|
|
|
|
calculateMessageTime(message).time())
|
|
|
|
.release();
|
2020-08-08 15:37:22 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
return ClearChatMessage{.message = timeoutMsg, .disableAllMessages = false};
|
|
|
|
}
|
2022-10-08 16:25:32 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
/**
|
|
|
|
* Parse a single IRC NOTICE message into 0 or more Chatterino messages
|
|
|
|
**/
|
|
|
|
std::vector<MessagePtr> parseNoticeMessage(Communi::IrcNoticeMessage *message)
|
|
|
|
{
|
|
|
|
assert(message != nullptr);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
if (message->content().startsWith("Login auth", Qt::CaseInsensitive))
|
2022-07-31 12:45:25 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
const auto linkColor = MessageColor(MessageColor::Link);
|
|
|
|
const auto accountsLink = Link(Link::OpenAccountsPage, QString());
|
|
|
|
const auto curUser = getApp()->accounts->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()};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->content().startsWith("You are permanently banned "))
|
|
|
|
{
|
|
|
|
return {generateBannedMessage(true)};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->tags().value("msg-id") == "msg_timedout")
|
|
|
|
{
|
|
|
|
std::vector<MessagePtr> builtMessage;
|
|
|
|
|
|
|
|
QString remainingTime =
|
|
|
|
formatTime(message->content().split(" ").value(5));
|
|
|
|
QString formattedMessage =
|
|
|
|
QString("You are timed out for %1.")
|
|
|
|
.arg(remainingTime.isEmpty() ? "0s" : remainingTime);
|
|
|
|
|
|
|
|
builtMessage.emplace_back(makeSystemMessage(
|
|
|
|
formattedMessage, calculateMessageTime(message).time()));
|
|
|
|
|
|
|
|
return builtMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
// default case
|
|
|
|
std::vector<MessagePtr> builtMessages;
|
|
|
|
|
|
|
|
auto content = message->content();
|
|
|
|
if (content.startsWith(
|
|
|
|
"Your settings prevent you from sending this whisper",
|
|
|
|
Qt::CaseInsensitive) &&
|
|
|
|
getSettings()->helixTimegateWhisper.getValue() ==
|
|
|
|
HelixTimegateOverride::Timegate)
|
|
|
|
{
|
|
|
|
content = content +
|
|
|
|
" Consider setting \"Helix timegate /w behaviour\" "
|
|
|
|
"to \"Always use Helix\" in your Chatterino settings.";
|
|
|
|
}
|
|
|
|
builtMessages.emplace_back(
|
|
|
|
makeSystemMessage(content, calculateMessageTime(message).time()));
|
|
|
|
|
|
|
|
return builtMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a single IRC USERNOTICE message into 0 or more Chatterino messages
|
|
|
|
**/
|
|
|
|
std::vector<MessagePtr> parseUserNoticeMessage(Channel *channel,
|
|
|
|
Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
assert(channel != nullptr);
|
|
|
|
assert(message != nullptr);
|
|
|
|
|
|
|
|
std::vector<MessagePtr> builtMessages;
|
|
|
|
|
|
|
|
auto tags = message->tags();
|
|
|
|
auto parameters = message->parameters();
|
|
|
|
|
|
|
|
QString msgType = tags.value("msg-id").toString();
|
|
|
|
QString content;
|
|
|
|
if (parameters.size() >= 2)
|
|
|
|
{
|
|
|
|
content = parameters[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isIgnoredMessage({
|
|
|
|
.message = content,
|
|
|
|
.twitchUserID = tags.value("user-id").toString(),
|
|
|
|
.isMod = channel->isMod(),
|
|
|
|
.isBroadcaster = channel->isBroadcaster(),
|
|
|
|
}))
|
|
|
|
{
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SPECIAL_MESSAGE_TYPES.contains(msgType))
|
|
|
|
{
|
|
|
|
// Messages are not required, so they might be empty
|
|
|
|
if (!content.isEmpty())
|
2022-07-31 12:45:25 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
MessageParseArgs args;
|
|
|
|
args.trimSubscriberUsername = true;
|
|
|
|
|
|
|
|
TwitchMessageBuilder builder(channel, message, args, content,
|
|
|
|
false);
|
|
|
|
builder->flags.set(MessageFlag::Subscription);
|
|
|
|
builder->flags.unset(MessageFlag::Highlighted);
|
|
|
|
builtMessages.emplace_back(builder.build());
|
2022-07-31 12:45:25 +02:00
|
|
|
}
|
2023-10-31 17:47:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
auto it = tags.find("system-msg");
|
|
|
|
|
|
|
|
if (it != tags.end())
|
|
|
|
{
|
|
|
|
// By default, we return value of system-msg tag
|
|
|
|
QString messageText = it.value().toString();
|
|
|
|
|
|
|
|
if (msgType == "bitsbadgetier")
|
2022-07-31 12:45:25 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
messageText =
|
|
|
|
QString("%1 just earned a new %2 Bits badge!")
|
|
|
|
.arg(tags.value("display-name").toString(),
|
|
|
|
kFormatNumbers(
|
|
|
|
tags.value("msg-param-threshold").toInt()));
|
|
|
|
}
|
|
|
|
else if (msgType == "announcement")
|
|
|
|
{
|
|
|
|
messageText = "Announcement";
|
|
|
|
}
|
2022-07-31 12:45:25 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
auto b = MessageBuilder(systemMessage, parseTagString(messageText),
|
|
|
|
calculateMessageTime(message).time());
|
|
|
|
|
|
|
|
b->flags.set(MessageFlag::Subscription);
|
|
|
|
auto newMessage = b.release();
|
|
|
|
builtMessages.emplace_back(newMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
return builtMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse a single IRC PRIVMSG into 0-1 Chatterino messages
|
|
|
|
*/
|
|
|
|
std::vector<MessagePtr> parsePrivMessage(Channel *channel,
|
|
|
|
Communi::IrcPrivateMessage *message)
|
|
|
|
{
|
|
|
|
assert(channel != nullptr);
|
|
|
|
assert(message != nullptr);
|
|
|
|
|
|
|
|
std::vector<MessagePtr> builtMessages;
|
|
|
|
MessageParseArgs args;
|
|
|
|
TwitchMessageBuilder builder(channel, message, args, message->content(),
|
|
|
|
message->isAction());
|
|
|
|
if (!builder.isIgnored())
|
|
|
|
{
|
|
|
|
builtMessages.emplace_back(builder.build());
|
|
|
|
builder.triggerHighlights();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->tags().contains(u"pinned-chat-paid-amount"_s))
|
|
|
|
{
|
|
|
|
auto ptr = TwitchMessageBuilder::buildHypeChatMessage(message);
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
builtMessages.emplace_back(std::move(ptr));
|
2022-07-31 12:45:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
return builtMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
|
|
|
using namespace literals;
|
|
|
|
|
|
|
|
IrcMessageHandler &IrcMessageHandler::instance()
|
|
|
|
{
|
|
|
|
static IrcMessageHandler instance;
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<MessagePtr> IrcMessageHandler::parseMessageWithReply(
|
|
|
|
Channel *channel, Communi::IrcMessage *message,
|
|
|
|
std::vector<MessagePtr> &otherLoaded)
|
|
|
|
{
|
|
|
|
std::vector<MessagePtr> builtMessages;
|
|
|
|
|
|
|
|
auto command = message->command();
|
|
|
|
|
|
|
|
if (command == u"PRIVMSG"_s)
|
|
|
|
{
|
|
|
|
auto *privMsg = dynamic_cast<Communi::IrcPrivateMessage *>(message);
|
|
|
|
auto *tc = dynamic_cast<TwitchChannel *>(channel);
|
|
|
|
if (!tc)
|
2018-06-04 12:23:23 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
return parsePrivMessage(channel, privMsg);
|
2018-08-07 01:35:24 +02:00
|
|
|
}
|
2020-02-02 14:31:37 +01:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
QString content = privMsg->content();
|
|
|
|
int messageOffset = stripLeadingReplyMention(privMsg->tags(), content);
|
|
|
|
MessageParseArgs args;
|
|
|
|
TwitchMessageBuilder builder(channel, message, args, content,
|
|
|
|
privMsg->isAction());
|
|
|
|
builder.setMessageOffset(messageOffset);
|
2020-02-02 14:31:37 +01:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
populateReply(tc, message, otherLoaded, builder);
|
|
|
|
|
|
|
|
if (!builder.isIgnored())
|
2020-02-02 14:31:37 +01:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
builtMessages.emplace_back(builder.build());
|
2020-02-02 14:31:37 +01:00
|
|
|
builder.triggerHighlights();
|
|
|
|
}
|
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
return builtMessages;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
if (command == u"USERNOTICE"_s)
|
|
|
|
{
|
|
|
|
return parseUserNoticeMessage(channel, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command == u"NOTICE"_s)
|
|
|
|
{
|
|
|
|
return parseNoticeMessage(
|
|
|
|
dynamic_cast<Communi::IrcNoticeMessage *>(message));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command == u"CLEARCHAT"_s)
|
|
|
|
{
|
|
|
|
auto cc = parseClearChatMessage(message);
|
|
|
|
if (!cc)
|
2018-08-07 01:35:24 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
return builtMessages;
|
|
|
|
}
|
|
|
|
auto &clearChat = *cc;
|
|
|
|
if (clearChat.disableAllMessages)
|
|
|
|
{
|
|
|
|
builtMessages.emplace_back(std::move(clearChat.message));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
addOrReplaceChannelTimeout(
|
|
|
|
otherLoaded, std::move(clearChat.message),
|
|
|
|
calculateMessageTime(message).time(),
|
|
|
|
[&](auto idx, auto /*msg*/, auto &&replacement) {
|
|
|
|
replacement->flags.set(MessageFlag::RecentMessage);
|
|
|
|
otherLoaded[idx] = replacement;
|
|
|
|
},
|
|
|
|
[&](auto &&msg) {
|
|
|
|
builtMessages.emplace_back(msg);
|
|
|
|
},
|
|
|
|
false);
|
2018-06-04 12:23:23 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
return builtMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
return builtMessages;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message,
|
|
|
|
TwitchIrcServer &server)
|
|
|
|
{
|
|
|
|
// This is for compatibility with older Chatterino versions. Twitch didn't use
|
|
|
|
// to allow ZERO WIDTH JOINER unicode character, so Chatterino used ESCAPE_TAG
|
|
|
|
// instead.
|
|
|
|
// See https://github.com/Chatterino/chatterino2/issues/3384 and
|
|
|
|
// https://mm2pl.github.io/emoji_rfc.pdf for more details
|
|
|
|
|
|
|
|
this->addMessage(
|
2023-11-08 18:14:48 +01:00
|
|
|
message, channelOrEmptyByTarget(message->target(), server),
|
2023-10-31 17:47:56 +01:00
|
|
|
message->content().replace(COMBINED_FIXER, ZERO_WIDTH_JOINER), server,
|
|
|
|
false, message->isAction());
|
|
|
|
|
|
|
|
auto chan = channelOrEmptyByTarget(message->target(), server);
|
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->tags().contains(u"pinned-chat-paid-amount"_s))
|
|
|
|
{
|
|
|
|
auto ptr = TwitchMessageBuilder::buildHypeChatMessage(message);
|
|
|
|
if (ptr)
|
2019-09-18 13:03:16 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
chan->addMessage(ptr);
|
2019-09-18 13:03:16 +02:00
|
|
|
}
|
2018-06-04 12:23:23 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-01 23:54:54 +01:00
|
|
|
void IrcMessageHandler::handleRoomStateMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
const auto &tags = message->tags();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-10-17 15:06:58 +02:00
|
|
|
// get Twitch channel
|
2018-05-24 08:58:34 +02:00
|
|
|
QString chanName;
|
|
|
|
if (!trimChannelName(message->parameter(0), chanName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-03-19 12:02:29 +01:00
|
|
|
auto chan = getApp()->twitch->getChannelOrEmpty(chanName);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
auto *twitchChannel = dynamic_cast<TwitchChannel *>(chan.get());
|
|
|
|
if (!twitchChannel)
|
2018-07-14 14:24:18 +02:00
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
// room-id
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
if (auto it = tags.find("room-id"); it != tags.end())
|
|
|
|
{
|
|
|
|
auto roomId = it.value().toString();
|
|
|
|
twitchChannel->setRoomId(roomId);
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
// Room modes
|
|
|
|
{
|
|
|
|
auto roomModes = *twitchChannel->accessRoomModes();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
if (auto it = tags.find("emote-only"); it != tags.end())
|
|
|
|
{
|
|
|
|
roomModes.emoteOnly = it.value() == "1";
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
2021-07-17 15:09:21 +02:00
|
|
|
if (auto it = tags.find("subs-only"); it != tags.end())
|
|
|
|
{
|
|
|
|
roomModes.submode = it.value() == "1";
|
|
|
|
}
|
|
|
|
if (auto it = tags.find("slow"); it != tags.end())
|
|
|
|
{
|
|
|
|
roomModes.slowMode = it.value().toInt();
|
|
|
|
}
|
|
|
|
if (auto it = tags.find("r9k"); it != tags.end())
|
|
|
|
{
|
|
|
|
roomModes.r9k = it.value() == "1";
|
|
|
|
}
|
|
|
|
if (auto it = tags.find("followers-only"); it != tags.end())
|
|
|
|
{
|
|
|
|
roomModes.followerOnly = it.value().toInt();
|
|
|
|
}
|
|
|
|
twitchChannel->setRoomModes(roomModes);
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
2021-07-17 15:09:21 +02:00
|
|
|
|
|
|
|
twitchChannel->roomModesChanged.invoke();
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-08-13 12:00:52 +02:00
|
|
|
void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
auto cc = parseClearChatMessage(message);
|
2023-08-13 12:00:52 +02:00
|
|
|
if (!cc)
|
2018-05-17 13:43:01 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-08-13 12:00:52 +02:00
|
|
|
auto &clearChat = *cc;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-17 13:43:01 +02:00
|
|
|
QString chanName;
|
2018-05-24 08:58:34 +02:00
|
|
|
if (!trimChannelName(message->parameter(0), chanName))
|
|
|
|
{
|
2018-05-17 13:43:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-17 13:43:01 +02:00
|
|
|
// get channel
|
2022-03-19 12:02:29 +01:00
|
|
|
auto chan = getApp()->twitch->getChannelOrEmpty(chanName);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-17 13:43:01 +02:00
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch)
|
2023-08-13 12:00:52 +02:00
|
|
|
<< "[IrcMessageHandler::handleClearChatMessage] Twitch channel"
|
2020-11-21 16:20:10 +01:00
|
|
|
<< chanName << "not found";
|
2018-05-17 13:43:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-08-13 12:00:52 +02:00
|
|
|
// chat has been cleared by a moderator
|
|
|
|
if (clearChat.disableAllMessages)
|
2018-05-17 13:43:01 +02:00
|
|
|
{
|
2018-06-22 23:44:02 +02:00
|
|
|
chan->disableAllMessages();
|
2023-08-13 12:00:52 +02:00
|
|
|
chan->addMessage(std::move(clearChat.message));
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-17 13:43:01 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-08-13 12:00:52 +02:00
|
|
|
chan->addOrReplaceTimeout(std::move(clearChat.message));
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-17 13:43:01 +02:00
|
|
|
// refresh all
|
2021-07-17 15:09:21 +02:00
|
|
|
getApp()->windows->repaintVisibleChatWidgets(chan.get());
|
2019-04-16 14:36:15 +02:00
|
|
|
if (getSettings()->hideModerated)
|
2019-04-15 22:55:10 +02:00
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
getApp()->windows->forceLayoutChannelViews();
|
2019-04-15 22:55:10 +02:00
|
|
|
}
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-04-19 22:44:02 +02:00
|
|
|
void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
// check parameter count
|
|
|
|
if (message->parameters().length() < 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-04-19 22:44:02 +02:00
|
|
|
QString chanName;
|
|
|
|
if (!trimChannelName(message->parameter(0), chanName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-04-19 22:44:02 +02:00
|
|
|
// get channel
|
2022-03-19 12:02:29 +01:00
|
|
|
auto chan = getApp()->twitch->getChannelOrEmpty(chanName);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-04-19 22:44:02 +02:00
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< "[IrcMessageHandler:handleClearMessageMessage] Twitch "
|
|
|
|
"channel"
|
|
|
|
<< chanName << "not found";
|
2019-04-19 22:44:02 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-04-19 22:44:02 +02:00
|
|
|
auto tags = message->tags();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-04-19 22:44:02 +02:00
|
|
|
QString targetID = tags.value("target-msg-id").toString();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-06-06 17:51:57 +02:00
|
|
|
auto msg = chan->findMessage(targetID);
|
2021-07-17 15:09:21 +02:00
|
|
|
if (msg == nullptr)
|
2023-10-31 17:47:56 +01:00
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
return;
|
2023-10-31 17:47:56 +01:00
|
|
|
}
|
2021-07-17 15:09:21 +02:00
|
|
|
|
|
|
|
msg->flags.set(MessageFlag::Disabled);
|
|
|
|
if (!getSettings()->hideDeletionActions)
|
2021-06-06 17:51:57 +02:00
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
MessageBuilder builder;
|
|
|
|
TwitchMessageBuilder::deletionMessage(msg, &builder);
|
|
|
|
chan->addMessage(builder.release());
|
2021-06-06 17:51:57 +02:00
|
|
|
}
|
2019-04-19 22:44:02 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-01 23:54:54 +01:00
|
|
|
void IrcMessageHandler::handleUserStateMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
2021-06-20 00:11:06 +02:00
|
|
|
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
|
|
|
|
|
|
|
// set received emote-sets, used in TwitchAccount::loadUserstateEmotes
|
|
|
|
bool emoteSetsChanged = currentUser->setUserstateEmoteSets(
|
|
|
|
message->tag("emote-sets").toString().split(","));
|
|
|
|
|
|
|
|
if (emoteSetsChanged)
|
|
|
|
{
|
2022-02-28 15:59:10 +01:00
|
|
|
currentUser->loadUserstateEmotes();
|
2021-06-20 00:11:06 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-04-13 15:26:47 +02:00
|
|
|
QString channelName;
|
|
|
|
if (!trimChannelName(message->parameter(0), channelName))
|
2018-01-17 18:36:12 +01:00
|
|
|
{
|
2019-04-13 15:26:47 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2022-03-19 12:02:29 +01:00
|
|
|
auto c = getApp()->twitch->getChannelOrEmpty(channelName);
|
2019-04-13 15:26:47 +02:00
|
|
|
if (c->isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 17:18:17 +02:00
|
|
|
// Checking if currentUser is a VIP or staff member
|
2023-10-31 17:47:56 +01:00
|
|
|
QVariant badgesTag = message->tag("badges");
|
|
|
|
if (badgesTag.isValid())
|
2019-04-13 15:26:47 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
auto *tc = dynamic_cast<TwitchChannel *>(c.get());
|
2019-04-13 15:26:47 +02:00
|
|
|
if (tc != nullptr)
|
2018-04-21 00:40:17 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
auto parsedBadges = parseBadges(badgesTag.toString());
|
2019-04-13 15:26:47 +02:00
|
|
|
tc->setVIP(parsedBadges.contains("vip"));
|
|
|
|
tc->setStaff(parsedBadges.contains("staff"));
|
2018-04-21 00:40:17 +02:00
|
|
|
}
|
2019-04-13 15:26:47 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 17:18:17 +02:00
|
|
|
// Checking if currentUser is a moderator
|
2023-10-31 17:47:56 +01:00
|
|
|
QVariant modTag = message->tag("mod");
|
|
|
|
if (modTag.isValid())
|
2019-04-13 15:26:47 +02:00
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
auto *tc = dynamic_cast<TwitchChannel *>(c.get());
|
2018-01-17 18:36:12 +01:00
|
|
|
if (tc != nullptr)
|
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
tc->setMod(modTag == "1");
|
2018-01-17 18:36:12 +01:00
|
|
|
}
|
|
|
|
}
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 17:18:17 +02:00
|
|
|
// This will emit only once and right after user logs in to IRC - reset emote data and reload emotes
|
|
|
|
void IrcMessageHandler::handleGlobalUserStateMessage(
|
|
|
|
Communi::IrcMessage *message)
|
|
|
|
{
|
|
|
|
auto currentUser = getApp()->accounts->twitch.getCurrent();
|
|
|
|
|
|
|
|
// set received emote-sets, this time used to initially load emotes
|
|
|
|
// NOTE: this should always return true unless we reconnect
|
|
|
|
auto emoteSetsChanged = currentUser->setUserstateEmoteSets(
|
|
|
|
message->tag("emote-sets").toString().split(","));
|
|
|
|
|
|
|
|
// We should always attempt to reload emotes even on reconnections where
|
|
|
|
// emoteSetsChanged, since we want to trigger emote reloads when
|
|
|
|
// "currentUserChanged" signal is emitted
|
|
|
|
qCDebug(chatterinoTwitch) << emoteSetsChanged << message->toData();
|
|
|
|
currentUser->loadEmotes();
|
|
|
|
}
|
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
void IrcMessageHandler::handleWhisperMessage(Communi::IrcMessage *ircMessage)
|
2018-01-01 23:54:54 +01:00
|
|
|
{
|
2018-06-28 19:38:57 +02:00
|
|
|
MessageParseArgs args;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-02-04 16:33:46 +01:00
|
|
|
args.isReceivedWhisper = true;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
auto *c = getApp()->twitch->whispersChannel.get();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2022-01-11 01:18:02 +01:00
|
|
|
TwitchMessageBuilder builder(
|
2023-10-31 17:47:56 +01:00
|
|
|
c, ircMessage, args,
|
|
|
|
ircMessage->parameter(1).replace(COMBINED_FIXER, ZERO_WIDTH_JOINER),
|
2022-01-11 01:18:02 +01:00
|
|
|
false);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
if (builder.isIgnored())
|
2018-02-04 16:33:46 +01:00
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
builder->flags.set(MessageFlag::Whisper);
|
|
|
|
MessagePtr message = builder.build();
|
|
|
|
builder.triggerHighlights();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
getApp()->twitch->lastUserThatWhisperedMe.set(builder.userName);
|
|
|
|
|
|
|
|
if (message->flags.has(MessageFlag::ShowInMentions))
|
|
|
|
{
|
|
|
|
getApp()->twitch->mentionsChannel->addMessage(message);
|
2019-04-13 19:14:58 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
c->addMessage(message);
|
|
|
|
|
|
|
|
auto overrideFlags = std::optional<MessageFlags>(message->flags);
|
|
|
|
overrideFlags->set(MessageFlag::DoNotTriggerNotification);
|
|
|
|
overrideFlags->set(MessageFlag::DoNotLog);
|
|
|
|
|
|
|
|
if (getSettings()->inlineWhispers &&
|
|
|
|
!(getSettings()->streamerModeSuppressInlineWhispers &&
|
|
|
|
isInStreamerMode()))
|
|
|
|
{
|
|
|
|
getApp()->twitch->forEachChannel(
|
|
|
|
[&message, overrideFlags](ChannelPtr channel) {
|
|
|
|
channel->addMessage(message, overrideFlags);
|
|
|
|
});
|
|
|
|
}
|
2019-04-13 19:14:58 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-06-04 12:23:23 +02:00
|
|
|
void IrcMessageHandler::handleUserNoticeMessage(Communi::IrcMessage *message,
|
2019-09-18 13:03:16 +02:00
|
|
|
TwitchIrcServer &server)
|
2018-01-01 23:54:54 +01:00
|
|
|
{
|
2018-06-05 14:14:00 +02:00
|
|
|
auto tags = message->tags();
|
|
|
|
auto parameters = message->parameters();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-06-05 14:14:00 +02:00
|
|
|
auto target = parameters[0];
|
2021-07-17 15:09:21 +02:00
|
|
|
QString msgType = tags.value("msg-id").toString();
|
2018-06-05 14:14:00 +02:00
|
|
|
QString content;
|
|
|
|
if (parameters.size() >= 2)
|
|
|
|
{
|
|
|
|
content = parameters[1];
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2023-08-05 14:45:43 +02:00
|
|
|
auto chn = server.getChannelOrEmpty(target);
|
|
|
|
if (isIgnoredMessage({
|
|
|
|
.message = content,
|
|
|
|
.twitchUserID = tags.value("user-id").toString(),
|
|
|
|
.isMod = chn->isMod(),
|
|
|
|
.isBroadcaster = chn->isBroadcaster(),
|
|
|
|
}))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
if (SPECIAL_MESSAGE_TYPES.contains(msgType))
|
2018-06-05 14:14:00 +02:00
|
|
|
{
|
2021-05-01 17:42:51 +02:00
|
|
|
// Messages are not required, so they might be empty
|
2018-06-05 14:14:00 +02:00
|
|
|
if (!content.isEmpty())
|
|
|
|
{
|
2023-11-08 18:14:48 +01:00
|
|
|
this->addMessage(message, chn, content, server, true, false);
|
2018-06-05 14:14:00 +02:00
|
|
|
}
|
2018-06-04 12:23:23 +02:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-06-04 12:23:23 +02:00
|
|
|
auto it = tags.find("system-msg");
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-06-04 12:23:23 +02:00
|
|
|
if (it != tags.end())
|
|
|
|
{
|
2021-05-01 17:42:51 +02:00
|
|
|
// By default, we return value of system-msg tag
|
2021-04-11 14:17:21 +02:00
|
|
|
QString messageText = it.value().toString();
|
|
|
|
|
|
|
|
if (msgType == "bitsbadgetier")
|
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
messageText =
|
|
|
|
QString("%1 just earned a new %2 Bits badge!")
|
|
|
|
.arg(tags.value("display-name").toString(),
|
|
|
|
kFormatNumbers(
|
|
|
|
tags.value("msg-param-threshold").toInt()));
|
2021-04-11 14:17:21 +02:00
|
|
|
}
|
2022-04-01 00:24:19 +02:00
|
|
|
else if (msgType == "announcement")
|
|
|
|
{
|
|
|
|
messageText = "Announcement";
|
|
|
|
}
|
2021-04-11 14:17:21 +02:00
|
|
|
|
|
|
|
auto b = MessageBuilder(systemMessage, parseTagString(messageText),
|
2022-05-15 08:08:28 +02:00
|
|
|
calculateMessageTime(message).time());
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-08-07 07:55:31 +02:00
|
|
|
b->flags.set(MessageFlag::Subscription);
|
2018-08-07 01:35:24 +02:00
|
|
|
auto newMessage = b.release();
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-06-04 12:23:23 +02:00
|
|
|
QString channelName;
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-06-04 12:23:23 +02:00
|
|
|
if (message->parameters().size() < 1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-06-04 12:23:23 +02:00
|
|
|
if (!trimChannelName(message->parameter(0), channelName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-06-04 12:23:23 +02:00
|
|
|
auto chan = server.getChannelOrEmpty(channelName);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-06-04 12:23:23 +02:00
|
|
|
if (!chan->isEmpty())
|
|
|
|
{
|
|
|
|
chan->addMessage(newMessage);
|
|
|
|
}
|
|
|
|
}
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-01-01 23:54:54 +01:00
|
|
|
void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message)
|
|
|
|
{
|
2023-10-31 17:47:56 +01:00
|
|
|
auto builtMessages = parseNoticeMessage(message);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
for (const auto &msg : builtMessages)
|
2018-06-23 23:08:15 +02:00
|
|
|
{
|
2019-04-13 19:14:58 +02:00
|
|
|
QString channelName;
|
2019-05-05 16:15:35 +02:00
|
|
|
if (!trimChannelName(message->target(), channelName) ||
|
|
|
|
channelName == "jtv")
|
2019-04-13 19:14:58 +02:00
|
|
|
{
|
|
|
|
// Notice wasn't targeted at a single channel, send to all twitch
|
|
|
|
// channels
|
2022-03-19 12:02:29 +01:00
|
|
|
getApp()->twitch->forEachChannelAndSpecialChannels(
|
2019-04-13 19:14:58 +02:00
|
|
|
[msg](const auto &c) {
|
2020-11-08 12:02:19 +01:00
|
|
|
c->addMessage(msg);
|
2019-04-13 19:14:58 +02:00
|
|
|
});
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-04-13 19:14:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2022-03-19 12:02:29 +01:00
|
|
|
auto channel = getApp()->twitch->getChannelOrEmpty(channelName);
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-04-13 19:14:58 +02:00
|
|
|
if (channel->isEmpty())
|
|
|
|
{
|
2020-11-21 16:20:10 +01:00
|
|
|
qCDebug(chatterinoTwitch)
|
|
|
|
<< "[IrcManager:handleNoticeMessage] Channel" << channelName
|
|
|
|
<< "not found in channel manager";
|
2019-04-13 19:14:58 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
QString tags = message->tags().value("msg-id").toString();
|
2021-11-13 13:34:04 +01:00
|
|
|
if (tags == "usage_delete")
|
2019-04-28 11:31:34 +02:00
|
|
|
{
|
|
|
|
channel->addMessage(makeSystemMessage(
|
2021-11-13 13:34:04 +01:00
|
|
|
"Usage: /delete <msg-id> - Deletes the specified message. "
|
|
|
|
"Can't take more than one argument."));
|
|
|
|
}
|
|
|
|
else if (tags == "bad_delete_message_error")
|
|
|
|
{
|
|
|
|
channel->addMessage(makeSystemMessage(
|
|
|
|
"There was a problem deleting the message. "
|
|
|
|
"It might be from another channel or too old to delete."));
|
2019-04-28 11:31:34 +02:00
|
|
|
}
|
2021-06-27 15:50:12 +02:00
|
|
|
else if (tags == "host_on" || tags == "host_target_went_offline")
|
2021-05-08 16:46:41 +02:00
|
|
|
{
|
2021-06-27 15:50:12 +02:00
|
|
|
bool hostOn = (tags == "host_on");
|
2021-05-08 16:46:41 +02:00
|
|
|
QStringList parts = msg->messageText.split(QLatin1Char(' '));
|
2021-06-27 15:50:12 +02:00
|
|
|
if ((hostOn && parts.size() != 3) || (!hostOn && parts.size() != 7))
|
2021-05-08 16:46:41 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-11-27 14:51:37 +01:00
|
|
|
auto &hostedChannelName = hostOn ? parts[2] : parts[0];
|
|
|
|
if (hostedChannelName.size() < 2)
|
2021-05-08 16:46:41 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-06-27 15:50:12 +02:00
|
|
|
if (hostOn)
|
|
|
|
{
|
2021-11-27 14:51:37 +01:00
|
|
|
hostedChannelName.chop(1);
|
2021-06-27 15:50:12 +02:00
|
|
|
}
|
2021-05-08 16:46:41 +02:00
|
|
|
MessageBuilder builder;
|
2021-11-27 14:51:37 +01:00
|
|
|
TwitchMessageBuilder::hostingSystemMessage(hostedChannelName,
|
|
|
|
&builder, hostOn);
|
2021-05-08 16:46:41 +02:00
|
|
|
channel->addMessage(builder.release());
|
|
|
|
}
|
2021-10-24 15:28:43 +02:00
|
|
|
else if (tags == "room_mods" || tags == "vips_success")
|
|
|
|
{
|
|
|
|
// /mods and /vips
|
|
|
|
// room_mods: The moderators of this channel are: ampzyh, antichriststollen, apa420, ...
|
|
|
|
// vips_success: The VIPs of this channel are: 8008, aiden, botfactory, ...
|
|
|
|
|
|
|
|
QString noticeText = msg->messageText;
|
|
|
|
if (tags == "vips_success")
|
|
|
|
{
|
|
|
|
// this one has a trailing period, need to get rid of it.
|
|
|
|
noticeText.chop(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList msgParts = noticeText.split(':');
|
|
|
|
MessageBuilder builder;
|
|
|
|
|
2023-10-31 17:47:56 +01:00
|
|
|
auto *tc = dynamic_cast<TwitchChannel *>(channel.get());
|
2021-10-24 15:28:43 +02:00
|
|
|
assert(tc != nullptr &&
|
|
|
|
"IrcMessageHandler::handleNoticeMessage. Twitch specific "
|
|
|
|
"functionality called in non twitch channel");
|
|
|
|
|
2021-11-13 12:11:18 +01:00
|
|
|
auto users = msgParts.at(1)
|
|
|
|
.mid(1) // there is a space before the first user
|
|
|
|
.split(", ");
|
2022-04-30 14:02:40 +02:00
|
|
|
users.sort(Qt::CaseInsensitive);
|
2021-11-20 14:53:05 +01:00
|
|
|
TwitchMessageBuilder::listOfUsersSystemMessage(msgParts.at(0),
|
|
|
|
users, tc, &builder);
|
2021-10-24 15:28:43 +02:00
|
|
|
channel->addMessage(builder.release());
|
|
|
|
}
|
2019-04-28 11:31:34 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
channel->addMessage(msg);
|
|
|
|
}
|
2019-04-13 19:14:58 +02:00
|
|
|
}
|
2018-01-01 23:54:54 +01:00
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-26 18:06:55 +02:00
|
|
|
void IrcMessageHandler::handleJoinMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
2022-03-19 12:02:29 +01:00
|
|
|
auto channel =
|
|
|
|
getApp()->twitch->getChannelOrEmpty(message->parameter(0).remove(0, 1));
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
|
|
|
if (!twitchChannel)
|
2018-05-26 18:06:55 +02:00
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-05-19 12:30:30 +02:00
|
|
|
if (message->nick() ==
|
|
|
|
getApp()->accounts->twitch.getCurrent()->getUserName())
|
|
|
|
{
|
|
|
|
twitchChannel->addMessage(makeSystemMessage("joined channel"));
|
2023-12-09 19:46:30 +01:00
|
|
|
twitchChannel->joined.invoke();
|
2023-05-19 12:30:30 +02:00
|
|
|
}
|
|
|
|
else if (getSettings()->showJoins.getValue())
|
2021-07-17 15:09:21 +02:00
|
|
|
{
|
|
|
|
twitchChannel->addJoinedUser(message->nick());
|
2018-05-26 18:06:55 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2018-05-26 18:06:55 +02:00
|
|
|
void IrcMessageHandler::handlePartMessage(Communi::IrcMessage *message)
|
|
|
|
{
|
2022-03-19 12:02:29 +01:00
|
|
|
auto channel =
|
|
|
|
getApp()->twitch->getChannelOrEmpty(message->parameter(0).remove(0, 1));
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
|
|
|
|
if (!twitchChannel)
|
2018-05-26 18:06:55 +02:00
|
|
|
{
|
2021-07-17 15:09:21 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-12-12 14:19:51 +01:00
|
|
|
|
2021-07-17 15:09:21 +02:00
|
|
|
const auto selfAccountName =
|
|
|
|
getApp()->accounts->twitch.getCurrent()->getUserName();
|
|
|
|
if (message->nick() != selfAccountName &&
|
|
|
|
getSettings()->showParts.getValue())
|
|
|
|
{
|
|
|
|
twitchChannel->addPartedUser(message->nick());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message->nick() == selfAccountName)
|
|
|
|
{
|
|
|
|
channel->addMessage(generateBannedMessage(false));
|
2018-05-26 18:06:55 +02:00
|
|
|
}
|
|
|
|
}
|
2023-10-31 17:47:56 +01:00
|
|
|
|
|
|
|
float IrcMessageHandler::similarity(
|
|
|
|
const MessagePtr &msg, const LimitedQueueSnapshot<MessagePtr> &messages)
|
|
|
|
{
|
|
|
|
float similarityPercent = 0.0F;
|
|
|
|
int checked = 0;
|
|
|
|
|
|
|
|
for (int i = 1; i <= messages.size(); ++i)
|
|
|
|
{
|
|
|
|
if (checked >= getSettings()->hideSimilarMaxMessagesToCheck)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const auto &prevMsg = messages[messages.size() - i];
|
|
|
|
if (prevMsg->parseTime.secsTo(QTime::currentTime()) >=
|
|
|
|
getSettings()->hideSimilarMaxDelay)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (getSettings()->hideSimilarBySameUser &&
|
|
|
|
msg->loginName != prevMsg->loginName)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
++checked;
|
|
|
|
similarityPercent = std::max(
|
|
|
|
similarityPercent,
|
|
|
|
relativeSimilarity(msg->messageText, prevMsg->messageText));
|
|
|
|
}
|
|
|
|
|
|
|
|
return similarityPercent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::setSimilarityFlags(const MessagePtr &message,
|
|
|
|
const ChannelPtr &channel)
|
|
|
|
{
|
|
|
|
if (getSettings()->similarityEnabled)
|
|
|
|
{
|
|
|
|
bool isMyself = message->loginName ==
|
|
|
|
getApp()->accounts->twitch.getCurrent()->getUserName();
|
|
|
|
bool hideMyself = getSettings()->hideSimilarMyself;
|
|
|
|
|
|
|
|
if (isMyself && !hideMyself)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IrcMessageHandler::similarity(message,
|
|
|
|
channel->getMessageSnapshot()) >
|
|
|
|
getSettings()->similarityPercentage)
|
|
|
|
{
|
|
|
|
message->flags.set(MessageFlag::Similar, true);
|
|
|
|
if (getSettings()->colorSimilarDisabled)
|
|
|
|
{
|
|
|
|
message->flags.set(MessageFlag::Disabled, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void IrcMessageHandler::addMessage(Communi::IrcMessage *message,
|
2023-11-08 18:14:48 +01:00
|
|
|
const ChannelPtr &chan,
|
2023-10-31 17:47:56 +01:00
|
|
|
const QString &originalContent,
|
|
|
|
TwitchIrcServer &server, bool isSub,
|
|
|
|
bool isAction)
|
|
|
|
{
|
|
|
|
if (chan->isEmpty())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageParseArgs args;
|
|
|
|
if (isSub)
|
|
|
|
{
|
|
|
|
args.isSubscriptionMessage = true;
|
|
|
|
args.trimSubscriberUsername = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chan->isBroadcaster())
|
|
|
|
{
|
|
|
|
args.isStaffOrBroadcaster = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto *channel = dynamic_cast<TwitchChannel *>(chan.get());
|
|
|
|
|
|
|
|
const auto &tags = message->tags();
|
|
|
|
if (const auto it = tags.find("custom-reward-id"); it != tags.end())
|
|
|
|
{
|
|
|
|
const auto rewardId = it.value().toString();
|
2023-11-08 18:14:48 +01:00
|
|
|
if (!rewardId.isEmpty() &&
|
|
|
|
!channel->isChannelPointRewardKnown(rewardId))
|
2023-10-31 17:47:56 +01:00
|
|
|
{
|
|
|
|
// Need to wait for pubsub reward notification
|
|
|
|
qCDebug(chatterinoTwitch) << "TwitchChannel reward added ADD "
|
|
|
|
"callback since reward is not known:"
|
|
|
|
<< rewardId;
|
2023-11-08 18:14:48 +01:00
|
|
|
channel->addQueuedRedemption(rewardId, originalContent, message);
|
2023-10-31 17:47:56 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
args.channelPointRewardId = rewardId;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString content = originalContent;
|
|
|
|
int messageOffset = stripLeadingReplyMention(tags, content);
|
|
|
|
|
2023-11-08 18:14:48 +01:00
|
|
|
TwitchMessageBuilder builder(channel, message, args, content, isAction);
|
2023-10-31 17:47:56 +01:00
|
|
|
builder.setMessageOffset(messageOffset);
|
|
|
|
|
2023-11-05 17:25:26 +01:00
|
|
|
if (const auto it = tags.find("reply-thread-parent-msg-id");
|
|
|
|
it != tags.end())
|
2023-10-31 17:47:56 +01:00
|
|
|
{
|
|
|
|
const QString replyID = it.value().toString();
|
2023-11-05 17:25:26 +01:00
|
|
|
auto threadIt = channel->threads().find(replyID);
|
|
|
|
std::shared_ptr<MessageThread> rootThread;
|
|
|
|
if (threadIt != channel->threads().end() && !threadIt->second.expired())
|
2023-10-31 17:47:56 +01:00
|
|
|
{
|
|
|
|
// Thread already exists (has a reply)
|
|
|
|
auto thread = threadIt->second.lock();
|
|
|
|
updateReplyParticipatedStatus(tags, message->nick(), builder,
|
|
|
|
thread, false);
|
|
|
|
builder.setThread(thread);
|
2023-11-05 17:25:26 +01:00
|
|
|
rootThread = thread;
|
2023-10-31 17:47:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Thread does not yet exist, find root reply and create thread.
|
|
|
|
auto root = channel->findMessage(replyID);
|
|
|
|
if (root)
|
|
|
|
{
|
|
|
|
// Found root reply message
|
|
|
|
auto newThread = std::make_shared<MessageThread>(root);
|
|
|
|
updateReplyParticipatedStatus(tags, message->nick(), builder,
|
|
|
|
newThread, true);
|
|
|
|
|
|
|
|
builder.setThread(newThread);
|
2023-11-05 17:25:26 +01:00
|
|
|
rootThread = newThread;
|
2023-10-31 17:47:56 +01:00
|
|
|
// Store weak reference to thread in channel
|
|
|
|
channel->addReplyThread(newThread);
|
|
|
|
}
|
|
|
|
}
|
2023-11-05 17:25:26 +01:00
|
|
|
|
|
|
|
if (const auto parentIt = tags.find("reply-parent-msg-id");
|
|
|
|
parentIt != tags.end())
|
|
|
|
{
|
|
|
|
const QString parentID = parentIt.value().toString();
|
|
|
|
if (replyID == parentID)
|
|
|
|
{
|
|
|
|
if (rootThread)
|
|
|
|
{
|
|
|
|
builder.setParent(rootThread->root());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto parentThreadIt = channel->threads().find(parentID);
|
|
|
|
if (parentThreadIt != channel->threads().end())
|
|
|
|
{
|
|
|
|
auto thread = parentThreadIt->second.lock();
|
|
|
|
if (thread)
|
|
|
|
{
|
|
|
|
builder.setParent(thread->root());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto parent = channel->findMessage(parentID);
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
builder.setParent(parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-31 17:47:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isSub || !builder.isIgnored())
|
|
|
|
{
|
|
|
|
if (isSub)
|
|
|
|
{
|
|
|
|
builder->flags.set(MessageFlag::Subscription);
|
|
|
|
builder->flags.unset(MessageFlag::Highlighted);
|
|
|
|
}
|
|
|
|
auto msg = builder.build();
|
|
|
|
|
|
|
|
IrcMessageHandler::setSimilarityFlags(msg, chan);
|
|
|
|
|
|
|
|
if (!msg->flags.has(MessageFlag::Similar) ||
|
|
|
|
(!getSettings()->hideSimilar &&
|
|
|
|
getSettings()->shownSimilarTriggerHighlights))
|
|
|
|
{
|
|
|
|
builder.triggerHighlights();
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto highlighted = msg->flags.has(MessageFlag::Highlighted);
|
|
|
|
const auto showInMentions = msg->flags.has(MessageFlag::ShowInMentions);
|
|
|
|
|
|
|
|
if (highlighted && showInMentions)
|
|
|
|
{
|
|
|
|
server.mentionsChannel->addMessage(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
chan->addMessage(msg);
|
|
|
|
if (auto *chatters = dynamic_cast<ChannelChatters *>(chan.get()))
|
|
|
|
{
|
|
|
|
chatters->addRecentChatter(msg->displayName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 02:22:57 +01:00
|
|
|
} // namespace chatterino
|