From 740b6f6cac91d3beff5658b1411b33311e68e947 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 10 Apr 2020 09:30:19 +0100 Subject: [PATCH] Composer pills respect showPillAvatar setting Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/rooms/_BasicMessageComposer.scss | 42 ++++++++++--------- .../views/rooms/BasicMessageComposer.js | 28 +++++++++---- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/res/css/views/rooms/_BasicMessageComposer.scss b/res/css/views/rooms/_BasicMessageComposer.scss index cc76623a8c..e9013eb7b7 100644 --- a/res/css/views/rooms/_BasicMessageComposer.scss +++ b/res/css/views/rooms/_BasicMessageComposer.scss @@ -44,27 +44,29 @@ limitations under the License. outline: none; overflow-x: hidden; - span.mx_UserPill, span.mx_RoomPill { - padding-left: 21px; - position: relative; + &.mx_BasicMessageComposer_input_shouldShowPillAvatar { + span.mx_UserPill, span.mx_RoomPill { + padding-left: 21px; + position: relative; - // avatar psuedo element - &::before { - position: absolute; - left: 2px; - top: 2px; - content: var(--avatar-letter); - width: 16px; - height: 16px; - background: var(--avatar-background), $avatar-bg-color; - color: $avatar-initial-color; - background-repeat: no-repeat; - background-size: 16px; - border-radius: 8px; - text-align: center; - font-weight: normal; - line-height: $font-16px; - font-size: $font-10-4px; + // avatar psuedo element + &::before { + position: absolute; + left: 2px; + top: 2px; + content: var(--avatar-letter); + width: 16px; + height: 16px; + background: var(--avatar-background), $avatar-bg-color; + color: $avatar-initial-color; + background-repeat: no-repeat; + background-size: 16px; + border-radius: 8px; + text-align: center; + font-weight: normal; + line-height: $font-16px; + font-size: $font-10-4px; + } } } } diff --git a/src/components/views/rooms/BasicMessageComposer.js b/src/components/views/rooms/BasicMessageComposer.js index e3cffd59f8..880bc352de 100644 --- a/src/components/views/rooms/BasicMessageComposer.js +++ b/src/components/views/rooms/BasicMessageComposer.js @@ -84,6 +84,7 @@ export default class BasicMessageEditor extends React.Component { super(props); this.state = { autoComplete: null, + showPillAvatar: SettingsStore.getValue("Pill.shouldShowPillAvatar"), }; this._editorRef = null; this._autocompleteRef = null; @@ -92,6 +93,7 @@ export default class BasicMessageEditor extends React.Component { this._isIMEComposing = false; this._hasTextSelected = false; this._emoticonSettingHandle = null; + this._shouldShowPillAvatarSettingHandle = null; } componentDidUpdate(prevProps) { @@ -508,10 +510,15 @@ export default class BasicMessageEditor extends React.Component { this.setState({completionIndex}); } - _configureEmoticonAutoReplace() { + _configureEmoticonAutoReplace = () => { const shouldReplace = SettingsStore.getValue('MessageComposerInput.autoReplaceEmoji'); this.props.model.setTransformCallback(shouldReplace ? this._replaceEmoticon : null); - } + }; + + _configureShouldShowPillAvatar = () => { + const showPillAvatar = SettingsStore.getValue("Pill.shouldShowPillAvatar"); + this.setState({ showPillAvatar }); + }; componentWillUnmount() { document.removeEventListener("selectionchange", this._onSelectionChange); @@ -519,15 +526,17 @@ export default class BasicMessageEditor extends React.Component { this._editorRef.removeEventListener("compositionstart", this._onCompositionStart, true); this._editorRef.removeEventListener("compositionend", this._onCompositionEnd, true); SettingsStore.unwatchSetting(this._emoticonSettingHandle); + SettingsStore.unwatchSetting(this._shouldShowPillAvatarSettingHandle); } componentDidMount() { const model = this.props.model; model.setUpdateCallback(this._updateEditorState); - this._emoticonSettingHandle = SettingsStore.watchSetting('MessageComposerInput.autoReplaceEmoji', null, () => { - this._configureEmoticonAutoReplace(); - }); + this._emoticonSettingHandle = SettingsStore.watchSetting('MessageComposerInput.autoReplaceEmoji', null, + this._configureEmoticonAutoReplace); this._configureEmoticonAutoReplace(); + this._shouldShowPillAvatarSettingHandle = SettingsStore.watchSetting("Pill.shouldShowPillAvatar", null, + this._configureShouldShowPillAvatar); const partCreator = model.partCreator; // TODO: does this allow us to get rid of EditorStateTransfer? // not really, but we could not serialize the parts, and just change the autoCompleter @@ -605,9 +614,12 @@ export default class BasicMessageEditor extends React.Component { /> ); } - const classes = classNames("mx_BasicMessageComposer", { + const wrapperClasses = classNames("mx_BasicMessageComposer", { "mx_BasicMessageComposer_input_error": this.state.showVisualBell, }); + const classes = classNames("mx_BasicMessageComposer_input", { + "mx_BasicMessageComposer_input_shouldShowPillAvatar": this.state.showPillAvatar, + }); const MessageComposerFormatBar = sdk.getComponent('rooms.MessageComposerFormatBar'); const shortcuts = { @@ -618,11 +630,11 @@ export default class BasicMessageEditor extends React.Component { const {completionIndex} = this.state; - return (
+ return (
{ autoComplete } this._formatBarRef = ref} onAction={this._onFormatAction} shortcuts={shortcuts} />