diff --git a/src/matrix-http-api.c b/src/matrix-http-api.c index 7f7ea81..1fa944e 100644 --- a/src/matrix-http-api.c +++ b/src/matrix-http-api.c @@ -1024,6 +1024,27 @@ i_get_presence_list(MatrixAPI *api, g_free(path); } +static void +i_get_user_presence(MatrixAPI *api, + MatrixAPICallback callback, + gpointer user_data, + const gchar *user_id, + GError **error) +{ + gchar *encoded_user_id; + gchar *path; + + encoded_user_id = soup_uri_encode(user_id, NULL); + path = g_strdup_printf("presence/%s/status", encoded_user_id); + g_free(encoded_user_id); + + _send(MATRIX_HTTP_API(api), + callback, user_data, + "GET", path, NULL, NULL, + error); + g_free(path); +} + static void matrix_http_api_matrix_api_init(MatrixAPIInterface *iface) { @@ -1042,7 +1063,7 @@ matrix_http_api_matrix_api_init(MatrixAPIInterface *iface) /* Presence */ iface->get_presence_list = i_get_presence_list; iface->update_presence_list = NULL; - iface->get_user_presence = NULL; + iface->get_user_presence = i_get_user_presence; iface->set_user_presence = NULL; /* Push notifications */ diff --git a/src/test-client.c b/src/test-client.c index 56514f8..3ff9be6 100644 --- a/src/test-client.c +++ b/src/test-client.c @@ -18,6 +18,7 @@ #include #include +#include #include "matrix-http-api.h" @@ -62,6 +63,34 @@ create_room_finished(MatrixAPI *api, matrix_api_list_public_rooms(api, NULL, NULL, NULL); } +static void +get_user_presence_finished(MatrixAPI *api, + JsonNode *json_content, + gpointer data, + GError *err) +{ + JsonObject *root_obj; + const gchar *avatar_url; + SoupURI *avatar_uri; + + root_obj = json_node_get_object(json_content); + avatar_url = json_object_get_string_member(root_obj, "avatar_url"); + + g_info("Avatar URL: %s", avatar_url); + + avatar_uri = soup_uri_new(avatar_url); + g_info("Scheme: %s; authority: %s; path: %s", + soup_uri_get_scheme(avatar_uri), + soup_uri_get_host(avatar_uri), + soup_uri_get_path(avatar_uri)); + matrix_api_media_download(api, + NULL, NULL, + soup_uri_get_host(avatar_uri), + soup_uri_get_path(avatar_uri) + 1, + NULL); + soup_uri_free(avatar_uri); +} + static void login_finished(MatrixAPI *api, JsonNode *content, gpointer data, GError *err) { @@ -103,6 +132,9 @@ login_finished(MatrixAPI *api, JsonNode *content, gpointer data, GError *err) MATRIX_API_ROOM_VISIBILITY_DEFAULT, NULL, NULL, NULL, NULL); matrix_api_get_presence_list(api, NULL, NULL, user_id, NULL); + matrix_api_get_user_presence(api, + get_user_presence_finished, NULL, + user_id, NULL); } else { g_printf("Login unsuccessful!\n"); }