Peer Cache
Part of the API Reference. Reached via client.peerCache. You rarely need to call this directly — every high-level ptgc call feeds it automatically — but it’s useful for debugging “why can’t ptgc see this peer yet” issues. See Inspecting the Peer Cache.
Telegram’s raw API requires an accessHash (not just an ID) to address most users and channels — a value only ever handed to you as part of a server response. PeerCache remembers the access hashes and usernames of every user/chat ptgc has seen this session, so you can address them by plain integer ID or @username afterwards without threading the access hash through your own code. A PeerNotFoundException means the opposite: ptgc has never seen that ID/username, so it has no access hash to use — resolve it once first, e.g. with Contacts.resolveUsername or Members.list.
feed
void feed({
Iterable<t.UserBase> users = const [],
Iterable<t.ChatBase> chats = const [],
}) {
Feeds users/chats from a raw response into the cache. Safe to call with empty lists. Every namespace method does this for you already.
cachedUser / cachedChat
t.UserBase? cachedUser(int id) => _users[id];
t.ChatBase? cachedChat(int id) => _chats[id];
Direct lookups into the cache by ID, returning the raw generated type as last seen (not the friendlier PtgcUser/PtgcChat) — mainly useful for debugging.
idForUsername
int? idForUsername(String username) {
Looks up a cached ID by @username (leading @ optional). Returns null if that username hasn’t been seen yet this session.
inputUser / inputPeerUser
t.InputUserBase inputUser(int id) {
t.InputPeerBase inputPeerUser(int id) {
Builds the raw InputUser/InputPeer Telegram’s API expects for id, using the cached access hash. Throws PeerNotFoundException if id hasn’t been seen yet.
inputChannel / inputPeerChannel
t.InputChannelBase inputChannel(int id) {
t.InputPeerBase inputPeerChannel(int id) {
The channel/supergroup equivalents of [inputUser]/[inputPeerUser].
inputPeerChat
t.InputPeerBase inputPeerChat(int id) => t.InputPeerChat(chatId: id);
A basic (non-super) group needs only its ID, never an access hash — this never throws.
kindOf
PeerKind kindOf(int id) {
What kind of peer id is, based on everything seen so far. Returns PeerKind.unknown if ptgc hasn’t encountered this ID this session.
inputPeer
t.InputPeerBase inputPeer(int id) {
Builds the right InputPeer* for id regardless of whether it’s a user, basic group, or supergroup/channel — used wherever the raw API takes a generic InputPeerBase (e.g. sending a message). Throws PeerNotFoundException if [kindOf] returns PeerKind.unknown.
isChannel
bool isChannel(int id) => kindOf(id) == PeerKind.channel;
Whether id is known to be a channel/supergroup (as opposed to a basic group) — used internally to route calls to the right namespace (channels.* vs messages.*).
Types
PeerKind
What kind of chat/peer an ID refers to, per everything PeerCache has seen this session: user, chat, channel, unknown.