From e06550b74877330ef31ebf74a65f9b0080e63a93 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 28 Oct 2020 12:47:59 +0000 Subject: [PATCH] Watch replyToEvent at RoomView to prevent races --- src/components/structures/RoomView.tsx | 3 +++ src/components/views/rooms/MessageComposer.js | 17 ++--------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/components/structures/RoomView.tsx b/src/components/structures/RoomView.tsx index 4b2fa67c1c..32834469c3 100644 --- a/src/components/structures/RoomView.tsx +++ b/src/components/structures/RoomView.tsx @@ -129,6 +129,7 @@ export interface IState { initialEventPixelOffset?: number; // Whether to highlight the event scrolled to isInitialEventHighlighted?: boolean; + replyToEvent?: MatrixEvent; forwardingEvent?: MatrixEvent; numUnreadMessages: number; draggingFile: boolean; @@ -315,6 +316,7 @@ export default class RoomView extends React.Component { joining: RoomViewStore.isJoining(), initialEventId: RoomViewStore.getInitialEventId(), isInitialEventHighlighted: RoomViewStore.isInitialEventHighlighted(), + replyToEvent: RoomViewStore.getQuotingEvent(), forwardingEvent: RoomViewStore.getForwardingEvent(), // we should only peek once we have a ready client shouldPeek: this.state.matrixClientIsReady && RoomViewStore.shouldPeek(), @@ -1899,6 +1901,7 @@ export default class RoomView extends React.Component { showApps={this.state.showApps} e2eStatus={this.state.e2eStatus} resizeNotifier={this.props.resizeNotifier} + replyToEvent={this.state.replyToEvent} permalinkCreator={this.getPermalinkCreatorForRoom(this.state.room)} />; } diff --git a/src/components/views/rooms/MessageComposer.js b/src/components/views/rooms/MessageComposer.js index 40eaf77272..c260389eab 100644 --- a/src/components/views/rooms/MessageComposer.js +++ b/src/components/views/rooms/MessageComposer.js @@ -23,7 +23,6 @@ import CallHandler from '../../../CallHandler'; import {MatrixClientPeg} from '../../../MatrixClientPeg'; import * as sdk from '../../../index'; import dis from '../../../dispatcher/dispatcher'; -import RoomViewStore from '../../../stores/RoomViewStore'; import Stickerpicker from './Stickerpicker'; import { makeRoomPermalink } from '../../../utils/permalinks/Permalinks'; import ContentMessages from '../../../ContentMessages'; @@ -254,7 +253,6 @@ export default class MessageComposer extends React.Component { super(props); this.onInputStateChanged = this.onInputStateChanged.bind(this); this._onRoomStateEvents = this._onRoomStateEvents.bind(this); - this._onRoomViewStoreUpdate = this._onRoomViewStoreUpdate.bind(this); this._onTombstoneClick = this._onTombstoneClick.bind(this); this.renderPlaceholderText = this.renderPlaceholderText.bind(this); WidgetStore.instance.on(UPDATE_EVENT, this._onWidgetUpdate); @@ -262,7 +260,6 @@ export default class MessageComposer extends React.Component { this._dispatcherRef = null; this.state = { - replyToEvent: RoomViewStore.getQuotingEvent(), tombstone: this._getRoomTombstone(), canSendMessages: this.props.room.maySendMessage(), showCallButtons: SettingsStore.getValue("showCallButtonsInComposer"), @@ -294,7 +291,6 @@ export default class MessageComposer extends React.Component { componentDidMount() { this.dispatcherRef = dis.register(this.onAction); MatrixClientPeg.get().on("RoomState.events", this._onRoomStateEvents); - this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate); this._waitForOwnMember(); } @@ -318,9 +314,6 @@ export default class MessageComposer extends React.Component { if (MatrixClientPeg.get()) { MatrixClientPeg.get().removeListener("RoomState.events", this._onRoomStateEvents); } - if (this._roomStoreToken) { - this._roomStoreToken.remove(); - } WidgetStore.instance.removeListener(UPDATE_EVENT, this._onWidgetUpdate); ActiveWidgetStore.removeListener('update', this._onActiveWidgetUpdate); dis.unregister(this.dispatcherRef); @@ -341,12 +334,6 @@ export default class MessageComposer extends React.Component { return this.props.room.currentState.getStateEvents('m.room.tombstone', ''); } - _onRoomViewStoreUpdate() { - const replyToEvent = RoomViewStore.getQuotingEvent(); - if (this.state.replyToEvent === replyToEvent) return; - this.setState({ replyToEvent }); - } - onInputStateChanged(inputState) { // Merge the new input state with old to support partial updates inputState = Object.assign({}, this.state.inputState, inputState); @@ -383,7 +370,7 @@ export default class MessageComposer extends React.Component { } renderPlaceholderText() { - if (this.state.replyToEvent) { + if (this.props.replyToEvent) { if (this.props.e2eStatus) { return _t('Send an encrypted reply…'); } else { @@ -429,7 +416,7 @@ export default class MessageComposer extends React.Component { placeholder={this.renderPlaceholderText()} resizeNotifier={this.props.resizeNotifier} permalinkCreator={this.props.permalinkCreator} - replyToEvent={this.state.replyToEvent} + replyToEvent={this.props.replyToEvent} />, , ,