Skip to content
Snippets Groups Projects
Commit 24dd76ee authored by Konstantinos Sideris's avatar Konstantinos Sideris
Browse files

Parse unsigned key

parent 9cf5bf38
No related branches found
No related tags found
No related merge requests found
......@@ -60,6 +60,24 @@ isMessageEvent(EventType type);
bool
isStateEvent(EventType type);
class UnsignedData
: public Deserializable
, public Serializable
{
public:
double age() const { return age_; }
QString transactionId() const { return transaction_id_; }
bool isEmpty() const { return age_ <= 0 && transaction_id_.isEmpty(); }
void deserialize(const QJsonValue &data) override;
QJsonObject serialize() const override;
private:
double age_ = 0;
QString transaction_id_;
};
template<class Content>
class Event
: public Deserializable
......@@ -68,6 +86,7 @@ class Event
public:
Content content() const;
EventType eventType() const;
UnsignedData unsignedData() const { return unsignedData_; }
void deserialize(const QJsonValue &data) override;
QJsonObject serialize() const override;
......@@ -75,6 +94,7 @@ public:
private:
Content content_;
EventType type_;
UnsignedData unsignedData_;
};
template<class Content>
......@@ -102,6 +122,9 @@ Event<Content>::deserialize(const QJsonValue &data)
content_.deserialize(object.value("content"));
type_ = extractEventType(object);
if (object.contains("unsigned"))
unsignedData_.deserialize(object.value("unsigned"));
}
template<class Content>
......@@ -151,6 +174,9 @@ Event<Content>::serialize() const
object["content"] = content_.serialize();
if (!unsignedData_.isEmpty())
object["unsigned"] = unsignedData_.serialize();
return object;
}
} // namespace events
......
......@@ -78,3 +78,29 @@ matrix::events::isMessageEvent(EventType type)
{
return type == EventType::RoomMessage;
}
void
matrix::events::UnsignedData::deserialize(const QJsonValue &data)
{
if (!data.isObject())
throw DeserializationException("UnsignedData is not a JSON object");
auto object = data.toObject();
transaction_id_ = object.value("transaction_id").toString();
age_ = object.value("age").toDouble();
}
QJsonObject
matrix::events::UnsignedData::serialize() const
{
QJsonObject object;
if (!transaction_id_.isEmpty())
object["transaction_id"] = transaction_id_;
if (age_ > 0)
object["age"] = age_;
return object;
}
This diff is collapsed.
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