Add serialization on matrix events
This commit is contained in:
parent
c6c024ccbf
commit
e5ccb73a20
27 changed files with 285 additions and 12 deletions
|
|
@ -36,3 +36,18 @@ void AliasesEventContent::deserialize(const QJsonValue &data)
|
|||
for (const auto &alias : aliases)
|
||||
aliases_.push_back(alias.toString());
|
||||
}
|
||||
|
||||
QJsonObject AliasesEventContent::serialize() const
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
QJsonArray aliases;
|
||||
|
||||
for (const auto &alias : aliases_)
|
||||
aliases.push_back(alias);
|
||||
|
||||
if (aliases.size() > 0)
|
||||
object["aliases"] = aliases;
|
||||
|
||||
return object;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,3 +36,13 @@ void AvatarEventContent::deserialize(const QJsonValue &data)
|
|||
if (!url_.isValid())
|
||||
qWarning() << "Invalid avatar url" << url_;
|
||||
}
|
||||
|
||||
QJsonObject AvatarEventContent::serialize() const
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
if (!url_.isEmpty())
|
||||
object["url"] = url_.toString();
|
||||
|
||||
return object;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,3 +31,13 @@ void CanonicalAliasEventContent::deserialize(const QJsonValue &data)
|
|||
|
||||
alias_ = object.value("alias").toString();
|
||||
}
|
||||
|
||||
QJsonObject CanonicalAliasEventContent::serialize() const
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
if (!alias_.isEmpty())
|
||||
object["alias"] = alias_;
|
||||
|
||||
return object;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,3 +31,13 @@ void CreateEventContent::deserialize(const QJsonValue &data)
|
|||
|
||||
creator_ = object.value("creator").toString();
|
||||
}
|
||||
|
||||
QJsonObject CreateEventContent::serialize() const
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
if (!creator_.isEmpty())
|
||||
object["creator"] = creator_;
|
||||
|
||||
return object;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,3 +42,19 @@ void HistoryVisibilityEventContent::deserialize(const QJsonValue &data)
|
|||
else
|
||||
throw DeserializationException(QString("Unknown history_visibility value: %1").arg(value).toUtf8().constData());
|
||||
}
|
||||
|
||||
QJsonObject HistoryVisibilityEventContent::serialize() const
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
if (history_visibility_ == HistoryVisibility::Invited)
|
||||
object["history_visibility"] = "invited";
|
||||
else if (history_visibility_ == HistoryVisibility::Joined)
|
||||
object["history_visibility"] = "joined";
|
||||
else if (history_visibility_ == HistoryVisibility::Shared)
|
||||
object["history_visibility"] = "shared";
|
||||
else if (history_visibility_ == HistoryVisibility::WorldReadable)
|
||||
object["history_visibility"] = "world_readable";
|
||||
|
||||
return object;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,3 +42,19 @@ void JoinRulesEventContent::deserialize(const QJsonValue &data)
|
|||
else
|
||||
throw DeserializationException(QString("Unknown join_rule value: %1").arg(value).toUtf8().constData());
|
||||
}
|
||||
|
||||
QJsonObject JoinRulesEventContent::serialize() const
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
if (join_rule_ == JoinRule::Invite)
|
||||
object["join_rule"] = "invite";
|
||||
else if (join_rule_ == JoinRule::Knock)
|
||||
object["join_rule"] = "knock";
|
||||
else if (join_rule_ == JoinRule::Private)
|
||||
object["join_rule"] = "private";
|
||||
else if (join_rule_ == JoinRule::Public)
|
||||
object["join_rule"] = "public";
|
||||
|
||||
return object;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,3 +55,27 @@ void MemberEventContent::deserialize(const QJsonValue &data)
|
|||
if (object.contains("displayname"))
|
||||
display_name_ = object.value("displayname").toString();
|
||||
}
|
||||
|
||||
QJsonObject MemberEventContent::serialize() const
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
if (membership_state_ == Membership::Ban)
|
||||
object["membership"] = "ban";
|
||||
else if (membership_state_ == Membership::Invite)
|
||||
object["membership"] = "invite";
|
||||
else if (membership_state_ == Membership::Join)
|
||||
object["membership"] = "join";
|
||||
else if (membership_state_ == Membership::Knock)
|
||||
object["membership"] = "knock";
|
||||
else if (membership_state_ == Membership::Leave)
|
||||
object["membership"] = "leave";
|
||||
|
||||
if (!avatar_url_.isEmpty())
|
||||
object["avatar_url"] = avatar_url_.toString();
|
||||
|
||||
if (!display_name_.isEmpty())
|
||||
object["displayname"] = display_name_;
|
||||
|
||||
return object;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,3 +61,11 @@ void MessageEventContent::deserialize(const QJsonValue &data)
|
|||
|
||||
body_ = object.value("body").toString();
|
||||
}
|
||||
|
||||
QJsonObject MessageEventContent::serialize() const
|
||||
{
|
||||
// TODO: Add for all the message contents.
|
||||
QJsonObject object;
|
||||
|
||||
return object;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,3 +31,13 @@ void NameEventContent::deserialize(const QJsonValue &data)
|
|||
|
||||
name_ = object.value("name").toString();
|
||||
}
|
||||
|
||||
QJsonObject NameEventContent::serialize() const
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
if (!name_.isEmpty())
|
||||
object["name"] = name_;
|
||||
|
||||
return object;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,34 @@ void PowerLevelsEventContent::deserialize(const QJsonValue &data)
|
|||
}
|
||||
}
|
||||
|
||||
QJsonObject PowerLevelsEventContent::serialize() const
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
object["ban"] = ban_;
|
||||
object["invite"] = invite_;
|
||||
object["kick"] = kick_;
|
||||
object["redact"] = redact_;
|
||||
|
||||
object["events_default"] = events_default_;
|
||||
object["users_default"] = users_default_;
|
||||
object["state_default"] = state_default_;
|
||||
|
||||
QJsonObject users;
|
||||
QJsonObject events;
|
||||
|
||||
for (auto it = users_.constBegin(); it != users_.constEnd(); it++)
|
||||
users.insert(it.key(), it.value());
|
||||
|
||||
for (auto it = events_.constBegin(); it != events_.constEnd(); it++)
|
||||
events.insert(it.key(), it.value());
|
||||
|
||||
object["users"] = users;
|
||||
object["events"] = events;
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
int PowerLevelsEventContent::eventLevel(QString event_type) const
|
||||
{
|
||||
if (events_.contains(event_type))
|
||||
|
|
|
|||
|
|
@ -31,3 +31,13 @@ void TopicEventContent::deserialize(const QJsonValue &data)
|
|||
|
||||
topic_ = object.value("topic").toString();
|
||||
}
|
||||
|
||||
QJsonObject TopicEventContent::serialize() const
|
||||
{
|
||||
QJsonObject object;
|
||||
|
||||
if (!topic_.isEmpty())
|
||||
object["topic"] = topic_;
|
||||
|
||||
return object;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue