From 347a0a1759432258a865dcd9d4639ebdafd3f49a Mon Sep 17 00:00:00 2001 From: f0x Date: Wed, 22 May 2019 01:04:29 +0200 Subject: [PATCH] partly working thumbnail work --- app.js | 1 + components/events/Event.js | 3 ++- components/events/image.js | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index 858dabb..016c747 100644 --- a/app.js +++ b/app.js @@ -56,6 +56,7 @@ let App = create({ }, startClient: function(client) { + console.log(client) client.on("sync", (state, prevState, data) => { if (state == "ERROR") { } else if (state == "SYNCING") { diff --git a/components/events/Event.js b/components/events/Event.js index 1bf4749..01e58d8 100644 --- a/components/events/Event.js +++ b/components/events/Event.js @@ -10,7 +10,8 @@ const User = require('./user.js') const elements = { "m.text": require('./text.js'), - "m.image": require('./image.js') + "m.image": require('./image.js'), + "m.video": require('./video.js') } const mxReplyRegex = /^[\s\S]+<\/mx-reply>/ diff --git a/components/events/image.js b/components/events/image.js index 13f2e02..d0e5690 100644 --- a/components/events/image.js +++ b/components/events/image.js @@ -3,6 +3,7 @@ const React = require('react') const ReactDOM = require('react-dom') const create = require('create-react-class') const Promise = require('bluebird') +const defaultValue = require('default-value') const Text = require('./text.js') @@ -10,22 +11,43 @@ let Event = create({ displayName: "m.image", getInitialState: function() { + let client = this.props.client let hs = this.props.client.baseUrl let event = this.props.event if (event.content.url == undefined) { return {url: {media: null, thumb: null}} } - let media_mxc = event.content.url.slice(6) - let thumb_mxc = media_mxc - if (event.content.info != undefined && event.content.info.thumbnail_info != undefined) { - thumb_mxc = event.content.info.thumbnail_url.slice(6) + console.log(event) + + let h = 1000 + let w = 1000 + try { + if (event.content.info.h < h) { + h = event.content.info.h + } + + if (event.content.info.w < w) { + w = event.content.info.w + } + + if (event.content.info.thumbnail_info < h) { + h = event.content.info.thumbnail_info.h + } + + if (event.content.info.thumbnail_info < w) { + w = event.content.info.thumbnail_info.w + } + } catch(error) { + } - let download = `${hs}/_matrix/media/v1/download` - let thumbnail = `${hs}/_matrix/media/v1/thumbnail/${thumb_mxc}?width=1000&height=1000&method=scale` + + let media_url = client.mxcUrlToHttp(event.content.url) + let thumb_url = client.mxcUrlToHttp(event.content.url, w, h, "scale", false) + return { url: { - media: `${download}/${media_mxc}`, - thumb: thumbnail + media: media_url, + thumb: thumb_url } } },