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: Change power level without changing memory #1929

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

Conversation

krille-chan
Copy link
Contributor

The problem here is that we
have not created a deep copy
of the power level map. By using .copy() we create a
deep copy now.

Closes https://github.com/famedly/product-management/issues/2412

@krille-chan krille-chan requested a review from a team as a code owner October 4, 2024 11:42
lib/src/room.dart Outdated Show resolved Hide resolved
The problem here is that we
have not created a deep copy
of the power level map. By using .copy() we create a
deep copy now.
Copy link
Member

@td-famedly td-famedly left a comment

Choose a reason for hiding this comment

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

lg

Copy link
Member

@nico-famedly nico-famedly left a comment

Choose a reason for hiding this comment

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

Strictly speaking I guess there could be an edge case if the users map is set to a list, where we won't set the permissions ever now. I think those rooms probably fail to federate and so this is fine and we don't need to care about it :D

: (powerMap['users'] = <String, Object?>{});
Future<String> setPower(String userId, int power) async {
final powerLevelMapCopy =
getState(EventTypes.RoomPowerLevels)?.content.copy() ?? {};
Copy link
Member

Choose a reason for hiding this comment

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

Can you also apply this fix to enableGroupCalls() (and possibly a few others)?


usersPowerMap[userID] = power;
powerLevelMapCopy['users'] ??= <String, Object?>{};
powerLevelMapCopy.tryGetMap<String, Object?>('users')?[userId] = power;
Copy link
Member

Choose a reason for hiding this comment

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

This operates on a copy of powerLevelMapCopy, so this actually never modifies the power levels of that user! That's probably also why the tests hang, but for me at least the command test with the op command explicitly fails. Maybe we can add a proper test for this?


usersPowerMap[userID] = power;
powerLevelMapCopy['users'] ??= <String, Object?>{};
powerLevelMapCopy.tryGetMap<String, Object?>('users')?[userId] = power;

return await client.setRoomStateWithKey(
Copy link
Member

Choose a reason for hiding this comment

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

this actually now means that the changes will only be reflected in the state event later. I would bet there is some code that depends on this function having immediately reflected the changes. Should we consider this a breaking change or maybe wait for the event to come down in sync? Maybe we can just ignore that, but I think it makes sense to consider the impact of that. For example the following code would now only set the permissions for one of the users:

await room.setPower('@a:example.org', 10);
await room.setPower('@b:example.org', 10);

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.

3 participants