Add type MatrixUnsignedEventData

This commit is contained in:
Gergely Polonkai 2016-01-27 14:14:56 +01:00
parent 526da5f114
commit 033139672f
2 changed files with 90 additions and 0 deletions

View File

@ -194,6 +194,20 @@ matrix_presence_event_get_presence
matrix_presence_event_set_last_active_ago matrix_presence_event_set_last_active_ago
matrix_presence_event_get_last_active_ago matrix_presence_event_get_last_active_ago
<SUBSECTION>
MatrixUnsignedEventData
matrix_unsigned_event_data_new
matrix_unsigned_event_data_new_from_json
matrix_unsigned_event_data_ref
matrix_unsigned_event_data_unref
matrix_unsigned_event_data_set_age
matrix_unsigned_event_data_get_age
matrix_unsigned_event_data_set_redact_reason
matrix_unsigned_event_data_get_redact_reason
matrix_unsigned_event_data_set_transaction_id
matrix_unsigned_event_data_get_transaction_id
matrix_unsigned_event_data_get_json_node
<SUBSECTION Standard> <SUBSECTION Standard>
MATRIX_TYPE_EVENT_FORMAT MATRIX_TYPE_EVENT_FORMAT
matrix_event_format_get_type matrix_event_format_get_type
@ -229,6 +243,8 @@ MATRIX_TYPE_STATE_EVENT
matrix_state_event_get_type matrix_state_event_get_type
MATRIX_TYPE_PRESENCE_EVENT MATRIX_TYPE_PRESENCE_EVENT
matrix_presence_event_get_type matrix_presence_event_get_type
MATRIX_TYPE_UNSIGNED_EVENT_DATA
matrix_unsigned_event_data_get_type
</SECTION> </SECTION>
<SECTION> <SECTION>

View File

@ -724,4 +724,78 @@ namespace Matrix {
return ret; return ret;
} }
/**
* Class to hold unsigned event data, like event age, redact
* reason or a transaction ID.
*/
public class UnsignedEventData : JsonCompact {
/**
* The age of the event, in seconds.
*/
public uint age { get; set; default = 0; }
/**
* The reason of redaction, if any.
*/
public string? redact_reason { get; set; default = null; }
/**
* The transaction ID of the message.
*/
public string? transaction_id { get; set; default = null; }
/**
* Create an UnsignedEventData object based
* on @param json_data.
*/
public
UnsignedEventData.from_json(Json.Node json_data)
requires(json_data.get_node_type() == Json.NodeType.OBJECT)
{
var root = json_data.get_object();
Json.Node node;
if ((node = root.get_member("age")) != null) {
age = (uint)node.get_int();
}
if ((node = root.get_member("redacted_because")) != null) {
redact_reason = node.get_string();
}
if ((node = root.get_member("transaction_id")) != null) {
transaction_id = node.get_string();
}
}
/**
* Get the unsigned event data as a JSON node.
*/
public override Json.Node?
get_json_node()
throws Matrix.Error
{
var builder = new Json.Builder();
builder.begin_object();
builder.set_member_name("age");
builder.add_int_value(age);
if (redact_reason != null) {
builder.set_member_name("redacted_because");
builder.add_string_value(redact_reason);
}
if (transaction_id != null) {
builder.set_member_name("transaction_id");
builder.add_string_value(transaction_id);
}
builder.end_object();
return builder.get_root();
}
}
} }