Skip to content

Commit

Permalink
TW-2018 Changed powerlevels in group chats
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledNjim authored and hoangdat committed Nov 6, 2024
1 parent f8d3a83 commit e9ed8fb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/pages/new_group/new_group_chat_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ class NewGroupChatInfoController extends State<NewGroupChatInfo>
urlAvatar: urlAvatar,
powerLevelContentOverride: {
'events': powerLevelManager.getDefaultPowerLevelEventForMember(),
'invite': powerLevelManager.getAdminPowerLevel(),
'kick': powerLevelManager.getAdminPowerLevel(),
},
),
);
Expand Down
8 changes: 5 additions & 3 deletions lib/utils/power_level_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class PowerLevelManager {
return DefaultPowerLevelMember.user.powerLevel;
}

int getAdminPowerLevel() => DefaultPowerLevelMember.admin.powerLevel;

Map<String, dynamic> getDefaultPowerLevelEventForMember() {
return {
EventTypes.RoomPinnedEvents: getUserPowerLevel(),
EventTypes.RoomName: getUserPowerLevel(),
EventTypes.RoomAvatar: getUserPowerLevel(),
EventTypes.RoomName: getAdminPowerLevel(),
EventTypes.RoomAvatar: getAdminPowerLevel(),
EventTypes.RoomMember: getUserPowerLevel(),
EventTypes.RoomTopic: getUserPowerLevel(),
EventTypes.RoomTopic: getAdminPowerLevel(),
};
}
}
40 changes: 40 additions & 0 deletions test/utils/power_level_manager_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:fluffychat/utils/power_level_manager.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fluffychat/config/default_power_level_member.dart';
import 'package:matrix/matrix.dart';

void main() {
group('PowerLevelManager', () {
late PowerLevelManager powerLevelManager;

setUp(() {
powerLevelManager = PowerLevelManager();
});

test('should return correct power levels for each event type', () {
final userPowerLevel = DefaultPowerLevelMember.user.powerLevel;
final adminPowerLevel = DefaultPowerLevelMember.admin.powerLevel;
final result = powerLevelManager.getDefaultPowerLevelEventForMember();

expect(result[EventTypes.RoomPinnedEvents], equals(userPowerLevel));
expect(result[EventTypes.RoomName], equals(adminPowerLevel));
expect(result[EventTypes.RoomAvatar], equals(adminPowerLevel));
expect(result[EventTypes.RoomMember], equals(userPowerLevel));
expect(result[EventTypes.RoomTopic], equals(adminPowerLevel));
});

test('should contain all expected event types', () {
final result = powerLevelManager.getDefaultPowerLevelEventForMember();
expect(
result.keys,
containsAll([
EventTypes.RoomPinnedEvents,
EventTypes.RoomName,
EventTypes.RoomAvatar,
EventTypes.RoomMember,
EventTypes.RoomTopic,
]),
);
});
});
}

0 comments on commit e9ed8fb

Please sign in to comment.