From 4666ac7c830c54ff65a51d6bfed54d1e624474a4 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 12 Dec 2017 23:29:43 +0000 Subject: [PATCH] hide rich quoting behind flags, retaining original quoting for now Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/messages/TextualBody.js | 4 ++- .../views/rooms/MessageComposerInput.js | 32 ++++++++++++++++++- src/settings/Settings.js | 6 ++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index 1899e8428a..4c41cbe669 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -202,7 +202,9 @@ module.exports = React.createClass({ // update the current node with one that's now taken its place node = pillContainer; - } else if (this.props.tileShape !== 'quote' && Quote.isMessageUrl(href)) { + } else if (SettingsStore.isFeatureEnabled("feature_rich_quoting") && this.props.tileShape !== 'quote' && + Quote.isMessageUrl(href) + ) { // only allow this branch if we're not already in a quote, as fun as infinite nesting is. const quoteContainer = document.createElement('span'); diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index ad7e81ccb1..3305ba7994 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -297,6 +297,36 @@ export default class MessageComposerInput extends React.Component { }); } break; + + case 'quote': { // old quoting, whilst rich quoting is in labs + /// XXX: Not doing rich-text quoting from formatted-body because draft-js + /// has regressed such that when links are quoted, errors are thrown. See + /// https://github.com/vector-im/riot-web/issues/4756. + const body = escape(payload.text); + if (body) { + let content = RichText.htmlToContentState(`
${body}
`); + if (!this.state.isRichtextEnabled) { + content = ContentState.createFromText(RichText.stateToMarkdown(content)); + } + + const blockMap = content.getBlockMap(); + let startSelection = SelectionState.createEmpty(contentState.getFirstBlock().getKey()); + contentState = Modifier.splitBlock(contentState, startSelection); + startSelection = SelectionState.createEmpty(contentState.getFirstBlock().getKey()); + contentState = Modifier.replaceWithFragment(contentState, + startSelection, + blockMap); + startSelection = SelectionState.createEmpty(contentState.getFirstBlock().getKey()); + if (this.state.isRichtextEnabled) { + contentState = Modifier.setBlockType(contentState, startSelection, 'blockquote'); + } + let editorState = EditorState.push(this.state.editorState, contentState, 'insert-characters'); + editorState = EditorState.moveSelectionToEnd(editorState); + this.onEditorContentChanged(editorState); + editor.focus(); + } + } + break; } }; @@ -1146,7 +1176,7 @@ export default class MessageComposerInput extends React.Component { return (
- + { SettingsStore.isFeatureEnabled("feature_rich_quoting") && } this.autocomplete = e} room={this.props.room} diff --git a/src/settings/Settings.js b/src/settings/Settings.js index 07de17ccfd..4a5ed3f661 100644 --- a/src/settings/Settings.js +++ b/src/settings/Settings.js @@ -76,6 +76,12 @@ export const SETTINGS = { // // level is always appended to the end. // supportedLevelsAreOrdered: false, // }, + "feature_rich_quoting": { + isFeature: true, + displayName: _td("Rich Quoting"), + supportedLevels: LEVELS_FEATURE, + default: false, + }, "feature_pinning": { isFeature: true, displayName: _td("Message Pinning"),