-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: main
Are you sure you want to change the base?
Conversation
c3e282a
to
7014278
Compare
7014278
to
1fd31c2
Compare
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.
1fd31c2
to
3de1c17
Compare
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.
lg
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.
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() ?? {}; |
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.
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; |
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.
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( |
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.
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);
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