Implement get_user_presence

This commit is contained in:
Gergely Polonkai 2016-01-15 12:45:32 +01:00
parent 451c7e4863
commit 441287a880
2 changed files with 54 additions and 1 deletions

View File

@ -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 */

View File

@ -18,6 +18,7 @@
#include <glib/gprintf.h>
#include <json-glib/json-glib.h>
#include <libsoup/soup.h>
#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");
}