aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDr. David Alan Gilbert <dave@treblig.org>2016-11-13 20:37:49 +0000
committerDr. David Alan Gilbert <dave@treblig.org>2016-12-27 20:19:08 +0000
commit4e6c861ff049e77cda34b20e9f82d1bd2e14f8d7 (patch)
tree9529297c57e29bc1c4e2de0380cae10c2b988a33
parent187aa40e245f007e307356a4d2afcf8cbb15df89 (diff)
downloadpurple-matrix-4e6c861ff049e77cda34b20e9f82d1bd2e14f8d7.tar.gz
Download thumbnails for images that are too large
When we decide from the image info that an image is too large, try a thumb instead. Pick 640x480 because a) we need to pick a size and b) That's the right size. c) We should make it configurable. (We could also try this if we didn't have the image info when we get the error). Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
-rw-r--r--matrix-room.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/matrix-room.c b/matrix-room.c
index ab631af..86dcf89 100644
--- a/matrix-room.c
+++ b/matrix-room.c
@@ -600,6 +600,7 @@ static gboolean _handle_incoming_image(PurpleConversation *conv,
MatrixConnectionData *conn = _get_connection_data_from_conversation(conv);
MatrixApiRequestData *fetch_data = NULL;
struct ReceiveImageData *rid;
+ gboolean use_thumb = FALSE;
const gchar *url;
JsonObject *json_info_object;
@@ -625,9 +626,7 @@ static gboolean _handle_incoming_image(PurpleConversation *conv,
/* OK, we've got some (optional) info on the image */
size = matrix_json_object_get_int_member(json_info_object, "size");
if (size > purple_max_image_size) {
- purple_debug_info("matrixprpl", "image too large %" PRId64 "\n", size);
- /* TODO: Switch to a thumbnail */
- return FALSE;
+ use_thumb = TRUE;
}
mime_type = matrix_json_object_get_string_member(json_info_object,
"mimetype");
@@ -649,10 +648,26 @@ static gboolean _handle_incoming_image(PurpleConversation *conv,
rid->room_id = room_id;
rid->original_body = g_strdup(msg_body);
- fetch_data = matrix_api_download_file(conn, url, purple_max_image_size,
- _image_download_complete,
- _image_download_error,
- _image_download_bad_response, rid);
+ if (!use_thumb) {
+ fetch_data = matrix_api_download_file(conn, url,
+ purple_max_image_size,
+ _image_download_complete,
+ _image_download_error,
+ _image_download_bad_response, rid);
+ } else {
+ /* TODO: Configure the size of thumbnails, and provide
+ * a way for the user to get the full image if they want.
+ * 640x480 is a good a width as any and reasonably likely to
+ * fit in the byte size limit unless someone has a big long
+ * tall png.
+ */
+ fetch_data = matrix_api_download_thumb(conn, url,
+ purple_max_image_size,
+ 640, 480, TRUE, /* Scaled */
+ _image_download_complete,
+ _image_download_error,
+ _image_download_bad_response, rid);
+ }
purple_conversation_set_data(conv, PURPLE_CONV_DATA_ACTIVE_SEND,
fetch_data);