From 8bd0b6ee79fcc676a8613d59def362c7cde8bcb4 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 10 Mar 2024 12:09:33 +0100 Subject: [PATCH 1/7] unrelated refactor: define/create chan once on privmsg --- src/providers/twitch/IrcMessageHandler.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index b0eec1f8c6e..d76c9c82bd9 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -653,23 +653,22 @@ std::vector IrcMessageHandler::parseMessageWithReply( void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message, TwitchIrcServer &server) { + auto chan = channelOrEmptyByTarget(message->target(), server); + if (chan->isEmpty()) + { + return; + } + // 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( - message, channelOrEmptyByTarget(message->target(), server), + message, chan, 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); From 0d9d663f0810b9e5c55db7fdfea5b713c2e2890f Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 10 Mar 2024 12:11:36 +0100 Subject: [PATCH 2/7] fix: update vip/staff/mod status when you type a message --- src/providers/twitch/IrcMessageHandler.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index d76c9c82bd9..8a9cc9e6c2c 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -659,6 +659,24 @@ void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message, return; } + auto *twitchChannel = dynamic_cast(chan.get()); + + if (twitchChannel != nullptr) + { + auto currentUser = getIApp()->getAccounts()->twitch.getCurrent(); + if (message->tag("user-id") == currentUser->getUserId()) + { + auto badgesTag = message->tag("badges"); + if (badgesTag.isValid()) + { + auto parsedBadges = parseBadges(badgesTag.toString()); + twitchChannel->setMod(parsedBadges.contains("moderator")); + twitchChannel->setVIP(parsedBadges.contains("vip")); + twitchChannel->setStaff(parsedBadges.contains("staff")); + } + } + } + // 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. From 74352347316ec51254ba6fc4838ae5dba0e3d217 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 10 Mar 2024 12:12:55 +0100 Subject: [PATCH 3/7] rename SplitHeader::updateModerationModeIcon to SplitHeader::updateIcons --- src/widgets/splits/Split.cpp | 8 ++++---- src/widgets/splits/SplitHeader.cpp | 6 +++--- src/widgets/splits/SplitHeader.hpp | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index 780d0998d23..bdd91f1d273 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -331,7 +331,7 @@ Split::Split(QWidget *parent) }, this->signalHolder_); - this->header_->updateModerationModeIcon(); + this->header_->updateIcons(); this->overlay_->hide(); this->setSizePolicy(QSizePolicy::MinimumExpanding, @@ -813,7 +813,7 @@ void Split::joinChannelInNewTab(ChannelPtr channel) void Split::refreshModerationMode() { - this->header_->updateModerationModeIcon(); + this->header_->updateIcons(); this->view_->queueLayout(); } @@ -865,7 +865,7 @@ void Split::setChannel(IndirectChannel newChannel) if (tc != nullptr) { this->usermodeChangedConnection_ = tc->userStateChanged.connect([this] { - this->header_->updateModerationModeIcon(); + this->header_->updateIcons(); this->header_->updateRoomModes(); }); @@ -881,7 +881,7 @@ void Split::setChannel(IndirectChannel newChannel) }); }); - this->header_->updateModerationModeIcon(); + this->header_->updateIcons(); this->header_->updateChannelText(); this->header_->updateRoomModes(); diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index 7e27ad16b17..a649f53142e 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -230,7 +230,7 @@ SplitHeader::SplitHeader(Split *split) this->setMouseTracking(true); this->updateChannelText(); this->handleChannelChanged(); - this->updateModerationModeIcon(); + this->updateIcons(); // The lifetime of these signals are tied to the lifetime of the Split. // Since the SplitHeader is owned by the Split, they will always be destroyed @@ -247,7 +247,7 @@ SplitHeader::SplitHeader(Split *split) this->bSignals_.emplace_back( getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] { - this->updateModerationModeIcon(); + this->updateIcons(); })); auto _ = [this](const auto &, const auto &) { @@ -838,7 +838,7 @@ void SplitHeader::updateChannelText() this->titleLabel_->setText(title.isEmpty() ? "" : title); } -void SplitHeader::updateModerationModeIcon() +void SplitHeader::updateIcons() { auto moderationMode = this->split_->getModerationMode() && !getSettings()->moderationActions.empty(); diff --git a/src/widgets/splits/SplitHeader.hpp b/src/widgets/splits/SplitHeader.hpp index 872ba8a8b7d..319f30c664e 100644 --- a/src/widgets/splits/SplitHeader.hpp +++ b/src/widgets/splits/SplitHeader.hpp @@ -32,7 +32,7 @@ class SplitHeader final : public BaseWidget void setChattersButtonVisible(bool value); void updateChannelText(); - void updateModerationModeIcon(); + void updateIcons(); // Invoked when SplitHeader should update anything refering to a TwitchChannel's mode // has changed (e.g. sub mode toggled) void updateRoomModes(); From e4f59268c7896249ea4d59eda959993b2f362388 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 10 Mar 2024 12:13:25 +0100 Subject: [PATCH 4/7] fix: hide chatter list in split header for non-moderators --- src/widgets/splits/SplitHeader.cpp | 32 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index a649f53142e..1d86e181ea7 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -840,24 +840,36 @@ void SplitHeader::updateChannelText() void SplitHeader::updateIcons() { - auto moderationMode = this->split_->getModerationMode() && - !getSettings()->moderationActions.empty(); - - this->moderationButton_->setPixmap( - moderationMode ? getResources().buttons.modModeEnabled - : getResources().buttons.modModeDisabled); - auto channel = this->split_->getChannel(); auto *twitchChannel = dynamic_cast(channel.get()); - if (twitchChannel != nullptr && - (twitchChannel->hasModRights() || moderationMode)) + if (twitchChannel != nullptr) { - this->moderationButton_->show(); + auto moderationMode = this->split_->getModerationMode() && + !getSettings()->moderationActions.empty(); + + this->moderationButton_->setPixmap( + moderationMode ? getResources().buttons.modModeEnabled + : getResources().buttons.modModeDisabled); + + if (twitchChannel->hasModRights() || moderationMode) + { + this->moderationButton_->show(); + } + else + { + this->moderationButton_->hide(); + } + + if (twitchChannel->hasModRights()) + { + this->chattersButton_->show(); + } } else { this->moderationButton_->hide(); + this->chattersButton_->hide(); } } From babf438aa6cf7fe2ab0f6228c1f8a8fe060e3cb2 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 10 Mar 2024 12:13:50 +0100 Subject: [PATCH 5/7] fix: remove chatter button visible code since this is now handled elsewhere --- src/widgets/splits/Split.cpp | 9 --------- src/widgets/splits/SplitHeader.cpp | 5 ----- src/widgets/splits/SplitHeader.hpp | 1 - 3 files changed, 15 deletions(-) diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index bdd91f1d273..9e31263197f 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -885,15 +885,6 @@ void Split::setChannel(IndirectChannel newChannel) this->header_->updateChannelText(); this->header_->updateRoomModes(); - if (newChannel.getType() == Channel::Type::Twitch) - { - this->header_->setChattersButtonVisible(true); - } - else - { - this->header_->setChattersButtonVisible(false); - } - this->channelSignalHolder_.managedConnect( this->channel_.get()->displayNameChanged, [this] { this->actionRequested.invoke(Action::RefreshTab); diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index 1d86e181ea7..b3d92d3e0d9 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -755,11 +755,6 @@ void SplitHeader::setAddButtonVisible(bool value) this->addButton_->setVisible(value); } -void SplitHeader::setChattersButtonVisible(bool value) -{ - this->chattersButton_->setVisible(value); -} - void SplitHeader::updateChannelText() { auto indirectChannel = this->split_->getIndirectChannel(); diff --git a/src/widgets/splits/SplitHeader.hpp b/src/widgets/splits/SplitHeader.hpp index 319f30c664e..efae94849ab 100644 --- a/src/widgets/splits/SplitHeader.hpp +++ b/src/widgets/splits/SplitHeader.hpp @@ -29,7 +29,6 @@ class SplitHeader final : public BaseWidget explicit SplitHeader(Split *split); void setAddButtonVisible(bool value); - void setChattersButtonVisible(bool value); void updateChannelText(); void updateIcons(); From 1e39eb99bfac70cfb4368b03e2deea3da4de7f81 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 10 Mar 2024 12:16:04 +0100 Subject: [PATCH 6/7] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4606d64d23c..7b4ea7dbeae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - Minor: Updated the flatpakref link included with nightly builds to point to up-to-date flathub-beta builds. (#5008) - Minor: Add a new completion API for experimental plugins feature. (#5000, #5047) - Minor: Re-enabled _Restart on crash_ option on Windows. (#5012) +- Minor: The chatter list button is now hidden if you don't have moderator privileges. (#5245) - Minor: The whisper highlight color can now be configured through the settings. (#5053) - Minor: Added an option to always include the broadcaster in user completions. This is enabled by default. (#5193, #5244) - Minor: Added missing periods at various moderator messages and commands. (#5061) From 227b1b7afce6b334467e6e86e990ce70cddd545b Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sun, 10 Mar 2024 12:19:33 +0100 Subject: [PATCH 7/7] hide chatter button if losing mod rights --- src/widgets/splits/SplitHeader.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/widgets/splits/SplitHeader.cpp b/src/widgets/splits/SplitHeader.cpp index b3d92d3e0d9..b8b811ca4c4 100644 --- a/src/widgets/splits/SplitHeader.cpp +++ b/src/widgets/splits/SplitHeader.cpp @@ -860,6 +860,10 @@ void SplitHeader::updateIcons() { this->chattersButton_->show(); } + else + { + this->chattersButton_->hide(); + } } else {