Copy PL state events with evolve

This commit is contained in:
Andrew Ferrazzutti 2022-04-28 22:28:39 -04:00
parent 780dbed7c2
commit b7df79e65d
1 changed files with 3 additions and 3 deletions

View File

@ -33,7 +33,7 @@ import asyncio
import re
import time
from attr import dataclass
from attr import dataclass, evolve
from mautrix.appservice import IntentAPI
from mautrix.bridge import BasePortal, NotificationDisabler, async_getter_lock
@ -420,7 +420,7 @@ class Portal(DBPortal, BasePortal):
sender_intent = sender.intent_for(self) if sender else self.main_intent
admin_level = orig_power_levels.get_user_level(sender_intent.mxid)
demoter_ids: list[UserID] = []
power_levels = PowerLevelStateEventContent(**orig_power_levels.serialize())
power_levels = evolve(orig_power_levels)
for user_id, new_level in user_power_levels.items():
curr_level = orig_power_levels.get_user_level(user_id)
if curr_level < admin_level or user_id == sender_intent.mxid:
@ -436,7 +436,7 @@ class Portal(DBPortal, BasePortal):
except:
self.log.exception("Failed to set power level")
if demoter_ids:
power_levels = PowerLevelStateEventContent(**orig_power_levels.serialize())
power_levels = evolve(orig_power_levels)
for demoter_id in demoter_ids:
power_levels.set_user_level(demoter_id, user_power_levels[demoter_id])
try: