Rename PackedChat type to PeerRef

This commit is contained in:
Lonami Exo
2024-03-17 13:21:26 +01:00
parent 7e413e4ee2
commit 46223bcbcc
20 changed files with 65 additions and 65 deletions

View File

@@ -28,7 +28,7 @@ The following types are chat-like:
* An ``'+1 23'`` phone number string. It must be an :class:`str` and start with the plus-sign ``+`` character.
* An ``123`` integer identifier. It must be an :class:`int` and cannot be negative.
* An existing :class:`~types.User`, :class:`~types.Group` or :class:`~types.Channel`.
* A :class:`~types.PackedChat`.
* A :class:`~types.PeerRef`.
Previous versions of Telethon referred to this term as "entity" or "entities" instead.
@@ -72,7 +72,7 @@ The Bot API follows a certain convention when it comes to identifiers:
* Chat IDs are negative.
* Channel IDs are *also* negative, but are prefixed by ``-100``.
Telethon encourages the use of :class:`~types.PackedChat` instead of naked identifiers.
Telethon encourages the use of :class:`~types.PeerRef` instead of naked identifiers.
As a reminder, negative identifiers are not supported in Telethon's chat-like parameters.
If you got an Bot API-style ID from somewhere else, you will need to explicitly say what type it is:
@@ -104,7 +104,7 @@ Chats access hash
Users, supergroups and channels all need an :term:`access hash`.
In Telethon, the :class:`~types.PackedChat` is the recommended way to deal with the identifier-hash pairs.
In Telethon, the :class:`~types.PeerRef` is the recommended way to deal with the identifier-hash pairs.
This compact type can be used anywhere a chat is expected.
It's designed to be easy to store and cache in any way your application chooses.
@@ -113,7 +113,7 @@ The same is true for user accounts, although to a lesser extent.
When using just the identifier to refer to a chat, Telethon will attempt to retrieve its hash from its in-memory cache.
If this fails, an invalid hash will be used. This may or may not make the API call succeed.
For this reason, it is recommended that you always use :class:`~types.PackedChat` instead.
For this reason, it is recommended that you always use :class:`~types.PeerRef` instead.
Remember that an :term:`access hash` is account-bound.
You cannot obtain an :term:`access hash` in Account-A and use it in Account-B.

View File

@@ -96,7 +96,7 @@ and instead favours more standard `HTML elements <https://developer.mozilla.org/
Both markdown and HTML recognise the following special URLs using the ``tg:`` protocol:
* ``tg://user?id=ab1234cd6789`` for inline mentions.
To make sure the mention works, use :attr:`types.PackedChat.hex`.
To make sure the mention works, use :attr:`types.PeerRef.hex`.
You can also use :attr:`types.User.id`, but the mention will fail if the user is not in cache.
* ``tg://emoji?id=1234567890`` for custom emoji.
You must use the document identifier as the value.

View File

@@ -443,14 +443,14 @@ This doesn't mean the ``.chat`` or ``.sender`` will have all the information.
Telegram may still choose to send their ``min`` version with only basic details.
But it means you don't have to remember 5 different ways of using chats.
To replace the concept of "input chats", v2 introduces :class:`types.PackedChat`.
To replace the concept of "input chats", v2 introduces :class:`types.PeerRef`.
A "packed chat" is a chat with *just* enough information that you can use it without relying on Telethon's cache.
This is the most efficient way to call methods like :meth:`Client.send_message` too.
The concept of "marked IDs" also no longer exists.
This means v2 no longer supports the ``-`` or ``-100`` prefixes on identifiers.
:tl:`Peer`-wrapping is gone, too.
Instead, you're strongly encouraged to use :class:`types.PackedChat` instances.
Instead, you're strongly encouraged to use :class:`types.PeerRef` instances.
The concepts of of "entity" or "peer" are unified to simply :term:`chat`.
Overall, dealing with users, groups and channels should feel a lot more natural.
@@ -477,7 +477,7 @@ The v1 cache that allowed you to use just chat identifiers to call methods is no
Sessions now only contain crucial information to have a working client.
This includes the server address, authorization key, update state, and some very basic details.
To work around this, you can use :class:`types.PackedChat`, which is designed to be easy to store.
To work around this, you can use :class:`types.PeerRef`, which is designed to be easy to store.
This means your application can choose the best way to deal with them rather than being forced into Telethon's session.
.. seealso::