Make MatrixAPIRoomFilter a boxed type
This commit is contained in:
parent
e11dbc503d
commit
90a360ecd6
@ -18,6 +18,8 @@ matrix_client_get_type
|
|||||||
<SECTION>
|
<SECTION>
|
||||||
<FILE>matrix-api-types</FILE>
|
<FILE>matrix-api-types</FILE>
|
||||||
<TITLE>Fundamental types for MatrixAPI</TITLE>
|
<TITLE>Fundamental types for MatrixAPI</TITLE>
|
||||||
|
|
||||||
|
<SUBSECTION>
|
||||||
MatrixAPIFilterRules
|
MatrixAPIFilterRules
|
||||||
matrix_api_filter_rules_new
|
matrix_api_filter_rules_new
|
||||||
matrix_api_filter_rules_ref
|
matrix_api_filter_rules_ref
|
||||||
@ -51,9 +53,27 @@ matrix_api_filter_rules_get_excluded_types
|
|||||||
matrix_api_filter_rules_get_json_node
|
matrix_api_filter_rules_get_json_node
|
||||||
matrix_api_filter_rules_get_json_data
|
matrix_api_filter_rules_get_json_data
|
||||||
|
|
||||||
|
<SUBSECTION>
|
||||||
|
MatrixAPIRoomFilter
|
||||||
|
matrix_api_room_filter_new
|
||||||
|
matrix_api_room_filter_ref
|
||||||
|
matrix_api_room_filter_unref
|
||||||
|
matrix_api_room_filter_set_include_leave
|
||||||
|
matrix_api_room_filter_get_include_leave
|
||||||
|
matrix_api_room_filter_set_ephemeral
|
||||||
|
matrix_api_room_filter_get_ephemeral
|
||||||
|
matrix_api_room_filter_set_state
|
||||||
|
matrix_api_room_filter_get_state
|
||||||
|
matrix_api_room_filter_set_timeline
|
||||||
|
matrix_api_room_filter_get_timeline
|
||||||
|
matrix_api_room_filter_get_json_node
|
||||||
|
matrix_api_room_filter_get_json_data
|
||||||
|
|
||||||
<SUBSECTION Standard>
|
<SUBSECTION Standard>
|
||||||
MATRIX_TYPE_API_FILTER_RULES
|
MATRIX_TYPE_API_FILTER_RULES
|
||||||
matrix_api_filter_rules_get_type
|
matrix_api_filter_rules_get_type
|
||||||
|
MATRIX_TYPE_API_ROOM_FILTER
|
||||||
|
matrix_api_room_filter_get_type
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
|
||||||
<SECTION>
|
<SECTION>
|
||||||
@ -166,7 +186,6 @@ MATRIX_API_ERROR
|
|||||||
<SUBSECTION>
|
<SUBSECTION>
|
||||||
MatrixAPIEventFormat
|
MatrixAPIEventFormat
|
||||||
MatrixAPIFilter
|
MatrixAPIFilter
|
||||||
MatrixAPIRoomFilter
|
|
||||||
MatrixAPIStateEvent
|
MatrixAPIStateEvent
|
||||||
MatrixAPI3PidCredential
|
MatrixAPI3PidCredential
|
||||||
|
|
||||||
|
@ -760,3 +760,299 @@ matrix_api_filter_rules_get_json_data(MatrixAPIFilterRules *rules,
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MatrixAPIRoomFilter:
|
||||||
|
*
|
||||||
|
* An opaque structure to hold room filters.
|
||||||
|
*/
|
||||||
|
struct _MatrixAPIRoomFilter {
|
||||||
|
gboolean include_leave;
|
||||||
|
MatrixAPIFilterRules *ephemeral;
|
||||||
|
MatrixAPIFilterRules *state;
|
||||||
|
MatrixAPIFilterRules *timeline;
|
||||||
|
guint refcount;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_BOXED_TYPE(MatrixAPIRoomFilter, matrix_api_room_filter,
|
||||||
|
(GBoxedCopyFunc)matrix_api_room_filter_ref,
|
||||||
|
(GBoxedFreeFunc)matrix_api_room_filter_unref);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_new:
|
||||||
|
*
|
||||||
|
* Create a new #MatrixAPIRoomFilter object with reference count of 1.
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): a new #MatrixAPIRoomFilter
|
||||||
|
*/
|
||||||
|
MatrixAPIRoomFilter *
|
||||||
|
matrix_api_room_filter_new(void)
|
||||||
|
{
|
||||||
|
MatrixAPIRoomFilter *filter;
|
||||||
|
|
||||||
|
filter = g_new0(MatrixAPIRoomFilter, 1);
|
||||||
|
filter->refcount = 1;
|
||||||
|
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
matrix_api_room_filter_free(MatrixAPIRoomFilter *filter)
|
||||||
|
{
|
||||||
|
if (filter->ephemeral) {
|
||||||
|
matrix_api_filter_rules_unref(filter->ephemeral);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter->state) {
|
||||||
|
matrix_api_filter_rules_unref(filter->state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter->timeline) {
|
||||||
|
matrix_api_filter_rules_unref(filter->timeline);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free(filter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_ref:
|
||||||
|
* @filter: a #MatrixAPIRoomFilter
|
||||||
|
*
|
||||||
|
* Increase reference count of @filter by one.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): the same #MatrixAPIRoomFilter
|
||||||
|
*/
|
||||||
|
MatrixAPIRoomFilter *
|
||||||
|
matrix_api_room_filter_ref(MatrixAPIRoomFilter *filter)
|
||||||
|
{
|
||||||
|
filter->refcount++;
|
||||||
|
|
||||||
|
return filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_unref:
|
||||||
|
* @filter: a #MatrixAPIRoomFilter
|
||||||
|
*
|
||||||
|
* Decrease reference count of @filter by one. If reference count
|
||||||
|
* reaches zero, @filter is freed.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
matrix_api_room_filter_unref(MatrixAPIRoomFilter *filter)
|
||||||
|
{
|
||||||
|
if (--filter->refcount == 0) {
|
||||||
|
matrix_api_room_filter_free(filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_set_include_leave:
|
||||||
|
* @filter: a #MatrixAPIRoomFilter
|
||||||
|
* @include_leave: %TRUE if events from left rooms should be included
|
||||||
|
*
|
||||||
|
* Sets if events for rooms that the user has left should be included
|
||||||
|
* in the filtered event list.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
matrix_api_room_filter_set_include_leave(MatrixAPIRoomFilter *filter,
|
||||||
|
gboolean include_leave)
|
||||||
|
{
|
||||||
|
filter->include_leave = include_leave;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_get_include_leave:
|
||||||
|
* @filter: a #MatrixAPIRoomFilter
|
||||||
|
*
|
||||||
|
* If %TRUE, events from rooms that the user has left will be included
|
||||||
|
* in the filtered event list.
|
||||||
|
*
|
||||||
|
* Returns: the value of <code>include_leave</code>
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
matrix_api_room_filter_get_include_leave(MatrixAPIRoomFilter *filter)
|
||||||
|
{
|
||||||
|
return filter->include_leave;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_set_ephemeral:
|
||||||
|
* @filter: a #MatrixAPIRoomFilter
|
||||||
|
* @rules: (transfer none): filtering rules for ephemeral events
|
||||||
|
*
|
||||||
|
* Set filtering rules for ephemeral events, i.e. events that are not
|
||||||
|
* recorded in the room history (typing notifications, receipts, etc.)
|
||||||
|
* @filter gets a reference on @rules, so the caller may unref it.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
matrix_api_room_filter_set_ephemeral(MatrixAPIRoomFilter *filter,
|
||||||
|
MatrixAPIFilterRules *rules)
|
||||||
|
{
|
||||||
|
if (filter->ephemeral) {
|
||||||
|
matrix_api_filter_rules_unref(filter->ephemeral);
|
||||||
|
}
|
||||||
|
|
||||||
|
filter->ephemeral = matrix_api_filter_rules_ref(rules);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_get_ephemeral:
|
||||||
|
* @filter: a #MatrixAPIRoomFilter
|
||||||
|
*
|
||||||
|
* Gets the filtering rules for ephemeral events. See
|
||||||
|
* matrix_api_room_filter_set_ephemeral() for details.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): the filtering rules for ephemeral events.
|
||||||
|
*/
|
||||||
|
MatrixAPIFilterRules *
|
||||||
|
matrix_api_room_filter_get_ephemeral(MatrixAPIRoomFilter *filter)
|
||||||
|
{
|
||||||
|
return filter->ephemeral;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_set_state:
|
||||||
|
* @filter: a #MatrixAPIRoomFilter
|
||||||
|
* @rules: (transfer none): filtering rules for state events
|
||||||
|
*
|
||||||
|
* Sets filtering rules for state events. @filter obtains a reference
|
||||||
|
* on @rules, so the caller may unref it safely.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
matrix_api_room_filter_set_state(MatrixAPIRoomFilter *filter,
|
||||||
|
MatrixAPIFilterRules *rules)
|
||||||
|
{
|
||||||
|
if (filter->state) {
|
||||||
|
matrix_api_filter_rules_unref(filter->state);
|
||||||
|
}
|
||||||
|
|
||||||
|
filter->state = matrix_api_filter_rules_ref(rules);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_get_state:
|
||||||
|
* @filter: a #MatrixAPIRoomFilter
|
||||||
|
*
|
||||||
|
* Gets the filtering rules for state events.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): the filtering rules for state events
|
||||||
|
*/
|
||||||
|
MatrixAPIFilterRules *
|
||||||
|
matrix_api_room_filter_get_state(MatrixAPIRoomFilter *filter)
|
||||||
|
{
|
||||||
|
return filter->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_set_timeline:
|
||||||
|
* @filter: a #MatrixAPIRoomFilter
|
||||||
|
* @rules: (transfer none): filtering rules for timeline events
|
||||||
|
* (messages and state events from rooms)
|
||||||
|
*
|
||||||
|
* Set filtering rules for timeline events.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
matrix_api_room_filter_set_timeline(MatrixAPIRoomFilter *filter,
|
||||||
|
MatrixAPIFilterRules *rules)
|
||||||
|
{
|
||||||
|
if (filter->timeline) {
|
||||||
|
matrix_api_filter_rules_unref(filter->timeline);
|
||||||
|
}
|
||||||
|
|
||||||
|
filter->timeline = matrix_api_filter_rules_ref(rules);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_get_timeline:
|
||||||
|
* @filter: a #MatrixAPIRoomFilter
|
||||||
|
*
|
||||||
|
* Gets filtering rules for timeline events (see
|
||||||
|
* matrix_api_room_filter_set_timeline() for details.
|
||||||
|
*
|
||||||
|
* Returns: (transfer none): the filtering rules for timeline events
|
||||||
|
*/
|
||||||
|
MatrixAPIFilterRules *
|
||||||
|
matrix_api_room_filter_get_timeline(MatrixAPIRoomFilter *filter)
|
||||||
|
{
|
||||||
|
return filter->timeline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_get_json_node:
|
||||||
|
* @filter: a #MatrixAPIRoomFilter
|
||||||
|
*
|
||||||
|
* Gets the #JsonNode representation of the filtering ruleset.
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): the JSON representation of the filtering
|
||||||
|
* ruleset as a #JsonNode
|
||||||
|
*/
|
||||||
|
JsonNode *
|
||||||
|
matrix_api_room_filter_get_json_node(MatrixAPIRoomFilter *filter)
|
||||||
|
{
|
||||||
|
JsonBuilder *builder;
|
||||||
|
JsonNode *node;
|
||||||
|
|
||||||
|
builder = json_builder_new();
|
||||||
|
json_builder_begin_object(builder);
|
||||||
|
|
||||||
|
json_builder_set_member_name(builder, "include_leave");
|
||||||
|
json_builder_add_boolean_value(builder, filter->include_leave);
|
||||||
|
|
||||||
|
if (filter->ephemeral) {
|
||||||
|
json_builder_set_member_name(builder, "ephemeral");
|
||||||
|
json_builder_add_value(builder,
|
||||||
|
matrix_api_filter_rules_get_json_node(
|
||||||
|
filter->ephemeral));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter->state) {
|
||||||
|
json_builder_set_member_name(builder, "state");
|
||||||
|
json_builder_add_value(builder,
|
||||||
|
matrix_api_filter_rules_get_json_node(
|
||||||
|
filter->state));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filter->timeline) {
|
||||||
|
json_builder_set_member_name(builder, "timeline");
|
||||||
|
json_builder_add_value(builder,
|
||||||
|
matrix_api_filter_rules_get_json_node(
|
||||||
|
filter->timeline));
|
||||||
|
}
|
||||||
|
|
||||||
|
json_builder_end_object(builder);
|
||||||
|
|
||||||
|
node = json_builder_get_root(builder);
|
||||||
|
g_object_unref(builder);
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_room_filter_get_json_data:
|
||||||
|
* @filter: a #MatrixAPIRoomFilter
|
||||||
|
* @datalen: (out) (allow-none): storage for the length of the JSON
|
||||||
|
* data, or %NULL
|
||||||
|
*
|
||||||
|
* Get the string representation of the filtering ruleset as a JSON
|
||||||
|
* object.
|
||||||
|
*
|
||||||
|
* Returns: the JSON object representation of the filtering ruleset
|
||||||
|
* data as a string
|
||||||
|
*/
|
||||||
|
gchar *
|
||||||
|
matrix_api_room_filter_get_json_data(MatrixAPIRoomFilter *filter,
|
||||||
|
gsize *datalen)
|
||||||
|
{
|
||||||
|
JsonGenerator *generator;
|
||||||
|
JsonNode *node = matrix_api_room_filter_get_json_node(filter);
|
||||||
|
gchar *data;
|
||||||
|
|
||||||
|
generator = json_generator_new();
|
||||||
|
json_generator_set_root(generator, node);
|
||||||
|
json_node_free(node);
|
||||||
|
|
||||||
|
data = json_generator_to_data(generator, datalen);
|
||||||
|
g_object_unref(generator);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include <glib-object.h>
|
#include <glib-object.h>
|
||||||
#include <json-glib/json-glib.h>
|
#include <json-glib/json-glib.h>
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
typedef struct _MatrixAPIFilterRules MatrixAPIFilterRules;
|
typedef struct _MatrixAPIFilterRules MatrixAPIFilterRules;
|
||||||
|
|
||||||
GType matrix_api_filter_rules_get_type(void);
|
GType matrix_api_filter_rules_get_type(void);
|
||||||
@ -79,4 +81,30 @@ JsonNode *matrix_api_filter_rules_get_json_node(MatrixAPIFilterRules *rules);
|
|||||||
gchar *matrix_api_filter_rules_get_json_data(MatrixAPIFilterRules *rules,
|
gchar *matrix_api_filter_rules_get_json_data(MatrixAPIFilterRules *rules,
|
||||||
gsize *datalen);
|
gsize *datalen);
|
||||||
|
|
||||||
|
typedef struct _MatrixAPIRoomFilter MatrixAPIRoomFilter;
|
||||||
|
|
||||||
|
GType matrix_api_room_filter_get_type(void);
|
||||||
|
#define MATRIX_TYPE_API_ROOM_FILTER (matrix_api_room_filter_get_type())
|
||||||
|
|
||||||
|
MatrixAPIRoomFilter *matrix_api_room_filter_new(void);
|
||||||
|
MatrixAPIRoomFilter *matrix_api_room_filter_ref(MatrixAPIRoomFilter *filter);
|
||||||
|
void matrix_api_room_filter_unref(MatrixAPIRoomFilter *filter);
|
||||||
|
void matrix_api_room_filter_set_include_leave(MatrixAPIRoomFilter *filter,
|
||||||
|
gboolean include_leave);
|
||||||
|
gboolean matrix_api_room_filter_get_include_leave(MatrixAPIRoomFilter *filter);
|
||||||
|
void matrix_api_room_filter_set_ephemeral(MatrixAPIRoomFilter *filter,
|
||||||
|
MatrixAPIFilterRules *rules);
|
||||||
|
MatrixAPIFilterRules *matrix_api_room_filter_get_ephemeral(MatrixAPIRoomFilter *filter);
|
||||||
|
void matrix_api_room_filter_set_state(MatrixAPIRoomFilter *filter,
|
||||||
|
MatrixAPIFilterRules *rules);
|
||||||
|
MatrixAPIFilterRules *matrix_api_room_filter_get_state(MatrixAPIRoomFilter *filter);
|
||||||
|
void matrix_api_room_filter_set_timeline(MatrixAPIRoomFilter *filter,
|
||||||
|
MatrixAPIFilterRules *rules);
|
||||||
|
MatrixAPIFilterRules *matrix_api_room_filter_get_timeline(MatrixAPIRoomFilter *filter);
|
||||||
|
JsonNode *matrix_api_room_filter_get_json_node(MatrixAPIRoomFilter *filter);
|
||||||
|
gchar *matrix_api_room_filter_get_json_data(MatrixAPIRoomFilter *filter,
|
||||||
|
gsize *datalen);
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __MATRIX_API_TYPES_H__ */
|
#endif /* __MATRIX_API_TYPES_H__ */
|
||||||
|
@ -307,17 +307,6 @@
|
|||||||
* communication.
|
* communication.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* MatrixAPIRoomFilter:
|
|
||||||
* @ephemeral: the events that aren't recorded in the room history,
|
|
||||||
* e.g. typing and receipts, to include for rooms
|
|
||||||
* @include_leave: include rooms that the user has left in the sync
|
|
||||||
* @state: the state events to include for rooms
|
|
||||||
* @timeline: the message and state update events to include for rooms
|
|
||||||
*
|
|
||||||
* A struct to hold a room event filter
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MatrixAPIFilter:
|
* MatrixAPIFilter:
|
||||||
* @event_fields: (element-type GString): list of event fields to
|
* @event_fields: (element-type GString): list of event fields to
|
||||||
|
@ -107,13 +107,6 @@ typedef enum {
|
|||||||
MATRIX_API_PUSHER_CONDITION_KIND_ROOM_MEMBER_COUNT
|
MATRIX_API_PUSHER_CONDITION_KIND_ROOM_MEMBER_COUNT
|
||||||
} MatrixAPIPusherConditionKind;
|
} MatrixAPIPusherConditionKind;
|
||||||
|
|
||||||
typedef struct _MatrixAPIRoomFilter {
|
|
||||||
MatrixAPIFilterRules *ephemeral;
|
|
||||||
gboolean include_leave;
|
|
||||||
MatrixAPIFilterRules *state;
|
|
||||||
MatrixAPIFilterRules *timeline;
|
|
||||||
} MatrixAPIRoomFilter;
|
|
||||||
|
|
||||||
typedef struct _MatrixAPIFilter {
|
typedef struct _MatrixAPIFilter {
|
||||||
GList *event_fields;
|
GList *event_fields;
|
||||||
MatrixAPIEventFormat event_format;
|
MatrixAPIEventFormat event_format;
|
||||||
|
Loading…
Reference in New Issue
Block a user