almost works

This commit is contained in:
or-else
2020-01-18 11:36:57 +03:00
parent f7a52d70d6
commit ed6518df9c
6 changed files with 263 additions and 141 deletions
+27 -35
View File
@@ -74,8 +74,6 @@ class MessagesView extends React.Component {
this.handleNewMessage = this.handleNewMessage.bind(this);
this.handleAllMessagesReceived = this.handleAllMessagesReceived.bind(this);
this.handleInfoReceipt = this.handleInfoReceipt.bind(this);
this.handleDocPreview = this.handleDocPreview.bind(this);
this.handleImagePreview = this.handleImagePreview.bind(this);
this.handleImagePostview = this.handleImagePostview.bind(this);
this.handleClosePreview = this.handleClosePreview.bind(this);
this.handleFormResponse = this.handleFormResponse.bind(this);
@@ -513,43 +511,41 @@ class MessagesView extends React.Component {
}
}
sendFileAttachment(mime, bits, fname, size, uploadCompletionPromise, uploader) {
if (uploadCompletionPromise) {
// Format data and initiate upload.
const msg = Drafty.attachFile(null, mime, null, fname, size, uploadCompletionPromise);
sendFileAttachment(file) {
if (file.size > MAX_INBAND_ATTACHMENT_SIZE) {
// Too large to send inband - uploading out of band and sending as a link.
const uploader = this.props.tinode.getLargeFileHelper();
if (!uploader) {
this.props.onError(formatMessage(messages.cannot_initiate_upload));
return;
}
const uploadCompletionPromise = uploader.upload(file);
const msg = Drafty.attachFile(null, file.type, null, file.name, file.size, uploadCompletionPromise);
// Pass data and the uploader to the TinodeWeb.
this.props.sendMessage(msg, uploadCompletionPromise, uploader);
} else {
this.props.sendMessage(Drafty.attachFile(null, mime, bits, fname));
// Small enough to send inband.
fileToBase64(file,
(mime, bits, fname) => {
this.props.sendMessage(Drafty.attachFile(null, mime, bits, fname));
},
this.props.onError
);
}
}
handleDocPreview(content) {
this.setState({ docPreview: content });
}
handleAttachFile(file) {
if (file.size > MAX_EXTERN_ATTACHMENT_SIZE) {
// Too large.
this.props.onError(formatMessage(messages.file_attachment_too_large,
{size: bytesToHumanSize(file.size), limit: bytesToHumanSize(MAX_EXTERN_ATTACHMENT_SIZE)}), 'err');
} else if (file.size > MAX_INBAND_ATTACHMENT_SIZE) {
// Too large to send inband - uploading out of band and sending as a link.
const uploader = this.props.tinode.getLargeFileHelper();
if (!uploader) {
this.props.onError(formatMessage(messages.cannot_initiate_upload));
return;
}
// Pass data and the uploader to the TinodeWeb.
this.sendFileAttachment(file.type, null, file.name, file.size, uploadCompletionPromise, uploader);
} else {
// Small enough to send inband.
fileToBase64(file,
(mime, bits, fname) => {
this.sendFileAttachment(mime, bits, fname);
},
this.props.onError
);
this.setState({ docPreview: {
file: file,
filename: file.name,
size: file.size,
type: file.type
}});
}
}
@@ -562,10 +558,6 @@ class MessagesView extends React.Component {
this.props.sendMessage(msg);
}
handleImagePreview(content) {
this.setState({ imagePreview: content });
}
handleAttachImage(file) {
// Check if the uploaded file is indeed an image and if it isn't too large.
if (file.size > MAX_INBAND_ATTACHMENT_SIZE || SUPPORTED_IMAGE_FORMATS.indexOf(file.type) < 0) {
@@ -573,7 +565,7 @@ class MessagesView extends React.Component {
imageFileScaledToBase64(file, MAX_IMAGE_DIM, MAX_IMAGE_DIM, false,
// Success
(bits, mime, width, height, fname) => {
this.handleImagePreview({
this.setState({imagePreview: {
url: URL.createObjectURL(file),
bits: bits,
filename: fname,
@@ -581,7 +573,7 @@ class MessagesView extends React.Component {
height: height,
size: bits.length,
type: mime
});
}});
},
// Failure
(err) => {
@@ -592,7 +584,7 @@ class MessagesView extends React.Component {
imageFileToBase64(file,
// Success
(bits, mime, width, height, fname) => {
this.handleImagePreview({
this.setState({imagePreview: {
url: URL.createObjectURL(file),
bits: bits,
filename: fname,
@@ -600,7 +592,7 @@ class MessagesView extends React.Component {
height: height,
size: bits.length,
type: mime
});
}});
},
// Failure
(err) => {
+3 -6
View File
@@ -29,9 +29,8 @@ export default class DocPreview extends React.PureComponent {
if (!this.props.content) {
return null;
}
const doc = iconFromMime(this.props.content.type);
return (
const doc = iconFromMime(this.props.content.type);
<div id="image-preview">
<div id="image-preview-caption-panel">
<span>{this.props.content.filename}</span>
@@ -42,13 +41,11 @@ export default class DocPreview extends React.PureComponent {
</div>
<div id="image-preview-footer">
<div>
<div><b><FormattedMessage id="label_content_type" defaultMessage="Content type:"
description="Label for file content type (mime)" /></b></div>
<div><b><FormattedMessage id="label_content_type" /></b></div>
<div>{this.props.content.type}</div>
</div>
<div>
<div><b><FormattedMessage id="label_size" defaultMessage="Size:"
description="Label for file size" /></b></div>
<div><b><FormattedMessage id="label_size" /></b></div>
<div>{bytesToHumanSize(this.props.content.size)}</div>
</div>
</div>
+230 -97
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long