Skip to content

Commit

Permalink
Remove User.ensure_connected checks
Browse files Browse the repository at this point in the history
The underlying MQTT/HTTP calls will raise exceptions and this method
duplicates the timeout handling, which is currently mismatched with
recent MQTT changes.
  • Loading branch information
Fizzadar committed Jun 9, 2023
1 parent ee832d1 commit 17caf72
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 15 deletions.
3 changes: 0 additions & 3 deletions mautrix_instagram/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,6 @@ async def _handle_matrix_message(
) -> None:
sender, is_relay = await self.get_relay_sender(orig_sender, f"message {event_id}")
assert sender, "user is not logged in"
await sender.ensure_connected()

if is_relay:
await self.apply_relay_message_format(orig_sender, message)
Expand Down Expand Up @@ -753,8 +752,6 @@ async def handle_matrix_redaction(
await self._send_bridge_success(sender, redaction_event_id, EventType.ROOM_REDACTION)

async def _handle_matrix_redaction(self, sender: u.User, event_id: EventID) -> None:
await sender.ensure_connected()

reaction = await DBReaction.get_by_mxid(event_id, self.mxid)
if reaction:
try:
Expand Down
12 changes: 0 additions & 12 deletions mautrix_instagram/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,6 @@ def api_log(self) -> TraceLogger:
def is_connected(self) -> bool:
return bool(self.client) and bool(self.mqtt) and self._is_connected

async def ensure_connected(self, max_wait_seconds: int = 5) -> None:
sleep_interval = 0.1
max_attempts = max_wait_seconds / sleep_interval
attempts = 0
while True:
if self.is_connected:
return
attempts += 1
if attempts > max_attempts:
raise Exception("You're not connected to instagram")
await asyncio.sleep(sleep_interval)

async def connect(self, user: CurrentUser | None = None) -> None:
if not self.state:
await self.push_bridge_state(
Expand Down

0 comments on commit 17caf72

Please sign in to comment.