fix: disable reply options where we know it wouldn't work (#6119)
This commit is contained in:
@@ -159,4 +159,44 @@ QJsonObject Message::toJson() const
|
||||
return msg;
|
||||
}
|
||||
|
||||
Message::ReplyStatus Message::isReplyable() const
|
||||
{
|
||||
if (this->loginName.isEmpty())
|
||||
{
|
||||
// no replies can happen
|
||||
return ReplyStatus::NotReplyable;
|
||||
}
|
||||
|
||||
constexpr int oneDayInSeconds = 24 * 60 * 60;
|
||||
bool messageReplyable = true;
|
||||
if (this->flags.hasAny({MessageFlag::System, MessageFlag::Subscription,
|
||||
MessageFlag::Timeout, MessageFlag::Whisper,
|
||||
MessageFlag::ModerationAction,
|
||||
MessageFlag::InvalidReplyTarget}) ||
|
||||
this->serverReceivedTime.secsTo(QDateTime::currentDateTime()) >
|
||||
oneDayInSeconds)
|
||||
{
|
||||
messageReplyable = false;
|
||||
}
|
||||
|
||||
if (this->replyThread != nullptr)
|
||||
{
|
||||
if (const auto &rootPtr = this->replyThread->root(); rootPtr != nullptr)
|
||||
{
|
||||
assert(this != rootPtr.get());
|
||||
if (rootPtr->isReplyable() == ReplyStatus::NotReplyable)
|
||||
{
|
||||
// thread parent must be replyable to be replyable
|
||||
return ReplyStatus::NotReplyableDueToThread;
|
||||
}
|
||||
|
||||
return messageReplyable ? ReplyStatus::ReplyableWithThread
|
||||
: ReplyStatus::NotReplyableWithThread;
|
||||
}
|
||||
}
|
||||
|
||||
return messageReplyable ? ReplyStatus::Replyable
|
||||
: ReplyStatus::NotReplyable;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -62,6 +62,29 @@ struct Message {
|
||||
// The root of the thread does not have replyThread set.
|
||||
std::shared_ptr<MessageThread> replyThread;
|
||||
MessagePtr replyParent;
|
||||
enum class ReplyStatus : std::uint8_t {
|
||||
/// message has no reply thread, and message is not replyable
|
||||
///
|
||||
/// e.g. due to message being deleted or too old
|
||||
NotReplyable,
|
||||
|
||||
/// message has no reply thread, but message is replyable
|
||||
Replyable,
|
||||
|
||||
/// message is part of a reply thread. both message & thread are replyable
|
||||
ReplyableWithThread,
|
||||
|
||||
/// message is part of a reply thread. thread is replyable, but message is not replyable
|
||||
///
|
||||
/// e.g. due to message being deleted or too old
|
||||
NotReplyableWithThread,
|
||||
|
||||
/// message is part of a reply thread. neither reply or message is replyable
|
||||
///
|
||||
/// e.g. due to message at the top of the thread being deleted
|
||||
NotReplyableDueToThread,
|
||||
};
|
||||
ReplyStatus isReplyable() const;
|
||||
uint32_t count = 1;
|
||||
std::vector<std::unique_ptr<MessageElement>> elements;
|
||||
|
||||
|
||||
@@ -65,6 +65,12 @@ enum class MessageFlag : std::int64_t {
|
||||
/// - forsen added "blockedterm" as a blocked term
|
||||
/// - Your message is being checked by mods and has not been sent
|
||||
ModerationAction = (1LL << 41),
|
||||
/// The message can't be replied to
|
||||
/// Examples:
|
||||
/// - message was deleted via single channel chat message deletion (IRC: CLEARMSG, EVENTSUB: channel.chat.message_delete)
|
||||
/// - message was deleted via chat clear user messages (IRC: CLEARCHAT(user), EVENTSUB: channel.chat.clear_user_messages)
|
||||
/// Note: If this message is inside a reply thread, the root must not have the flag either.
|
||||
InvalidReplyTarget = (1LL << 42),
|
||||
};
|
||||
using MessageFlags = FlagsEnum<MessageFlag>;
|
||||
|
||||
|
||||
@@ -544,22 +544,4 @@ void MessageLayout::addSelectionText(QString &str, uint32_t from, uint32_t to,
|
||||
this->container_.addSelectionText(str, from, to, copymode);
|
||||
}
|
||||
|
||||
bool MessageLayout::isReplyable() const
|
||||
{
|
||||
if (this->message_->loginName.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this->message_->flags.hasAny(
|
||||
{MessageFlag::System, MessageFlag::Subscription,
|
||||
MessageFlag::Timeout, MessageFlag::Whisper,
|
||||
MessageFlag::ModerationAction}))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -110,7 +110,6 @@ public:
|
||||
|
||||
// Misc
|
||||
bool isDisabled() const;
|
||||
bool isReplyable() const;
|
||||
|
||||
private:
|
||||
// methods
|
||||
|
||||
Reference in New Issue
Block a user