-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Second batch: Replace MatrixClient.isRoomEncrypted
by MatrixClient.CryptoApi.isEncryptionEnabledInRoom
#28466
base: develop
Are you sure you want to change the base?
Changes from all commits
6533a6b
f8c5eac
d7ef409
6bf06da
de765bb
a0d0fa7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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 }, | ||
); | ||
} | ||
Comment on lines
+266
to
+274
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if |
||
} | ||
|
||
public componentDidUpdate(prevProps: ISendMessageComposerProps): void { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,12 +127,27 @@ interface IProps { | |
room: Room; | ||
} | ||
|
||
export default class RolesRoomSettingsTab extends React.Component<IProps> { | ||
interface RolesRoomSettingsTabState { | ||
isRoomEncrypted: boolean; | ||
} | ||
|
||
export default class RolesRoomSettingsTab extends React.Component<IProps, RolesRoomSettingsTabState> { | ||
public static contextType = MatrixClientContext; | ||
public declare context: React.ContextType<typeof MatrixClientContext>; | ||
|
||
public componentDidMount(): void { | ||
public constructor(props: IProps) { | ||
super(props); | ||
this.state = { | ||
isRoomEncrypted: false, | ||
}; | ||
} | ||
|
||
public async componentDidMount(): Promise<void> { | ||
this.context.on(RoomStateEvent.Update, this.onRoomStateUpdate); | ||
this.setState({ | ||
isRoomEncrypted: | ||
(await this.context.getCrypto()?.isEncryptionEnabledInRoom(this.props.room.roomId)) || false, | ||
}); | ||
} | ||
|
||
public componentWillUnmount(): void { | ||
|
@@ -416,7 +431,7 @@ export default class RolesRoomSettingsTab extends React.Component<IProps> { | |
.filter(Boolean); | ||
|
||
// hide the power level selector for enabling E2EE if it the room is already encrypted | ||
if (client.isRoomEncrypted(this.props.room.roomId)) { | ||
if (this.state.isRoomEncrypted) { | ||
delete eventsLevels[EventType.RoomEncryption]; | ||
} | ||
Comment on lines
433
to
436
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it'll cause a UI flicker, where a row disappears after all rooms are checked, this is undesirable, we should not show UI until we are sure it is relevant. |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ export class MemberListStore { | |
return []; | ||
} | ||
|
||
if (!this.isLazyLoadingEnabled(roomId) || this.loadedRooms.has(roomId)) { | ||
if (!(await this.isLazyLoadingEnabled(roomId)) || this.loadedRooms.has(roomId)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we reverse this if condition so that the synchronous path is not blocked behind the async one? |
||
// nice and easy, we must already have all the members so just return them. | ||
return this.loadMembersInRoom(room); | ||
} | ||
|
@@ -121,10 +121,10 @@ export class MemberListStore { | |
* @param roomId The room to check if lazy loading is enabled | ||
* @returns True if enabled | ||
*/ | ||
private isLazyLoadingEnabled(roomId: string): boolean { | ||
private async isLazyLoadingEnabled(roomId: string): Promise<boolean> { | ||
if (SettingsStore.getValue("feature_sliding_sync")) { | ||
// only unencrypted rooms use lazy loading | ||
return !this.stores.client!.isRoomEncrypted(roomId); | ||
return !(await this.stores.client?.getCrypto()?.isEncryptionEnabledInRoom(roomId)); | ||
} | ||
return this.stores.client!.hasLazyLoadMembersEnabled(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,6 +328,16 @@ export async function asyncSome<T>(values: Iterable<T>, predicate: (value: T) => | |
return false; | ||
} | ||
|
||
/** | ||
* Async version of Array.filter. | ||
* @param values | ||
* @param predicate | ||
Comment on lines
+332
to
+334
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doc could do with clarification on what happens when a rejection occurs |
||
*/ | ||
export async function asyncFilter<T>(values: Array<T>, predicate: (value: T) => Promise<boolean>): Promise<Array<T>> { | ||
const results = await Promise.all(values.map(predicate)); | ||
return values.filter((_, i) => results[i]); | ||
} | ||
|
||
export function filterBoolean<T>(values: Array<T | null | undefined>): T[] { | ||
return values.filter(Boolean) as T[]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure this method can be async? It could make events be handled out-of-order unless we add something to serialise the data flow