Fix composer localStorage key for draft event in a thread (#7526)

This commit is contained in:
Germain 2022-01-12 17:13:47 +00:00 committed by GitHub
parent 9ca429d15c
commit 61116377f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 13 deletions

View file

@ -451,9 +451,8 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
private get editorStateKey() {
let key = `mx_cider_state_${this.props.room.roomId}`;
const thread = this.props.replyToEvent?.getThread();
if (thread) {
key += `_${thread.id}`;
if (this.props.relation?.rel_type === RelationType.Thread) {
key += `_${this.props.relation.event_id}`;
}
return key;
}

View file

@ -19,6 +19,7 @@ import React from "react";
import { act } from "react-dom/test-utils";
import { sleep } from "matrix-js-sdk/src/utils";
import { mount } from 'enzyme';
import { RelationType } from 'matrix-js-sdk/src/@types/event';
import SendMessageComposer, {
createMessageContent,
@ -290,13 +291,6 @@ describe('<SendMessageComposer/>', () => {
});
it('correctly sets the editorStateKey for threads', () => {
const mockThread ={
getThread: () => {
return {
id: 'myFakeThreadId',
};
},
} as any;
const wrapper = mount(<MatrixClientContext.Provider value={mockClient}>
<RoomContext.Provider value={roomContext}>
@ -304,14 +298,15 @@ describe('<SendMessageComposer/>', () => {
room={mockRoom as any}
placeholder=""
permalinkCreator={new SpecPermalinkConstructor() as any}
replyToEvent={mockThread}
relation={{
rel_type: RelationType.Thread,
event_id: "myFakeThreadId",
}}
/>
</RoomContext.Provider>
</MatrixClientContext.Provider>);
const instance = wrapper.find(SendMessageComposerClass).instance();
const key = instance.editorStateKey;
expect(key).toEqual('mx_cider_state_myfakeroom_myFakeThreadId');
});
});