Skip to content
Snippets Groups Projects
Verified Commit 72f9a20c authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Fix empty event type should be unsupported in hidden events

parent f7734a6f
Branches reportContent
No related tags found
No related merge requests found
Pipeline #5239 passed
......@@ -2,6 +2,8 @@
#include <nlohmann/json.hpp>
#include <mtx/log.hpp>
namespace mtx {
namespace events {
namespace account_data {
......@@ -13,8 +15,17 @@ from_json(const nlohmann::json &obj, HiddenEvents &content)
if (obj.contains("hidden_event_types")) {
content.hidden_event_types = std::vector<EventType>{};
for (const auto &typeStr : obj.at("hidden_event_types")) {
auto type = getEventType(typeStr.get<std::string>());
content.hidden_event_types->push_back(type);
auto type_ = typeStr.get<std::string>();
if (type_ == "") {
content.hidden_event_types->push_back(mtx::events::EventType::Unsupported);
} else {
try {
auto type = getEventType(type_);
content.hidden_event_types->push_back(type);
} catch (...) {
utils::log::log()->warn("Ignoring unknown event type to ignore: {}", type_);
}
}
}
}
}
......
......@@ -2000,8 +2000,8 @@ TEST(RoomAccountData, NhekoHiddenEvents)
json data = R"({
"content": {
"hidden_event_types": [
"m.reaction",
"m.room.member"
"m.reaction",
"m.room.member"
]
},
"type": "im.nheko.hidden_events"
......@@ -2015,6 +2015,21 @@ TEST(RoomAccountData, NhekoHiddenEvents)
ASSERT_EQ(event.content.hidden_event_types->size(), 2);
EXPECT_EQ(event.content.hidden_event_types.value()[0], ns::EventType::Reaction);
EXPECT_EQ(event.content.hidden_event_types.value()[1], ns::EventType::RoomMember);
json data2 = R"({
"content": {
"hidden_event_types": [
""
]
},
"type": "im.nheko.hidden_events"
})"_json;
ns::AccountDataEvent<ns::account_data::nheko_extensions::HiddenEvents> event2 =
data2.get<ns::AccountDataEvent<ns::account_data::nheko_extensions::HiddenEvents>>();
ASSERT_TRUE(event2.content.hidden_event_types.has_value());
ASSERT_EQ(event2.content.hidden_event_types.value().size(), 1);
EXPECT_EQ(event2.content.hidden_event_types.value().front(),
mtx::events::EventType::Unsupported);
}
TEST(RoomAccountData, NhekoEventExpiry)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment