Commit Graph

161 Commits

Author SHA1 Message Date
7e32aeffa4 Merge branch 'main' into refactor 2026-05-17 01:08:05 +00:00
Mikhail Kilin
42884d174e fix: stabilize multi-account chat handling 2026-05-17 04:06:19 +03:00
fea3e452ff Merge pull request 'docs: clean up project markdown' (#27) from refactor into main
Reviewed-on: #27
2026-05-17 00:58:16 +00:00
Mikhail Kilin
1208aa5afb docs: clean up project markdown 2026-05-17 03:56:04 +03:00
d3565c9ff9 Merge pull request 'fix(images): eliminate race condition when pressing v on downloading photo' (#26) from refactor into main
Reviewed-on: #26
2026-03-02 23:19:14 +00:00
Mikhail Kilin
90776448ce fix(images): eliminate race condition when pressing v on downloading photo
Some checks failed
ci/woodpecker/pr/check Pipeline failed
Previously, handle_view_image called td_client.download_file() synchronously
while process_pending_chat_init already had a background synchronous=true
download in flight for the same file. TDLib returned is_downloading_completed=false
causing the view to fail on first press.

Fix: replace the blocking download in NotDownloaded/Downloading branches with
a pending_image_open intent flag. The main loop opens the modal automatically
when the background download result arrives via photo_download_rx. If no
background channel exists, a new one is started via direct tdlib_rs call.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 02:15:51 +03:00
6344e0ff6a Merge pull request 'refactor' (#25) from refactor into main
Reviewed-on: #25
2026-03-02 22:22:24 +00:00
Mikhail Kilin
c89a5e13f8 chore: remove leftover backup files from src/
Some checks failed
ci/woodpecker/pr/check Pipeline failed
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 01:17:47 +03:00
Mikhail Kilin
07a41ff796 chore: remove unused and outdated files
- config.example.toml: duplicate of config.toml.example
- REFACTORING_ROADMAP.md, REFACTORING_OPPORTUNITIES.md: refactoring done in Phase 13
- TESTING_PROGRESS.md, TESTING_ROADMAP.md: stale since February, superseded by ROADMAP.md
- CHANGELOG.md: never maintained
- FAQ.md, CONTRIBUTING.md, SECURITY.md, INSTALL.md: boilerplate for a personal project
- .github/: GitHub templates unused (project hosted on Gitea)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 01:15:42 +03:00
Mikhail Kilin
e2971e5ff5 chore: add symbol_info_budget and language_backend fields to serena config
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 01:04:55 +03:00
de18d6978b Merge pull request 'refactor' (#24) from refactor into main
Reviewed-on: #24
2026-03-02 22:00:07 +00:00
Mikhail Kilin
dea3559da7 docs: remove out-of-scope items from Phase 14 Etap 4 roadmap
Some checks failed
ci/woodpecker/pr/check Pipeline failed
Remove account deletion from modal and parallel polling — these won't
be implemented in the current scope.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 00:57:18 +03:00
Mikhail Kilin
260b81443e style: replace DarkGray with Rgb(160,160,160) for better terminal compatibility
DarkGray renders differently across terminals; a specific RGB value gives
consistent appearance. Also always show the account indicator in the footer.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 00:57:06 +03:00
Mikhail Kilin
df89c4e376 test: update footer snapshots to always show account name
Snapshots now reflect the new behaviour where the account indicator
is always visible (including "default"), matching the footer.rs change.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 00:52:56 +03:00
Mikhail Kilin
ec2758ce18 refactor: consolidate message loading logic into chat_loader.rs
Move all three phases of chat message loading from scattered locations
into a single dedicated module for better cohesion and navigability:
- Phase 1: open_chat_and_load_data (from handlers/chat_list.rs)
- Phase 2: process_pending_chat_init (extracted from 70-line inline block in main.rs)
- Phase 3: load_older_messages_if_needed (from handlers/chat.rs)

No behaviour changes — pure refactoring.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-03 00:48:39 +03:00
564df43910 Merge pull request 'fix: always reserve space for selection marker to prevent text shift' (#23) from refactor into main
Reviewed-on: #23
2026-02-24 12:59:04 +00:00
Mikhail Kilin
a095fe277b fix: always reserve space for selection marker to prevent text shift
Some checks failed
ci/woodpecker/pr/check Pipeline failed
Render "  " (2 spaces) for unselected messages instead of nothing,
so text stays aligned when navigating with the ▶ selection indicator.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:49:08 +03:00
42f16b1a2b Merge pull request 'feat: per-account lock protection + fix message navigation' (#22) from refactor into main 2026-02-24 12:39:01 +00:00
Mikhail Kilin
dfd4184039 fix: keep selection on last/first message instead of deselecting
Some checks failed
ci/woodpecker/pr/check Pipeline failed
When pressing down on the last message or up on the first message in
chat navigation, stay on the current message instead of exiting
message selection mode.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:35:06 +03:00
Mikhail Kilin
25c57c55fb feat: add per-account lock file protection via fs2
Prevent running multiple tele-tui instances with the same account by
using advisory file locks (flock). Lock is acquired before raw mode so
errors print to normal terminal. Account switching acquires new lock
before releasing old. Also log set_tdlib_parameters errors via tracing
instead of silently discarding them.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 15:35:06 +03:00
044b859cec Merge pull request 'ci/woodpecker-checks' (#21) from ci/woodpecker-checks into main 2026-02-22 15:12:46 +00:00
Mikhail Kilin
51e7941668 chore: remove unused GitHub Actions workflow
All checks were successful
ci/woodpecker/pr/check Pipeline was successful
Woodpecker CI is the active CI system; GitHub Actions never runs on Gitea.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 18:04:32 +03:00
Mikhail Kilin
3b7ef41cae fix: resolve all 40 clippy warnings (dead_code, unused_imports, lints)
Some checks failed
ci/woodpecker/pr/check Pipeline was successful
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
- Add #[allow(unused_imports)] on pub re-exports used only by lib/tests
- Add #[allow(dead_code)] on public API items unused in binary target
- Fix collapsible_if, redundant_closure, unnecessary_map_or in main.rs
- Prefix unused test variables with underscore

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 17:50:18 +03:00
Mikhail Kilin
166fda93a4 style: fix formatting after clippy changes
Some checks failed
ci/woodpecker/pr/check Pipeline failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
2026-02-22 17:33:48 +03:00
Mikhail Kilin
d4e1ed1376 fix: resolve all 23 clippy warnings
Some checks failed
ci/woodpecker/pr/check Pipeline failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
2026-02-22 17:28:50 +03:00
Mikhail Kilin
d9eb61dda7 ci: use rust:latest image (deps require rustc 1.88+)
Some checks failed
ci/woodpecker/pr/check Pipeline failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
2026-02-22 17:14:31 +03:00
Mikhail Kilin
c7865b46a7 ci: bump rust image to 1.85 (edition 2024 support)
Some checks failed
ci/woodpecker/pr/check Pipeline failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
2026-02-22 17:12:14 +03:00
Mikhail Kilin
264f183510 style: auto-format entire codebase with cargo fmt (stable rustfmt.toml)
Some checks failed
ci/woodpecker/pr/check Pipeline failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
2026-02-22 17:09:51 +03:00
Mikhail Kilin
2442a90e23 ci: add Woodpecker CI pipeline for PR checks (fmt, clippy, test)
Some checks failed
ci/woodpecker/pr/check Pipeline failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
2026-02-22 16:53:15 +03:00
Mikhail Kilin
48d883a746 Merge branch 'refactor' 2026-02-22 16:52:31 +03:00
Mikhail Kilin
df19bc742c fix: add photo_download_rx channel and fix account switcher nav tests
Some checks failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
Add UnboundedReceiver for background photo downloads to App state,
reset it on close_chat. Fix account_switcher tests to navigate past
all accounts dynamically instead of assuming single account.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 16:19:04 +03:00
Mikhail Kilin
78fe09bf11 feat: implement photo albums (media groups) and persist account selection
Group photos with shared media_album_id into single album bubbles with
grid layout (up to 3x cols). Album navigation treats grouped photos as
one unit (j/k skip entire album). Persist selected account to
accounts.toml so it survives app restart.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 16:18:04 +03:00
Mikhail Kilin
8bd08318bb fixes
Some checks failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
2026-02-14 17:57:37 +03:00
Mikhail Kilin
6639dc876c fixes 2026-02-13 19:52:53 +03:00
Mikhail Kilin
6d08300daa feat: implement audio seeking with arrow keys via ffplay restart
Seek now works by restarting ffplay with -ss offset instead of the
broken player.seek() stub. MoveLeft/MoveRight added as aliases for
SeekBackward/SeekForward to fix HashMap non-deterministic iteration
order causing Left arrow to resolve to MoveLeft instead of SeekBackward.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 18:51:45 +03:00
Mikhail Kilin
8a467b6418 feat: complete Phase 12 — voice playback ticker, cache, config, and UI
Add playback position ticker in event loop with 1s UI refresh rate,
integrate VoiceCache for downloaded voice files, add [audio] config
section (cache_size_mb, auto_download_voice), and render progress bar
with waveform visualization in message bubbles.

Fix race conditions in AudioPlayer: add `starting` flag to prevent
false `is_stopped()` during ffplay startup, guard pid cleanup so old
threads don't overwrite newer process pids. Implement `resume_from()`
with ffplay `-ss` for real audio seek on unpause (-1s rewind).

Kill ffplay on app exit via `stop_playback()` in shutdown + Drop impl.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 16:37:02 +03:00
Mikhail Kilin
7bc264198f feat: implement Phase 12 — voice message playback with ffplay
Add voice message playback infrastructure:
- AudioPlayer using ffplay subprocess with SIGSTOP/SIGCONT for pause/resume
- VoiceCache with LRU eviction (100 MB limit)
- TDLib integration: VoiceInfo, VoiceDownloadState, PlaybackState types
- download_voice_note() in TdClientTrait
- Keybindings: Space (play/pause), ←/→ (seek ±5s)
- Auto-stop playback on message navigation
- Remove debug_log module
2026-02-09 02:35:49 +03:00
Mikhail Kilin
2a5fd6aa35 perf: optimize Phase 11 image rendering with dual-protocol architecture
Redesigned UX and performance for inline photo viewing:

UX changes:
- Always-show inline preview (fixed 50 chars width)
- Fullscreen modal on 'v' key with ←/→ navigation between photos
- Loading indicator " Загрузка..." in modal for first view
- ImageModalState type for modal state management

Performance optimizations:
- Dual renderer architecture:
  * inline_image_renderer: Halfblocks protocol (fast, Unicode blocks)
  * modal_image_renderer: iTerm2/Sixel protocol (high quality)
- Frame throttling: inline images 15 FPS (66ms), text remains 60 FPS
- Lazy loading: only visible images loaded (was: all images)
- LRU cache: max 100 protocols with eviction
- Skip partial rendering to prevent image shrinking/flickering

Technical changes:
- App: added inline_image_renderer, modal_image_renderer, last_image_render_time
- ImageRenderer: new() for modal (auto-detect), new_fast() for inline (Halfblocks)
- messages.rs: throttled second-pass rendering, visible-only loading
- modals/image_viewer.rs: NEW fullscreen modal with loading state
- ImagesConfig: added inline_image_max_width, auto_download_images

Result: 10x faster navigation, smooth 60 FPS text, quality modal viewing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-08 01:36:36 +03:00
Mikhail Kilin
b0f1f9fdc2 feat: implement Phase 11 — inline photo viewing with ratatui-image
Add feature-gated (`images`) inline photo support:
- New types: MediaInfo, PhotoInfo, PhotoDownloadState, ImagesConfig
- Media module: ImageCache (LRU filesystem cache), ImageRenderer (terminal protocol detection)
- Photo metadata extraction from TDLib MessagePhoto with download_file() API
- ViewImage command (v/м) to toggle photo expand/collapse in message selection
- Two-pass UI rendering: placeholder lines in message bubbles + StatefulImage overlay
- Collapse all expanded photos on Esc (exit selection mode)

Dependencies: ratatui-image 8.1, image 0.25 (optional, behind `images` feature flag)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 21:25:17 +03:00
Mikhail Kilin
6845ee69bf docs: trim CONTEXT.md and ROADMAP.md (3006→246 lines, -92%)
Completed phases condensed to summary tables, detailed history
removed (available in git log). Detailed plans kept only for
upcoming phases 11 (images) and 12 (voice messages).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 16:57:27 +03:00
Mikhail Kilin
ffd52d2384 refactor: complete Phase 13 deep architecture refactoring (etaps 3-7)
Split monolithic files into modular architecture:
- ui/messages.rs (893→365 lines): extract modals/, compose_bar.rs
- tdlib/messages.rs (836→3 files): split into messages/mod, convert, operations
- config/mod.rs (642→3 files): extract validation.rs, loader.rs
- Code duplication cleanup: shared components, ~220 lines removed
- Documentation: PROJECT_STRUCTURE.md rewrite, 16 files got //! docs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-06 15:28:11 +03:00
Mikhail Kilin
931954d829 refactor: split app/mod.rs into trait-based architecture (1015→371 lines)
Split monolithic App impl into 5 specialized trait modules:
- methods/navigation.rs (NavigationMethods) - 7 methods for chat navigation
- methods/messages.rs (MessageMethods) - 8 methods for message operations
- methods/compose.rs (ComposeMethods) - 10 methods for reply/forward/draft
- methods/search.rs (SearchMethods) - 15 methods for search functionality
- methods/modal.rs (ModalMethods) - 27 methods for modal dialogs

Changes:
- app/mod.rs: 1015→371 lines (removed 644 lines, -63%)
- Created app/methods/ with 5 trait impl blocks
- Left in app/mod.rs: constructors, get_command, get_selected_chat_id/chat, getters/setters
- 116 functions → 5 trait impl blocks (67 in traits + 48 in core)
- Single Responsibility Principle achieved
- Updated CONTEXT.md with refactoring metrics
- Updated ROADMAP.md: Phase 13 Etap 2 marked as DONE

Phase 13 Etap 2: COMPLETED (100%)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 00:59:14 +03:00
Mikhail Kilin
1d0bfb53e0 refactor: split main_input.rs into modular handlers (1199→164 lines)
Split monolithic input handler into 5 specialized modules:
- handlers/chat.rs (452 lines) - chat keyboard input
- handlers/modal.rs (316 lines) - modal dialogs
- handlers/chat_list.rs (142 lines) - chat list navigation
- handlers/search.rs (140 lines) - search functionality
- handlers/compose.rs (80 lines) - forward/reply/edit modes

Changes:
- main_input.rs: 1199→164 lines (removed 1035 lines, -86%)
- Preserved existing handlers: clipboard, global, profile
- Created clean router pattern in main_input.rs
- Fixed keybinding conflict: Ctrl+I→Ctrl+U for profile
- Fixed modifier handling in chat input (ignore Ctrl/Alt chars)
- Updated CONTEXT.md with refactoring metrics
- Updated ROADMAP.md: Phase 13 Etap 1 marked as DONE

Phase 13 Etap 1: COMPLETED (100%)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-06 00:43:52 +03:00
Mikhail Kilin
c5235de6e2 fix: disable notifications in config defaults
The previous commit only changed NotificationManager::new() but the config
layer was overriding it with default_notifications_enabled() = true.

Changed default_notifications_enabled() to return false, which is the
authoritative source for notification settings.

Modified:
- src/config/mod.rs - default_notifications_enabled: true -> false

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 22:01:25 +03:00
7ca9ea29ea Merge pull request 'refactor' (#19) from refactor into main
Some checks failed
CI / Check (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Clippy (push) Has been cancelled
CI / Build (macos-latest) (push) Has been cancelled
CI / Build (ubuntu-latest) (push) Has been cancelled
CI / Build (windows-latest) (push) Has been cancelled
Reviewed-on: #19
2026-02-05 18:58:39 +00:00
Mikhail Kilin
92cc89a2e6 feat: disable desktop notifications by default
Some checks failed
CI / Check (pull_request) Has been cancelled
CI / Format (pull_request) Has been cancelled
CI / Clippy (pull_request) Has been cancelled
CI / Build (macos-latest) (pull_request) Has been cancelled
CI / Build (ubuntu-latest) (pull_request) Has been cancelled
CI / Build (windows-latest) (pull_request) Has been cancelled
Changed NotificationManager::new() to set enabled: false
This completely disables all desktop notifications in the app.

Modified:
- src/notifications.rs:32 - enabled: true -> false

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 21:55:51 +03:00
Mikhail Kilin
7823efa724 fix: add retry delay to prevent infinite loop in message history loading
BUG FIX: When opening chat, only the last message was visible instead of
full history (100 messages).

Root cause:
In get_chat_history(), when TDLib returns fewer messages than requested on
first attempt (e.g., 1 message instead of 50), the retry logic would
`continue` without updating from_message_id. This caused the SAME request
to be repeated 20 times, loading the same single message repeatedly.

Code flow (BEFORE fix):
1. Request: get_chat_history(from_message_id=0, limit=50)
2. TDLib returns: 1 message (still syncing with server)
3. Check: received_count < chunk_size? YES → continue
4. Request: get_chat_history(from_message_id=0, limit=50)  // SAME request!
5. Repeat 20 times...
6. Result: Only 1 message loaded

Fix:
Added `sleep(Duration::from_millis(100))` before retry to give TDLib time
to sync with server between attempts. This prevents infinite retry loop and
allows TDLib to actually load more messages.

Code flow (AFTER fix):
1. Request: get_chat_history(from_message_id=0, limit=50)
2. TDLib returns: 1 message
3. Check: received_count < chunk_size? YES → sleep 100ms + continue
4. Request: get_chat_history(from_message_id=0, limit=50)
5. TDLib returns: 50 messages (had time to sync)
6. Result: Full history loaded

Also added missing imports:
- use tokio::time::{sleep, Duration};

Impact: Critical - users couldn't see message history when opening chats.

Related commit: 72c4a88 (which removed the sleep but didn't account for retry)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 21:52:08 +03:00
Mikhail Kilin
7dbb2209c8 fix: use char boundaries instead of byte indices for UTF-8 strings in notifications
PANIC FIX: Notification preview truncation was using byte indices (`[..147]`)
instead of char boundaries, causing panic when truncating UTF-8 strings
containing multi-byte characters (Cyrillic, emoji, etc.).

Error message:
"byte index 147 is not a char boundary; it is inside 'п' (bytes 146..148)"

Fix:
- Replace `beautified.len() > 150` with `beautified.chars().count() > MAX_PREVIEW_CHARS`
- Replace `&beautified[..147]` with `beautified.chars().take(MAX_PREVIEW_CHARS).collect()`
- Add constant MAX_PREVIEW_CHARS = 147 for clarity

This ensures we truncate at character boundaries, not byte boundaries,
preventing panics on multi-byte UTF-8 sequences.

Impact: Notifications for messages with Russian/emoji text crashed the app.

Root cause: Classic Rust UTF-8 indexing mistake - slicing by bytes instead
of characters.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 13:06:40 +03:00
Mikhail Kilin
5f1d715e8f fix: eliminate infinite recursion in TdClientTrait implementation
CRITICAL BUG FIX: Three methods in TdClientTrait impl were calling themselves recursively instead of delegating to actual implementations, causing stack overflow and application panic on startup.

Fixed methods:
1. user_cache_mut() - now returns &mut self.user_cache directly
2. sync_notification_muted_chats() - now delegates to notification_manager.sync_muted_chats()
3. handle_update() - now properly delegates to TdClient::handle_update() using qualified path

This bug caused the app to hang on "Инициализация TDLib..." screen and exit raw mode, displaying escape sequences ("CB52") on key presses when user tried to interact.

Root cause: Introduced in refactoring commit bd5e5be where trait implementations were created but incorrectly delegated to self.method() instead of accessing struct fields directly or using qualified path syntax.

Also added panic hook in main.rs to ensure terminal restoration on panic for better debugging experience.

Impact: Application completely broken - couldn't start. Stack overflow on first update.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 12:57:55 +03:00
Mikhail Kilin
bccf07501f docs: add Phase 13 - deep architecture refactoring plan
Added comprehensive plan for refactoring oversized files and God Objects
in the codebase. Current critical issues:

Critical Problems:
- input/main_input.rs: 1199 lines (largest file!)
- app/mod.rs: 1015 lines, 116 functions (God Object)
- ui/messages.rs: 893 lines
- tdlib/messages.rs: 833 lines
- config/mod.rs: 642 lines

Phase 13 Plan (7 stages):

Stage 1: Split input/main_input.rs (1199 → <200 lines)
- Create input/handlers/ directory
- handlers/chat.rs - open chat input handling (~300-400 lines)
- handlers/chat_list.rs - chat list input (~200-300 lines)
- handlers/compose.rs - edit/reply/forward modes (~200 lines)
- handlers/modal.rs - delete confirm, emoji picker (~150 lines)
- handlers/search.rs - search modes (~100 lines)
- main_input.rs becomes router only (<200 lines)

Stage 2: Reduce app/mod.rs (116 functions → traits)
- Create app/methods/ directory with traits:
  - NavigationMethods (~15 methods)
  - MessageMethods (~20 methods)
  - ComposeMethods (~15 methods)
  - SearchMethods (~5 methods)
  - ModalMethods (~10 methods)
- Keep only core in mod.rs (~30-40 methods)

Stage 3: Split ui/messages.rs (893 → <300 lines)
- Create ui/modals/ directory:
  - modals/delete_confirm.rs (~50 lines)
  - modals/emoji_picker.rs (~100 lines)
  - modals/search_modal.rs (~80 lines)
  - modals/profile_modal.rs (~100 lines)
- Create ui/compose_bar.rs (~150 lines)
- messages.rs keeps main layout (~300 lines)

Stage 4: Split tdlib/messages.rs (833 → 2 files)
- Create tdlib/messages/ directory:
  - messages/convert.rs - TDLib conversion (~500 lines)
  - messages/operations.rs - operations (~300 lines)

Stage 5: Split config/mod.rs (642 → 3 files)
- config/defaults.rs - all default_* functions (~100 lines)
- config/validation.rs - validation logic (~150 lines)
- config/loader.rs - file loading (~100 lines)
- mod.rs - struct definitions (~200-300 lines)

Stage 6: Code Duplication Cleanup
- Extract common handler logic
- Extract common UI components
- Apply DRY principle

Stage 7: Documentation Update
- Update CONTEXT.md with new structure
- Update PROJECT_STRUCTURE.md
- Add module-level documentation
- Create architecture diagram

Success Metrics:
Before: 4582 lines in 5 files
After: Same lines in ~20+ files
Benefits: Better readability, testability, maintainability, SRP compliance

Status: PLANNED (comprehensive refactoring plan documented)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 11:30:29 +03:00