plugins: include exhaustiveFlags in clone (#7195)

Reviewed-by: Mm2PL <mm2pl+gh@kotmisia.pl>
Reviewed-by: Nerixyz <nerixdev@outlook.de>
Parent-pr: 7192
This commit is contained in:
pajlada
2026-08-23 12:51:12 +00:00
committed by GitHub
parent e07c250ba3
commit 3b7aa53d1d
7 changed files with 38 additions and 6 deletions
+5
View File
@@ -592,6 +592,10 @@ function c2.Menu:insert_separator(before) end
c2.MessageElementBase = {}
-- ^^^ this is kinda fake - this table doesn't exist in Lua, we only declare it to add methods
--- Returns the pretty-printed JSON representation of the element.
--- This is meant for debugging and is subject to change.
function c2.MessageElementBase:to_json() end
--- Add flags to this element
---
---@param flags c2.MessageElementFlag
@@ -602,6 +606,7 @@ function c2.MessageElementBase:add_flags(flags) end
---@field tooltip? string Tooltip text
---@field trailing_space? boolean Whether to add a trailing space after the element (default: true)
---@field link? c2.Link An action when clicking on this element. Mention and Link elements don't support this. They manage the link themselves.
---@field exhaustive_flags? boolean Whether this message should only be laid out if all its flags exist in the message layout context.
---@class c2.TextElement : c2.MessageElementBase
---@field type "text"
+5
View File
@@ -11,6 +11,7 @@
# include "messages/Message.hpp"
# include "messages/MessageElement.hpp"
# include <QJsonDocument>
# include <sol/sol.hpp>
namespace {
@@ -590,6 +591,10 @@ void createUserType(sol::table &c2)
"type", sol::property([](const ElementRef &el) {
return el.cref().type();
}),
"to_json",
[](const ElementRef &el) {
return QJsonDocument(el.cref().toJson()).toJson();
},
"flags", sol::property([](const ElementRef &el) {
return el.cref().getFlags().value();
}),
+5
View File
@@ -24,6 +24,10 @@ namespace chatterino::lua::api::message {
c2.MessageElementBase = {}
-- ^^^ this is kinda fake - this table doesn't exist in Lua, we only declare it to add methods
--- Returns the pretty-printed JSON representation of the element.
--- This is meant for debugging and is subject to change.
function c2.MessageElementBase:to_json() end
--- Add flags to this element
---
---@param flags c2.MessageElementFlag
@@ -34,6 +38,7 @@ function c2.MessageElementBase:add_flags(flags) end
---@field tooltip? string Tooltip text
---@field trailing_space? boolean Whether to add a trailing space after the element (default: true)
---@field link? c2.Link An action when clicking on this element. Mention and Link elements don't support this. They manage the link themselves.
---@field exhaustive_flags? boolean Whether this message should only be laid out if all its flags exist in the message layout context.
---@class c2.TextElement : c2.MessageElementBase
---@field type "text"
+9 -1
View File
@@ -115,6 +115,7 @@ void MessageElement::cloneFrom(const MessageElement &source)
this->tooltip_ = source.tooltip_;
this->flags_ = source.flags_;
this->trailingSpace = source.trailingSpace;
this->exhaustiveFlags = source.exhaustiveFlags;
}
bool MessageElement::matchesFlags(MessageElementFlags contextFlags) const
@@ -125,7 +126,7 @@ bool MessageElement::matchesFlags(MessageElementFlags contextFlags) const
QJsonObject MessageElement::toJson() const
{
return {
QJsonObject msg{
{"trailingSpace"_L1, this->trailingSpace},
{
"link"_L1,
@@ -137,6 +138,13 @@ QJsonObject MessageElement::toJson() const
{"tooltip"_L1, this->tooltip_},
{"flags"_L1, qmagicenum::enumFlagsName(this->flags_.value())},
};
if (this->exhaustiveFlags)
{
msg["exhaustiveFlags"_L1] = this->exhaustiveFlags;
}
return msg;
}
// IMAGE
+2
View File
@@ -12,6 +12,8 @@
#include "util/Helpers.hpp"
#include "util/IrcHelpers.hpp"
#include <span>
namespace {
using namespace chatterino;
+4 -1
View File
@@ -22,7 +22,7 @@ local tests = {
server_received_time = 123345678,
highlight_color = "#00ff00",
elements = {
{ type = "text", text = "abcde" },
{ type = "text", text = "abcde", exhaustive_flags = true },
{ type = "twitch-moderation" },
},
})
@@ -47,6 +47,9 @@ local tests = {
assert(msg.server_received_time == clone.server_received_time)
assert(msg.highlight_color == clone.highlight_color)
assert(#msg:elements() == #clone:elements())
for i, element in pairs(msg:elements()) do
assert(element:to_json() == clone:elements()[i]:to_json())
end
end,
}
+8 -4
View File
@@ -20,13 +20,13 @@ local tests = {
local new_msg = c2.Message.new(msg)
local append_init_ok, append_init_err = pcall(function()
new_msg:append_element({
type = 'text',
text = 'foo'
type = "text",
text = "foo",
})
end)
assert(append_init_ok)
assert(new_msg:elements()[1])
assert(new_msg:elements()[1].type == 'text' and new_msg:elements()[1].words[1] == 'foo')
assert(new_msg:elements()[1].type == "text" and new_msg:elements()[1].words[1] == "foo")
local append_element_ok, append_element_err = pcall(function()
for index, element in ipairs(msg:elements()) do
new_msg:append_element(element)
@@ -34,7 +34,7 @@ local tests = {
end)
assert(append_element_ok)
assert(new_msg:elements()[2])
assert(new_msg:elements()[2].type == 'text' and new_msg:elements()[2].words[1] == 'abcde')
assert(new_msg:elements()[2].type == "text" and new_msg:elements()[2].words[1] == "abcde")
end,
exhaustive_flags = function()
local msg = c2.Message.new({
@@ -59,6 +59,10 @@ local tests = {
assert(msg:elements()[1].type == "text" and msg:elements()[1].exhaustive_flags == false)
assert(msg:elements()[2].type == "text" and msg:elements()[2].exhaustive_flags == false)
assert(msg:elements()[3].type == "text" and msg:elements()[3].exhaustive_flags == true)
local cloned = msg:clone()
assert(cloned:elements()[1].type == "text" and cloned:elements()[1].exhaustive_flags == false)
assert(cloned:elements()[2].type == "text" and cloned:elements()[2].exhaustive_flags == false)
assert(cloned:elements()[3].type == "text" and cloned:elements()[3].exhaustive_flags == true)
end,
}