From e9ed8fb911cc236c5c47f4ae0ee40222b85bbc10 Mon Sep 17 00:00:00 2001 From: "khaled.njim" Date: Thu, 31 Oct 2024 22:51:48 +0100 Subject: [PATCH] TW-2018 Changed powerlevels in group chats --- lib/pages/new_group/new_group_chat_info.dart | 2 + lib/utils/power_level_manager.dart | 8 ++-- test/utils/power_level_manager_test.dart | 40 ++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 test/utils/power_level_manager_test.dart diff --git a/lib/pages/new_group/new_group_chat_info.dart b/lib/pages/new_group/new_group_chat_info.dart index 375ef50edc..714fcb587b 100644 --- a/lib/pages/new_group/new_group_chat_info.dart +++ b/lib/pages/new_group/new_group_chat_info.dart @@ -106,6 +106,8 @@ class NewGroupChatInfoController extends State urlAvatar: urlAvatar, powerLevelContentOverride: { 'events': powerLevelManager.getDefaultPowerLevelEventForMember(), + 'invite': powerLevelManager.getAdminPowerLevel(), + 'kick': powerLevelManager.getAdminPowerLevel(), }, ), ); diff --git a/lib/utils/power_level_manager.dart b/lib/utils/power_level_manager.dart index 06de1e830d..cae3972ef1 100644 --- a/lib/utils/power_level_manager.dart +++ b/lib/utils/power_level_manager.dart @@ -14,13 +14,15 @@ class PowerLevelManager { return DefaultPowerLevelMember.user.powerLevel; } + int getAdminPowerLevel() => DefaultPowerLevelMember.admin.powerLevel; + Map 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(), }; } } diff --git a/test/utils/power_level_manager_test.dart b/test/utils/power_level_manager_test.dart new file mode 100644 index 0000000000..8bef90297c --- /dev/null +++ b/test/utils/power_level_manager_test.dart @@ -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, + ]), + ); + }); + }); +}