Skip to content

Commit

Permalink
Use existing power levels as base for user levels instead of hardcode…
Browse files Browse the repository at this point in the history
…d values
  • Loading branch information
tulir committed Oct 19, 2021
1 parent 74c4335 commit a9dcb34
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions mautrix_telegram/portal/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,15 @@ def _get_base_power_levels(self, levels: PowerLevelStateEventContent = None,
levels.users[self.main_intent.mxid] = 100
return levels

@staticmethod
def _get_level_from_participant(participant: TypeParticipant) -> int:
@classmethod
def _get_level_from_participant(cls, participant: TypeParticipant,
levels: PowerLevelStateEventContent) -> int:
# TODO use the power level requirements to get better precision in channels
if isinstance(participant, (ChatParticipantAdmin, ChannelParticipantAdmin)):
return 50
return levels.state_default or 50
elif isinstance(participant, (ChatParticipantCreator, ChannelParticipantCreator)):
return 95
return 0
return levels.get_user_level(cls.az.bot_mxid) - 5
return levels.users_default or 0

@staticmethod
def _participant_to_power_levels(levels: PowerLevelStateEventContent,
Expand Down Expand Up @@ -541,7 +542,7 @@ async def _participants_to_power_levels(self, users: List[Union[TypeUser, TypePa

puppet = p.Puppet.get(TelegramID(participant.user_id))
user = u.User.get_by_tgid(TelegramID(participant.user_id))
new_level = self._get_level_from_participant(participant)
new_level = self._get_level_from_participant(participant, levels)

if user:
await user.register_portal(self)
Expand Down

0 comments on commit a9dcb34

Please sign in to comment.