Hide chatter list button for non-moderators (#5245)

This commit is contained in:
pajlada 2024-03-10 12:46:26 +01:00 committed by GitHub
parent 9d02fa14ed
commit a958619860
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 63 additions and 44 deletions

View file

@ -20,6 +20,7 @@
- Minor: Updated the flatpakref link included with nightly builds to point to up-to-date flathub-beta builds. (#5008) - 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: Add a new completion API for experimental plugins feature. (#5000, #5047)
- Minor: Re-enabled _Restart on crash_ option on Windows. (#5012) - 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: 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 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) - Minor: Added missing periods at various moderator messages and commands. (#5061)

View file

@ -653,23 +653,40 @@ std::vector<MessagePtr> IrcMessageHandler::parseMessageWithReply(
void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message, void IrcMessageHandler::handlePrivMessage(Communi::IrcPrivateMessage *message,
TwitchIrcServer &server) TwitchIrcServer &server)
{ {
// 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->content().replace(COMBINED_FIXER, ZERO_WIDTH_JOINER), server,
false, message->isAction());
auto chan = channelOrEmptyByTarget(message->target(), server); auto chan = channelOrEmptyByTarget(message->target(), server);
if (chan->isEmpty()) if (chan->isEmpty())
{ {
return; return;
} }
auto *twitchChannel = dynamic_cast<TwitchChannel *>(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.
// See https://github.com/Chatterino/chatterino2/issues/3384 and
// https://mm2pl.github.io/emoji_rfc.pdf for more details
this->addMessage(
message, chan,
message->content().replace(COMBINED_FIXER, ZERO_WIDTH_JOINER), server,
false, message->isAction());
if (message->tags().contains(u"pinned-chat-paid-amount"_s)) if (message->tags().contains(u"pinned-chat-paid-amount"_s))
{ {
auto ptr = TwitchMessageBuilder::buildHypeChatMessage(message); auto ptr = TwitchMessageBuilder::buildHypeChatMessage(message);

View file

@ -331,7 +331,7 @@ Split::Split(QWidget *parent)
}, },
this->signalHolder_); this->signalHolder_);
this->header_->updateModerationModeIcon(); this->header_->updateIcons();
this->overlay_->hide(); this->overlay_->hide();
this->setSizePolicy(QSizePolicy::MinimumExpanding, this->setSizePolicy(QSizePolicy::MinimumExpanding,
@ -813,7 +813,7 @@ void Split::joinChannelInNewTab(ChannelPtr channel)
void Split::refreshModerationMode() void Split::refreshModerationMode()
{ {
this->header_->updateModerationModeIcon(); this->header_->updateIcons();
this->view_->queueLayout(); this->view_->queueLayout();
} }
@ -865,7 +865,7 @@ void Split::setChannel(IndirectChannel newChannel)
if (tc != nullptr) if (tc != nullptr)
{ {
this->usermodeChangedConnection_ = tc->userStateChanged.connect([this] { this->usermodeChangedConnection_ = tc->userStateChanged.connect([this] {
this->header_->updateModerationModeIcon(); this->header_->updateIcons();
this->header_->updateRoomModes(); this->header_->updateRoomModes();
}); });
@ -881,19 +881,10 @@ void Split::setChannel(IndirectChannel newChannel)
}); });
}); });
this->header_->updateModerationModeIcon(); this->header_->updateIcons();
this->header_->updateChannelText(); this->header_->updateChannelText();
this->header_->updateRoomModes(); this->header_->updateRoomModes();
if (newChannel.getType() == Channel::Type::Twitch)
{
this->header_->setChattersButtonVisible(true);
}
else
{
this->header_->setChattersButtonVisible(false);
}
this->channelSignalHolder_.managedConnect( this->channelSignalHolder_.managedConnect(
this->channel_.get()->displayNameChanged, [this] { this->channel_.get()->displayNameChanged, [this] {
this->actionRequested.invoke(Action::RefreshTab); this->actionRequested.invoke(Action::RefreshTab);

View file

@ -230,7 +230,7 @@ SplitHeader::SplitHeader(Split *split)
this->setMouseTracking(true); this->setMouseTracking(true);
this->updateChannelText(); this->updateChannelText();
this->handleChannelChanged(); this->handleChannelChanged();
this->updateModerationModeIcon(); this->updateIcons();
// The lifetime of these signals are tied to the lifetime of the Split. // 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 // 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( this->bSignals_.emplace_back(
getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] { getIApp()->getAccounts()->twitch.currentUserChanged.connect([this] {
this->updateModerationModeIcon(); this->updateIcons();
})); }));
auto _ = [this](const auto &, const auto &) { auto _ = [this](const auto &, const auto &) {
@ -755,11 +755,6 @@ void SplitHeader::setAddButtonVisible(bool value)
this->addButton_->setVisible(value); this->addButton_->setVisible(value);
} }
void SplitHeader::setChattersButtonVisible(bool value)
{
this->chattersButton_->setVisible(value);
}
void SplitHeader::updateChannelText() void SplitHeader::updateChannelText()
{ {
auto indirectChannel = this->split_->getIndirectChannel(); auto indirectChannel = this->split_->getIndirectChannel();
@ -838,26 +833,42 @@ void SplitHeader::updateChannelText()
this->titleLabel_->setText(title.isEmpty() ? "<empty>" : title); this->titleLabel_->setText(title.isEmpty() ? "<empty>" : title);
} }
void SplitHeader::updateModerationModeIcon() 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 channel = this->split_->getChannel();
auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get()); auto *twitchChannel = dynamic_cast<TwitchChannel *>(channel.get());
if (twitchChannel != nullptr && if (twitchChannel != nullptr)
(twitchChannel->hasModRights() || moderationMode))
{ {
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->chattersButton_->hide();
}
} }
else else
{ {
this->moderationButton_->hide(); this->moderationButton_->hide();
this->chattersButton_->hide();
} }
} }

View file

@ -29,10 +29,9 @@ public:
explicit SplitHeader(Split *split); explicit SplitHeader(Split *split);
void setAddButtonVisible(bool value); void setAddButtonVisible(bool value);
void setChattersButtonVisible(bool value);
void updateChannelText(); void updateChannelText();
void updateModerationModeIcon(); void updateIcons();
// Invoked when SplitHeader should update anything refering to a TwitchChannel's mode // Invoked when SplitHeader should update anything refering to a TwitchChannel's mode
// has changed (e.g. sub mode toggled) // has changed (e.g. sub mode toggled)
void updateRoomModes(); void updateRoomModes();