Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pasting files into the text box #605

Merged
merged 1 commit into from Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ContentMessages.js
Expand Up @@ -276,7 +276,7 @@ class ContentMessages {

sendContentToRoom(file, roomId, matrixClient) {
const content = {
body: file.name,
body: file.name || 'Attachment',
info: {
size: file.size,
}
Expand Down Expand Up @@ -316,7 +316,7 @@ class ContentMessages {
}

const upload = {
fileName: file.name,
fileName: file.name || 'Attachment',
roomId: roomId,
total: 0,
loaded: 0,
Expand Down
10 changes: 6 additions & 4 deletions src/components/views/rooms/MessageComposer.js
Expand Up @@ -91,16 +91,17 @@ export default class MessageComposer extends React.Component {
this.refs.uploadInput.click();
}

onUploadFileSelected(ev) {
let files = ev.target.files;
onUploadFileSelected(files, isPasted) {
if (!isPasted)
files = files.target.files;

let QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
let TintableSvg = sdk.getComponent("elements.TintableSvg");

let fileList = [];
for (let i=0; i<files.length; i++) {
fileList.push(<li key={i}>
<TintableSvg key={i} src="img/files.svg" width="16" height="16" /> {files[i].name}
<TintableSvg key={i} src="img/files.svg" width="16" height="16" /> {files[i].name || 'Attachment'}
</li>);
}

Expand Down Expand Up @@ -171,7 +172,7 @@ export default class MessageComposer extends React.Component {
}

onUpArrow() {
return this.refs.autocomplete.onUpArrow();
return this.refs.autocomplete.onUpArrow();
}

onDownArrow() {
Expand Down Expand Up @@ -293,6 +294,7 @@ export default class MessageComposer extends React.Component {
tryComplete={this._tryComplete}
onUpArrow={this.onUpArrow}
onDownArrow={this.onDownArrow}
onUploadFileSelected={this.onUploadFileSelected}
tabComplete={this.props.tabComplete} // used for old messagecomposerinput/tabcomplete
onContentChanged={this.onInputContentChanged}
onInputStateChanged={this.onInputStateChanged} />,
Expand Down
8 changes: 8 additions & 0 deletions src/components/views/rooms/MessageComposerInput.js
Expand Up @@ -83,6 +83,7 @@ export default class MessageComposerInput extends React.Component {
this.onAction = this.onAction.bind(this);
this.handleReturn = this.handleReturn.bind(this);
this.handleKeyCommand = this.handleKeyCommand.bind(this);
this.handlePastedFiles = this.handlePastedFiles.bind(this);
this.onEditorContentChanged = this.onEditorContentChanged.bind(this);
this.setEditorState = this.setEditorState.bind(this);
this.onUpArrow = this.onUpArrow.bind(this);
Expand Down Expand Up @@ -473,6 +474,10 @@ export default class MessageComposerInput extends React.Component {
return false;
}

handlePastedFiles(files) {
this.props.onUploadFileSelected(files, true);
}

handleReturn(ev) {
if (ev.shiftKey) {
this.onEditorContentChanged(RichUtils.insertSoftNewline(this.state.editorState));
Expand Down Expand Up @@ -728,6 +733,7 @@ export default class MessageComposerInput extends React.Component {
keyBindingFn={MessageComposerInput.getKeyBinding}
handleKeyCommand={this.handleKeyCommand}
handleReturn={this.handleReturn}
handlePastedFiles={this.handlePastedFiles}
stripPastedStyles={!this.state.isRichtextEnabled}
onTab={this.onTab}
onUpArrow={this.onUpArrow}
Expand Down Expand Up @@ -757,6 +763,8 @@ MessageComposerInput.propTypes = {

onDownArrow: React.PropTypes.func,

onUploadFileSelected: React.PropTypes.func,

// attempts to confirm currently selected completion, returns whether actually confirmed
tryComplete: React.PropTypes.func,

Expand Down