Skip to content

fix(deps): bump grammers 0.8.1 -> 0.10.0 (MTProto layer 227) - #13

Open
rafanate20 wants to merge 1 commit into
dgrr:mainfrom
rafanate20:fix/grammers-0.10-support
Open

fix(deps): bump grammers 0.8.1 -> 0.10.0 (MTProto layer 227)#13
rafanate20 wants to merge 1 commit into
dgrr:mainfrom
rafanate20:fix/grammers-0.10-support

Conversation

@rafanate20

@rafanate20 rafanate20 commented Aug 27, 2026

Copy link
Copy Markdown

Telegram servers reject the old MTProto layer 216 shipped with
grammers 0.8.x, causing every request to fail with rpc error 400
CONNECTION_LAYER_INVALID and breaking sync/daemon.

Upgrade all grammers crates (client, session, mtsender, tl-types)
to 0.10 and migrate to the new APIs:

  • grammers_session::defs -> grammers_session::types
  • PeerRef { id: PeerId, auth: PeerAuth } (no more Option auth);
    PeerId::user/chat/channel now return Option, bare_id() -> Option
  • Session::peer / SqliteSession::open / Client::new(SenderPoolFatHandle)
    and stream_updates / sync_update_state are now async
  • PeerRef::from(&Peer) removed; use Dialog::peer_ref() or
    Peer::to_ref() (new peer_to_ref / peer_to_ref_async helpers)
  • types module split: tl::types::update -> tl::types::updates,
    Message moved to tl::types root
  • Message::peer() -> Option<&Peer>, User::bare_id() -> User::id()
  • Document::name() -> Option<&str>
  • New required TL fields: SendMessage/EditMessage (rich_message,
    schedule_repeat_period), ForwardMessages (effect,
    schedule_repeat_period), InputReplyToMessage (poll_option),
    InputMediaPoll (attached_media, solution_media), Poll/PollAnswer,
    ChatBannedRights (edit_rank, send_reactions), ChatAdminRights
    (manage_ranks), contacts::Search (bots, broadcasts)
  • ImportChatInvite now returns ChatInviteJoinResult;
    InputMedia::Poll takes Box; EditAdmin rank is Option
  • from_raw() constructors now require &Client

Verified: profile show, sync chats (236 chats) and full sync with
message fetch all work against a real session.

fix(tg): restore 0.8 peer-resolution semantics after grammers 0.10 port

The 0.10 port turned several previously-infallible APIs into Option/Result
and the mechanical conversion changed behavior in a few places. This keeps
every command behaving as it did on 0.8.

Peer auth resolution:

  • PeerInfo::auth() is now Option<PeerAuth>, where None means the peer is
    cached but has no usable (non-min) access hash. Mapping that to
    PeerAuth::default() and returning early produced a zeroed access_hash and
    skipped the user/chat/dialog-scan fallbacks that used to recover the peer.
    Use Session::peer_ref() instead, which yields None in that case so the
    fallback chain runs as before. Affects chats, folders, users and sync.

  • peer_to_ref mapped every Peer::Group to ambient auth, but a Group wraps
    tl::enums::Chat, which may be a megagroup/gigagroup Chat::Channel that
    needs an access hash. Handle the channel variants, and propagate session
    errors instead of swallowing them into a silently-wrong PeerRef.

  • Unify the dialog-scan sites on peer_to_ref_async; Dialog::peer_ref()
    unwraps internally and would panic on a peer without auth.

Database keys:

  • PeerId::bare_id() is now Option<i64>. Writing unwrap_or(-1) into
    upsert_chat/upsert_contact would collide distinct peers on row -1, and
    the daemon did the same with 0 for its chat_id. Skip the record instead.
    Inside if let Peer::User(..) the enclosing id is already the user's bare
    id, so reuse it.

Cleanups:

  • Carry the resolved PeerRef out of the sync filter loop instead of
    re-resolving inside each task; the lookup is a database query in 0.10, so it
    was being paid twice per chat.
  • resolve_peer_from_session now delegates to resolve_peer_from_session_static
    rather than duplicating ~55 lines.
  • Flatten the duplicated branches in the chats member resolver.

