diff options
author | White_Rabbit <bruno@tracciabi.li> | 2017-09-27 14:53:44 +0200 |
---|---|---|
committer | White_Rabbit <bruno@tracciabi.li> | 2018-02-22 14:41:33 +0100 |
commit | 1ee4cc01f6e1c6ef88143fb0052d864576333dcb (patch) | |
tree | 98e218f5511c05e930871477133e0b795c4b9810 /matrix-api.c | |
parent | 1a53f61998407013719fdabdcff4ead3e9715340 (diff) | |
download | purple-matrix-1ee4cc01f6e1c6ef88143fb0052d864576333dcb.tar.gz |
Improve media handling
Handle m.video, m.file, m.audio and m.image in _handle_incoming_media.
Remove _handle incoming_image. On incoming media, always print a chat
message with the download link and mimetype/size. If a thumbnail_url is
available and the thumbnail size is small, download and show that. Otherwise,
only for m_image, ask for a server generated thumbnail.
Diffstat (limited to 'matrix-api.c')
-rw-r--r-- | matrix-api.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/matrix-api.c b/matrix-api.c index 2c22508..0cccc38 100644 --- a/matrix-api.c +++ b/matrix-api.c @@ -905,6 +905,20 @@ MatrixApiRequestData *matrix_api_upload_file(MatrixConnectionData *conn, return fetch_data; } +GString *get_download_url(const gchar *homeserver, const gchar *uri) +{ + GString *url; + + /* Sanity check the uri - TODO: Add more sanity */ + if (strncmp(uri, "mxc://", 6)) { + return NULL; + } + url = g_string_new(homeserver); + g_string_append(url, "_matrix/media/r0/download/"); + g_string_append(url, uri + 6); /* i.e. after the mxc:// */ + return url; +} + /** * Download a file * @param uri URI string in the form mxc://example.com/unique @@ -920,14 +934,11 @@ MatrixApiRequestData *matrix_api_download_file(MatrixConnectionData *conn, GString *url; MatrixApiRequestData *fetch_data; - /* Sanity check the uri - TODO: Add more sanity */ - if (strncmp(uri, "mxc://", 6)) { + url = get_download_url(conn->homeserver, uri); + if (!url) { error_callback(conn, user_data, "bad media uri"); return NULL; } - url = g_string_new(conn->homeserver); - g_string_append(url, "_matrix/media/r0/download/"); - g_string_append(url, uri + 6); /* i.e. after the mxc:// */ /* I'd like to validate the headers etc a bit before downloading the * data (maybe using _handle_header_completed), also I'm not convinced |