From b27a77745974dbfe538b183c6f5355b58b255c98 Mon Sep 17 00:00:00 2001 From: Nicolas Werner <nicolas.werner@hotmail.de> Date: Tue, 9 Aug 2022 22:58:33 +0200 Subject: [PATCH] Fix space suggestion --- include/mtx/events/spaces.hpp | 5 +++++ lib/structs/events/spaces.cpp | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/include/mtx/events/spaces.hpp b/include/mtx/events/spaces.hpp index ec1bb9f77..869047d5d 100644 --- a/include/mtx/events/spaces.hpp +++ b/include/mtx/events/spaces.hpp @@ -66,6 +66,11 @@ struct Child /// of more than 50 characters, are forbidden and the field should be ignored if received. std::optional<std::string> order; + //! Optional (default false) flag to denote whether the child is “suggested†or of interest to + //! members of the space. This is primarily intended as a rendering hint for clients to display + //! the room differently, such as eagerly rendering them in the room list. + bool suggested = false; + friend void from_json(const nlohmann::json &obj, Child &child); friend void to_json(nlohmann::json &obj, const Child &child); }; diff --git a/lib/structs/events/spaces.cpp b/lib/structs/events/spaces.cpp index eca9d3c9a..022d79d13 100644 --- a/lib/structs/events/spaces.cpp +++ b/lib/structs/events/spaces.cpp @@ -21,6 +21,8 @@ from_json(const nlohmann::json &obj, Parent &parent) void to_json(nlohmann::json &obj, const Parent &parent) { + obj = nlohmann::json::object(); + // event without via is invalid. if (!parent.via.has_value() || parent.via.value().empty()) return; @@ -53,11 +55,15 @@ from_json(const nlohmann::json &obj, Child &child) if (obj.contains("order") && obj.at("order").is_string() && is_valid_order_str(obj.at("order").get<std::string>())) child.order = obj.at("order").get<std::string>(); + + child.suggested = obj.value("suggested", false); } void to_json(nlohmann::json &obj, const Child &child) { + obj = nlohmann::json::object(); + // event without via is invalid. if (!child.via.has_value() || child.via.value().empty()) return; @@ -66,6 +72,9 @@ to_json(nlohmann::json &obj, const Child &child) if (child.order && is_valid_order_str(child.order.value())) obj["order"] = child.order.value(); + + if (child.suggested) + obj["suggested"] = true; } } } // namespace state -- GitLab