Add alt text to GIFs

This commit is contained in:
koyu 2022-06-07 14:14:54 +02:00 committed by Essem
parent 59b4901143
commit d659e6e37e
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
2 changed files with 5 additions and 3 deletions

View file

@ -294,7 +294,7 @@ export function tenorSet(options) {
}; };
}; };
export function uploadCompose(files) { export function uploadCompose(files, alt = '') {
return function (dispatch, getState) { return function (dispatch, getState) {
const uploadLimit = 4; const uploadLimit = 4;
const media = getState().getIn(['compose', 'media_attachments']); const media = getState().getIn(['compose', 'media_attachments']);
@ -320,6 +320,7 @@ export function uploadCompose(files) {
resizeImage(f).then(file => { resizeImage(f).then(file => {
const data = new FormData(); const data = new FormData();
data.append('file', file); data.append('file', file);
data.append('description', alt);
// Account for disparity in size of original image and resized data // Account for disparity in size of original image and resized data
total += file.size - f.size; total += file.size - f.size;

View file

@ -35,7 +35,7 @@ const mapDispatchToProps = dispatch => ({
/** Set options in the redux store */ /** Set options in the redux store */
setOpt: (opts) => dispatch(tenorSet(opts)), setOpt: (opts) => dispatch(tenorSet(opts)),
/** Submit GIF for upload */ /** Submit GIF for upload */
submit: (file) => dispatch(uploadCompose([file])), submit: (file, alt) => dispatch(uploadCompose([file], alt)),
}); });
export default @connect(mapStateToProps, mapDispatchToProps) export default @connect(mapStateToProps, mapDispatchToProps)
@ -52,6 +52,7 @@ class GIFModal extends ImmutablePureComponent {
onDoneButton = (result) => { onDoneButton = (result) => {
const url = result.media[0].mp4.url; const url = result.media[0].mp4.url;
const alt = result.content_description;
var modal = this; var modal = this;
// eslint-disable-next-line promise/catch-or-return // eslint-disable-next-line promise/catch-or-return
fetch(url).then(function(response) { fetch(url).then(function(response) {
@ -62,7 +63,7 @@ class GIFModal extends ImmutablePureComponent {
reader.onloadend = function() { reader.onloadend = function() {
var dataUrl = reader.result; var dataUrl = reader.result;
const file = dataURLtoFile(dataUrl, 'tenor.mp4'); const file = dataURLtoFile(dataUrl, 'tenor.mp4');
modal.props.submit(file); modal.props.submit(file, alt);
modal.props.onClose(); // close dialog modal.props.onClose(); // close dialog
}; };
}); });