CI:

  • cargo fmt.
  • map(..).flatten() -> and_then(..), matching the idiom used elsewhere in
    the port.
  • sort_by -> sort_by_key in two spots that current stable clippy rejects
    under -D warnings.

Co-Authored-By: Claude Opus 5 & Qwen3.8-27B

Telegram servers reject the old MTProto layer 216 shipped with
grammers 0.8.x, causing every request to fail with rpc error 400
CONNECTION_LAYER_INVALID and breaking sync/daemon.

Upgrade all grammers crates (client, session, mtsender, tl-types)
to 0.10 and migrate to the new APIs:
- grammers_session::defs -> grammers_session::types
- PeerRef { id: PeerId, auth: PeerAuth } (no more Option auth);
  PeerId::user/chat/channel now return Option, bare_id() -> Option<i64>
- Session::peer / SqliteSession::open / Client::new(SenderPoolFatHandle)
  and stream_updates / sync_update_state are now async
- PeerRef::from(&Peer) removed; use Dialog::peer_ref() or
  Peer::to_ref() (new peer_to_ref / peer_to_ref_async helpers)
- types module split: tl::types::update -> tl::types::updates,
  Message moved to tl::types root
- Message::peer() -> Option<&Peer>, User::bare_id() -> User::id()
- Document::name() -> Option<&str>
- New required TL fields: SendMessage/EditMessage (rich_message,
  schedule_repeat_period), ForwardMessages (effect,
  schedule_repeat_period), InputReplyToMessage (poll_option),
  InputMediaPoll (attached_media, solution_media), Poll/PollAnswer,
  ChatBannedRights (edit_rank, send_reactions), ChatAdminRights
  (manage_ranks), contacts::Search (bots, broadcasts)
- ImportChatInvite now returns ChatInviteJoinResult;
  InputMedia::Poll takes Box; EditAdmin rank is Option<String>
- from_raw() constructors now require &Client

Verified: profile show, sync chats (236 chats) and full sync with
message fetch all work against a real session.

fix(tg): restore 0.8 peer-resolution semantics after grammers 0.10 port

The 0.10 port turned several previously-infallible APIs into Option/Result
and the mechanical conversion changed behavior in a few places. This keeps
every command behaving as it did on 0.8.

Peer auth resolution:
- `PeerInfo::auth()` is now `Option<PeerAuth>`, where `None` means the peer is
  cached but has no usable (non-min) access hash. Mapping that to
  `PeerAuth::default()` and returning early produced a zeroed access_hash and
  skipped the user/chat/dialog-scan fallbacks that used to recover the peer.
  Use `Session::peer_ref()` instead, which yields `None` in that case so the
  fallback chain runs as before. Affects chats, folders, users and sync.

- `peer_to_ref` mapped every `Peer::Group` to ambient auth, but a `Group` wraps
  `tl::enums::Chat`, which may be a megagroup/gigagroup `Chat::Channel` that
  needs an access hash. Handle the channel variants, and propagate session
  errors instead of swallowing them into a silently-wrong `PeerRef`.

- Unify the dialog-scan sites on `peer_to_ref_async`; `Dialog::peer_ref()`
  unwraps internally and would panic on a peer without auth.

Database keys:
- `PeerId::bare_id()` is now `Option<i64>`. Writing `unwrap_or(-1)` into
  `upsert_chat`/`upsert_contact` would collide distinct peers on row -1, and
  the daemon did the same with 0 for its chat_id. Skip the record instead.
  Inside `if let Peer::User(..)` the enclosing `id` is already the user's bare
  id, so reuse it.

Cleanups:
- Carry the resolved `PeerRef` out of the sync filter loop instead of
  re-resolving inside each task; the lookup is a database query in 0.10, so it
  was being paid twice per chat.
- `resolve_peer_from_session` now delegates to `resolve_peer_from_session_static`
  rather than duplicating ~55 lines.
- Flatten the duplicated branches in the chats member resolver.

CI:
- `cargo fmt`.
- `map(..).flatten()` -> `and_then(..)`, matching the idiom used elsewhere in
  the port.
- `sort_by` -> `sort_by_key` in two spots that current stable clippy rejects
  under `-D warnings`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant