Skip to content

Commit

Permalink
Replace MatrixClient.isRoomEncrypted by `MatrixClient.CryptoApi.isE…
Browse files Browse the repository at this point in the history
…ncryptionEnabledInRoom` in `SendMessageComposer.tsx`
  • Loading branch information
florianduros committed Nov 14, 2024
1 parent d7ef409 commit 6bf06da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/components/views/rooms/SendMessageComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
public static contextType = RoomContext;
public declare context: React.ContextType<typeof RoomContext>;

private readonly prepareToEncrypt?: DebouncedFunc<() => void>;
private prepareToEncrypt?: DebouncedFunc<() => void>;
private readonly editorRef = createRef<BasicMessageComposer>();
private model: EditorModel;
private currentlyComposedEditorState: SerializedPart[] | null = null;
Expand All @@ -253,25 +253,25 @@ export class SendMessageComposer extends React.Component<ISendMessageComposerPro
public constructor(props: ISendMessageComposerProps, context: React.ContextType<typeof RoomContext>) {
super(props, context);

if (this.props.mxClient.getCrypto() && this.props.mxClient.isRoomEncrypted(this.props.room.roomId)) {
this.prepareToEncrypt = throttle(
() => {
this.props.mxClient.getCrypto()?.prepareToEncrypt(this.props.room);
},
60000,
{ 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 {
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.props.mxClient.getCrypto()?.prepareToEncrypt(this.props.room);
},
60000,
{ leading: true, trailing: false },
);
}
}

public componentDidUpdate(prevProps: ISendMessageComposerProps): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ describe("<SendMessageComposer/>", () => {

it("should call prepareToEncrypt when the user is typing", async () => {
const cli = stubClient();
cli.isRoomEncrypted = jest.fn().mockReturnValue(true);
jest.spyOn(cli.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(true);
const room = mkStubRoom("!roomId:server", "Room", cli);

expect(cli.getCrypto()!.prepareToEncrypt).not.toHaveBeenCalled();
Expand Down

0 comments on commit 6bf06da

Please sign in to comment.