Add buttons to Save/cancel power level changes

This commit is contained in:
miruka
2020-07-12 18:48:34 -04:00
parent 1adfa9f4a2
commit 6ff3cc5f39
4 changed files with 97 additions and 15 deletions

View File

@@ -191,6 +191,9 @@ class MatrixClient(nio.AsyncClient):
self.loaded_once_rooms: Set[str] = set() # {room_id}
self.cleared_events_rooms: Set[str] = set() # {room_id}
# {room_id: <m.room.power_levels event content dict>}
self.power_levels_content: Dict[str, Dict[str, Any]] = {}
self.nio_callbacks = NioCallbacks(self)
@@ -1120,6 +1123,20 @@ class MatrixClient(nio.AsyncClient):
])
async def room_set_member_power(
self, room_id: str, user_id: str, level: int,
) -> None:
"""Set a room member's power level."""
while room_id not in self.power_levels_content:
await asyncio.sleep(0.2)
content = deepcopy(self.power_levels_content[room_id])
content.setdefault("users", {})[user_id] = level
await self.room_put_state(room_id, "m.room.power_levels", content)
async def room_typing(
self, room_id: str, typing_state: bool = True, timeout: int = 5000,
):