Code review suggestions.
* Reply to broken images. * Remove 'viewportWidth' from SendMessage.
This commit is contained in:
@@ -883,6 +883,12 @@ class MessagesView extends React.Component {
|
|||||||
const promises = [];
|
const promises = [];
|
||||||
ents.map((ex) => {
|
ents.map((ex) => {
|
||||||
let p = new Promise((resolve, reject) => {
|
let p = new Promise((resolve, reject) => {
|
||||||
|
const handleFailure = () => {
|
||||||
|
ex.data.val = '';
|
||||||
|
ex.data.name = '';
|
||||||
|
ex.data.width = IMAGE_THUMBNAIL_DIM;
|
||||||
|
ex.data.height = IMAGE_THUMBNAIL_DIM;
|
||||||
|
};
|
||||||
const scale = (origBlob) => {
|
const scale = (origBlob) => {
|
||||||
imageScaled(origBlob, IMAGE_THUMBNAIL_DIM, IMAGE_THUMBNAIL_DIM, -1, false,
|
imageScaled(origBlob, IMAGE_THUMBNAIL_DIM, IMAGE_THUMBNAIL_DIM, -1, false,
|
||||||
// Success
|
// Success
|
||||||
@@ -901,6 +907,7 @@ class MessagesView extends React.Component {
|
|||||||
},
|
},
|
||||||
// Failure
|
// Failure
|
||||||
(err) => {
|
(err) => {
|
||||||
|
handleFailure();
|
||||||
reject(`Could not scale image: ${err}`);
|
reject(`Could not scale image: ${err}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -908,6 +915,8 @@ class MessagesView extends React.Component {
|
|||||||
const b = base64ToBlob(ex.data.val, ex.data.mime);
|
const b = base64ToBlob(ex.data.val, ex.data.mime);
|
||||||
if (b) {
|
if (b) {
|
||||||
scale(b);
|
scale(b);
|
||||||
|
} else {
|
||||||
|
handleFailure();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const from = this.props.tinode.authorizeURL(sanitizeImageUrl(ex.data.ref));
|
const from = this.props.tinode.authorizeURL(sanitizeImageUrl(ex.data.ref));
|
||||||
@@ -916,6 +925,7 @@ class MessagesView extends React.Component {
|
|||||||
if (e.ok) {
|
if (e.ok) {
|
||||||
return e.blob();
|
return e.blob();
|
||||||
} else {
|
} else {
|
||||||
|
handleFailure();
|
||||||
reject(`Image fetch unsuccessful: ${e.status} - ${e.statusText}`);
|
reject(`Image fetch unsuccessful: ${e.status} - ${e.statusText}`);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -929,13 +939,13 @@ class MessagesView extends React.Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Promise.all(promises)
|
Promise.all(promises)
|
||||||
.then((_) => {
|
.catch((err) => {
|
||||||
|
this.props.onError(err, 'err');
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
// All done. Create a reply quote.
|
// All done. Create a reply quote.
|
||||||
const msg = Drafty.createQuote(header, cont, letterTileColorId(thisFrom));
|
const msg = Drafty.createQuote(header, cont, letterTileColorId(thisFrom));
|
||||||
this.setState({reply: {content: msg, seq: m.seq}});
|
this.setState({reply: {content: msg, seq: m.seq}});
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
this.props.onError(err, 'err');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@@ -982,7 +992,6 @@ class MessagesView extends React.Component {
|
|||||||
<ImagePreview
|
<ImagePreview
|
||||||
content={this.state.imagePreview}
|
content={this.state.imagePreview}
|
||||||
tinode={this.props.tinode}
|
tinode={this.props.tinode}
|
||||||
viewportWidth={this.props.viewportWidth} // Used by `formatter`.
|
|
||||||
replyTo={this.state.reply}
|
replyTo={this.state.reply}
|
||||||
formatter={draftyFormatter}
|
formatter={draftyFormatter}
|
||||||
onCancelReply={this.handleCancelReply}
|
onCancelReply={this.handleCancelReply}
|
||||||
@@ -1002,7 +1011,6 @@ class MessagesView extends React.Component {
|
|||||||
<DocPreview
|
<DocPreview
|
||||||
content={this.state.docPreview}
|
content={this.state.docPreview}
|
||||||
tinode={this.props.tinode}
|
tinode={this.props.tinode}
|
||||||
viewportWidth={this.props.viewportWidth} // Used by `formatter`.
|
|
||||||
replyTo={this.state.reply}
|
replyTo={this.state.reply}
|
||||||
formatter={draftyFormatter}
|
formatter={draftyFormatter}
|
||||||
onCancelReply={this.handleCancelReply}
|
onCancelReply={this.handleCancelReply}
|
||||||
@@ -1191,7 +1199,6 @@ class MessagesView extends React.Component {
|
|||||||
<SendMessage
|
<SendMessage
|
||||||
tinode={this.props.tinode}
|
tinode={this.props.tinode}
|
||||||
disabled={!this.state.isWriter}
|
disabled={!this.state.isWriter}
|
||||||
viewportWidth={this.props.viewportWidth}
|
|
||||||
onKeyPress={this.sendKeyPress}
|
onKeyPress={this.sendKeyPress}
|
||||||
onSendMessage={this.sendMessage}
|
onSendMessage={this.sendMessage}
|
||||||
onAttachFile={this.handleAttachFile}
|
onAttachFile={this.handleAttachFile}
|
||||||
@@ -1280,7 +1287,8 @@ function draftyFormatter(style, data, values, key) {
|
|||||||
if (data) {
|
if (data) {
|
||||||
attr.className = 'inline-image';
|
attr.className = 'inline-image';
|
||||||
const dim = fitImageSize(data.width, data.height,
|
const dim = fitImageSize(data.width, data.height,
|
||||||
Math.min(this.props.viewportWidth - REM_SIZE * 6.5, REM_SIZE * 34.5), REM_SIZE * 24, false) ||
|
this.props.hasOwnProperty('viewportWidth') ? Math.min(this.props.viewportWidth - REM_SIZE * 6.5, REM_SIZE * 34.5) : REM_SIZE * 34.5,
|
||||||
|
REM_SIZE * 24, false) ||
|
||||||
{dstWidth: BROKEN_IMAGE_SIZE, dstHeight: BROKEN_IMAGE_SIZE};
|
{dstWidth: BROKEN_IMAGE_SIZE, dstHeight: BROKEN_IMAGE_SIZE};
|
||||||
attr.style = {
|
attr.style = {
|
||||||
width: dim.dstWidth + 'px',
|
width: dim.dstWidth + 'px',
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ export default class DocPreview extends React.PureComponent {
|
|||||||
<SendMessage
|
<SendMessage
|
||||||
noInput={true}
|
noInput={true}
|
||||||
tinode={this.props.tinode}
|
tinode={this.props.tinode}
|
||||||
viewportWidth={this.props.viewportWidth} // Used by `formatter`.
|
|
||||||
replyTo={this.props.replyTo}
|
replyTo={this.props.replyTo}
|
||||||
formatter={this.props.formatter}
|
formatter={this.props.formatter}
|
||||||
onCancelReply={this.props.onCancelReply}
|
onCancelReply={this.props.onCancelReply}
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ export default class ImagePreview extends React.PureComponent {
|
|||||||
messagePrompt="add_image_caption"
|
messagePrompt="add_image_caption"
|
||||||
acceptBlank={true}
|
acceptBlank={true}
|
||||||
tinode={this.props.tinode}
|
tinode={this.props.tinode}
|
||||||
viewportWidth={this.props.viewportWidth} // Used by `formatter`.
|
|
||||||
replyTo={this.props.replyTo}
|
replyTo={this.props.replyTo}
|
||||||
formatter={this.props.formatter}
|
formatter={this.props.formatter}
|
||||||
onCancelReply={this.props.onCancelReply}
|
onCancelReply={this.props.onCancelReply}
|
||||||
|
|||||||
Reference in New Issue
Block a user