Rewrite logic for when to show moderation buttons next to messages (#2800)

Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
fourtf 2021-08-14 13:06:58 +02:00 committed by GitHub
parent 75458a1a25
commit d5ecba3d30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 23 deletions

View file

@ -184,29 +184,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>();
}
@ -1230,6 +1208,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)

View file

@ -90,6 +90,8 @@ private:
void appendFfzBadges();
Outcome tryParseCheermote(const QString &string);
bool shouldAddModerationElements() const;
QString roomID_;
bool hasBits_ = false;
QString bits;