Skip to content

feat(peers): add channel recommendations helper#1762

Merged
ernado merged 1 commit into
mainfrom
feat/1267-channel-recommendations
Jun 11, 2026
Merged

feat(peers): add channel recommendations helper#1762
ernado merged 1 commit into
mainfrom
feat/1267-channel-recommendations

Conversation

@ernado

@ernado ernado commented Jun 11, 2026

Copy link
Copy Markdown
Member

Summary

Adds a helper for channel recommendations (#1267).

channels.getChannelRecommendations (layer 227) has no offset or hash parameter, so the result genuinely can't be paginated through — the original issue's premise (paging to fetch all ~82 recommendations) isn't achievable via the API. What the server actually does, and what tdlib relies on, is:

  • return the full list to Premium accounts;
  • return a capped subset to non-Premium accounts, but as messages.chatsSlice whose count reports the true total.

So this helper returns the recommended channels together with that total Count, letting callers detect that more recommendations exist (e.g. to prompt for Premium):

type RecommendedChannels struct {
    Channels []peers.Channel
    Count    int // total available; may exceed len(Channels) for non-Premium
}

func (c Channel) RecommendedChannels(ctx) (RecommendedChannels, error)   // related to a channel
func (m *Manager) RecommendedChannels(ctx) (RecommendedChannels, error)  // for the current user

It applies the returned chats to the peers.Manager cache (consistent with the existing resolve helpers) and skips any non-channel chats while preserving the reported total.

Testing

Offline tgmock-based unit tests cover the error path, the messages.chats case (Count == len), the messages.chatsSlice case (Count reports the true total, e.g. 82), non-channel filtering, and the manager-level (no-channel) variant. Added a runnable compile-checked example. gofmt, go build ./..., go vet ./telegram/peers/, and go test -race ./telegram/peers/ all pass. No generated code changed; no network access.

Closes #1267

🤖 Generated with Claude Code

channels.getChannelRecommendations has no offset/hash parameter, so the
recommendations can't be paginated through. Instead, the server returns the
full set to Premium accounts and a capped subset to others, with
messages.chatsSlice carrying the true total.

Add Channel.RecommendedChannels and Manager.RecommendedChannels returning the
recommended channels together with the total Count, so callers can detect that
more recommendations exist (e.g. to prompt for Premium).

Closes #1267

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ernado ernado force-pushed the feat/1267-channel-recommendations branch from aa026bb to e2de203 Compare June 11, 2026 15:23
@ernado ernado merged commit 6a5585c into main Jun 11, 2026
12 of 13 checks passed
@ernado ernado deleted the feat/1267-channel-recommendations branch June 11, 2026 15:33
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.

Channel recommendations pagination support

1 participant