From 52c4d7b6b09ea433f54cea2f1ca5875e992cf14d Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 15 May 2019 15:53:02 +0100 Subject: [PATCH 1/5] fixup edit icon --- res/img/edit.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/img/edit.svg b/res/img/edit.svg index 95bd44f606..9674b31690 100644 --- a/res/img/edit.svg +++ b/res/img/edit.svg @@ -1 +1 @@ - \ No newline at end of file + From b081a3156f86d2f3b952edaa1ddcb16f00c5cde5 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 15 May 2019 15:53:49 +0100 Subject: [PATCH 2/5] dont show edit button for messages that are not your own --- src/components/views/messages/MessageActionBar.js | 14 +++++++------- src/utils/EventUtils.js | 6 ++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/views/messages/MessageActionBar.js b/src/components/views/messages/MessageActionBar.js index fe6c22ab1e..84474710cd 100644 --- a/src/components/views/messages/MessageActionBar.js +++ b/src/components/views/messages/MessageActionBar.js @@ -23,7 +23,7 @@ import dis from '../../../dispatcher'; import Modal from '../../../Modal'; import { createMenu } from '../../structures/ContextualMenu'; import SettingsStore from '../../../settings/SettingsStore'; -import { isContentActionable } from '../../../utils/EventUtils'; +import { isContentActionable, canEditContent } from '../../../utils/EventUtils'; export default class MessageActionBar extends React.PureComponent { static propTypes = { @@ -148,12 +148,12 @@ export default class MessageActionBar extends React.PureComponent { title={_t("Reply")} onClick={this.onReplyClick} />; - if (this.isEditingEnabled()) { - editButton = ; - } + } + if (this.isEditingEnabled() && canEditContent(this.props.mxEvent)) { + editButton = ; } return
diff --git a/src/utils/EventUtils.js b/src/utils/EventUtils.js index 911257f95c..ac415ca6de 100644 --- a/src/utils/EventUtils.js +++ b/src/utils/EventUtils.js @@ -15,6 +15,7 @@ limitations under the License. */ import { EventStatus } from 'matrix-js-sdk'; +import MatrixClientPeg from '../MatrixClientPeg'; /** * Returns whether an event should allow actions like reply, reactions, edit, etc. @@ -43,3 +44,8 @@ export function isContentActionable(mxEvent) { return false; } + +export function canEditContent(mxEvent) { + return isContentActionable(mxEvent) && + mxEvent.getSender() === MatrixClientPeg.get().getUserId(); +} From 6366371c0db064860024aff6cfa2e1e229de9d0b Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 15 May 2019 15:54:05 +0100 Subject: [PATCH 3/5] add * to fallback messages for edits --- src/components/views/elements/MessageEditor.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/views/elements/MessageEditor.js b/src/components/views/elements/MessageEditor.js index a2005feace..20d6dc6f66 100644 --- a/src/components/views/elements/MessageEditor.js +++ b/src/components/views/elements/MessageEditor.js @@ -110,9 +110,15 @@ export default class MessageEditor extends React.Component { "msgtype": "m.text", "body": textSerialize(this.model), }; + const contentBody = { + msgtype: newContent.msgtype, + body: ` * ${newContent.body}`, + }; if (requiresHtml(this.model)) { newContent.format = "org.matrix.custom.html"; newContent.formatted_body = htmlSerialize(this.model); + contentBody.format = newContent.format; + contentBody.formatted_body = ` * ${newContent.formatted_body}`; } const content = Object.assign({ "m.new_content": newContent, @@ -120,7 +126,7 @@ export default class MessageEditor extends React.Component { "rel_type": "m.replace", "event_id": this.props.event.getId(), }, - }, newContent); + }, contentBody); const roomId = this.props.event.getRoomId(); this.context.matrixClient.sendMessage(roomId, content); From d73f547f556d98013d76fefcc95069f321015e4c Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 15 May 2019 15:55:03 +0100 Subject: [PATCH 4/5] reapply pills, link preview, code highlighting, ... after edit --- src/components/views/messages/TextualBody.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/views/messages/TextualBody.js b/src/components/views/messages/TextualBody.js index deb3c5cc0f..34769c060f 100644 --- a/src/components/views/messages/TextualBody.js +++ b/src/components/views/messages/TextualBody.js @@ -88,7 +88,10 @@ module.exports = React.createClass({ componentDidMount: function() { this._unmounted = false; + this._applyFormatting(); + }, + _applyFormatting() { // pillifyLinks BEFORE linkifyElement because plain room/user URLs in the composer // are still sent as plaintext URLs. If these are ever pillified in the composer, // we should be pillify them here by doing the linkifying BEFORE the pillifying. @@ -123,7 +126,11 @@ module.exports = React.createClass({ } }, - componentDidUpdate: function() { + componentDidUpdate: function(prevProps) { + const messageWasEdited = prevProps.replacingEventId !== this.props.replacingEventId; + if (messageWasEdited) { + this._applyFormatting(); + } this.calculateUrlPreview(); }, From 085f2d199de8468ae363428872d0a34101f695f0 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 15 May 2019 17:17:35 +0100 Subject: [PATCH 5/5] focus editor after clicking edit --- src/components/views/elements/MessageEditor.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/views/elements/MessageEditor.js b/src/components/views/elements/MessageEditor.js index 20d6dc6f66..b42923954b 100644 --- a/src/components/views/elements/MessageEditor.js +++ b/src/components/views/elements/MessageEditor.js @@ -144,6 +144,13 @@ export default class MessageEditor extends React.Component { componentDidMount() { this._updateEditorState(); + const sel = document.getSelection(); + const range = document.createRange(); + range.selectNodeContents(this._editorRef); + range.collapse(false); + sel.removeAllRanges(); + sel.addRange(range); + this._editorRef.focus(); } render() {