diff options
author | White_Rabbit <bruno@tracciabi.li> | 2017-11-17 18:30:55 +0100 |
---|---|---|
committer | White_Rabbit <bruno@tracciabi.li> | 2018-02-22 14:42:30 +0100 |
commit | 71db01cf3fac34ef3769d50a310e8864c50dd58a (patch) | |
tree | a21108e2c34a4220752b027dfed4d43074189570 /matrix-room.c | |
parent | 1ee4cc01f6e1c6ef88143fb0052d864576333dcb (diff) | |
download | purple-matrix-71db01cf3fac34ef3769d50a310e8864c50dd58a.tar.gz |
[matrix-room] Update thumbnail request to r0.3.0
With r0.3.0 thumbnail_info and thumbnail_url for m.image and m.file have
been moved from content to content.info. With this commit those objects
are looked for at the new location and if they're not found, the old
location is checked. Furthermore, if the thumbnail provided is too big,
we ask the server to make a thumbnail of it.
Diffstat (limited to 'matrix-room.c')
-rw-r--r-- | matrix-room.c | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/matrix-room.c b/matrix-room.c index 5020ee3..6ae3c85 100644 --- a/matrix-room.c +++ b/matrix-room.c @@ -72,8 +72,12 @@ static MatrixConnectionData *_get_connection_data_from_conversation( #define PURPLE_CONV_FLAGS "flags" #define PURPLE_CONV_FLAG_NEEDS_NAME_UPDATE 0x1 -/* Arbitrary limit on the size of an image to receive; should make configurable */ -static const size_t purple_max_media_size=250*1024; +/* Arbitrary limit on the size of an image to receive; should make + * configurable. This is based on the worst-case assumption of a + * 640x480 pixels, each with 3 bytes i.e. 900KiB. 640x480 is also the + * server generated thumbnail size. + */ +static const size_t purple_max_media_size=640*480*3; /** * Get the member table for a room @@ -744,24 +748,29 @@ static gboolean _handle_incoming_media(PurpleConversation *conv, const gchar *thumb_url = ""; JsonObject *json_thumb_info; guint64 thumb_size = 0; - if ((!strcmp("m.video", msg_type)) && json_info_object) { - /* m.video can have an info object containing thumbnail_* memebers */ - thumb_url = matrix_json_object_get_string_member(json_info_object, "thumbnail_url"); - json_thumb_info = matrix_json_object_get_object_member(json_info_object, "thumbnail_info"); + /* r0.2.0 -> r0.3.0 + * m.image content.thumb* -> content.info.thumb* + * m.video - + * m.file content.thumb* -> content.info.thumb* + */ + thumb_url = matrix_json_object_get_string_member(json_info_object, "thumbnail_url"); + json_thumb_info = matrix_json_object_get_object_member(json_info_object, "thumbnail_info"); + if (json_thumb_info) { + thumb_size = matrix_json_object_get_int_member(json_thumb_info, "size"); } else { - /* m.image and m.file can have thumbnail_* members directly in the content object */ + /* m.image and m.file had thumbnail_* members directly in the content object prior to r0.3.0 */ thumb_url = matrix_json_object_get_string_member(json_content_object, "thumbnail_url"); json_thumb_info = matrix_json_object_get_object_member(json_content_object, "thumbnail_info"); - } - if (json_thumb_info) { - thumb_size = matrix_json_object_get_int_member(json_thumb_info, "size"); + if (json_thumb_info) { + thumb_size = matrix_json_object_get_int_member(json_thumb_info, "size"); + } } if (is_image && (size > 0) && (size < purple_max_media_size)) { /* if an m.image is small, get that instead of the thumbnail */ thumb_url = url; thumb_size = size; } - if ((thumb_url && (thumb_size > 0) && (thumb_size < purple_max_media_size)) || is_image) { + if (thumb_url || is_image) { struct ReceiveImageData *rid; rid = g_new0(struct ReceiveImageData, 1); rid->conv = conv; @@ -777,6 +786,18 @@ static gboolean _handle_incoming_media(PurpleConversation *conv, _image_download_error, _image_download_bad_response, rid); + } else if (thumb_url) { + /* Ask the server to generate a thumbnail of the thumbnail. + * Useful to improve the chance of showing something when the + * original thumbnail is too big. + */ + fetch_data = matrix_api_download_thumb(conn, thumb_url, + purple_max_media_size, + 640, 480, TRUE, /* Scaled */ + _image_download_complete, + _image_download_error, + _image_download_bad_response, + rid); } else { /* Ask the server to generate a thumbnail. Only for m.image. * TODO: Configure the size of thumbnails. |