Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into chatterino7
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Jan 25, 2025
2 parents 5b60c10 + 8554bd4 commit e3048e6
Show file tree
Hide file tree
Showing 52 changed files with 437 additions and 2,777 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ jobs:
working-directory: build-test

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5.1.2
uses: codecov/codecov-action@v5.3.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
plugins: gcov
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
- Minor: Treat all browsers starting with `firefox` as a Firefox browser. (#5805)
- Minor: Remove incognito browser support for `opera/launcher` (this should no longer be a thing). (#5805)
- Minor: Remove incognito browser support for `iexplore`, because internet explorer is EOL. (#5810)
- Minor: When (re-)connecting, visible channels are now joined first. (#5850)
- Bugfix: Fixed a potential way to escape the Lua Plugin sandbox. (#5846)
- Bugfix: Fixed a crash relating to Lua HTTP. (#5800)
- Bugfix: Fixed a crash that could occur on Linux and macOS when clicking "Install" from the update prompt. (#5818)
- Bugfix: Fixed missing word wrap in update popup. (#5811)
- Bugfix: Fixed tabs not scaling to the default scale when changing the scale from a non-default value. (#5794)
- Bugfix: Closing a usercard will no longer cause stop-logging messages to be generated in channel logs. (#5828)
- Bugfix: Fixed tabs not scaling to the default scale when changing the scale from a non-default value. (#5794, #5833)
- Bugfix: Fixed deleted messages not immediately disappearing when "Hide deleted messages" is enabled. (#5844, #5854)
- Dev: Highlight checks now use non-capturing groups for the boundaries. (#5784)
- Dev: Updated Conan dependencies. (#5776)
- Dev: Replaced usage of `parseTime` with `serverReceivedTime` for clearchat messages. (#5824)
- Dev: Replaced usage of `parseTime` with `serverReceivedTime` for clearchat messages. (#5824, #5855)
- Dev: Support Boost 1.87. (#5832)
- Dev: Words from `TextElement`s are now combined where possible. (#5847)

## 2.5.2

Expand Down
2 changes: 1 addition & 1 deletion lib/settings
15 changes: 0 additions & 15 deletions src/common/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,10 @@
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "messages/MessageSimilarity.hpp"
#include "providers/twitch/IrcMessageHandler.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Emotes.hpp"
#include "singletons/Logging.hpp"
#include "singletons/Settings.hpp"
#include "singletons/WindowManager.hpp"
#include "util/ChannelHelpers.hpp"

#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonValue>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>

namespace chatterino {

//
Expand Down Expand Up @@ -135,9 +123,6 @@ void Channel::addOrReplaceTimeout(MessagePtr message, const QDateTime &now)
this->addMessage(msg, MessageContext::Original);
},
true);

// XXX: Might need the following line
// WindowManager::instance().repaintVisibleChatWidgets(this);
}

void Channel::addOrReplaceClearChat(MessagePtr message, const QDateTime &now)
Expand Down
46 changes: 45 additions & 1 deletion src/controllers/commands/builtin/chatterino/Debugging.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#include "controllers/commands/builtin/chatterino/Debugging.hpp"

#include "Application.hpp"
#include "common/Channel.hpp"
#include "common/Env.hpp"
#include "common/Literals.hpp"
#include "controllers/commands/CommandContext.hpp"
#include "messages/Image.hpp"
#include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp"
#include "messages/MessageElement.hpp"
#include "providers/twitch/PubSubActions.hpp"
#include "providers/twitch/TwitchChannel.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"
#include "singletons/Theme.hpp"
#include "util/PostToThread.hpp"

Expand Down Expand Up @@ -140,7 +145,46 @@ QString debugTest(const CommandContext &ctx)
return "";
}

ctx.channel->addSystemMessage("debug-test called");
const auto command = ctx.words.value(1);

if (command == "timeout-pubsub")
{
QJsonObject data;
data["created_by_user_id"] = ctx.twitchChannel->roomId();
data["created_by"] = ctx.twitchChannel->getName();

BanAction action(data, ctx.twitchChannel->roomId());

action.source.id = ctx.twitchChannel->roomId();
action.source.login = ctx.twitchChannel->getName();

action.target.id = "11148817";
action.target.login = "pajlada";
action.duration = 10;

MessageBuilder msg(action, QDateTime::currentDateTime());
msg->flags.set(MessageFlag::PubSub);
ctx.channel->addOrReplaceTimeout(msg.release(),
QDateTime::currentDateTime());
}
else if (command == "timeout-irc")
{
auto nowMillis = QDateTime::currentDateTime().toSecsSinceEpoch();

const auto ircText =
QString(
"@tmi-sent-ts=%1;room-id=117166826;user-id=11148817;badges=;"
"badge-info=;flags=;user-type=;emotes=;target-user-id=11148817;"
"ban-"
"duration=1 :tmi.twitch.tv CLEARCHAT #testaccount_420 pajlada")
.arg(nowMillis);
getApp()->getTwitch()->addFakeMessage(ircText);
}
else
{
ctx.channel->addSystemMessage(
QString("debug-test called with command: '%1'").arg(command));
}

return "";
}
Expand Down
77 changes: 56 additions & 21 deletions src/messages/MessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,7 @@ MessageBuilder::MessageBuilder(SystemMessageTag, const QString &text,
continue;
}

this->emplace<TextElement>(word, MessageElementFlag::Text,
MessageColor::System);
this->appendOrEmplaceText(word, MessageColor::System);
}
this->message().flags.set(MessageFlag::System);
this->message().flags.set(MessageFlag::DoNotTriggerNotification);
Expand All @@ -564,8 +563,7 @@ MessagePtrMut MessageBuilder::makeSystemMessageWithUser(
continue;
}

builder.emplace<TextElement>(word, MessageElementFlag::Text,
MessageColor::System);
builder.appendOrEmplaceText(word, MessageColor::System);
}

builder->flags.set(MessageFlag::System);
Expand Down Expand Up @@ -631,8 +629,7 @@ MessagePtrMut MessageBuilder::makeSubgiftMessage(const QString &text,
continue;
}

builder.emplace<TextElement>(word, MessageElementFlag::Text,
MessageColor::System);
builder.appendOrEmplaceText(word, MessageColor::System);
}

builder->flags.set(MessageFlag::System);
Expand Down Expand Up @@ -734,7 +731,8 @@ MessageBuilder::MessageBuilder(TimeoutMessageTag, const QString &username,
this->message().serverReceivedTime = time;
}

MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count)
MessageBuilder::MessageBuilder(const BanAction &action, const QDateTime &time,
uint32_t count)
: MessageBuilder()
{
auto current = getApp()->getAccounts()->twitch.getCurrent();
Expand All @@ -755,18 +753,18 @@ MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count)
this->emplaceSystemTextAndUpdate("were", text);
if (action.isBan())
{
this->emplaceSystemTextAndUpdate("banned", text);
this->appendOrEmplaceSystemTextAndUpdate("banned", text);
}
else
{
this->emplaceSystemTextAndUpdate(
this->appendOrEmplaceSystemTextAndUpdate(
QString("timed out for %1").arg(formatTime(action.duration)),
text);
}

if (!action.source.login.isEmpty())
{
this->emplaceSystemTextAndUpdate("by", text);
this->appendOrEmplaceSystemTextAndUpdate("by", text);
this->emplaceSystemTextAndUpdate(
action.source.login + (action.reason.isEmpty() ? "." : ":"),
text)
Expand All @@ -775,7 +773,7 @@ MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count)

if (!action.reason.isEmpty())
{
this->emplaceSystemTextAndUpdate(
this->appendOrEmplaceSystemTextAndUpdate(
QString("\"%1\".").arg(action.reason), text);
}
}
Expand Down Expand Up @@ -824,17 +822,19 @@ MessageBuilder::MessageBuilder(const BanAction &action, uint32_t count)

if (count > 1)
{
this->emplaceSystemTextAndUpdate(
this->appendOrEmplaceSystemTextAndUpdate(
QString("(%1 times)").arg(count), text);
}
}
}

this->message().messageText = text;
this->message().searchText = text;

this->message().serverReceivedTime = time;
}

MessageBuilder::MessageBuilder(const UnbanAction &action)
MessageBuilder::MessageBuilder(const UnbanAction &action, const QDateTime &time)
: MessageBuilder()
{
this->emplace<TimestampElement>();
Expand All @@ -854,6 +854,8 @@ MessageBuilder::MessageBuilder(const UnbanAction &action)

this->message().messageText = text;
this->message().searchText = text;

this->message().serverReceivedTime = time;
}

MessageBuilder::MessageBuilder(const WarnAction &action)
Expand Down Expand Up @@ -1238,6 +1240,42 @@ bool MessageBuilder::isIgnored(const QString &originalMessage,
});
}

void MessageBuilder::appendOrEmplaceText(const QString &text,
MessageColor color)
{
auto fallback = [&] {
this->emplace<TextElement>(text, MessageElementFlag::Text, color);
};
if (this->message_->elements.empty())
{
fallback();
return;
}

auto *back =
dynamic_cast<TextElement *>(this->message_->elements.back().get());
if (!back || //
dynamic_cast<MentionElement *>(back) || //
dynamic_cast<LinkElement *>(back) || //
!back->hasTrailingSpace() || //
back->getFlags() != MessageElementFlag::Text || //
back->color() != color)
{
fallback();
return;
}

back->appendText(text);
}

void MessageBuilder::appendOrEmplaceSystemTextAndUpdate(const QString &text,
QString &toUpdate)
{
toUpdate.append(text);
toUpdate.append(' ');
this->appendOrEmplaceText(text, MessageColor::System);
}

void MessageBuilder::triggerHighlights(const Channel *channel,
const HighlightAlert &alert)
{
Expand Down Expand Up @@ -1771,22 +1809,19 @@ MessagePtr MessageBuilder::makeAutomodInfoMessage(
QString info("Hey! Your message is being checked "
"by mods and has not been sent.");
text += info;
builder.emplace<TextElement>(info, MessageElementFlag::Text,
MessageColor::Text);
builder.appendOrEmplaceText(info, MessageColor::Text);
}
break;
case AutomodInfoAction::Denied: {
QString info("Mods have removed your message.");
text += info;
builder.emplace<TextElement>(info, MessageElementFlag::Text,
MessageColor::Text);
builder.appendOrEmplaceText(info, MessageColor::Text);
}
break;
case AutomodInfoAction::Approved: {
QString info("Mods have accepted your message.");
text += info;
builder.emplace<TextElement>(info, MessageElementFlag::Text,
MessageColor::Text);
builder.appendOrEmplaceText(info, MessageColor::Text);
}
break;
}
Expand Down Expand Up @@ -2031,7 +2066,7 @@ MessagePtrMut MessageBuilder::makeClearChatMessage(const QDateTime &now,

if (count > 1)
{
builder.emplaceSystemTextAndUpdate(
builder.appendOrEmplaceSystemTextAndUpdate(
'(' % QString::number(count) % u" times)", messageText);
}

Expand Down Expand Up @@ -2344,7 +2379,7 @@ void MessageBuilder::addTextOrEmote(TextState &state, QString string)
}
}

this->emplace<TextElement>(string, MessageElementFlag::Text, textColor);
this->appendOrEmplaceText(string, textColor);
}

bool MessageBuilder::isEmpty() const
Expand Down
9 changes: 7 additions & 2 deletions src/messages/MessageBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ class MessageBuilder
MessageBuilder(TimeoutMessageTag, const QString &username,
const QString &durationInSeconds, bool multipleTimes,
const QDateTime &time);
MessageBuilder(const BanAction &action, uint32_t count = 1);
MessageBuilder(const UnbanAction &action);
MessageBuilder(const BanAction &action, const QDateTime &time,
uint32_t count = 1);
MessageBuilder(const UnbanAction &action, const QDateTime &time);
MessageBuilder(const WarnAction &action);
MessageBuilder(const RaidAction &action);
MessageBuilder(const UnraidAction &action);
Expand Down Expand Up @@ -168,6 +169,10 @@ class MessageBuilder
return pointer;
}

void appendOrEmplaceText(const QString &text, MessageColor color);
void appendOrEmplaceSystemTextAndUpdate(const QString &text,
QString &toUpdate);

static void triggerHighlights(const Channel *channel,
const HighlightAlert &alert);

Expand Down
6 changes: 6 additions & 0 deletions src/messages/MessageColor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ struct MessageColor {

QString toString() const;

bool operator==(const MessageColor &other) const noexcept
{
return this->type_ == other.type_ &&
this->customColor_ == other.customColor_;
}

private:
Type type_;
QColor customColor_;
Expand Down
Loading

0 comments on commit e3048e6

Please sign in to comment.