Skip to content

Commit

Permalink
Fix filter crash introduced in Chatterino#3092 (Chatterino#3110)
Browse files Browse the repository at this point in the history
  • Loading branch information
pajlada committed Aug 3, 2021
1 parent 784fdd2 commit 95044ef
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- 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)
- 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)
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
14 changes: 4 additions & 10 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 @@ -83,9 +84,8 @@ ContextMap buildContextMap(const MessagePtr &m)
};
{
using namespace chatterino;
auto channel = getApp()->twitch2->getChannelOrEmpty(m->channelName);
auto *tc = dynamic_cast<TwitchChannel *>(channel.get());
if (!channel->isEmpty() && tc)
auto *tc = dynamic_cast<TwitchChannel *>(channel);
if (channel && !channel->isEmpty() && tc)
{
vars["channel.live"] = tc->isLive();
}
Expand All @@ -104,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
2 changes: 1 addition & 1 deletion src/widgets/helper/ChannelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,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
2 changes: 1 addition & 1 deletion src/widgets/helper/SearchPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ChannelPtr SearchPopup::filter(const QString &text, const QString &channelName,
}

if (accept && filterSet)
accept = filterSet->filter(message);
accept = filterSet->filter(message, channel);

// If all predicates match, add the message to the channel
if (accept)
Expand Down

0 comments on commit 95044ef

Please sign in to comment.