Merge branch 'next' into features

This commit is contained in:
aforge
2021-09-28 11:25:18 +03:00
13 changed files with 366 additions and 294 deletions
+2 -2
View File
@@ -9,7 +9,7 @@ import UploadingImage from '../widgets/uploading-image.jsx'
import { IMAGE_THUMBNAIL_DIM, BROKEN_IMAGE_SIZE, REM_SIZE } from '../config.js';
import { base64ToBlob, blobToBase64, fitImageSize, imageScaled } from './blob-helpers.js';
import { idToColorClass, shortenFileName } from './strformat.js';
import { sanitizeImageUrl } from './utils.js';
import { cancelablePromise, sanitizeImageUrl } from './utils.js';
const messages = defineMessages({
drafty_form: {
@@ -389,7 +389,7 @@ export function replyFormatter(style, data, values, key) {
return quoteFormatter.call(this, style, data, values, key);
}
const attr = inlineImageAttr.call(this, {key: key}, data);
attr.whenDone = quoteImage.call(this, data);
attr.whenDone = cancelablePromise(quoteImage.call(this, data));
values = [React.createElement(LazyImage, attr, null), ' ', attr.alt];
return React.createElement(React.Fragment, {key: key}, values);
}
+19
View File
@@ -181,3 +181,22 @@ export function deliveryMarker(received) {
}
return null;
}
// Wraps a promise to make it cancelable.
export function cancelablePromise(promise) {
let hasCanceled = false;
const wrappedPromise = new Promise((resolve, reject) => {
promise.then(
result => hasCanceled ? reject({isCanceled: true}) : resolve(result),
error => hasCanceled ? reject({isCanceled: true}) : reject(error)
);
});
return {
promise: wrappedPromise,
cancel( ) {
hasCanceled = true;
},
};
};
+1 -1
View File
@@ -689,7 +689,7 @@ class MessagesView extends React.Component {
if (typeof msg == 'string') {
msg = Drafty.parse(msg);
}
msg = Drafty.append(Drafty.appendLineBreak(this.state.reply.content), msg);
msg = Drafty.append(this.state.reply.content, msg);
this.handleCancelReply();
}
this.props.sendMessage(msg, uploadCompletionPromise, uploader, head);
+6
View File
@@ -16,11 +16,17 @@ export default class LazyImage extends React.PureComponent {
}
componentDidMount() {
// whenDone is a wrapper around an actual promise to be able to cancel it.
this.props.whenDone
.promise
.then(data => this.setState({src: data.src, style: {...this.state.style, padding: 0}}))
.catch(() => this.setState({src: 'img/broken_image.png'}));
}
componentWillUnmount() {
this.props.whenDone.cancel();
}
componentDidUpdate(prevProps) {
if (prevProps.whenDone != this.props.whenDone) {
this.setState({src: 'img/placeholder.png', style: {...this.state.style, padding: '4px'}});