From a9f7ab785cae4604914b67df70ed2be5e7a3afb7 Mon Sep 17 00:00:00 2001 From: Germain Souquet Date: Thu, 23 Sep 2021 10:59:33 +0100 Subject: [PATCH 1/2] Change CIDER state persistence key to cater for threads Extending the CIDER state persistence to threads and make sure that SendMessageComposer can restore drafts for specific threads This also prevents the thread's replyToEvent to leaking in the room composer --- .../views/rooms/SendMessageComposer.tsx | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/SendMessageComposer.tsx b/src/components/views/rooms/SendMessageComposer.tsx index 05c41f74bf..4138b00bdf 100644 --- a/src/components/views/rooms/SendMessageComposer.tsx +++ b/src/components/views/rooms/SendMessageComposer.tsx @@ -164,6 +164,20 @@ export default class SendMessageComposer extends React.Component { window.addEventListener("beforeunload", this.saveStoredEditorState); } + public componentDidUpdate(prevProps: IProps): void { + const replyToEventChanged = this.props.replyToEvent !== prevProps.replyToEvent; + if (replyToEventChanged) { + this.model.reset([]); + } + + if (this.props.replyInThread && this.props.replyToEvent && (!prevProps.replyToEvent || replyToEventChanged)) { + const partCreator = new CommandPartCreator(this.props.room, this.context); + const parts = this.restoreStoredEditorState(partCreator) || []; + this.model.reset(parts); + this.editorRef.current?.focus(); + } + } + private onKeyDown = (event: KeyboardEvent): void => { // ignore any keypress while doing IME compositions if (this.editorRef.current?.isComposing(event)) { @@ -484,7 +498,12 @@ export default class SendMessageComposer extends React.Component { } private get editorStateKey() { - return `mx_cider_state_${this.props.room.roomId}`; + let key = `mx_cider_state_${this.props.room.roomId}`; + const thread = this.props.replyToEvent?.getThread(); + if (thread) { + key += `_${thread.id}`; + } + return key; } private clearStoredEditorState(): void { @@ -492,6 +511,10 @@ export default class SendMessageComposer extends React.Component { } private restoreStoredEditorState(partCreator: PartCreator): Part[] { + if (this.props.replyInThread && !this.props.replyToEvent) { + return null; + } + const json = localStorage.getItem(this.editorStateKey); if (json) { try { From 836e427dc8fd275c418acac6e142f4726e8c5454 Mon Sep 17 00:00:00 2001 From: Germain Souquet Date: Fri, 24 Sep 2021 11:13:57 +0100 Subject: [PATCH 2/2] Scope editor reset when reply changed for thread view --- src/components/views/rooms/SendMessageComposer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/views/rooms/SendMessageComposer.tsx b/src/components/views/rooms/SendMessageComposer.tsx index 4138b00bdf..cc27ccf153 100644 --- a/src/components/views/rooms/SendMessageComposer.tsx +++ b/src/components/views/rooms/SendMessageComposer.tsx @@ -165,7 +165,7 @@ export default class SendMessageComposer extends React.Component { } public componentDidUpdate(prevProps: IProps): void { - const replyToEventChanged = this.props.replyToEvent !== prevProps.replyToEvent; + const replyToEventChanged = this.props.replyInThread && (this.props.replyToEvent !== prevProps.replyToEvent); if (replyToEventChanged) { this.model.reset([]); }