Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
devonh committed May 8, 2024
1 parent 396909f commit 821a74b
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions synapse/events/auto_accept_invites.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
from http import HTTPStatus
from typing import Any, Dict, Tuple

from synapse.api.constants import AccountDataTypes, EventTypes, Membership
from synapse.api.errors import SynapseError
from synapse.config.auto_accept_invites import AutoAcceptInvitesConfig
from synapse.module_api import EventBase, ModuleApi, run_as_background_process

logger = logging.getLogger(__name__)
ACCOUNT_DATA_DIRECT_MESSAGE_LIST = "m.direct"


class InviteAutoAccepter:
Expand All @@ -37,7 +37,6 @@ def __init__(self, config: AutoAcceptInvitesConfig, api: ModuleApi):
self._config = config

if not self._config.enabled:
logger.info("Not starting InviteAutoAccepter as it is not enabled")
return

should_run_on_this_worker = config.worker_to_run_on == self._api.worker_name
Expand Down Expand Up @@ -68,9 +67,9 @@ async def on_new_event(self, event: EventBase, *args: Any) -> None:
"""
# Check if the event is an invite for a local user.
is_invite_for_local_user = (
event.type == "m.room.member"
event.type == EventTypes.Member
and event.is_state()
and event.membership == "invite"
and event.membership == Membership.INVITE
and self._api.is_mine(event.state_key)
)

Expand Down Expand Up @@ -132,7 +131,7 @@ async def _mark_room_as_direct_message(
# etc.)
dm_map: Dict[str, Tuple[str, ...]] = dict(
await self._api.account_data_manager.get_global(
user_id, ACCOUNT_DATA_DIRECT_MESSAGE_LIST
user_id, AccountDataTypes.DIRECT
)
or {}
)
Expand All @@ -146,7 +145,7 @@ async def _mark_room_as_direct_message(
dm_map[dm_user_id] = tuple(dm_rooms_for_user) + (room_id,)

await self._api.account_data_manager.put_global(
user_id, ACCOUNT_DATA_DIRECT_MESSAGE_LIST, dm_map
user_id, AccountDataTypes.DIRECT, dm_map
)

async def _retry_make_join(
Expand Down Expand Up @@ -189,9 +188,9 @@ async def _retry_make_join(
logger.warn(
f"Update_room_membership raised the following unexpected exception: {e}"
)
finally:
sleep = 2**retries
retries += 1

sleep = 2**retries
retries += 1

if join_event is not None:
break

0 comments on commit 821a74b

Please sign in to comment.