Skip to content
Snippets Groups Projects
Verified Commit 1893cd61 authored by Joe Donofry's avatar Joe Donofry
Browse files

Add RelationType enum

parent acb1bc9e
No related branches found
No related tags found
No related merge requests found
......@@ -155,11 +155,30 @@ from_json(const nlohmann::json &obj, InReplyTo &in_reply_to);
void
to_json(nlohmann::json &obj, const InReplyTo &in_reply_to);
//! Definition of rel_type for relations.
enum class RelationType
{
// m.annotation rel_type
Annotation,
// m.reference rel_type
Reference,
// m.replace rel_type
Replace,
// not one of the supported types
Unsupported
};
void
from_json(const nlohmann::json &obj, RelationType &type);
void
to_json(nlohmann::json &obj, const RelationType &type);
//! Relates to for reactions
struct ReactionRelatesTo
{
// Type of relation
std::string rel_type;
RelationType rel_type;
// event id being reacted to
std::string event_id;
// key is the reaction itself
......
......@@ -182,11 +182,44 @@ to_json(json &obj, const InReplyTo &in_reply_to)
obj["event_id"] = in_reply_to.event_id;
}
void
to_json(json &obj, const RelationType &type)
{
switch (type) {
case RelationType::Annotation:
obj = "m.annotation";
break;
case RelationType::Reference:
obj = "m.reference";
break;
case RelationType::Replace:
obj = "m.replace";
break;
case RelationType::Unsupported:
default:
obj = "unsupported";
break;
}
}
void
from_json(const json &obj, RelationType &type)
{
if (obj.get<std::string>() == "m.annotation")
type = RelationType::Annotation;
else if (obj.get<std::string>() == "m.reference")
type = RelationType::Reference;
else if (obj.get<std::string>() == "m.replace")
type = RelationType::Replace;
else
type = RelationType::Unsupported;
}
void
from_json(const json &obj, ReactionRelatesTo &relates_to)
{
if (obj.find("rel_type") != obj.end())
relates_to.rel_type = obj.at("rel_type").get<std::string>();
relates_to.rel_type = obj.at("rel_type").get<RelationType>();
if (obj.find("event_id") != obj.end())
relates_to.event_id = obj.at("event_id").get<std::string>();
if (obj.find("key") != obj.end())
......
......@@ -38,7 +38,7 @@ TEST(RoomEvents, Reaction)
EXPECT_EQ(event.content.relates_to.event_id,
"$oGKg0tfsnDamWPsGxUptGLWR5b8Xq6QNFFsysQNSnake");
EXPECT_EQ(event.content.relates_to.key, "👀");
EXPECT_EQ(event.content.relates_to.rel_type, "m.annotation");
EXPECT_EQ(event.content.relates_to.rel_type, mtx::common::RelationType::Annotation);
EXPECT_EQ(data.dump(), json(event).dump());
};
......
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