Port MatrixEventRoomAvatar to C
This commit is contained in:
parent
a6899e054f
commit
350afd8ca1
1
.gitignore
vendored
1
.gitignore
vendored
@ -60,7 +60,6 @@ Makefile.in
|
||||
/src/matrix-event-room-canonical-alias.c
|
||||
/src/matrix-event-room-create.c
|
||||
/src/matrix-event-room-power-levels.c
|
||||
/src/matrix-event-room-avatar.c
|
||||
/src/matrix-event-room-message-feedback.c
|
||||
/src/matrix-event-room-guest-access.c
|
||||
/src/matrix-event-room-redaction.c
|
||||
|
@ -28,7 +28,6 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
|
||||
matrix-event-room-canonical-alias.vala \
|
||||
matrix-event-room-create.vala \
|
||||
matrix-event-room-power-levels.vala \
|
||||
matrix-event-room-avatar.vala \
|
||||
matrix-event-room-message-feedback.vala \
|
||||
matrix-event-room-guest-access.vala \
|
||||
matrix-event-room-redaction.vala \
|
||||
@ -111,6 +110,7 @@ INST_H_SRC_FILES = \
|
||||
matrix-event-room-member.h \
|
||||
matrix-event-room-topic.h \
|
||||
matrix-event-room-aliases.h \
|
||||
matrix-event-room-avatar.h \
|
||||
matrix-event-typing.h \
|
||||
matrix-event-receipt.h \
|
||||
utils.h \
|
||||
@ -149,6 +149,7 @@ libmatrix_glib_0_0_la_SOURCES = \
|
||||
matrix-event-receipt.c \
|
||||
matrix-event-room-topic.c \
|
||||
matrix-event-room-aliases.c \
|
||||
matrix-event-room-avatar.c \
|
||||
matrix-profile.c \
|
||||
utils.c \
|
||||
matrix-enumtypes.c \
|
||||
|
512
src/matrix-event-room-avatar.c
Normal file
512
src/matrix-event-room-avatar.c
Normal file
@ -0,0 +1,512 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "matrix-event-room-avatar.h"
|
||||
#include "config.h"
|
||||
|
||||
/**
|
||||
* SECTION:matrix-event-room-avatar
|
||||
* @short_description: event holding the room avatar
|
||||
*
|
||||
* This is the default handler for `m.room.avatar` events.
|
||||
*
|
||||
* A picture that is associated with the room. This can be displayed alongside the room
|
||||
* information.
|
||||
*/
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_URL,
|
||||
PROP_THUMBNAIL_URL,
|
||||
PROP_INFO,
|
||||
PROP_THUMBNAIL_INFO,
|
||||
NUM_PROPERTIES
|
||||
};
|
||||
|
||||
static GParamSpec *matrix_event_room_avatar_properties[NUM_PROPERTIES];
|
||||
|
||||
typedef struct {
|
||||
gchar* _url;
|
||||
gchar* _thumbnail_url;
|
||||
MatrixImageInfo* _info;
|
||||
MatrixImageInfo* _thumbnail_info;
|
||||
} MatrixEventRoomAvatarPrivate;
|
||||
|
||||
/**
|
||||
* MatrixEventRoomAvatar:
|
||||
*/
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(MatrixEventRoomAvatar, matrix_event_room_avatar, MATRIX_EVENT_TYPE_STATE);
|
||||
|
||||
static void
|
||||
matrix_event_room_avatar_real_from_json(MatrixEventBase *matrix_event_base, JsonNode *json_data, GError **error)
|
||||
{
|
||||
MatrixEventRoomAvatarPrivate *priv;
|
||||
JsonObject *root;
|
||||
JsonObject *content_root;
|
||||
JsonNode *content_node;
|
||||
JsonNode *node;
|
||||
|
||||
g_return_if_fail(json_data != NULL);
|
||||
|
||||
priv = matrix_event_room_avatar_get_instance_private(MATRIX_EVENT_ROOM_AVATAR(matrix_event_base));
|
||||
root = json_node_get_object(json_data);
|
||||
content_node = json_object_get_member(root, "content");
|
||||
content_root = json_node_get_object(content_node);
|
||||
|
||||
if (DEBUG) {
|
||||
if ((node = json_object_get_member(root, "state_key")) != NULL) {
|
||||
const char *sk = json_node_get_string(node);
|
||||
|
||||
if ((sk != NULL) && (*sk != 0)) {
|
||||
g_warning("state_key of a m.room.avatar event is non-empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = json_object_get_member(content_root, "url")) != NULL) {
|
||||
g_free(priv->_url);
|
||||
priv->_url = g_strdup(json_node_get_string(node));
|
||||
} else {
|
||||
g_warning("content.url is missing from a m.room.avatar event");
|
||||
}
|
||||
|
||||
if ((node = json_object_get_member(content_root, "thumbnail_url")) != NULL) {
|
||||
g_free(priv->_thumbnail_url);
|
||||
priv->_thumbnail_url = g_strdup(json_node_get_string(node));
|
||||
}
|
||||
|
||||
if ((node = json_object_get_member(content_root, "info")) != NULL) {
|
||||
matrix_image_info_unref(priv->_info);
|
||||
priv->_info = matrix_image_info_new();
|
||||
matrix_image_info_set_from_json(priv->_info, node);
|
||||
}
|
||||
|
||||
if ((node = json_object_get_member(content_root, "thumbnail_info")) != NULL) {
|
||||
matrix_image_info_unref(priv->_thumbnail_info);
|
||||
priv->_thumbnail_info = matrix_image_info_new();
|
||||
matrix_image_info_set_from_json(priv->_thumbnail_info, node);
|
||||
}
|
||||
|
||||
MATRIX_EVENT_BASE_CLASS(matrix_event_room_avatar_parent_class)->from_json(matrix_event_base, json_data, error);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_event_room_avatar_real_to_json(MatrixEventBase *matrix_event_base, JsonNode *json_data, GError **error)
|
||||
{
|
||||
MatrixEventRoomAvatarPrivate *priv;
|
||||
JsonObject *root;
|
||||
JsonObject *content_root;
|
||||
JsonNode *content_node;
|
||||
JsonNode *node;
|
||||
const gchar *state_key;
|
||||
GError *inner_error = NULL;
|
||||
|
||||
g_return_if_fail (json_data != NULL);
|
||||
|
||||
priv = matrix_event_room_avatar_get_instance_private(MATRIX_EVENT_ROOM_AVATAR(matrix_event_base));
|
||||
|
||||
if (priv->_url == NULL) {
|
||||
g_set_error(error, MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE,
|
||||
"Won't generate a m.room.avatar event without url");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
root = json_node_get_object(json_data);
|
||||
content_node = json_object_get_member(root, "content");
|
||||
content_root = json_node_get_object(content_node);
|
||||
|
||||
state_key = matrix_event_state_get_state_key(MATRIX_EVENT_STATE(matrix_event_base));
|
||||
|
||||
if ((state_key == NULL) || (*state_key == 0)) {
|
||||
g_set_error(error, MATRIX_ERROR, MATRIX_ERROR_INCOMPLETE,
|
||||
"Won't generate a m.room.avatar event with a non-empty state_key");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
json_object_set_string_member(content_root, "url", priv->_url);
|
||||
|
||||
if (priv->_thumbnail_url != NULL) {
|
||||
json_object_set_string_member(content_root, "thumbnail_url", priv->_thumbnail_url);
|
||||
}
|
||||
|
||||
if (priv->_info != NULL) {
|
||||
node = matrix_image_info_get_json_node(priv->_info, &inner_error);
|
||||
|
||||
if (inner_error != NULL) {
|
||||
g_propagate_error(error, inner_error);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
json_object_set_member(content_root, "info", node);
|
||||
}
|
||||
|
||||
if (priv->_thumbnail_info != NULL) {
|
||||
node = matrix_image_info_get_json_node(priv->_thumbnail_info, &inner_error);
|
||||
|
||||
if (inner_error != NULL) {
|
||||
g_propagate_error(error, inner_error);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
json_object_set_member(content_root, "thumbnail_info", node);
|
||||
}
|
||||
|
||||
MATRIX_EVENT_BASE_CLASS(matrix_event_room_avatar_parent_class)->to_json(matrix_event_base, json_data, error);
|
||||
}
|
||||
|
||||
MatrixEventRoomAvatar *
|
||||
matrix_event_room_avatar_construct(GType object_type)
|
||||
{
|
||||
return (MatrixEventRoomAvatar *)matrix_event_state_construct(object_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_event_room_avatar_new:
|
||||
*
|
||||
* Create a new #MatrixEventRoomAvatar object.
|
||||
*
|
||||
* Returns: (transfer full): a new #MatrixEventRoomAvatar object
|
||||
*/
|
||||
MatrixEventRoomAvatar *
|
||||
matrix_event_room_avatar_new(void)
|
||||
{
|
||||
return matrix_event_room_avatar_construct(MATRIX_EVENT_TYPE_ROOM_AVATAR);
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_event_room_avatar_get_url:
|
||||
* @event: a #MatrixEventRoomAvatar
|
||||
*
|
||||
* Get the URL of the room avatar from @event.
|
||||
*
|
||||
* The returned value is owned by @event and should no be freed.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): an avatar URL
|
||||
*/
|
||||
const gchar *
|
||||
matrix_event_room_avatar_get_url(MatrixEventRoomAvatar *matrix_event_room_avatar)
|
||||
{
|
||||
MatrixEventRoomAvatarPrivate *priv;
|
||||
|
||||
g_return_val_if_fail(matrix_event_room_avatar != NULL, NULL);
|
||||
|
||||
priv = matrix_event_room_avatar_get_instance_private(matrix_event_room_avatar);
|
||||
|
||||
return priv->_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_event_room_avatar_set_url:
|
||||
* @event: a #MatrixEventRoomAvatar
|
||||
* @url: (transfer none) (nullable): an URL to set as the room avatar
|
||||
*
|
||||
* Set the room avatar URL.
|
||||
*/
|
||||
void
|
||||
matrix_event_room_avatar_set_url(MatrixEventRoomAvatar *matrix_event_room_avatar, const gchar *url)
|
||||
{
|
||||
MatrixEventRoomAvatarPrivate *priv;
|
||||
|
||||
g_return_if_fail(matrix_event_room_avatar != NULL);
|
||||
|
||||
priv = matrix_event_room_avatar_get_instance_private(matrix_event_room_avatar);
|
||||
|
||||
if (g_strcmp0(url, priv->_url) != 0) {
|
||||
g_free(priv->_url);
|
||||
priv->_url = g_strdup(url);
|
||||
|
||||
g_object_notify_by_pspec((GObject *)matrix_event_room_avatar, matrix_event_room_avatar_properties[PROP_URL]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_event_room_avatar_get_thumbnail_url:
|
||||
* @event: a #MatrixEventRoomAvatar
|
||||
*
|
||||
* Get the URL of the avatar’s thumbnail.
|
||||
*
|
||||
* The returned value is owned by @event and should not be freed.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): the URL of the avatar thumbnail
|
||||
*/
|
||||
const gchar *
|
||||
matrix_event_room_avatar_get_thumbnail_url(MatrixEventRoomAvatar *matrix_event_room_avatar)
|
||||
{
|
||||
MatrixEventRoomAvatarPrivate *priv;
|
||||
|
||||
g_return_val_if_fail(matrix_event_room_avatar != NULL, NULL);
|
||||
|
||||
priv = matrix_event_room_avatar_get_instance_private(matrix_event_room_avatar);
|
||||
|
||||
return priv->_thumbnail_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_event_room_avatar_set_thumbnail_url:
|
||||
* @event: a #MatrixEventRoomAvatar
|
||||
* @thumbnail_url: (transfer none) (nullable): the URL of the room avatar’s thumbnail
|
||||
*
|
||||
* Set the URL of the room avatar’s thumbnail.
|
||||
*/
|
||||
void
|
||||
matrix_event_room_avatar_set_thumbnail_url(MatrixEventRoomAvatar *matrix_event_room_avatar, const gchar *thumbnail_url)
|
||||
{
|
||||
MatrixEventRoomAvatarPrivate *priv;
|
||||
|
||||
g_return_if_fail(matrix_event_room_avatar != NULL);
|
||||
|
||||
priv = matrix_event_room_avatar_get_instance_private(matrix_event_room_avatar);
|
||||
|
||||
if (g_strcmp0(thumbnail_url, priv->_thumbnail_url) != 0) {
|
||||
g_free(priv->_thumbnail_url);
|
||||
priv->_thumbnail_url = g_strdup(thumbnail_url);
|
||||
|
||||
g_object_notify_by_pspec((GObject *)matrix_event_room_avatar, matrix_event_room_avatar_properties[PROP_THUMBNAIL_URL]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_event_room_avatar_get_info:
|
||||
* @event: a #MatrixEventRoomAvatar
|
||||
*
|
||||
* Get the image info for the room avatar.
|
||||
*
|
||||
* The returned value is owned by @event and should not be freed.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): the image info for the room avatar image.
|
||||
*/
|
||||
MatrixImageInfo *
|
||||
matrix_event_room_avatar_get_info(MatrixEventRoomAvatar *matrix_event_room_avatar)
|
||||
{
|
||||
MatrixEventRoomAvatarPrivate *priv;
|
||||
|
||||
g_return_val_if_fail(matrix_event_room_avatar != NULL, NULL);
|
||||
|
||||
priv = matrix_event_room_avatar_get_instance_private(matrix_event_room_avatar);
|
||||
|
||||
return priv->_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_event_room_avatar_set_info:
|
||||
* @event: a #MatrixEventRoomAvatar
|
||||
* @info: a #MatrixImageInfo
|
||||
*
|
||||
* Set the image information for the avatar image.
|
||||
*/
|
||||
void
|
||||
matrix_event_room_avatar_set_info(MatrixEventRoomAvatar *matrix_event_room_avatar, MatrixImageInfo *info)
|
||||
{
|
||||
MatrixEventRoomAvatarPrivate *priv;
|
||||
|
||||
g_return_if_fail(matrix_event_room_avatar != NULL);
|
||||
|
||||
priv = matrix_event_room_avatar_get_instance_private(matrix_event_room_avatar);
|
||||
|
||||
if (priv->_info != info) {
|
||||
matrix_image_info_unref(priv->_info);
|
||||
priv->_info = matrix_image_info_ref(info);
|
||||
|
||||
g_object_notify_by_pspec((GObject *)matrix_event_room_avatar, matrix_event_room_avatar_properties[PROP_INFO]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_event_room_avatar_get_thumbnail_info:
|
||||
* @event: a #MatrixEventRoomAvatar
|
||||
*
|
||||
* Get the image info for the room avatar’s thumbnail.
|
||||
*
|
||||
* The returned value is owned by @event and should not be freed.
|
||||
*
|
||||
* Returns: (transfer none) (nullable): the image info for the avatar’s thumbnail
|
||||
*/
|
||||
MatrixImageInfo *
|
||||
matrix_event_room_avatar_get_thumbnail_info(MatrixEventRoomAvatar *matrix_event_room_avatar)
|
||||
{
|
||||
MatrixEventRoomAvatarPrivate *priv;
|
||||
|
||||
g_return_val_if_fail(matrix_event_room_avatar != NULL, NULL);
|
||||
|
||||
priv = matrix_event_room_avatar_get_instance_private(matrix_event_room_avatar);
|
||||
|
||||
return priv->_thumbnail_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* matrix_event_room_avatar_set_thumbnail_info:
|
||||
* @event: a #MatrixEventRoomAvatar
|
||||
* @thumbnail_info: (transfer none) (nullable): a #MatrixImageInfo
|
||||
*
|
||||
* Set the image info for the room avatar’s thumbnail.
|
||||
*/
|
||||
void
|
||||
matrix_event_room_avatar_set_thumbnail_info(MatrixEventRoomAvatar *matrix_event_room_avatar, MatrixImageInfo *thumbnail_info)
|
||||
{
|
||||
MatrixEventRoomAvatarPrivate *priv;
|
||||
|
||||
g_return_if_fail(matrix_event_room_avatar != NULL);
|
||||
|
||||
priv = matrix_event_room_avatar_get_instance_private(matrix_event_room_avatar);
|
||||
|
||||
if (priv->_thumbnail_info != thumbnail_info) {
|
||||
matrix_image_info_unref(priv->_thumbnail_info);
|
||||
priv->_thumbnail_info = matrix_image_info_ref(thumbnail_info);
|
||||
|
||||
g_object_notify_by_pspec((GObject *)matrix_event_room_avatar, matrix_event_room_avatar_properties[PROP_THUMBNAIL_INFO]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_event_room_avatar_finalize(GObject *gobject)
|
||||
{
|
||||
MatrixEventRoomAvatarPrivate *priv = matrix_event_room_avatar_get_instance_private(MATRIX_EVENT_ROOM_AVATAR(gobject));
|
||||
|
||||
g_free(priv->_url);
|
||||
g_free(priv->_thumbnail_url);
|
||||
matrix_image_info_unref(priv->_info);
|
||||
matrix_image_info_unref(priv->_thumbnail_info);
|
||||
|
||||
G_OBJECT_CLASS(matrix_event_room_avatar_parent_class)->finalize(gobject);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_event_room_avatar_get_property(GObject *gobject, guint property_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
MatrixEventRoomAvatar *matrix_event_room_avatar = MATRIX_EVENT_ROOM_AVATAR(gobject);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_URL:
|
||||
g_value_set_string(value, matrix_event_room_avatar_get_url(matrix_event_room_avatar));
|
||||
|
||||
break;
|
||||
case PROP_THUMBNAIL_URL:
|
||||
g_value_set_string(value, matrix_event_room_avatar_get_thumbnail_url(matrix_event_room_avatar));
|
||||
|
||||
break;
|
||||
case PROP_INFO:
|
||||
g_value_set_boxed(value, matrix_event_room_avatar_get_info(matrix_event_room_avatar));
|
||||
|
||||
break;
|
||||
case PROP_THUMBNAIL_INFO:
|
||||
g_value_set_boxed(value, matrix_event_room_avatar_get_thumbnail_info(matrix_event_room_avatar));
|
||||
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_event_room_avatar_set_property(GObject *gobject, guint property_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
MatrixEventRoomAvatar *matrix_event_room_avatar = MATRIX_EVENT_ROOM_AVATAR(gobject);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_URL:
|
||||
matrix_event_room_avatar_set_url(matrix_event_room_avatar, g_value_get_string(value));
|
||||
|
||||
break;
|
||||
case PROP_THUMBNAIL_URL:
|
||||
matrix_event_room_avatar_set_thumbnail_url(matrix_event_room_avatar, g_value_get_string(value));
|
||||
|
||||
break;
|
||||
case PROP_INFO:
|
||||
matrix_event_room_avatar_set_info(matrix_event_room_avatar, g_value_get_boxed(value));
|
||||
|
||||
break;
|
||||
case PROP_THUMBNAIL_INFO:
|
||||
matrix_event_room_avatar_set_thumbnail_info(matrix_event_room_avatar, g_value_get_boxed(value));
|
||||
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, property_id, pspec);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_event_room_avatar_class_init(MatrixEventRoomAvatarClass *klass)
|
||||
{
|
||||
((MatrixEventBaseClass *)klass)->from_json = matrix_event_room_avatar_real_from_json;
|
||||
((MatrixEventBaseClass *)klass)->to_json = matrix_event_room_avatar_real_to_json;
|
||||
G_OBJECT_CLASS(klass)->get_property = matrix_event_room_avatar_get_property;
|
||||
G_OBJECT_CLASS(klass)->set_property = matrix_event_room_avatar_set_property;
|
||||
G_OBJECT_CLASS(klass)->finalize = matrix_event_room_avatar_finalize;
|
||||
|
||||
/**
|
||||
* MatrixEventRoomAvatar:url:
|
||||
*
|
||||
* The URL to the image.
|
||||
*/
|
||||
matrix_event_room_avatar_properties[PROP_URL] = g_param_spec_string(
|
||||
"url", "url", "url",
|
||||
NULL,
|
||||
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_URL, matrix_event_room_avatar_properties[PROP_URL]);
|
||||
|
||||
/**
|
||||
* MatrixEventRoomAvatar:thumbnail-url:
|
||||
*
|
||||
* The URL to the thumbnail of the image.
|
||||
*/
|
||||
matrix_event_room_avatar_properties[PROP_THUMBNAIL_URL] = g_param_spec_string(
|
||||
"thumbnail-url", "thumbnail-url", "thumbnail-url",
|
||||
NULL,
|
||||
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_THUMBNAIL_URL, matrix_event_room_avatar_properties[PROP_THUMBNAIL_URL]);
|
||||
|
||||
/**
|
||||
* MatrixEventRoomAvatar:info:
|
||||
*
|
||||
* The image info for the room avatar.
|
||||
*/
|
||||
matrix_event_room_avatar_properties[PROP_INFO] = g_param_spec_boxed(
|
||||
"info", "info", "info",
|
||||
MATRIX_TYPE_IMAGE_INFO,
|
||||
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_INFO, matrix_event_room_avatar_properties[PROP_INFO]);
|
||||
|
||||
/**
|
||||
* MatrixEventRoomAvatar:thumbnail-info:
|
||||
*
|
||||
* The image info for the room avatar’s thumbnail.
|
||||
*/
|
||||
matrix_event_room_avatar_properties[PROP_INFO] = g_param_spec_boxed(
|
||||
"thumbnail-info", "thumbnail-info", "thumbnail-info",
|
||||
MATRIX_TYPE_IMAGE_INFO,
|
||||
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
|
||||
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_INFO, matrix_event_room_avatar_properties[PROP_INFO]);
|
||||
}
|
||||
|
||||
static void
|
||||
matrix_event_room_avatar_init(MatrixEventRoomAvatar *matrix_event_room_avatar)
|
||||
{
|
||||
MatrixEventRoomAvatarPrivate *priv = matrix_event_room_avatar_get_instance_private(matrix_event_room_avatar);
|
||||
|
||||
priv->_url = NULL;
|
||||
priv->_thumbnail_url = NULL;
|
||||
priv->_info = NULL;
|
||||
priv->_thumbnail_info = NULL;
|
||||
}
|
48
src/matrix-event-room-avatar.h
Normal file
48
src/matrix-event-room-avatar.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __MATRIX_GLIB_SDK_EVENT_ROOM_AVATAR_H__
|
||||
# define __MATRIX_GLIB_SDK_EVENT_ROOM_AVATAR_H__
|
||||
|
||||
# include <glib-object.h>
|
||||
# include "matrix-event-state-base.h"
|
||||
# include "matrix-types.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
# define MATRIX_EVENT_TYPE_ROOM_AVATAR matrix_event_room_avatar_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(MatrixEventRoomAvatar, matrix_event_room_avatar, MATRIX_EVENT, ROOM_AVATAR, MatrixEventState);
|
||||
|
||||
struct _MatrixEventRoomAvatarClass {
|
||||
MatrixEventStateClass parent_class;
|
||||
};
|
||||
|
||||
MatrixEventRoomAvatar* matrix_event_room_avatar_new (void);
|
||||
MatrixEventRoomAvatar* matrix_event_room_avatar_construct (GType object_type);
|
||||
const gchar *matrix_event_room_avatar_get_url (MatrixEventRoomAvatar *event);
|
||||
void matrix_event_room_avatar_set_url (MatrixEventRoomAvatar *event, const gchar *url);
|
||||
const gchar *matrix_event_room_avatar_get_thumbnail_url (MatrixEventRoomAvatar *event);
|
||||
void matrix_event_room_avatar_set_thumbnail_url (MatrixEventRoomAvatar *event, const gchar *thumbnail_url);
|
||||
MatrixImageInfo *matrix_event_room_avatar_get_info (MatrixEventRoomAvatar *event);
|
||||
void matrix_event_room_avatar_set_info (MatrixEventRoomAvatar *event, MatrixImageInfo *info);
|
||||
MatrixImageInfo *matrix_event_room_avatar_get_thumbnail_info (MatrixEventRoomAvatar *event);
|
||||
void matrix_event_room_avatar_set_thumbnail_info (MatrixEventRoomAvatar *event, MatrixImageInfo *thumbnail_info);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MATRIX_GLIB_SDK_EVENT_ROOM_AVATAR_H__ */
|
@ -1,121 +0,0 @@
|
||||
/*
|
||||
* This file is part of matrix-glib-sdk
|
||||
*
|
||||
* matrix-glib-sdk is free software: you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation, either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* matrix-glib-sdk is distributed in the hope that it will be
|
||||
* useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with matrix-glib-sdk. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class to hold a m.room.avatar event
|
||||
*
|
||||
* A picture that is associated with the room. This can be displayed
|
||||
* alongside the room information.
|
||||
*/
|
||||
public class Matrix.Event.RoomAvatar : Matrix.Event.State {
|
||||
/**
|
||||
* The URL to the image.
|
||||
*/
|
||||
public string? url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The URL to the thumbnail of the image.
|
||||
*/
|
||||
public string? thumbnail_url { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Metadata about the image referred to in url.
|
||||
*/
|
||||
public ImageInfo? info { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* Metadata about the image referred to in thumbnail_url.
|
||||
*/
|
||||
public ImageInfo? thumbnail_info { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
Json.Node? node;
|
||||
|
||||
if (Config.DEBUG) {
|
||||
if ((node = root.get_member("state_key")) != null) {
|
||||
var sk = node.get_string();
|
||||
|
||||
if (sk != "") {
|
||||
warning("state_key of a m.room.avatar event is non-empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("url")) != null) {
|
||||
_url = node.get_string();
|
||||
} else {
|
||||
warning("content.url is missing from a m.room.avatar event");
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("thumbnail_url")) != null) {
|
||||
_thumbnail_url = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("info")) != null) {
|
||||
_info = ImageInfo();
|
||||
_info.set_from_json(node);
|
||||
}
|
||||
|
||||
if ((node = content_root.get_member("thumbnail_info")) != null) {
|
||||
_thumbnail_info = ImageInfo();
|
||||
_thumbnail_info.set_from_json(node);
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_url == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.avatar event without url");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
var content_root = root.get_member("content").get_object();
|
||||
|
||||
if (_state_key != "") {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.avatar event with a non-empty state_key");
|
||||
}
|
||||
|
||||
content_root.set_string_member("url", _url);
|
||||
|
||||
if (_thumbnail_url != null) {
|
||||
content_root.set_string_member("thumbnail_url", _thumbnail_url);
|
||||
}
|
||||
|
||||
if (_info != null) {
|
||||
content_root.set_member("info", _info.get_json_node());
|
||||
}
|
||||
|
||||
if (_thumbnail_info != null) {
|
||||
content_root.set_member("thumbnail_info",
|
||||
_thumbnail_info.get_json_node());
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
#include "matrix-event-receipt.h"
|
||||
#include "matrix-event-room-topic.h"
|
||||
#include "matrix-event-room-aliases.h"
|
||||
#include "matrix-event-room-avatar.h"
|
||||
|
||||
#include "matrix-message-text.h"
|
||||
#include "matrix-message-location.h"
|
||||
|
@ -206,8 +206,8 @@ namespace Matrix {
|
||||
|
||||
[CCode (cheader_filename = "matrix-types.h")]
|
||||
public struct FileInfo {
|
||||
public void set_size(ssize size);
|
||||
public ssize get_size();
|
||||
public void set_size(int64 size);
|
||||
public int64 get_size();
|
||||
|
||||
public void set_mimetype(string? mimetype);
|
||||
public string? get_mimetype();
|
||||
@ -220,8 +220,8 @@ namespace Matrix {
|
||||
|
||||
[CCode (cheader_filename = "matrix-types.h")]
|
||||
public struct AudioInfo {
|
||||
public ssize get_size();
|
||||
public void set_size(ssize size);
|
||||
public int64 get_size();
|
||||
public void set_size(int64 size);
|
||||
|
||||
public string? get_mimetype();
|
||||
public void set_mimetype(string? mimetype);
|
||||
@ -237,8 +237,8 @@ namespace Matrix {
|
||||
|
||||
[CCode (cheader_filename = "matrix-types.h")]
|
||||
public struct ImageInfo {
|
||||
public ssize get_size();
|
||||
public void set_size(ssize size);
|
||||
public int64 get_size();
|
||||
public void set_size(int64 size);
|
||||
public int get_height();
|
||||
public void set_height(int height);
|
||||
public int get_width();
|
||||
@ -255,8 +255,8 @@ namespace Matrix {
|
||||
|
||||
[CCode (cheader_filename = "matrix-types.h")]
|
||||
public struct VideoInfo {
|
||||
public ssize get_size();
|
||||
public void set_size(ssize size);
|
||||
public int64 get_size();
|
||||
public void set_size(int64 size);
|
||||
|
||||
public string? get_mimetype();
|
||||
public void set_mimetype(string? mimetype);
|
||||
@ -604,6 +604,22 @@ namespace Matrix {
|
||||
protected override void to_json(Json.Node json_data)
|
||||
throws Matrix.Error;
|
||||
}
|
||||
|
||||
[CCode (cheader_filename = "matrix-event-room-avatar.h")]
|
||||
public class RoomAvatar : State {
|
||||
public string? url { get; set; default = null; }
|
||||
public string? thumbnail_url { get; set; default = null; }
|
||||
public ImageInfo? info { get; set; default = null; }
|
||||
public ImageInfo? thumbnail_info { get; set; default = null; }
|
||||
|
||||
protected override void
|
||||
from_json(Json.Node json_data)
|
||||
throws Matrix.Error;
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error;
|
||||
}
|
||||
}
|
||||
|
||||
[CCode (gir_namespace = "MatrixMessage", gir_version = "0.0")]
|
||||
|
Loading…
Reference in New Issue
Block a user