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

fix: Delete empty dm room on createRoom error #1912

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mErrenst
Copy link
Contributor

@mErrenst mErrenst commented Sep 3, 2024

@mErrenst mErrenst requested a review from a team as a code owner September 3, 2024 20:19
@mErrenst mErrenst force-pushed the malin/delete-empty-dm-room-on-create-room-error branch from 632a54b to c32ab79 Compare September 4, 2024 19:23

return roomId;
return roomId;
} catch (e) {
Copy link
Member

Choose a reason for hiding this comment

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

This is catching any error, not just the room creation error. You should narrowly scope the try catch and handle specific errors, not all of them and assume it is the one error you intended to handle.

Comment on lines +821 to +823
/// The room is empty since createRoom threw an error. To make sure not to
/// delete other empty rooms by accident, the creation time is checked.
/// Should be fixed in Synapse and then be removed
Copy link
Member

Choose a reason for hiding this comment

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

You should really document, why this throws an error, because the synapse code tries to handle all errors ahead of time, so it is not clear, why you are getting an error on room creation. If the problem is invites, we can for example move those out of the room creation.

Comment on lines +824 to +832
final sortedRooms = rooms.sortedBy((room) => room.timeCreated).reversed;
final emptyRoom = sortedRooms.firstWhereOrNull((room) =>
room.name.isEmpty &&
!room.isDirectChat &&
room.summary.mJoinedMemberCount == 1 &&
room.summary.mInvitedMemberCount == 0 &&
room.timeCreated
.isAfter(DateTime.now().subtract(Duration(seconds: 20))));
final roomId = emptyRoom?.id;
Copy link
Member

Choose a reason for hiding this comment

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

it's probably more robust to handle the room id list differences from before and after the room creation instead of going purely by timestamp?

Comment on lines +836 to +837
await leaveRoom(roomId);
await forgetRoom(roomId);
Copy link
Member

Choose a reason for hiding this comment

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

This can throw and needs error handling to not cause weird error messages.

/// The room is empty since createRoom threw an error. To make sure not to
/// delete other empty rooms by accident, the creation time is checked.
/// Should be fixed in Synapse and then be removed
final sortedRooms = rooms.sortedBy((room) => room.timeCreated).reversed;
Copy link
Member

Choose a reason for hiding this comment

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

How do you know, that the room is already synced back to the client?

await forgetRoom(roomId);
}
rethrow;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This code needs tests imo.

@nico-famedly
Copy link
Member

I think I agree with td now, that if this only happens for invites rejected by the invite checker, that we should fix this in Synapse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants