Create setter for MatrixAPI.user_id and MatrixAPI.homeserver
This commit is contained in:
parent
c8bc5e7d6b
commit
4132035bcd
@ -73,7 +73,9 @@ matrix_api_media_upload
|
|||||||
matrix_api_get_token
|
matrix_api_get_token
|
||||||
matrix_api_set_token
|
matrix_api_set_token
|
||||||
matrix_api_get_user_id
|
matrix_api_get_user_id
|
||||||
|
matrix_api_set_user_id
|
||||||
matrix_api_get_homeserver
|
matrix_api_get_homeserver
|
||||||
|
matrix_api_set_homeserver
|
||||||
MatrixAPI
|
MatrixAPI
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
|
||||||
|
@ -101,7 +101,9 @@
|
|||||||
* @get_token: the virtual function pointer to matrix_api_get_token()
|
* @get_token: the virtual function pointer to matrix_api_get_token()
|
||||||
* @set_token: the virtual function pointer to matrix_api_set_token()
|
* @set_token: the virtual function pointer to matrix_api_set_token()
|
||||||
* @get_user_id: the virtual function pointer to matrix_api_get_user_id()
|
* @get_user_id: the virtual function pointer to matrix_api_get_user_id()
|
||||||
|
* @set_user_id: the virtual function pointer to matrix_api_set_user_id()
|
||||||
* @get_homeserver: the virtual function pointer to matrix_api_get_homeserver()
|
* @get_homeserver: the virtual function pointer to matrix_api_get_homeserver()
|
||||||
|
* @set_homeserver: the virtual function pointer to matrix_api_set_homeserver()
|
||||||
*
|
*
|
||||||
* The virtual function table for for #MatrixAPI.
|
* The virtual function table for for #MatrixAPI.
|
||||||
*/
|
*/
|
||||||
@ -1935,6 +1937,21 @@ matrix_api_get_user_id(MatrixAPI *matrix_api)
|
|||||||
return MATRIX_API_GET_IFACE(matrix_api)->get_user_id(matrix_api);
|
return MATRIX_API_GET_IFACE(matrix_api)->get_user_id(matrix_api);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_set_user_id:
|
||||||
|
* @api: a #MatrixAPI
|
||||||
|
* @user_id: (nullable): a Matrix ID
|
||||||
|
*
|
||||||
|
* Set the user ID of the user logged in using @api. This might be useful for restoring state.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
matrix_api_set_user_id(MatrixAPI *matrix_api, const gchar *user_id)
|
||||||
|
{
|
||||||
|
g_return_if_fail(matrix_api != NULL);
|
||||||
|
|
||||||
|
MATRIX_API_GET_IFACE(matrix_api)->set_user_id(matrix_api, user_id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* matrix_api_get_homeserver:
|
* matrix_api_get_homeserver:
|
||||||
* @api: a #MatrixAPI
|
* @api: a #MatrixAPI
|
||||||
@ -1953,6 +1970,22 @@ matrix_api_get_homeserver(MatrixAPI *matrix_api)
|
|||||||
return MATRIX_API_GET_IFACE(matrix_api)->get_homeserver(matrix_api);
|
return MATRIX_API_GET_IFACE(matrix_api)->get_homeserver(matrix_api);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* matrix_api_set_homeserver:
|
||||||
|
* @api: a #MatrixAPI
|
||||||
|
* @homeserver: (nullable): a homeserver name
|
||||||
|
*
|
||||||
|
* Set the name of the homeserver, as it calls itself. This might be useful for
|
||||||
|
* restoring state.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
matrix_api_set_homeserver(MatrixAPI *api, const gchar *homeserver)
|
||||||
|
{
|
||||||
|
g_return_if_fail(api != NULL);
|
||||||
|
|
||||||
|
MATRIX_API_GET_IFACE(api)->set_homeserver(api, homeserver);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
matrix_api_default_init(MatrixAPIInterface *iface)
|
matrix_api_default_init(MatrixAPIInterface *iface)
|
||||||
{
|
{
|
||||||
|
@ -456,7 +456,9 @@ struct _MatrixAPIInterface {
|
|||||||
const gchar *(*get_token)(MatrixAPI *api);
|
const gchar *(*get_token)(MatrixAPI *api);
|
||||||
void (*set_token)(MatrixAPI *api, const gchar *value);
|
void (*set_token)(MatrixAPI *api, const gchar *value);
|
||||||
const gchar *(*get_user_id)(MatrixAPI *api);
|
const gchar *(*get_user_id)(MatrixAPI *api);
|
||||||
|
void (*set_user_id)(MatrixAPI *api, const gchar *user_id);
|
||||||
const gchar *(*get_homeserver)(MatrixAPI *api);
|
const gchar *(*get_homeserver)(MatrixAPI *api);
|
||||||
|
void (*set_homeserver)(MatrixAPI *api, const gchar *homeserver);
|
||||||
};
|
};
|
||||||
|
|
||||||
void matrix_api_abort_pending(MatrixAPI *api);
|
void matrix_api_abort_pending(MatrixAPI *api);
|
||||||
@ -875,7 +877,9 @@ void matrix_api_media_upload(MatrixAPI *api,
|
|||||||
const gchar *matrix_api_get_token(MatrixAPI *api);
|
const gchar *matrix_api_get_token(MatrixAPI *api);
|
||||||
void matrix_api_set_token(MatrixAPI *api, const gchar *token);
|
void matrix_api_set_token(MatrixAPI *api, const gchar *token);
|
||||||
const gchar *matrix_api_get_user_id(MatrixAPI *api);
|
const gchar *matrix_api_get_user_id(MatrixAPI *api);
|
||||||
|
void matrix_api_set_user_id(MatrixAPI *api, const gchar *user_id);
|
||||||
const gchar *matrix_api_get_homeserver(MatrixAPI *api);
|
const gchar *matrix_api_get_homeserver(MatrixAPI *api);
|
||||||
|
void matrix_api_set_homeserver(MatrixAPI *api, const gchar *homeserver);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@ -51,6 +51,8 @@ typedef struct {
|
|||||||
SoupURI *api_uri;
|
SoupURI *api_uri;
|
||||||
SoupURI *media_uri;
|
SoupURI *media_uri;
|
||||||
gchar *token;
|
gchar *token;
|
||||||
|
gchar *homeserver;
|
||||||
|
gchar *user_id;
|
||||||
} MatrixHTTPAPIPrivate;
|
} MatrixHTTPAPIPrivate;
|
||||||
|
|
||||||
static void matrix_http_api_matrix_api_interface_init(MatrixAPIInterface * iface);
|
static void matrix_http_api_matrix_api_interface_init(MatrixAPIInterface * iface);
|
||||||
@ -222,8 +224,8 @@ _matrix_http_api_response_callback(SoupSession *session, SoupMessage *msg, gpoin
|
|||||||
g_debug("Our home server calls itself %s", homeserver);
|
g_debug("Our home server calls itself %s", homeserver);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_free(matrix_http_api->_homeserver);
|
g_free(priv->homeserver);
|
||||||
matrix_http_api->_homeserver = g_strdup(homeserver);
|
priv->homeserver = g_strdup(homeserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the response holds a user ID; if it does,
|
/* Check if the response holds a user ID; if it does,
|
||||||
@ -235,8 +237,8 @@ _matrix_http_api_response_callback(SoupSession *session, SoupMessage *msg, gpoin
|
|||||||
g_debug("We are reported to be logged in as %s", user_id);
|
g_debug("We are reported to be logged in as %s", user_id);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_free(matrix_http_api->_user_id);
|
g_free(priv->user_id);
|
||||||
matrix_http_api->_user_id = g_strdup(user_id);
|
priv->user_id = g_strdup(user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the response holds an error */
|
/* Check if the response holds an error */
|
||||||
@ -2237,11 +2239,11 @@ matrix_http_api_set_base_url(MatrixHTTPAPI *matrix_http_api, const gchar *base_u
|
|||||||
priv->base_url = g_strdup(base_url);
|
priv->base_url = g_strdup(base_url);
|
||||||
|
|
||||||
g_free(priv->token);
|
g_free(priv->token);
|
||||||
g_free(matrix_http_api->_homeserver);
|
|
||||||
g_free(matrix_http_api->_user_id);
|
|
||||||
priv->token = NULL;
|
priv->token = NULL;
|
||||||
matrix_http_api->_homeserver = NULL;
|
g_free(priv->homeserver);
|
||||||
matrix_http_api->_user_id = NULL;
|
g_free(priv->user_id);
|
||||||
|
priv->homeserver = NULL;
|
||||||
|
priv->user_id = NULL;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
gchar *uri;
|
gchar *uri;
|
||||||
@ -2293,7 +2295,9 @@ matrix_http_api_set_validate_certificate(MatrixHTTPAPI *matrix_http_api, gboolea
|
|||||||
static const gchar *
|
static const gchar *
|
||||||
matrix_http_api_get_user_id (MatrixAPI *api)
|
matrix_http_api_get_user_id (MatrixAPI *api)
|
||||||
{
|
{
|
||||||
return MATRIX_HTTP_API(matrix_api)->_user_id;
|
MatrixHTTPAPIPrivate *priv = matrix_http_api_get_instance_private(MATRIX_HTTP_API(api));
|
||||||
|
|
||||||
|
return priv->user_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const gchar *
|
static const gchar *
|
||||||
@ -2319,13 +2323,14 @@ matrix_http_api_set_token(MatrixAPI *matrix_api, const gchar *token)
|
|||||||
|
|
||||||
static const gchar *
|
static const gchar *
|
||||||
matrix_http_api_get_homeserver(MatrixAPI *api) {
|
matrix_http_api_get_homeserver(MatrixAPI *api) {
|
||||||
return MATRIX_HTTP_API(api)->_homeserver;
|
MatrixHTTPAPIPrivate *priv = matrix_http_api_get_instance_private(MATRIX_HTTP_API(api));
|
||||||
|
|
||||||
|
return priv->homeserver;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
matrix_http_api_finalize(GObject *gobject)
|
matrix_http_api_finalize(GObject *gobject)
|
||||||
{
|
{
|
||||||
MatrixHTTPAPI *matrix_http_api = MATRIX_HTTP_API(gobject);
|
|
||||||
MatrixHTTPAPIPrivate *priv = matrix_http_api_get_instance_private(MATRIX_HTTP_API(gobject));
|
MatrixHTTPAPIPrivate *priv = matrix_http_api_get_instance_private(MATRIX_HTTP_API(gobject));
|
||||||
|
|
||||||
g_object_unref(priv->soup_session);
|
g_object_unref(priv->soup_session);
|
||||||
@ -2339,9 +2344,9 @@ matrix_http_api_finalize(GObject *gobject)
|
|||||||
soup_uri_free(priv->media_uri);
|
soup_uri_free(priv->media_uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(matrix_http_api->_user_id);
|
|
||||||
g_free(priv->token);
|
g_free(priv->token);
|
||||||
g_free(matrix_http_api->_homeserver);
|
g_free(priv->user_id);
|
||||||
|
g_free(priv->homeserver);
|
||||||
|
|
||||||
G_OBJECT_CLASS(matrix_http_api_parent_class)->finalize(gobject);
|
G_OBJECT_CLASS(matrix_http_api_parent_class)->finalize(gobject);
|
||||||
}
|
}
|
||||||
@ -2537,4 +2542,6 @@ matrix_http_api_init(MatrixHTTPAPI *matrix_http_api)
|
|||||||
priv->api_uri = NULL;
|
priv->api_uri = NULL;
|
||||||
priv->media_uri = NULL;
|
priv->media_uri = NULL;
|
||||||
priv->token = NULL;
|
priv->token = NULL;
|
||||||
|
priv->homeserver = NULL;
|
||||||
|
priv->user_id = NULL;
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(MatrixHTTPAPI, g_object_unref);
|
|||||||
|
|
||||||
struct _MatrixHTTPAPI {
|
struct _MatrixHTTPAPI {
|
||||||
GObject parent_instance;
|
GObject parent_instance;
|
||||||
|
|
||||||
gchar *_homeserver;
|
|
||||||
gchar *_user_id;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _MatrixHTTPAPIClass {
|
struct _MatrixHTTPAPIClass {
|
||||||
|
@ -808,20 +808,18 @@ matrix_http_client_real_load_state(MatrixClient *matrix_client, const gchar *fil
|
|||||||
matrix_http_api_set_validate_certificate(MATRIX_HTTP_API(matrix_client), json_node_get_boolean(node));
|
matrix_http_api_set_validate_certificate(MATRIX_HTTP_API(matrix_client), json_node_get_boolean(node));
|
||||||
|
|
||||||
if ((node = json_object_get_member(root, "user_id")) != NULL) {
|
if ((node = json_object_get_member(root, "user_id")) != NULL) {
|
||||||
g_free(MATRIX_HTTP_API(matrix_client)->_user_id);
|
matrix_api_set_user_id(MATRIX_API(matrix_client), json_node_get_string(node));
|
||||||
MATRIX_HTTP_API(matrix_client)->_user_id = g_strdup(json_node_get_string(node));
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
g_debug("Loaded user ID %s", MATRIX_HTTP_API(matrix_client)->_user_id);
|
g_debug("Loaded user ID %s", matrix_api_get_user_id(MATRIX_API(matrix_client)));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((node = json_object_get_member(root, "homeserver_name")) != NULL) {
|
if ((node = json_object_get_member(root, "homeserver_name")) != NULL) {
|
||||||
g_free(MATRIX_HTTP_API(matrix_client)->_homeserver);
|
matrix_api_set_homeserver(MATRIX_API(matrix_client), json_node_get_string(node));
|
||||||
MATRIX_HTTP_API(matrix_client)->_homeserver = g_strdup(json_node_get_string(node));
|
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
g_debug("Loaded homeserver name %s", MATRIX_HTTP_API(matrix_client)->_homeserver);
|
g_debug("Loaded homeserver name %s", matrix_api_get_homeserver(MATRIX_API(matrix_client)));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user