Skip to content

fix: stop treating unjoined public channels as private - #102

Merged
craigcarlyle merged 2 commits into
mainfrom
craigcarlyle/unjoined-public-channels
Nov 2, 2026
Merged

craigcarlyle merged 2 commits into
mainfrom
craigcarlyle/unjoined-public-channels

Conversation

@craigcarlyle

Copy link
Copy Markdown
Contributor

Lets tdc thread view, channel threads and the other thread commands read public channels you haven't joined, without --include-private-channels.

Fixes #61

Why: the private-channel check only knew about the channels you've joined, so it reported every other channel as private, public ones included. Agents pass that message on as fact, and the only way round it was --include-private-channels, which switches the check off for private channels too.

What changes: when a channel isn't one you've joined, the check now looks for it among the workspace's public channels before failing. It's option 2 from @lmjabreu's write-up, except it checks the workspace's list rather than the channel itself (the reason is in a comment on the line). Channels you've joined work as before, with no extra call, and joined private channels still need the flag.

Testing: three new tests. The two that cover an unjoined public channel fail on main with "This thread belongs to a private channel". Against a public channel I haven't joined:

$ tdc channel threads id:<public channel I haven't joined> --limit 1 --json
main:   NOT_FOUND "This thread belongs to a private channel."
branch: 1 thread

$ tdc thread view id:<thread in that channel> --json --limit 1
main:   NOT_FOUND "This thread belongs to a private channel."
branch: the thread

A joined private channel still fails without the flag. npm test (1192 tests), type-check and lint:check pass.

Not addressed: tdc inbox and search. They filter on the same list of joined channels, so a thread from a public channel you haven't joined is still left out unless you pass the flag. The same fallback would work there, but this PR sticks to the check from the issue.

🤖 Generated with Claude Code

The private-channel check only knew about the channels you've joined,
so a thread in a public channel you hadn't joined failed with "This
thread belongs to a private channel" and needed
--include-private-channels.

When a channel isn't one you've joined, the check now looks for it
among the workspace's public channels before failing. Joined channels
work as before with no extra call, and joined private channels still
need the flag.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
const isPublic =
joined.get(channelId) ??
// getChannels only returns joined channels, so an unjoined one could still be public.
(await getWorkspacePublicChannelIds(workspaceId)).has(channelId)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the workspace's public channels and not getChannel for just this one: channels/getone is the call with the per-user rate limit (see #94), and thread view already makes one for the channel name. The public channel list has no limit but is much bigger, since it carries every public channel's members: about 0.3s extra on an unjoined channel in a quick timing (1.31s against 0.98s for a joined one). It's only fetched when the channel isn't one you've joined, once per run. It also comes back empty for guests, so it can only be a fallback, not a replacement for the joined list.

@doistbot doistbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR fixes the visibility check so unjoined public channels no longer get misreported as private — joined channels short-circuit with no extra API call, joined private channels still require the flag, and the new workspace public-channel fallback is cached with tests covering the new paths.

Few things worth tightening:

  • For tdc channel threads <name> resolving to an unjoined public channel, the fallback refetches workspaces.getPublicChannels right after resolveChannelRef already fetched the same list to resolve the name — doubling the heaviest call on exactly the path this PR enables. Since showChannelThreads already has the resolved Channel with its public flag, passing that known value into assertChannelIsPublic (or sharing the public-channel cache) would avoid the duplicate fetch.

Share Feedback • Review Logs

const isPublic =
joined.get(channelId) ??
// getChannels only returns joined channels, so an unjoined one could still be public.
(await getWorkspacePublicChannelIds(workspaceId)).has(channelId)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 For tdc channel threads <name> resolving to an unjoined public channel, this fallback fetches workspaces.getPublicChannels again right after resolveChannelRef in src/lib/refs.ts has already fetched the same list to resolve the name (channels.getChannels is also fetched by both paths). That doubles the heaviest call on the exact path this PR enables — the list the PR otherwise treats as expensive. showChannelThreads already has the resolved Channel with its public flag, so pass that known value into assertChannelIsPublic (or otherwise share the public-channel cache) to avoid the duplicate fetch.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 3d6924d, and in thread create too.

channel threads and thread create already have the channel they
resolved, so the private-channel check now takes its public flag
instead of looking it up. For an unjoined channel resolved by name,
the lookup was fetching the workspace's public channels a second time.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@craigcarlyle craigcarlyle added the 👀 Show PR requires passing checks before merge and independent human review before or after merge. label Nov 2, 2026
@craigcarlyle

Copy link
Copy Markdown
Contributor Author

@doistbot /review

@doistbot doistbot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR fixes the private-channel guard so unjoined public channels work with tdc thread view, channel threads, and related thread commands, falling back to the workspace's public-channel list when a channel isn't in your joined set — joined private channels still require --include-private-channels.

Few things worth tightening:

  • In viewThread, the unconditional getChannel(thread.channelId) fetch for the channel name happens after the guard, so unjoined public channels trigger both the workspace-wide public-channel list (with members) and the channel lookup. Reorder so the existing getChannel result feeds the guard via channel.public, avoiding the extra workspace-wide call entirely.

Share Feedback • Review Logs

return (
joined.get(channelId) ??
// getChannels only returns joined channels, so an unjoined one could still be public.
(await getWorkspacePublicChannelIds(workspaceId)).has(channelId)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Reuse thread view's existing channel lookup. viewThread calls this guard before unconditionally fetching client.channels.getChannel(thread.channelId) for the channel name. For an unjoined public channel, it therefore downloads the workspace-wide public-channel list, including channel members, even though the subsequent channel lookup supplies the same visibility flag. Move that existing lookup before the guard and pass channel.public; this avoids the new workspace-wide request without adding another rate-limited getChannel call.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this one. Thread view's channel lookup is the rate-limited call, and #94 is making a 429 there show the thread without the channel name instead of failing. If the private-channel check relied on that lookup, those views would fail again. The list call only runs for channels you haven't joined, about 0.3s there. Once #94 is in, the lookup could feed the check, with the list as the fallback on a 429.

@craigcarlyle
craigcarlyle merged commit f8b2719 into main Nov 2, 2026
6 checks passed
@craigcarlyle
craigcarlyle deleted the craigcarlyle/unjoined-public-channels branch November 2, 2026 21:33
doist-release-bot Bot added a commit that referenced this pull request Nov 2, 2026
## [3.9.1](v3.9.0...v3.9.1) (2026-11-02)

### Bug Fixes

* **channel:** list every thread in the window, not just the newest 20 ([#101](#101)) ([5d18feb](5d18feb))
* stop treating unjoined public channels as private ([#102](#102)) ([f8b2719](f8b2719))
@doist-release-bot

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.9.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released 👀 Show PR requires passing checks before merge and independent human review before or after merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unjoined public channel is reported as a private channel

3 participants