[NEW] Image preview as 32x32 base64 jpeg#9218
Conversation
|
@rodrigok, now it is all ok! |
graywolf336
left a comment
There was a problem hiding this comment.
Let's convert this into using promises and using Promise.await, that way the sendFileMessage is has less callbacks being passed around.
| Meteor.defer(() => RocketChat.callbacks.run('afterFileUpload', { user, room, message: msg })); | ||
|
|
||
| return msg; | ||
| return msg; |
There was a problem hiding this comment.
This is wrong, now the method will have nothing returned
| attachment.image_size = file.size; | ||
| if (file.identify && file.identify.size) { | ||
| attachment.image_dimensions = file.identify.size; | ||
| Meteor.wrapAsync(FileUpload.resizeImagePreview(file, Meteor.bindEnvironment(function(base64Preview) { |
There was a problem hiding this comment.
You could check if file is image and call this only for images, makes more sense to me.
| } else { | ||
| callback(); | ||
| } | ||
| }, |
There was a problem hiding this comment.
You can create a new method like resizeImagePreviewSync that does not receive the callback and do the wrapAsync inside
There was a problem hiding this comment.
ok, i will do that!
There was a problem hiding this comment.
I tried to do that, but the file does not finish to send, might i'm doing something wrong.
I think the Bradley suggestion that uses Promises is nice, but i don't know if you like that..
What do you think?
| } | ||
|
|
||
| const message = RocketChat.callbacks.run('renderMessage', msg); | ||
|
|
There was a problem hiding this comment.
Do not introduce unnecessary changes.
There was a problem hiding this comment.
sorry, it was a mistake when i was making tests..
| const image = FileUpload.getStore('Uploads')._store.getReadStream(file._id, file); | ||
|
|
||
| const transformer = sharp().resize(50, 50).max().toBuffer(function(err, out) { | ||
| if (err) { reject(err); } |
There was a problem hiding this comment.
Without a return you will reject and resolve the promise right?
| if (file.identify && file.identify.size) { | ||
| attachment.image_dimensions = file.identify.size; | ||
| } | ||
|
|
There was a problem hiding this comment.
You could execute the resize here using await to keep the flow sync
| Meteor.defer(() => RocketChat.callbacks.run('afterFileUpload', { user, room, message: msg })); | ||
|
|
||
| return msg; | ||
|
|
There was a problem hiding this comment.
Do not introduce unnecessary changes
|
@rodrigok, now i guess it is ok. |
| title_link: fileUrl, | ||
| title_link_download: true | ||
| }; | ||
| (async function() { |
There was a problem hiding this comment.
Did you try to remove this wrapper? AFAIK all meteor methods are async by default allowing you to call await inside.
There was a problem hiding this comment.
I had tested a lot of ways to do it, when i tryed to call await without the wrapper it was failing in the build...
# Conflicts: # package-lock.json # package.json
0b1f6dc to
5e5bd85
Compare
sampaiodiego
left a comment
There was a problem hiding this comment.
should we start using image_preview already?
|
@sampaiodiego It is mainly for mobile guys right now, once merged I'll create a new issue for UI guys to start using it. |
@RocketChat/core
Open #5563
Added a image preview as small base64 50x50 pictures embedded on the msg object.
I just made a function, and had call it on the sendFileMessage method, and i fixed the build errors.
I open another PR because my old branch was in conflict, at this time i did some build tests.