diff --git a/matrix_alertbot/matrix.py b/matrix_alertbot/matrix.py index 0580749..8112201 100644 --- a/matrix_alertbot/matrix.py +++ b/matrix_alertbot/matrix.py @@ -236,7 +236,7 @@ class MatrixClientPool: ) -> None: async with self._lock: if matrix_client is self.matrix_client: - unactive_accounts = self.unactive_user_ids() + unactive_user_ids = self.unactive_user_ids() self.dm_rooms = await self.find_existing_dm_rooms( account=account, matrix_client=matrix_client, config=config @@ -262,13 +262,16 @@ class MatrixClientPool: logger.info( f"Bot {account.id} | Creating direct room with user {user_id}" ) - invitations = unactive_accounts + [user_id] + invitations = unactive_user_ids + [user_id] + room_user_ids = invitations + [account.id] + power_levels = {"users": dict.fromkeys(room_user_ids, 100)} create_room_response = await matrix_client.room_create( visibility=RoomVisibility.private, name=room_title, invite=invitations, is_direct=True, preset=RoomPreset.private_chat, + power_level_override=power_levels, ) if isinstance(create_room_response, RoomCreateError): error = create_room_response.message diff --git a/tests/test_matrix.py b/tests/test_matrix.py index d57135e..e23c8fa 100644 --- a/tests/test_matrix.py +++ b/tests/test_matrix.py @@ -476,6 +476,13 @@ class MatrixClientPoolTestCase(unittest.IsolatedAsyncioTestCase): invite=["@other_user:chat.example.com", "@fake_dm_user:example.com"], is_direct=True, preset=RoomPreset.private_chat, + power_level_override={ + "users": { + "@fake_user:matrix.example.com": 100, + "@other_user:chat.example.com": 100, + "@fake_dm_user:example.com": 100, + } + }, ) self.assertDictEqual( { @@ -528,6 +535,13 @@ class MatrixClientPoolTestCase(unittest.IsolatedAsyncioTestCase): invite=["@other_user:chat.example.com", "@fake_dm_user:example.com"], is_direct=True, preset=RoomPreset.private_chat, + power_level_override={ + "users": { + "@fake_user:matrix.example.com": 100, + "@other_user:chat.example.com": 100, + "@fake_dm_user:example.com": 100, + } + }, ) self.assertDictEqual( { @@ -581,6 +595,13 @@ class MatrixClientPoolTestCase(unittest.IsolatedAsyncioTestCase): invite=["@other_user:chat.example.com", "@fake_dm_user:example.com"], is_direct=True, preset=RoomPreset.private_chat, + power_level_override={ + "users": { + "@fake_user:matrix.example.com": 100, + "@other_user:chat.example.com": 100, + "@fake_dm_user:example.com": 100, + } + }, ) self.assertDictEqual( { @@ -631,6 +652,13 @@ class MatrixClientPoolTestCase(unittest.IsolatedAsyncioTestCase): invite=["@other_user:chat.example.com", "@fake_dm_user:example.com"], is_direct=True, preset=RoomPreset.private_chat, + power_level_override={ + "users": { + "@fake_user:matrix.example.com": 100, + "@other_user:chat.example.com": 100, + "@fake_dm_user:example.com": 100, + } + }, ) self.assertDictEqual( {