Add API method for /notifications

This commit is contained in:
Gergely Polonkai 2018-02-28 11:13:09 +01:00
parent db912dd701
commit 18b7aeb1e4
4 changed files with 79 additions and 0 deletions

View File

@ -61,6 +61,7 @@ matrix_api_set_presence
matrix_api_list_public_rooms
matrix_api_get_pushers
matrix_api_update_pusher
matrix_api_get_notifications
matrix_api_get_pushrules
matrix_api_delete_pushrule
matrix_api_get_pushrule

View File

@ -91,6 +91,7 @@
* @list_public_rooms: the virtual function pointer to matrix_api_list_public_rooms()
* @get_pushers: the virtual function pointer to matrix_api_get_pushers()
* @update_pusher: the virtual function pointer to matrix_api_update_pusher()
* @get_notifications: the virtual function pointer to matrix_api_get_notifications()
* @get_pushrules: the virtual function pointer to matrix_api_get_pushrules()
* @delete_pushrule: the virtual function pointer to matrix_api_delete_pushrule()
* @get_pushrule: the virtual function pointer to matrix_api_get_pushrule()
@ -1670,6 +1671,33 @@ matrix_api_update_pusher(MatrixAPI *matrix_api,
MATRIX_API_GET_IFACE(matrix_api)->update_pusher(matrix_api, callback, user_data, pusher, error);
}
/**
* matrix_api_get_notifications:
* @api: a #MatrixAPI
* @from_token: (nullable): Pagination token to retrieve the next set of events
* @limit: Limit on the number of events to return in the request. Set to 0 for no limit
* @filter: (nullable): Allows basic filtering of the events returned. Set it to `"highlight"` to
* return only events where the notification had the highlight tweak set.
* @callback: (scope async): a function to call when the request is finished
* @user_data: user data to be passed to @callback
* @error: (nullable): a #GError, or %NULL to ignore errors
*
* Get notifications from the server.
*/
void
matrix_api_get_notifications(MatrixAPI *api,
const gchar *from_token,
guint limit,
const gchar *filter,
MatrixAPICallback callback,
gpointer user_data,
GError **error)
{
g_return_if_fail(api != NULL);
MATRIX_API_GET_IFACE(api)->get_notifications(api, from_token, limit, filter, callback, user_data, error);
}
/**
* matrix_api_get_pushrules:
* @api: a #MatrixAPI

View File

@ -399,6 +399,13 @@ struct _MatrixAPIInterface {
gpointer user_data,
MatrixPusher *pusher,
GError **error);
void (*get_notifications)(MatrixAPI *api,
const gchar *from_token,
guint limit,
const gchar *filter,
MatrixAPICallback callback,
gpointer user_data,
GError **error);
void (*get_pushrules)(MatrixAPI *api,
MatrixAPICallback callback,
gpointer user_data,
@ -836,6 +843,13 @@ void matrix_api_update_pusher(MatrixAPI *api,
MatrixAPICallback callback,
gpointer user_data,
GError **error);
void matrix_api_get_notifications(MatrixAPI *api,
const gchar *from_token,
guint limit,
const gchar *filter,
MatrixAPICallback callback,
gpointer user_data,
GError **error);
void matrix_api_get_pushrules(MatrixAPI *api,
MatrixAPICallback callback,
gpointer user_data,

View File

@ -2215,6 +2215,41 @@ get_joined_rooms(MatrixAPI *api, MatrixAPICallback cb, void *cb_target, GError *
NULL, NULL, NULL, NULL, FALSE, error);
}
static void
get_notifications(MatrixAPI *api, const gchar *from_token, guint limit, const gchar *filter, MatrixAPICallback callback, gpointer user_data, GError **error)
{
GHashTable *parms = NULL;
if (from_token != NULL) {
parms = _matrix_http_api_create_query_params();
g_hash_table_replace(parms, g_strdup("from"), g_strdup(from_token));
}
if (limit != 0) {
if (parms == NULL) {
parms = _matrix_http_api_create_query_params();
}
g_hash_table_replace(parms, g_strdup("limit"), g_strdup_printf("%u", limit));
}
if (filter != NULL) {
if (parms == NULL) {
parms = _matrix_http_api_create_query_params();
}
g_hash_table_replace(parms, g_strdup("only"), g_strdup(filter));
}
_matrix_http_api_send(MATRIX_HTTP_API(api),
callback, user_data,
CALL_TYPE_API, "POST", "register",
parms, NULL, NULL, NULL, FALSE, error);
g_hash_table_unref(parms);
}
static void
matrix_http_api_abort_pending (MatrixAPI *matrix_api)
{
@ -2587,6 +2622,7 @@ matrix_http_api_matrix_api_interface_init(MatrixAPIInterface * iface)
iface->get_homeserver = matrix_http_api_get_homeserver;
iface->whoami = whoami;
iface->get_joined_rooms = get_joined_rooms;
iface->get_notifications = get_notifications;
}
static void