Generate placeholder text in separate method

To make the MessageComposer render() method a bit less busy

Signed-off-by: YaoiFangirl420 <48789208+YaoiFangirl420@users.noreply.github.com>
pull/21833/head
YaoiFangirl420 2019-04-06 20:57:45 -07:00
parent cfb9172121
commit 452f0e6dcc
1 changed files with 19 additions and 17 deletions

View File

@ -131,6 +131,7 @@ export default class MessageComposer extends React.Component {
this._onRoomStateEvents = this._onRoomStateEvents.bind(this); this._onRoomStateEvents = this._onRoomStateEvents.bind(this);
this._onRoomViewStoreUpdate = this._onRoomViewStoreUpdate.bind(this); this._onRoomViewStoreUpdate = this._onRoomViewStoreUpdate.bind(this);
this._onTombstoneClick = this._onTombstoneClick.bind(this); this._onTombstoneClick = this._onTombstoneClick.bind(this);
this.renderPlaceholderText = this.renderPlaceholderText.bind(this);
this.state = { this.state = {
inputState: { inputState: {
@ -289,6 +290,23 @@ export default class MessageComposer extends React.Component {
}); });
} }
renderPlaceholderText() {
const roomIsEncrypted = MatrixClientPeg.get().isRoomEncrypted(this.props.room.roomId);
if (this.state.isQuoting) {
if (roomIsEncrypted) {
return _t('Send an encrypted reply…');
} else {
return _t('Send a reply (unencrypted)…');
}
} else {
if (roomIsEncrypted) {
return _t('Send an encrypted message…');
} else {
return _t('Send a message (unencrypted)…');
}
}
}
render() { render() {
const uploadInputStyle = {display: 'none'}; const uploadInputStyle = {display: 'none'};
const MessageComposerInput = sdk.getComponent("rooms.MessageComposerInput"); const MessageComposerInput = sdk.getComponent("rooms.MessageComposerInput");
@ -329,22 +347,6 @@ export default class MessageComposer extends React.Component {
key="controls_formatting" /> key="controls_formatting" />
) : null; ) : null;
const roomIsEncrypted = MatrixClientPeg.get().isRoomEncrypted(this.props.room.roomId);
let placeholderText;
if (this.state.isQuoting) {
if (roomIsEncrypted) {
placeholderText = _t('Send an encrypted reply…');
} else {
placeholderText = _t('Send a reply (unencrypted)…');
}
} else {
if (roomIsEncrypted) {
placeholderText = _t('Send an encrypted message…');
} else {
placeholderText = _t('Send a message (unencrypted)…');
}
}
const stickerpickerButton = <Stickerpicker key='stickerpicker_controls_button' room={this.props.room} />; const stickerpickerButton = <Stickerpicker key='stickerpicker_controls_button' room={this.props.room} />;
controls.push( controls.push(
@ -352,7 +354,7 @@ export default class MessageComposer extends React.Component {
ref={(c) => this.messageComposerInput = c} ref={(c) => this.messageComposerInput = c}
key="controls_input" key="controls_input"
room={this.props.room} room={this.props.room}
placeholder={placeholderText} placeholder={this.renderPlaceholderText()}
onInputStateChanged={this.onInputStateChanged} onInputStateChanged={this.onInputStateChanged}
permalinkCreator={this.props.permalinkCreator} />, permalinkCreator={this.props.permalinkCreator} />,
formattingButton, formattingButton,