mirror of
https://github.com/element-hq/element-web
synced 2024-11-25 10:45:51 +03:00
Replace MatrixClient.isRoomEncrypted
by MatrixClient.CryptoApi.isEncryptionEnabledInRoom
in SendMessageComposer.tsx
This commit is contained in:
parent
d7ef409df8
commit
6bf06da02c
2 changed files with 13 additions and 13 deletions
|
@ -243,7 +243,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
||||||
public static contextType = RoomContext;
|
public static contextType = RoomContext;
|
||||||
public declare context: React.ContextType<typeof RoomContext>;
|
public declare context: React.ContextType<typeof RoomContext>;
|
||||||
|
|
||||||
private readonly prepareToEncrypt?: DebouncedFunc<() => void>;
|
private prepareToEncrypt?: DebouncedFunc<() => void>;
|
||||||
private readonly editorRef = createRef<BasicMessageComposer>();
|
private readonly editorRef = createRef<BasicMessageComposer>();
|
||||||
private model: EditorModel;
|
private model: EditorModel;
|
||||||
private currentlyComposedEditorState: SerializedPart[] | null = null;
|
private currentlyComposedEditorState: SerializedPart[] | null = null;
|
||||||
|
@ -253,7 +253,17 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
||||||
public constructor(props: ISendMessageComposerProps, context: React.ContextType<typeof RoomContext>) {
|
public constructor(props: ISendMessageComposerProps, context: React.ContextType<typeof RoomContext>) {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
|
|
||||||
if (this.props.mxClient.getCrypto() && this.props.mxClient.isRoomEncrypted(this.props.room.roomId)) {
|
const partCreator = new CommandPartCreator(this.props.room, this.props.mxClient);
|
||||||
|
const parts = this.restoreStoredEditorState(partCreator) || [];
|
||||||
|
this.model = new EditorModel(parts, partCreator);
|
||||||
|
this.sendHistoryManager = new SendHistoryManager(this.props.room.roomId, "mx_cider_history_");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async componentDidMount(): Promise<void> {
|
||||||
|
window.addEventListener("beforeunload", this.saveStoredEditorState);
|
||||||
|
this.dispatcherRef = dis.register(this.onAction);
|
||||||
|
|
||||||
|
if (await this.props.mxClient.getCrypto()?.isEncryptionEnabledInRoom(this.props.room.roomId)) {
|
||||||
this.prepareToEncrypt = throttle(
|
this.prepareToEncrypt = throttle(
|
||||||
() => {
|
() => {
|
||||||
this.props.mxClient.getCrypto()?.prepareToEncrypt(this.props.room);
|
this.props.mxClient.getCrypto()?.prepareToEncrypt(this.props.room);
|
||||||
|
@ -262,16 +272,6 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
|
||||||
{ leading: true, trailing: false },
|
{ leading: true, trailing: false },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const partCreator = new CommandPartCreator(this.props.room, this.props.mxClient);
|
|
||||||
const parts = this.restoreStoredEditorState(partCreator) || [];
|
|
||||||
this.model = new EditorModel(parts, partCreator);
|
|
||||||
this.sendHistoryManager = new SendHistoryManager(this.props.room.roomId, "mx_cider_history_");
|
|
||||||
}
|
|
||||||
|
|
||||||
public componentDidMount(): void {
|
|
||||||
window.addEventListener("beforeunload", this.saveStoredEditorState);
|
|
||||||
this.dispatcherRef = dis.register(this.onAction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidUpdate(prevProps: ISendMessageComposerProps): void {
|
public componentDidUpdate(prevProps: ISendMessageComposerProps): void {
|
||||||
|
|
|
@ -605,7 +605,7 @@ describe("<SendMessageComposer/>", () => {
|
||||||
|
|
||||||
it("should call prepareToEncrypt when the user is typing", async () => {
|
it("should call prepareToEncrypt when the user is typing", async () => {
|
||||||
const cli = stubClient();
|
const cli = stubClient();
|
||||||
cli.isRoomEncrypted = jest.fn().mockReturnValue(true);
|
jest.spyOn(cli.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(true);
|
||||||
const room = mkStubRoom("!roomId:server", "Room", cli);
|
const room = mkStubRoom("!roomId:server", "Room", cli);
|
||||||
|
|
||||||
expect(cli.getCrypto()!.prepareToEncrypt).not.toHaveBeenCalled();
|
expect(cli.getCrypto()!.prepareToEncrypt).not.toHaveBeenCalled();
|
||||||
|
|
Loading…
Reference in a new issue