Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into chatterino7
Browse files Browse the repository at this point in the history
Now we're on commit 95044ef; Changes from upstream we pulled:

- Minor: Now uses spaces instead of magic Unicode character for sending duplicate messages (Chatterino#3081)
- Minor: Added `channel.live` filter variable (Chatterino#3092, Chatterino#3110)
- Bugfix: Channel point redemptions from ignored users are now properly blocked. (Chatterino#3102)
  • Loading branch information
zneix committed Aug 3, 2021
2 parents a2144ad + 95044ef commit 1ec8084
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 77 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
- Minor: Received IRC messages use `time` message tag for timestamp if it's available. (#3021)
- Minor: Added informative messages for recent-messages API's errors. (#3029)
- Minor: Added section with helpful Chatterino-related links to the About page. (#3068)
- Minor: Now uses spaces instead of magic Unicode character for sending duplicate messages (#3081)
- Minor: Added `channel.live` filter variable (#3092, #3110)
- Bugfix: Fixed "smiley" emotes being unable to be "Tabbed" with autocompletion, introduced in v2.3.3. (#3010)
- Bugfix: Fixed PubSub not properly trying to resolve pending listens when the pending listens list was larger than 50. (#3037)
- Bugfix: Copy buttons in usercard now show properly in light mode (#3057)
- Bugfix: Fixed comma appended to username completion when not at the beginning of the message. (#3060)
- Bugfix: Fixed bug misplacing chat when zooming on Chrome with Chatterino Native Host extension (#1936)
- Bugfix: Channel point redemptions from ignored users are now properly blocked. (#3102)
- Dev: Ubuntu packages are now available (#2936)
- Dev: Disabled update checker on Flatpak. (#3051)
- Dev: Add logging for HTTP requests (#2991)
Expand Down
1 change: 1 addition & 0 deletions chatterino.pro
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ SOURCES += \
src/controllers/highlights/HighlightModel.cpp \
src/controllers/highlights/HighlightPhrase.cpp \
src/controllers/highlights/UserHighlightModel.cpp \
src/controllers/ignores/IgnoreController.cpp \
src/controllers/ignores/IgnoreModel.cpp \
src/controllers/moderationactions/ModerationAction.cpp \
src/controllers/moderationactions/ModerationActionModel.cpp \
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ set(SOURCE_FILES
controllers/highlights/UserHighlightModel.cpp
controllers/highlights/UserHighlightModel.hpp

controllers/ignores/IgnoreController.cpp
controllers/ignores/IgnoreController.hpp
controllers/ignores/IgnoreModel.cpp
controllers/ignores/IgnoreModel.hpp

Expand Down
5 changes: 0 additions & 5 deletions src/controllers/filters/FilterRecord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ class FilterRecord
return this->parser_->valid();
}

bool filter(const MessagePtr &message) const
{
return this->parser_->execute(message);
}

bool filter(const filterparser::ContextMap &context) const
{
return this->parser_->execute(context);
Expand Down
5 changes: 3 additions & 2 deletions src/controllers/filters/FilterSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ class FilterSet
this->listener_.disconnect();
}

bool filter(const MessagePtr &m) const
bool filter(const MessagePtr &m, ChannelPtr channel) const
{
if (this->filters_.size() == 0)
return true;

filterparser::ContextMap context = filterparser::buildContextMap(m);
filterparser::ContextMap context =
filterparser::buildContextMap(m, channel.get());
for (const auto &f : this->filters_.values())
{
if (!f->valid() || !f->filter(context))
Expand Down
25 changes: 16 additions & 9 deletions src/controllers/filters/parser/FilterParser.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "FilterParser.hpp"

#include "Application.hpp"
#include "common/Channel.hpp"
#include "controllers/filters/parser/Types.hpp"
#include "providers/twitch/TwitchIrcServer.hpp"

namespace filterparser {

ContextMap buildContextMap(const MessagePtr &m)
ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel)
{
auto watchingChannel =
chatterino::getApp()->twitch.server->watchingChannel.get();
Expand Down Expand Up @@ -61,8 +62,7 @@ ContextMap buildContextMap(const MessagePtr &m)
subLength = m->badgeInfos.at(subBadge).toInt();
}
}

return {
ContextMap vars = {
{"author.badges", std::move(badges)},
{"author.color", m->usernameColor},
{"author.name", m->displayName},
Expand All @@ -82,6 +82,19 @@ ContextMap buildContextMap(const MessagePtr &m)
{"message.content", m->messageText},
{"message.length", m->messageText.length()},
};
{
using namespace chatterino;
auto *tc = dynamic_cast<TwitchChannel *>(channel);
if (channel && !channel->isEmpty() && tc)
{
vars["channel.live"] = tc->isLive();
}
else
{
vars["channel.live"] = false;
}
}
return vars;
}

FilterParser::FilterParser(const QString &text)
Expand All @@ -91,12 +104,6 @@ FilterParser::FilterParser(const QString &text)
{
}

bool FilterParser::execute(const MessagePtr &message) const
{
auto context = buildContextMap(message);
return this->execute(context);
}

bool FilterParser::execute(const ContextMap &context) const
{
return this->builtExpression_->execute(context).toBool();
Expand Down
9 changes: 7 additions & 2 deletions src/controllers/filters/parser/FilterParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
#include "controllers/filters/parser/Tokenizer.hpp"
#include "controllers/filters/parser/Types.hpp"

namespace chatterino {

class Channel;

} // namespace chatterino

namespace filterparser {

ContextMap buildContextMap(const MessagePtr &m);
ContextMap buildContextMap(const MessagePtr &m, chatterino::Channel *channel);

class FilterParser
{
public:
FilterParser(const QString &text);
bool execute(const MessagePtr &message) const;
bool execute(const ContextMap &context) const;
bool valid() const;

Expand Down
1 change: 1 addition & 0 deletions src/controllers/filters/parser/Tokenizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static const QMap<QString, QString> validIdentifiersMap = {
{"author.sub_length", "author sub length"},
{"channel.name", "channel name"},
{"channel.watching", "/watching channel?"},
{"channel.live", "Channel live?"},
{"flags.highlighted", "highlighted?"},
{"flags.points_redeemed", "redeemed points?"},
{"flags.sub_message", "sub/resub message?"},
Expand Down
63 changes: 63 additions & 0 deletions src/controllers/ignores/IgnoreController.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "controllers/ignores/IgnoreController.hpp"

#include "common/QLogging.hpp"
#include "controllers/ignores/IgnorePhrase.hpp"
#include "singletons/Settings.hpp"

namespace chatterino {

bool isIgnoredMessage(IgnoredMessageParameters &&params)
{
if (!params.message.isEmpty())
{
// TODO(pajlada): Do we need to check if the phrase is valid first?
auto phrases = getCSettings().ignoredMessages.readOnly();
for (const auto &phrase : *phrases)
{
if (phrase.isBlock() && phrase.isMatch(params.message))
{
qCDebug(chatterinoMessage)
<< "Blocking message because it contains ignored phrase"
<< phrase.getPattern();
return true;
}
}
}

if (!params.twitchUserID.isEmpty() &&
getSettings()->enableTwitchBlockedUsers)
{
auto sourceUserID = params.twitchUserID;

auto blocks =
getApp()->accounts->twitch.getCurrent()->accessBlockedUserIds();

if (auto it = blocks->find(sourceUserID); it != blocks->end())
{
switch (static_cast<ShowIgnoredUsersMessages>(
getSettings()->showBlockedUsersMessages.getValue()))
{
case ShowIgnoredUsersMessages::IfModerator:
if (params.isMod || params.isBroadcaster)
{
return false;
}
break;
case ShowIgnoredUsersMessages::IfBroadcaster:
if (params.isBroadcaster)
{
return false;
}
break;
case ShowIgnoredUsersMessages::Never:
break;
}

return true;
}
}

return false;
}

} // namespace chatterino
12 changes: 12 additions & 0 deletions src/controllers/ignores/IgnoreController.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
#pragma once

#include <QString>

namespace chatterino {

enum class ShowIgnoredUsersMessages { Never, IfModerator, IfBroadcaster };

struct IgnoredMessageParameters {
QString message;

QString twitchUserID;
bool isMod;
bool isBroadcaster;
};

bool isIgnoredMessage(IgnoredMessageParameters &&params);

} // namespace chatterino
18 changes: 4 additions & 14 deletions src/messages/SharedMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Application.hpp"
#include "common/QLogging.hpp"
#include "controllers/ignores/IgnoreController.hpp"
#include "controllers/ignores/IgnorePhrase.hpp"
#include "messages/Message.hpp"
#include "messages/MessageElement.hpp"
Expand Down Expand Up @@ -104,20 +105,9 @@ void SharedMessageBuilder::parse()

bool SharedMessageBuilder::isIgnored() const
{
// TODO(pajlada): Do we need to check if the phrase is valid first?
auto phrases = getCSettings().ignoredMessages.readOnly();
for (const auto &phrase : *phrases)
{
if (phrase.isBlock() && phrase.isMatch(this->originalMessage_))
{
qCDebug(chatterinoMessage)
<< "Blocking message because it contains ignored phrase"
<< phrase.getPattern();
return true;
}
}

return false;
return isIgnoredMessage({
/*.message = */ this->originalMessage_,
});
}

void SharedMessageBuilder::parseUsernameColor()
Expand Down
15 changes: 13 additions & 2 deletions src/providers/twitch/TwitchChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ void TwitchChannel::addChannelPointReward(const ChannelPointReward &reward)
if (!reward.isUserInputRequired)
{
MessageBuilder builder;
TwitchMessageBuilder::appendChannelPointRewardMessage(reward, &builder);
TwitchMessageBuilder::appendChannelPointRewardMessage(
reward, &builder, this->isMod(), this->isBroadcaster());
this->addMessage(builder.release());
return;
}
Expand Down Expand Up @@ -390,7 +391,17 @@ void TwitchChannel::sendMessage(const QString &message)
{
if (parsedMessage == this->lastSentMessage_)
{
parsedMessage.append(MAGIC_MESSAGE_SUFFIX);
auto spaceIndex = parsedMessage.indexOf(' ');
if (spaceIndex == -1)
{
// no spaces found, fall back to old magic character
parsedMessage.append(MAGIC_MESSAGE_SUFFIX);
}
else
{
// replace the space we found in spaceIndex with two spaces
parsedMessage.replace(spaceIndex, 1, " ");
}
}
}
}
Expand Down
61 changes: 21 additions & 40 deletions src/providers/twitch/TwitchMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,44 +115,12 @@ TwitchMessageBuilder::TwitchMessageBuilder(

bool TwitchMessageBuilder::isIgnored() const
{
if (SharedMessageBuilder::isIgnored())
{
return true;
}

auto app = getApp();

if (getSettings()->enableTwitchBlockedUsers &&
this->tags.contains("user-id"))
{
auto sourceUserID = this->tags.value("user-id").toString();

auto blocks =
app->accounts->twitch.getCurrent()->accessBlockedUserIds();

if (auto it = blocks->find(sourceUserID); it != blocks->end())
{
switch (static_cast<ShowIgnoredUsersMessages>(
getSettings()->showBlockedUsersMessages.getValue()))
{
case ShowIgnoredUsersMessages::IfModerator:
if (this->channel->isMod() ||
this->channel->isBroadcaster())
return false;
break;
case ShowIgnoredUsersMessages::IfBroadcaster:
if (this->channel->isBroadcaster())
return false;
break;
case ShowIgnoredUsersMessages::Never:
break;
}

return true;
}
}

return false;
return isIgnoredMessage({
/*.message = */ this->originalMessage_,
/*.twitchUserID = */ this->tags.value("user-id").toString(),
/*.isMod = */ this->channel->isMod(),
/*.isBroadcaster = */ this->channel->isBroadcaster(),
});
}

void TwitchMessageBuilder::triggerHighlights()
Expand Down Expand Up @@ -191,7 +159,9 @@ MessagePtr TwitchMessageBuilder::build()
this->args.channelPointRewardId);
if (reward)
{
this->appendChannelPointRewardMessage(reward.get(), this);
this->appendChannelPointRewardMessage(
reward.get(), this, this->channel->isMod(),
this->channel->isBroadcaster());
}
}

Expand Down Expand Up @@ -1281,8 +1251,19 @@ Outcome TwitchMessageBuilder::tryParseCheermote(const QString &string)
}

void TwitchMessageBuilder::appendChannelPointRewardMessage(
const ChannelPointReward &reward, MessageBuilder *builder)
const ChannelPointReward &reward, MessageBuilder *builder, bool isMod,
bool isBroadcaster)
{
if (isIgnoredMessage({
/*.message = */ "",
/*.twitchUserID = */ reward.user.id,
/*.isMod = */ isMod,
/*.isBroadcaster = */ isBroadcaster,
}))
{
return;
}

builder->emplace<TimestampElement>();
QString redeemed = "Redeemed";
QStringList textList;
Expand Down
3 changes: 2 additions & 1 deletion src/providers/twitch/TwitchMessageBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class TwitchMessageBuilder : public SharedMessageBuilder
MessagePtr build() override;

static void appendChannelPointRewardMessage(
const ChannelPointReward &reward, MessageBuilder *builder);
const ChannelPointReward &reward, MessageBuilder *builder, bool isMod,
bool isBroadcaster);

// Message in the /live chat for channel going live
static void liveMessage(const QString &channelName,
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/helper/ChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ bool ChannelView::shouldIncludeMessage(const MessagePtr &m) const
m->loginName, Qt::CaseInsensitive) == 0)
return true;

return this->channelFilters_->filter(m);
return this->channelFilters_->filter(m, this->channel_);
}

return true;
Expand Down

0 comments on commit 1ec8084

Please sign in to comment.