Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

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 1d664f8; Changes from upstream we've pulled:

- Minor: Allow resub messages to show in `/mentions` tab (Chatterino#3148)
- Minor: Added a setting to hide similar messages by any user. (Chatterino#2716)
- Minor: Duplicate spaces now count towards the display message length. (Chatterino#3002)
- Minor: Commands are now backed up. (Chatterino#3168)
- Bugfix: Restored ability to send duplicate `/me` messages. (Chatterino#3166)
- Bugfix: Notifications for moderators about other moderators deleting messages can now be disabled. (Chatterino#3121)
  • Loading branch information
zneix committed Aug 15, 2021
2 parents f7feb0d + 1d664f8 commit ba3b6dc
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 80 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
- Minor: Remove TwitchEmotes.com attribution and the open/copy options when right-clicking a Twitch Emote. (#2214, #3136)
- Minor: Strip leading @ and trailing , from username in /user and /usercard commands. (#3143)
- Minor: Display a system message when reloading subscription emotes to match BTTV/FFZ behavior (#3135)
- Minor: Allow resub messages to show in `/mentions` tab (#3148)
- Minor: Added a setting to hide similar messages by any user. (#2716)
- Minor: Duplicate spaces now count towards the display message length. (#3002)
- Minor: Commands are now backed up. (#3168)
- Bugfix: Restored ability to send duplicate `/me` messages. (#3166)
- Bugfix: Notifications for moderators about other moderators deleting messages can now be disabled. (#3121)
- Bugfix: Moderation mode and active filters are now preserved when opening a split as a popup. (#3113, #3130)
- Bugfix: Fixed a bug that caused all badge highlights to use the same color. (#3132, #3134)
- Dev: Renamed CMake's build option `USE_SYSTEM_QT5KEYCHAIN` to `USE_SYSTEM_QTKEYCHAIN`. (#3103)
Expand Down
2 changes: 1 addition & 1 deletion src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void Application::initPubsub()
auto chan =
this->twitch.server->getChannelOrEmptyByID(action.roomID);

if (chan->isEmpty())
if (chan->isEmpty() || getSettings()->hideDeletionActions)
{
return;
}
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/commands/CommandController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ void CommandController::initialize(Settings &, Paths &paths)
auto path = combinePath(paths.settingsDirectory, "commands.json");
this->sm_ = std::make_shared<pajlada::Settings::SettingManager>();
this->sm_->setPath(path.toStdString());
this->sm_->setBackupEnabled(true);
this->sm_->setBackupSlots(9);

// Delayed initialization of the setting storing all commands
this->commandsSetting_.reset(
Expand Down
20 changes: 13 additions & 7 deletions src/messages/SharedMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ void SharedMessageBuilder::parseHighlights()
this->message().flags.set(MessageFlag::Highlighted);
this->message().highlightColor =
ColorProvider::instance().color(ColorType::Subscription);

// This message was a subscription.
// Don't check for any other highlight phrases.
return;
}

// XXX: Non-common term in SharedMessageBuilder
Expand Down Expand Up @@ -220,7 +216,10 @@ void SharedMessageBuilder::parseHighlights()
<< "sent a message";

this->message().flags.set(MessageFlag::Highlighted);
this->message().highlightColor = userHighlight.getColor();
if (!this->message().flags.has(MessageFlag::Subscription))
{
this->message().highlightColor = userHighlight.getColor();
}

if (userHighlight.showInMentions())
{
Expand Down Expand Up @@ -289,7 +288,10 @@ void SharedMessageBuilder::parseHighlights()
}

this->message().flags.set(MessageFlag::Highlighted);
this->message().highlightColor = highlight.getColor();
if (!this->message().flags.has(MessageFlag::Subscription))
{
this->message().highlightColor = highlight.getColor();
}

if (highlight.showInMentions())
{
Expand Down Expand Up @@ -344,7 +346,11 @@ void SharedMessageBuilder::parseHighlights()
if (!badgeHighlightSet)
{
this->message().flags.set(MessageFlag::Highlighted);
this->message().highlightColor = highlight.getColor();
if (!this->message().flags.has(MessageFlag::Subscription))
{
this->message().highlightColor = highlight.getColor();
}

badgeHighlightSet = true;
}

Expand Down
19 changes: 8 additions & 11 deletions src/providers/twitch/IrcMessageHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ float IrcMessageHandler::similarity(
MessagePtr msg, const LimitedQueueSnapshot<MessagePtr> &messages)
{
float similarityPercent = 0.0f;
int bySameUser = 0;
for (int i = 1; bySameUser < getSettings()->hideSimilarMaxMessagesToCheck;
++i)
int checked = 0;
for (int i = 1; i <= messages.size(); ++i)
{
if (messages.size() < i)
if (checked >= getSettings()->hideSimilarMaxMessagesToCheck)
{
break;
}
Expand All @@ -126,11 +125,12 @@ float IrcMessageHandler::similarity(
{
break;
}
if (msg->loginName != prevMsg->loginName)
if (getSettings()->hideSimilarBySameUser &&
msg->loginName != prevMsg->loginName)
{
continue;
}
++bySameUser;
++checked;
similarityPercent = std::max(
similarityPercent,
relativeSimilarity(msg->messageText, prevMsg->messageText));
Expand Down Expand Up @@ -313,12 +313,9 @@ void IrcMessageHandler::addMessage(Communi::IrcMessage *_message,
const auto highlighted = msg->flags.has(MessageFlag::Highlighted);
const auto showInMentions = msg->flags.has(MessageFlag::ShowInMentions);

if (!isSub)
if (highlighted && showInMentions)
{
if (highlighted && showInMentions)
{
server.mentionsChannel->addMessage(msg);
}
server.mentionsChannel->addMessage(msg);
}

chan->addMessage(msg);
Expand Down
10 changes: 10 additions & 0 deletions src/providers/twitch/TwitchChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ void TwitchChannel::sendMessage(const QString &message)
if (parsedMessage == this->lastSentMessage_)
{
auto spaceIndex = parsedMessage.indexOf(' ');
// If the message starts with either '/' or '.' Twitch will treat it as a command, omitting
// first space and only rest of the arguments treated as actual message content
// In cases when user sends a message like ". .a b" first character and first space are omitted as well
bool ignoreFirstSpace =
parsedMessage.at(0) == '/' || parsedMessage.at(0) == '.';
if (ignoreFirstSpace)
{
spaceIndex = parsedMessage.indexOf(' ', spaceIndex + 1);
}

if (spaceIndex == -1)
{
// no spaces found, fall back to old magic character
Expand Down
42 changes: 19 additions & 23 deletions src/providers/twitch/TwitchMessageBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,29 +185,7 @@ MessagePtr TwitchMessageBuilder::build()
this->emplace<TimestampElement>(
calculateMessageTimestamp(this->ircMessage));

bool addModerationElement = true;
if (this->senderIsBroadcaster)
{
addModerationElement = false;
}
else
{
bool hasUserType = this->tags.contains("user-type");
if (hasUserType)
{
QString userType = this->tags.value("user-type").toString();

if (userType == "mod")
{
if (!args.isStaffOrBroadcaster)
{
addModerationElement = false;
}
}
}
}

if (addModerationElement)
if (this->shouldAddModerationElements())
{
this->emplace<TwitchModerationElement>();
}
Expand Down Expand Up @@ -1258,6 +1236,24 @@ Outcome TwitchMessageBuilder::tryParseCheermote(const QString &string)
return Success;
}

bool TwitchMessageBuilder::shouldAddModerationElements() const
{
if (this->senderIsBroadcaster)
{
// You cannot timeout the broadcaster
return false;
}

if (this->tags.value("user-type").toString() == "mod" &&
!this->args.isStaffOrBroadcaster)
{
// You cannot timeout moderators UNLESS you are Twitch Staff or the broadcaster of the channel
return false;
}

return true;
}

void TwitchMessageBuilder::appendChannelPointRewardMessage(
const ChannelPointReward &reward, MessageBuilder *builder, bool isMod,
bool isBroadcaster)
Expand Down
2 changes: 2 additions & 0 deletions src/providers/twitch/TwitchMessageBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class TwitchMessageBuilder : public SharedMessageBuilder
void appendFfzBadges();
Outcome tryParseCheermote(const QString &string);

bool shouldAddModerationElements() const;

QString roomID_;
bool hasBits_ = false;
QString bits;
Expand Down
2 changes: 2 additions & 0 deletions src/singletons/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ class Settings : public ABSettings, public ConcurrentSettings
BoolSetting colorSimilarDisabled = {"/similarity/colorSimilarDisabled",
true};
BoolSetting hideSimilar = {"/similarity/hideSimilar", false};
BoolSetting hideSimilarBySameUser = {"/similarity/hideSimilarBySameUser",
true};
BoolSetting hideSimilarMyself = {"/similarity/hideSimilarMyself", false};
BoolSetting shownSimilarTriggerHighlights = {
"/similarity/shownSimilarTriggerHighlights", false};
Expand Down
2 changes: 1 addition & 1 deletion src/util/StreamLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void openStreamlinkForChannel(const QString &channel)
if (preferredQuality == "choose")
{
getStreamQualities(channelURL, [=](QStringList qualityOptions) {
QualityPopup::showDialog(channel, qualityOptions);
QualityPopup::showDialog(channelURL, qualityOptions);
});

return;
Expand Down
64 changes: 64 additions & 0 deletions src/widgets/BasePopup.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "widgets/BasePopup.hpp"

#include <QAbstractButton>
#include <QDialogButtonBox>
#include <QKeyEvent>

namespace chatterino {
Expand All @@ -20,4 +22,66 @@ void BasePopup::keyPressEvent(QKeyEvent *e)
BaseWindow::keyPressEvent(e);
}

bool BasePopup::handleEscape(QKeyEvent *e, QDialogButtonBox *buttonBox)
{
assert(buttonBox != nullptr);

if (e->key() == Qt::Key_Escape)
{
auto buttons = buttonBox->buttons();
for (auto *button : buttons)
{
if (auto role = buttonBox->buttonRole(button);
role == QDialogButtonBox::ButtonRole::RejectRole)
{
button->click();
return true;
}
}
}

return false;
}

bool BasePopup::handleEnter(QKeyEvent *e, QDialogButtonBox *buttonBox)
{
assert(buttonBox != nullptr);

if (!e->modifiers() ||
(e->modifiers() & Qt::KeypadModifier && e->key() == Qt::Key_Enter))
{
switch (e->key())
{
case Qt::Key_Enter:
case Qt::Key_Return: {
auto buttons = buttonBox->buttons();
QAbstractButton *acceptButton = nullptr;
for (auto *button : buttons)
{
if (button->hasFocus())
{
button->click();
return true;
}

if (auto role = buttonBox->buttonRole(button);
role == QDialogButtonBox::ButtonRole::AcceptRole)
{
acceptButton = button;
}
}

if (acceptButton != nullptr)
{
acceptButton->click();
return true;
}
}
break;
}
}

return false;
}

} // namespace chatterino
8 changes: 8 additions & 0 deletions src/widgets/BasePopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "common/FlagsEnum.hpp"
#include "widgets/BaseWindow.hpp"

class QDialogButtonBox;

namespace chatterino {

class BasePopup : public BaseWindow
Expand All @@ -13,6 +15,12 @@ class BasePopup : public BaseWindow

protected:
void keyPressEvent(QKeyEvent *e) override;

// handleEscape is a helper function for clicking the "Reject" role button of a button box when the Escape button is pressed
bool handleEscape(QKeyEvent *e, QDialogButtonBox *buttonBox);

// handleEnter is a helper function for clicking the "Accept" role button of a button box when Return or Enter is pressed
bool handleEnter(QKeyEvent *e, QDialogButtonBox *buttonBox);
};

} // namespace chatterino
Loading

0 comments on commit ba3b6dc

Please sign in to comment.