mirror of
https://github.com/element-hq/element-web
synced 2024-11-27 19:56:47 +03:00
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
This commit is contained in:
parent
2cd5b731bf
commit
a9f7ab785c
1 changed files with 24 additions and 1 deletions
|
@ -164,6 +164,20 @@ export default class SendMessageComposer extends React.Component<IProps> {
|
|||
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<IProps> {
|
|||
}
|
||||
|
||||
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<IProps> {
|
|||
}
|
||||
|
||||
private restoreStoredEditorState(partCreator: PartCreator): Part[] {
|
||||
if (this.props.replyInThread && !this.props.replyToEvent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const json = localStorage.getItem(this.editorStateKey);
|
||||
if (json) {
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue