Don't update power levels at startup unless something changes
This commit is contained in:
@@ -189,12 +189,16 @@ class IntentAPI:
|
|||||||
return self.client.create_room(alias, is_public, name, topic, is_direct, invitees,
|
return self.client.create_room(alias, is_public, name, topic, is_direct, invitees,
|
||||||
initial_state or {})
|
initial_state or {})
|
||||||
|
|
||||||
def invite(self, room_id, user_id):
|
def invite(self, room_id, user_id, check_cache):
|
||||||
self.ensure_joined(room_id)
|
self.ensure_joined(room_id)
|
||||||
try:
|
try:
|
||||||
response = self.client.invite_user(room_id, user_id)
|
do_invite = (not check_cache
|
||||||
self.state_store.invited(room_id, user_id)
|
or self.state_store.get_membership(room_id, user_id) not in {"invite",
|
||||||
return response
|
"join"})
|
||||||
|
if do_invite:
|
||||||
|
response = self.client.invite_user(room_id, user_id)
|
||||||
|
self.state_store.invited(room_id, user_id)
|
||||||
|
return response
|
||||||
except MatrixRequestError as e:
|
except MatrixRequestError as e:
|
||||||
if matrix_error_code(e) != "M_FORBIDDEN":
|
if matrix_error_code(e) != "M_FORBIDDEN":
|
||||||
raise IntentError(f"Failed to invite {user_id} to {room_id}", e)
|
raise IntentError(f"Failed to invite {user_id} to {room_id}", e)
|
||||||
|
|||||||
@@ -133,10 +133,10 @@ class Portal:
|
|||||||
|
|
||||||
def invite_matrix(self, users):
|
def invite_matrix(self, users):
|
||||||
if isinstance(users, str):
|
if isinstance(users, str):
|
||||||
self.main_intent.invite(self.mxid, users)
|
self.main_intent.invite(self.mxid, users, check_cache=True)
|
||||||
elif isinstance(users, list):
|
elif isinstance(users, list):
|
||||||
for user in users:
|
for user in users:
|
||||||
self.main_intent.invite(self.mxid, user)
|
self.main_intent.invite(self.mxid, user, check_cache=True)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Invalid invite identifier given to invite_matrix()")
|
raise ValueError("Invalid invite identifier given to invite_matrix()")
|
||||||
|
|
||||||
@@ -770,10 +770,16 @@ class Portal:
|
|||||||
new_level = 50
|
new_level = 50
|
||||||
elif isinstance(participant, (ChatParticipantCreator, ChannelParticipantCreator)):
|
elif isinstance(participant, (ChatParticipantCreator, ChannelParticipantCreator)):
|
||||||
new_level = 95
|
new_level = 95
|
||||||
if user and (user.mxid in levels["users"] or new_level > 0):
|
|
||||||
|
update_user_level = (user and (user.mxid in levels["users"] or new_level > 0)
|
||||||
|
and levels["users"][user.mxid] != new_level)
|
||||||
|
if update_user_level:
|
||||||
levels["users"][user.mxid] = new_level
|
levels["users"][user.mxid] = new_level
|
||||||
changed = True
|
changed = True
|
||||||
if puppet and (puppet.mxid in levels["users"] or new_level > 0):
|
|
||||||
|
update_puppet_level = (puppet and (puppet.mxid in levels["users"] or new_level > 0)
|
||||||
|
and levels["users"][puppet.mxid] != new_level)
|
||||||
|
if update_puppet_level:
|
||||||
levels["users"][puppet.mxid] = new_level
|
levels["users"][puppet.mxid] = new_level
|
||||||
changed = True
|
changed = True
|
||||||
if changed:
|
if changed:
|
||||||
|
|||||||
Reference in New Issue
Block a user