Skip to content

Commit

Permalink
Wrap requests in InvokeWithoutUpdatesRequest if no event handlers
Browse files Browse the repository at this point in the history
Closes #1270.
  • Loading branch information
Lonami committed Aug 22, 2021
1 parent 9285e50 commit 49713b2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions telethon/client/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ async def _call(self: 'TelegramClient', sender, request, ordered=False, flood_sl
else:
raise errors.FloodWaitError(request=r, capture=diff)

if not self._event_builders and not self._conversations:
r = functions.InvokeWithoutUpdatesRequest(r)

request_index = 0
last_error = None
self._last_request = time.time()
Expand Down
2 changes: 1 addition & 1 deletion telethon/events/callbackquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Event(EventCommon, SenderGetter):
The object returned by the ``data=`` parameter
when creating the event builder, if any. Similar
to ``pattern_match`` for the new message event.
pattern_match (`obj`, optional):
Alias for ``data_match``.
"""
Expand Down

3 comments on commit 49713b2

@penn5
Copy link
Contributor

@penn5 penn5 commented on 49713b2 Aug 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an event handler later gets added you have to call a high level function to make updates start...

@Lonami
Copy link
Member Author

@Lonami Lonami commented on 49713b2 Aug 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run_until_disconnected calls getState:

async def _run_until_disconnected(self: 'TelegramClient'):
try:
# Make a high-level request to notify that we want updates
await self(functions.updates.GetStateRequest())
return await self.disconnected
except KeyboardInterrupt:
pass
finally:
await self.disconnect()

However it is true people may use things like loop.run_forever(), or run_until_disconnected on another client. Do you think this will be a big issue? If so, we can just add another bool to the client's parameters.

@penn5
Copy link
Contributor

@penn5 penn5 commented on 49713b2 Aug 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It think it's an issue, for example if some code registers handlers entirely dynamically based on telegram state

Please sign in to comment.