Move from using Lists to arrays

This commit is contained in:
Gergely Polonkai 2016-03-17 10:04:26 +00:00
parent f6df2200b7
commit c9465dc1c0
9 changed files with 107 additions and 271 deletions

View File

@ -164,8 +164,8 @@ public interface Matrix.API : GLib.Object {
update_presence_list([CCode (delegate_target_pos = 1.5, scope = "async")] update_presence_list([CCode (delegate_target_pos = 1.5, scope = "async")]
owned Matrix.API.Callback? @callback, owned Matrix.API.Callback? @callback,
string user_id, string user_id,
GLib.List<string> drop_ids, string[] drop_ids,
GLib.List<string> invite_ids) string[] invite_ids)
throws Matrix.Error; throws Matrix.Error;
/** /**
@ -299,8 +299,8 @@ public interface Matrix.API : GLib.Object {
string rule_id, string rule_id,
string? before, string? before,
string? after, string? after,
GLib.List<string> actions, string[] actions,
GLib.List<Matrix.PusherConditionKind>? conditions) Matrix.PusherConditionKind[] conditions)
throws Matrix.Error; throws Matrix.Error;
/** /**
@ -357,9 +357,9 @@ public interface Matrix.API : GLib.Object {
string? topic, string? topic,
Matrix.RoomVisibility visibility, Matrix.RoomVisibility visibility,
Json.Node? creation_content, Json.Node? creation_content,
GLib.List<Matrix.Event.State>? initial_state, Matrix.Event.State[] initial_state,
GLib.List<string>? invitees, string[] invitees,
GLib.List<Matrix.3PidCredential>? invite_3pids) Matrix.3PidCredential[] invite_3pids)
throws Matrix.Error; throws Matrix.Error;
/* Room directory */ /* Room directory */

View File

@ -41,22 +41,10 @@ namespace Matrix {
* Class to hold a filter. * Class to hold a filter.
*/ */
public class Filter : JsonCompact { public class Filter : JsonCompact {
private List<string>? _event_fields;
/** /**
* The event fields to include in the filtered events. * The event fields to include in the filtered events.
*/ */
public List<string>? event_fields { public string[] event_fields { get; set; }
get {
return _event_fields;
}
set {
_event_fields = value.copy();
}
default = null;
}
/** /**
* The desired event format for the filtered events (e.g. for * The desired event format for the filtered events (e.g. for
@ -179,13 +167,6 @@ namespace Matrix {
* Class to hold filtering rules. * Class to hold filtering rules.
*/ */
public class FilterRules : JsonCompact { public class FilterRules : JsonCompact {
private List<string>? _types;
private List<string>? _excluded_types;
private List<string>? _senders;
private List<string>? _excluded_senders;
private List<string>? _rooms;
private List<string>? _excluded_rooms;
/** /**
* The limit of the count of returned events. * The limit of the count of returned events.
*/ */
@ -194,98 +175,38 @@ namespace Matrix {
/** /**
* List of message types to include in the filtered result. * List of message types to include in the filtered result.
*/ */
public List<string>? types { public string[] types { get; set; }
get {
return _types;
}
set {
_types = value.copy();
}
default = null;
}
/** /**
* List of message types to exclude from the filtered * List of message types to exclude from the filtered
* result. A matching type will be excluded from the result * result. A matching type will be excluded from the result
* even if it is listed in the types to include. * even if it is listed in the types to include.
*/ */
public List<string>? excluded_types { public string[] excluded_types { get; set; }
get {
return _excluded_types;
}
set {
_excluded_types = value.copy();
}
default = null;
}
/** /**
* List of senders to include in the filtered results. * List of senders to include in the filtered results.
*/ */
public List<string>? senders { public string[] senders { get; set; }
get {
return _senders;
}
set {
_senders = value.copy();
}
default = null;
}
/** /**
* List of senders to exclude from the filtered result. A * List of senders to exclude from the filtered result. A
* matching sender will be excluded from the result even if it * matching sender will be excluded from the result even if it
* is listed in the senders to include. * is listed in the senders to include.
*/ */
public List<string>? excluded_senders { public string[] excluded_senders { get; set; }
get {
return _excluded_senders;
}
set {
_excluded_senders = value.copy();
}
default = null;
}
/** /**
* List of rooms to include in the filtered results. * List of rooms to include in the filtered results.
*/ */
public List<string>? rooms { public string[] rooms { get; set; }
get {
return _rooms;
}
set {
_rooms = value.copy();
}
default = null;
}
/** /**
* List of rooms to exclude from the filtered result. A * List of rooms to exclude from the filtered result. A
* matching room will be excluded from the result even if it * matching room will be excluded from the result even if it
* is listed in the rooms to include. * is listed in the rooms to include.
*/ */
public List<string>? excluded_rooms { public string[] excluded_rooms { get; set; }
get {
return _excluded_rooms;
}
set {
_excluded_rooms = value.copy();
}
default = null;
}
/** /**
* Get the filtering rules as a JSON node. * Get the filtering rules as a JSON node.
@ -609,18 +530,7 @@ namespace Matrix {
} }
public class SearchGroupings : JsonCompact { public class SearchGroupings : JsonCompact {
private List<SearchGrouping>? _group_by = null; public SearchGrouping[] group_by { get; set; }
public List<SearchGrouping>? group_by {
get {
return _group_by;
}
set {
_group_by = value.copy();
}
default = null;
}
public override Json.Node? public override Json.Node?
get_json_node() get_json_node()
@ -654,19 +564,8 @@ namespace Matrix {
} }
public class SearchRoomEvents : JsonCompact { public class SearchRoomEvents : JsonCompact {
private List<SearchKey?>? _keys = null; public SearchOrder order_by { get; set; default = SearchOrder.RECENT; }
public SearchKey[] keys { get; set; }
public SearchOrder? order_by { get; set; default = SearchOrder.RECENT; }
public List<SearchKey?>? keys {
get {
return _keys;
}
set {
_keys = value.copy();
}
default = null; }
public EventContext? event_context { get; set; default = null; } public EventContext? event_context { get; set; default = null; }
public bool? include_state { get; set; default = false; } public bool? include_state { get; set; default = false; }
public string? filter_id { get; set; default = null; } public string? filter_id { get; set; default = null; }
@ -689,24 +588,20 @@ namespace Matrix {
builder.begin_object(); builder.begin_object();
if (order_by != null) { builder.set_member_name("order_by");
builder.set_member_name("order_by"); builder.add_string_value(
builder.add_string_value( _g_enum_value_to_nick(typeof(SearchOrder), order_by));
_g_enum_value_to_nick(typeof(SearchOrder), order_by));
}
if (keys != null) { if (keys.length > 0) {
EnumClass key_class = (EnumClass)(typeof(SearchKey).class_ref()); EnumClass key_class = (EnumClass)(typeof(SearchKey).class_ref());
var key_array = new Json.Array(); var key_array = new Json.Array();
foreach (var entry in keys) { foreach (var entry in keys) {
if (entry != null) { unowned EnumValue? key_value = key_class.get_value(entry);
unowned EnumValue? key_value = key_class.get_value(entry);
if (key_value != null) { if (key_value != null) {
key_array.add_string_element( key_array.add_string_element(
key_value.value_nick.replace("-", ".")); key_value.value_nick.replace("-", "."));
}
} }
} }

View File

@ -33,19 +33,7 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Call {
/** /**
* The list of candidates. * The list of candidates.
*/ */
public List<Candidate?>? candidates { public Candidate[] candidates { get; set; }
get {
return _candidates;
}
set {
_candidates = value.copy();
}
default = null;
}
private List<Candidate?>? _candidates;
protected override void protected override void
from_json(Json.Node json_data) from_json(Json.Node json_data)
@ -56,6 +44,8 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Call {
Json.Node? node; Json.Node? node;
if ((node = content_root.get_member("candidates")) != null) { if ((node = content_root.get_member("candidates")) != null) {
_candidates = new Candidate[node.get_array().get_length()];
node.get_array().foreach_element((ary, idx, cand_node) => { node.get_array().foreach_element((ary, idx, cand_node) => {
var cand_root = cand_node.get_object(); var cand_root = cand_node.get_object();
var cand = Candidate(); var cand = Candidate();
@ -78,7 +68,7 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Call {
warning("candidate is missing from a candidate of a m.call.candidates event"); warning("candidate is missing from a candidate of a m.call.candidates event");
} }
_candidates.prepend(cand); _candidates[idx] = cand;
}); });
} else { } else {
warning("content.candidates is missing from a m.call.candidates event"); warning("content.candidates is missing from a m.call.candidates event");
@ -91,7 +81,7 @@ public class Matrix.Event.CallCandidates : Matrix.Event.Call {
to_json(Json.Node json_data) to_json(Json.Node json_data)
throws Matrix.Error throws Matrix.Error
{ {
if ((_candidates == null) || (_candidates.length() < 1)) { if (_candidates.length < 1) {
throw new Matrix.Error.INCOMPLETE( throw new Matrix.Error.INCOMPLETE(
"Won't generate a m.call.candidates event without candidates"); "Won't generate a m.call.candidates event without candidates");
} }

View File

@ -34,22 +34,10 @@
* whether it receives the correct room ID. * whether it receives the correct room ID.
*/ */
public class Matrix.Event.RoomAliases : Matrix.Event.State { public class Matrix.Event.RoomAliases : Matrix.Event.State {
private List<string>? _aliases = null;
/** /**
* A list of room aliases. * A list of room aliases.
*/ */
public List<string>? aliases { public string[] aliases { get; set; }
get {
return _aliases;
}
set {
_aliases = value.copy();
}
default = null;
}
protected override void protected override void
from_json(Json.Node json_data) from_json(Json.Node json_data)
@ -60,10 +48,10 @@ public class Matrix.Event.RoomAliases : Matrix.Event.State {
Json.Node? node; Json.Node? node;
if ((node = content_root.get_member("aliases")) != null) { if ((node = content_root.get_member("aliases")) != null) {
_aliases = null; _aliases = new string[node.get_array().get_length()];
node.get_array().foreach_element((ary, idx, member_node) => { node.get_array().foreach_element((ary, idx, member_node) => {
_aliases.prepend(member_node.get_string()); _aliases[idx] = member_node.get_string();
}); });
} else if (Config.DEBUG) { } else if (Config.DEBUG) {
warning("content.aliases is missing from a m.room.aliases event"); warning("content.aliases is missing from a m.room.aliases event");
@ -76,7 +64,7 @@ public class Matrix.Event.RoomAliases : Matrix.Event.State {
to_json(Json.Node json_data) to_json(Json.Node json_data)
throws Matrix.Error throws Matrix.Error
{ {
if ((_aliases == null) || (_aliases.length() == 0)) { if (_aliases.length == 0) {
throw new Matrix.Error.INCOMPLETE( throw new Matrix.Error.INCOMPLETE(
"Won't generate a m.room.aliases event without aliases"); "Won't generate a m.room.aliases event without aliases");
} }

View File

@ -55,8 +55,6 @@
* events such as the room name. * events such as the room name.
*/ */
public class Matrix.Event.RoomMember : Matrix.Event.State { public class Matrix.Event.RoomMember : Matrix.Event.State {
private List<Matrix.Event.State>? _invite_room_state = null;
/** /**
* The membership state of the user. * The membership state of the user.
*/ */
@ -106,17 +104,7 @@ public class Matrix.Event.RoomMember : Matrix.Event.State {
* A subset of the state of the room at the time of the invite, if * A subset of the state of the room at the time of the invite, if
* membership is invite. * membership is invite.
*/ */
public List<Matrix.Event.State>? invite_room_state { public Matrix.Event.State[] invite_room_state { get; set; }
get {
return _invite_room_state;
}
set {
_invite_room_state = value.copy();
}
default = null;
}
/** /**
* The user ID whom this event relates to. * The user ID whom this event relates to.
@ -207,14 +195,14 @@ public class Matrix.Event.RoomMember : Matrix.Event.State {
var events = node.get_array(); var events = node.get_array();
if (events.get_length() > 0) { if (events.get_length() > 0) {
_invite_room_state = null; _invite_room_state = new Matrix.Event.State[node.get_array().get_length()];
events.foreach_element((ary, idx, member_node) => { events.foreach_element((ary, idx, member_node) => {
try { try {
var evt = Matrix.Event.Base.new_from_json( var evt = Matrix.Event.Base.new_from_json(
null, member_node); null, member_node);
_invite_room_state.prepend((Matrix.Event.State)evt); _invite_room_state[idx] = (Matrix.Event.State)evt;
} catch (GLib.Error e) {} } catch (GLib.Error e) {}
}); });
} }

View File

@ -31,8 +31,6 @@ public class Matrix.Event.RoomThirdPartyInvite : Matrix.Event.State {
string? validity_url; string? validity_url;
} }
private List<PublicKey?> _public_keys = null;
/** /**
* A user-readable string which represents the user who has been * A user-readable string which represents the user who has been
* invited. This should not contain the user's third party ID, as * invited. This should not contain the user's third party ID, as
@ -59,17 +57,7 @@ public class Matrix.Event.RoomThirdPartyInvite : Matrix.Event.State {
/** /**
* Keys with which the token may be signed. * Keys with which the token may be signed.
*/ */
List<PublicKey?>? public_keys { public PublicKey[] public_keys { get; set; }
get {
return _public_keys;
}
set {
_public_keys = value.copy();
}
default = null;
}
/** /**
* The token, of which a signature must be produced in order to * The token, of which a signature must be produced in order to
@ -161,11 +149,6 @@ public class Matrix.Event.RoomThirdPartyInvite : Matrix.Event.State {
var key_list = new Json.Array(); var key_list = new Json.Array();
foreach (var entry in _public_keys) { foreach (var entry in _public_keys) {
if (entry == null) {
throw new Matrix.Error.INCOMPLETE(
"Won't generate a m.room.third_party_invite with an empty public_key under additional keys");
}
if (entry.key == null) { if (entry.key == null) {
throw new Matrix.Error.INCOMPLETE( throw new Matrix.Error.INCOMPLETE(
"Won't generate a m.room.third_party_invite with a missing key under public_keys"); "Won't generate a m.room.third_party_invite with a missing key under public_keys");

View File

@ -30,19 +30,7 @@ public class Matrix.Event.Typing : Matrix.Event.Base {
/** /**
* The list of user IDs typing in this room, if any. * The list of user IDs typing in this room, if any.
*/ */
public List<string>? user_ids { public string[] user_ids { get; set; }
get {
return _user_ids;
}
set {
_user_ids = value.copy();
}
default = null;
}
private List<string>? _user_ids = null;
protected override void protected override void
from_json(Json.Node json_data) from_json(Json.Node json_data)
@ -59,10 +47,10 @@ public class Matrix.Event.Typing : Matrix.Event.Base {
} }
if ((node = content_root.get_member("user_ids")) != null) { if ((node = content_root.get_member("user_ids")) != null) {
_user_ids = null; _user_ids = new string[node.get_array().get_length()];
node.get_array().foreach_element((ary, idx, user_node) => { node.get_array().foreach_element((ary, idx, user_node) => {
_user_ids.prepend(user_node.get_string()); _user_ids[idx] = user_node.get_string();
}); });
} else if (Config.DEBUG) { } else if (Config.DEBUG) {
warning("content.user_ids is missing from a m.typing event"); warning("content.user_ids is missing from a m.typing event");

View File

@ -551,8 +551,8 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
public void public void
update_presence_list(API.Callback? cb, update_presence_list(API.Callback? cb,
string user_id, string user_id,
List<string> drop_ids, string[] drop_ids,
List<string> invite_ids) string[] invite_ids)
throws Matrix.Error throws Matrix.Error
{ {
Json.Builder builder; Json.Builder builder;
@ -563,23 +563,25 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
builder = new Json.Builder(); builder = new Json.Builder();
builder.begin_object(); builder.begin_object();
if (drop_ids != null) { if (drop_ids.length > 0) {
builder.set_member_name("drop"); builder.set_member_name("drop");
builder.begin_array(); builder.begin_array();
drop_ids.foreach(
(entry) => { foreach (var entry in drop_ids) {
builder.add_string_value(entry); builder.add_string_value(entry);
}); }
builder.end_array(); builder.end_array();
} }
if (invite_ids != null) { if (invite_ids.length > 0) {
builder.set_member_name("invite"); builder.set_member_name("invite");
builder.begin_array(); builder.begin_array();
invite_ids.foreach(
(entry) => { foreach (var entry in invite_ids) {
builder.add_string_value(entry); builder.add_string_value(entry);
}); }
builder.end_array(); builder.end_array();
} }
@ -718,8 +720,8 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
string rule_id, string rule_id,
string? before, string? before,
string? after, string? after,
List<string> actions, string[] actions,
List<PusherConditionKind?>? conditions) PusherConditionKind[] conditions)
throws Matrix.Error throws Matrix.Error
{ {
Json.Builder builder; Json.Builder builder;
@ -738,32 +740,32 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
builder.set_member_name("actions"); builder.set_member_name("actions");
builder.begin_array(); builder.begin_array();
actions.foreach( foreach (var entry in actions) {
(entry) => { builder.add_string_value(entry);
builder.add_string_value(entry); }
});
builder.end_array(); builder.end_array();
if (conditions != null) { if (conditions.length > 0) {
builder.set_member_name("conditions"); builder.set_member_name("conditions");
builder.begin_array(); builder.begin_array();
conditions.foreach(
(entry) => {
string? kind_string = _g_enum_value_to_nick(
typeof(Matrix.PusherConditionKind),
entry);
if (kind_string == null) { foreach (var entry in conditions) {
warning("Invalid condition kind"); string? kind_string = _g_enum_value_to_nick(
typeof(Matrix.PusherConditionKind),
entry);
return; if (kind_string == null) {
} warning("Invalid condition kind");
return;
}
builder.begin_object();
builder.set_member_name("kind");
builder.add_string_value(kind_string);
builder.end_object();
}
builder.begin_object();
builder.set_member_name("kind");
builder.add_string_value(kind_string);
builder.end_object();
});
builder.end_array(); builder.end_array();
} }
@ -809,9 +811,9 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
string? topic, string? topic,
RoomVisibility visibility, RoomVisibility visibility,
Json.Node? creation_content, Json.Node? creation_content,
List<Matrix.Event.State>? initial_state, Matrix.Event.State[] initial_state,
List<string>? invitees, string[] invitees,
List<3PidCredential>? invite_3pids) 3PidCredential[] invite_3pids)
throws Matrix.Error throws Matrix.Error
{ {
Json.Builder builder = new Json.Builder(); Json.Builder builder = new Json.Builder();
@ -823,37 +825,39 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API {
builder.add_value(creation_content); builder.add_value(creation_content);
} }
if (initial_state != null) { if (initial_state.length > 0) {
builder.set_member_name("initial_state"); builder.set_member_name("initial_state");
builder.begin_array(); builder.begin_array();
initial_state.foreach(
(entry) => { foreach (var entry in initial_state) {
builder.add_value(entry.json); builder.add_value(entry.json);
}); }
builder.end_array(); builder.end_array();
} }
if (invitees != null) { if (invitees.length > 0) {
builder.set_member_name("invite"); builder.set_member_name("invite");
builder.begin_array(); builder.begin_array();
invitees.foreach(
(entry) => { foreach (var entry in invitees) {
builder.add_string_value(entry); builder.add_string_value(entry);
}); }
builder.end_array(); builder.end_array();
} }
if (invite_3pids != null) { if (invite_3pids.length > 0) {
builder.set_member_name("invite_3pid"); builder.set_member_name("invite_3pid");
builder.begin_array(); builder.begin_array();
invite_3pids.foreach(
(entry) => { foreach (var entry in invite_3pids) {
try { try {
builder.add_value(entry.get_json_node()); builder.add_value(entry.get_json_node());
// TODO exceptions should be handled // TODO exceptions should be handled here somehow
// here somehow } catch (Matrix.Error e) {}
} catch (Matrix.Error e) {} }
});
builder.end_array(); builder.end_array();
} }

View File

@ -135,13 +135,13 @@ login_finished(MatrixAPI *api,
initial_sync_finished, initial_sync_finished,
data, 10, TRUE, data, 10, TRUE,
NULL); NULL);
matrix_api_create_room(api, matrix_api_create_room (api,
create_room_finished, NULL, create_room_finished, NULL,
MATRIX_ROOM_PRESET_PUBLIC, MATRIX_ROOM_PRESET_PUBLIC,
"GLib SDK test room", "matrix-glib-sdk-test", "GLib SDK test room", "matrix-glib-sdk-test",
"GLib SDK test room", "GLib SDK test room",
MATRIX_ROOM_VISIBILITY_DEFAULT, MATRIX_ROOM_VISIBILITY_DEFAULT,
NULL, NULL, NULL, NULL, NULL); NULL, NULL, 0, NULL, 0, NULL, 0, NULL);
matrix_api_get_presence_list(api, NULL, NULL, user_id, NULL); matrix_api_get_presence_list(api, NULL, NULL, user_id, NULL);
matrix_api_get_presence(api, matrix_api_get_presence(api,
get_presence_finished, NULL, get_presence_finished, NULL,