← Back to PRs

#3368: fix: sessions navigation, DM thread display, and DM thread delivery regression

by Lukavyi open 2026-01-28 14:15 View on GitHub →
channel: telegram app: web-ui
## Summary <img width="3656" height="2560" alt="CleanShot 2026-01-28 at 16 27 14@2x" src="https://github.com/user-attachments/assets/b97801c3-9536-4b06-8c67-38a31ef88ea8" /> Fixes #3367 Three related fixes for Telegram DM topics: 1. **Display**: Adds `ThreadLabel` so DM topic sessions show their thread ID 2. **Navigation**: Fixes clicking a session in Sessions tab redirecting to Main instead of the selected session 3. **Delivery**: Fixes bot replies going to General instead of the originating DM thread (regression from commit 9154971) ## Changes - **src/telegram/bot-message-context.ts**: Set `ThreadLabel: "Thread: N"` for non-group messages with `messageThreadId`; introduce `effectiveThreadId` for correct outbound delivery in DM threads - **src/telegram/bot-message-context.dm-threads.test.ts**: Add tests for ThreadLabel in DM threads - **ui/src/ui/app-lifecycle.ts**: Read URL session param before `syncTabWithLocation` overwrites it with localStorage value ## Problem 1: Display All DM topic sessions showed the same display name. Now each shows its thread ID (`Thread: 42`, `Thread: 99`). ## Problem 2: Navigation Clicking a session in the Sessions tab redirected to Main instead of the clicked session. **Root cause**: `syncTabWithLocation()` was called before `applySettingsFromUrl()`, overwriting the URL `?session=` param with localStorage. **Fix**: Call `applySettingsFromUrl()` first. ## Problem 3: DM Thread Delivery (regression) Commit 9154971 (`fix(telegram): ignore message_thread_id for non-forum group sessions`) changed `resolveTelegramForumThreadId` to return `undefined` when `is_forum` is false. This correctly fixed reply-chain pollution in regular groups, but broke DM thread delivery: - Telegram Bot API **never** sets `is_forum=true` for private chats (only supergroups) - `context.resolvedThreadId` (used by `bot-message-dispatch.ts` for draft streaming and reply delivery) became `undefined` for all DM threads - Replies, typing indicators, and voice recording indicators all went to General **Fix**: Introduce `effectiveThreadId = isGroup ? resolvedThreadId : messageThreadId` — uses raw `messageThreadId` for DMs (bypassing the forum gate) while preserving forum-resolved value for groups. ## Testing ```bash pnpm test src/telegram/bot-message-context.dm-threads.test.ts ``` All 7 tests pass, including 2 new tests for ThreadLabel. <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR fixes three related Telegram DM-topic regressions: (1) adds a `ThreadLabel` payload field so DM topic sessions can be distinguished in the Sessions UI, (2) ensures URL settings (including `?session=`) are applied before `syncTabWithLocation()` overwrites state from localStorage, and (3) restores correct DM-thread outbound routing by using a DM-specific thread id (`message_thread_id`) for typing indicators and dispatch context when `is_forum` is absent (private chats never set `is_forum=true`). The changes integrate into the existing Telegram context builder (`buildTelegramMessageContext`) by adjusting how thread IDs are computed and emitted, and into the UI lifecycle by reordering initialization to preserve URL-driven navigation. <h3>Confidence Score: 4/5</h3> - This PR is generally safe to merge, with one edge-case routing concern around non-group non-DM chat types. - Changes are localized and covered by targeted tests for DM thread session keys/labels; the main remaining risk is that `effectiveThreadId` is applied to all non-group chats (e.g., channels), which may not support `message_thread_id` semantics and could cause misrouting or Telegram API errors. - src/telegram/bot-message-context.ts <!-- greptile_other_comments_section --> <!-- /greptile_comment --> --- lobster-biscuit

Most Similar PRs