Skip to content

Updates Overhaul Update

Pre-release
Pre-release
Compare
Choose a tag to compare
@Lonami Lonami released this 01 Oct 15:41

After hundreds of lines changed on a major refactor, it's finally here. It's the Updates Overhaul Update; let's get right into it!

New stuff and enhancements

  • You can invoke requests from update handlers. And any other thread. A new temporary will be made, so that you can be sending even several requests at the same time!
  • Several worker threads for your updates! By default, None will spawn. I recommend you to work with update_workers=4 to get started, these will be polling constantly for updates.
  • You can also change the number of workers at any given time.
  • The library can now run in a single thread again, if you don't need to spawn any at all. Simply set spawn_read_thread=False when creating the TelegramClient!
  • You can specify limit=None on .get_dialogs() to get all of them[1].
  • Updates are expanded, so you don't need to check if the update has .updates or an inner .update anymore.
  • All InputPeer entities are saved in the session file, but you can disable this by setting save_entities=False.
  • New .get_input_entity method, which makes use of the above feature. You should use this when a request needs a InputPeer, rather than the whole entity (although both work).

Less important enhancements

  • Assert that either all or None dependent-flag parameters are set before sending the request.
  • Phone numbers can have dashes, spaces, or parenthesis. They'll be removed before making the request.
  • You can override the phone and its hash on .sign_in(), if you're creating a new TelegramClient on two different places.

Compatibility breaks

  • .create_new_connection() is gone for good. No need to deal with this manually since new connections are now handled on demand by the library itself.

Bugs fixed

  • .log_out() was consuming all retries. It should work just fine now.
  • The session would fail to load if the auth_key had been removed manually.
  • Updates.check_error was popping wrong side, although it's been completely removed.
  • ServerError's will be ignored, and the request will immediately be retried.
  • Cross-thread safety when saving the session file.
  • Some things changed on a matter of when to reconnect, so please report any bugs!

Internal changes

  • TelegramClient is now only an abstraction over the TelegramBareClient, which can only do basic things, such as invoking requests, working with files, etc. If you don't need any of the abstractions the TelegramClient, you can now use the TelegramBareClient in a much more comfortable way.
  • MtProtoSender is not thread-safe, but it doesn't need to be since a new connection will be spawned when needed.
  • New connections used to be cached and then reused. Now only their sessions are saved, as temporary connections are spawned only when needed.
  • Added more RPC errors to the list.

[1]: Broken due to a condition which should had been the opposite (sigh), fixed 4 commits ahead on 62ea77c.


That's pretty much it, although there's more work to be done to make the overall experience of working with updates even better. Stay tuned!