Skip to content
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

Replace MatrixClient.isRoomEncrypted by MatrixClient.CryptoApi.isEncryptionEnabledInRoom in FilePanel #28275

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

florianduros
Copy link
Member

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • I have licensed the changes to Element by completing the Contributor License Agreement (CLA)

Task #26922
Replace MatrixClient.isRoomEncrypted by MatrixClient.CryptoApi.isEncryptionEnabledInRoom in FilePanel.
The new function is async.

@@ -265,7 +270,7 @@ class FilePanel extends React.Component<IProps, IState> {
/>
);

const isRoomEncrypted = this.noRoom ? false : MatrixClientPeg.safeGet().isRoomEncrypted(this.props.roomId);
const isRoomEncrypted = this.noRoom ? false : this.state.isRoomEncrypted;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to have a risk of being racy, would we not need an interstitial loading state while we figure out if the room is encrypted? Otherwise the search warning may flicker in

Comment on lines -134 to 147
if (client === null) return;

if (!client.isRoomEncrypted(this.props.roomId)) return;
if (client === null || !this.state.isRoomEncrypted) return;

if (EventIndexPeg.get() !== null) {
client.removeListener(RoomEvent.Timeline, this.onRoomTimeline);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since componentDidMount is async, I think there's another potential for races here: the component mounts, then if it unmounts before componentDidMount even finishes determining whether the room is encrypted, it will set up event listeners that will never get removed.

@@ -173,7 +181,7 @@ class FilePanel extends React.Component<IProps, IState> {
// the event index to fulfill the pagination request. Asking the server
// to paginate won't ever work since the server can't correctly filter
// out events containing URLs
if (room && client.isRoomEncrypted(roomId) && eventIndex !== null) {
if (room && this.state.isRoomEncrypted && eventIndex !== null) {
return eventIndex.paginateTimelineWindow(room, timelineWindow, direction, limit);
} else {
return timelineWindow.paginate(direction, limit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will anything go wrong if this branch gets executed while this.state.isRoomEncrypted is null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I conditioned the TimelinePanel under the isRoomEncryptedLoaded check. So this case should not happen now

Comment on lines -209 to +217
if (client.isRoomEncrypted(roomId) && eventIndex !== null) {
if (this.state.isRoomEncrypted && eventIndex !== null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same kind of question here… will this method only get called after this.state.isRoomEncrypted is loaded? If not, is that okay?

@florianduros
Copy link
Member Author

florianduros commented Oct 23, 2024

Putting back to draft, I have to add extra tests. Since I have to take time for this component, I will refactor the component into a functional component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Task Tasks for the team like planning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants