Skip to content

refactor(client): split hooks/builders.rs by event category#49

Merged
BlindMaster24 merged 1 commit intomainfrom
devin/1776939922-split-hooks-builders
Apr 24, 2026
Merged

refactor(client): split hooks/builders.rs by event category#49
BlindMaster24 merged 1 commit intomainfrom
devin/1776939922-split-hooks-builders

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot commented Apr 23, 2026

Summary

client/hooks/builders.rs had grown to 574 lines containing ~60
on_* builder methods in one flat file. Split by event category
per the AGENTS.md guideline ("split files when a module grows
beyond ~400-600 lines or mixes multiple responsibilities"):

  • builders/mod.rs - module wiring + the catch-all on_event
    hook (keeps its existing spot because it is cross-cutting, not
    tied to a specific event category).
  • builders/connection.rs - connect success/fail/crypt/lost,
    max-payload updates, command processing/error/success.
  • builders/session.rs - login/logout/kick/user presence
    (logged-in, logged-out, user-update, joined, user-joined,
    user-left, text messages, user-state-change).
  • builders/directory.rs - channel/server/file/account/ban
    directory mutations.
  • builders/media.rs - audio block/video/desktop/voice-activation/
    hotkey/file-transfer/sound-device events.
  • builders/reconnect.rs - internal errors + auto-reconnect/
    auto-login/auto-join recovery pipeline.

Each submodule adds impl ClientHooks methods to the same
ClientHooks struct defined in the parent hooks/ module. No new
public items, no re-exports needed; external call sites
(ClientHooks::new().on_*(...)) continue to compile unchanged.

Structural only, no semantic change:

  • All public items keep their paths and visibilities.
  • Method bodies are byte-for-byte identical to the pre-split file.
  • No new imports beyond what each subcategory needs (e.g.
    session.rs uses ChannelId, TextMessage, User;
    media.rs and reconnect.rs only need Client, Message).

Net diff: builders.rs deleted (574 lines), six new files created
(mod.rs ~45, connection.rs ~75, session.rs ~90,
directory.rs ~105, media.rs ~235, reconnect.rs ~100). Git
detects builders.rs -> builders/mod.rs as the primary rename.

Local verification:

  • cargo fmt --all --check clean
  • cargo clippy --workspace --all-targets --all-features -- -D warnings clean
  • cargo test --workspace --all-features -> 287 passed / 0 failed

Review & Testing Checklist for Human

  • Spot-check that ClientHooks::new().on_*(...) chains still
    compile from crates/teamtalk/tests/ and any downstream
    crates. Each on_* method is a #[must_use] builder that
    stores a boxed closure in the matching optional field on
    ClientHooks and returns self; no runtime behavior has
    changed.
  • Confirm the category groupings are reasonable:
    connection = transport + command lifecycle;
    session = auth + presence + text;
    directory = channels/server/files/accounts/bans;
    media = audio/video/desktop/sound devices/hotkeys/voice
    activation/file transfer;
    reconnect = internal-error + auto-recovery pipeline.
    Boundaries are subjective; on_event is intentionally kept
    in builders/mod.rs as the one truly cross-cutting hook.
  • Verify feature-gated builds (--no-default-features,
    --features async, --features mock, --features all) still
    compile. Local cargo check --all-features is clean; CI
    covers the matrix.

Notes

Next PR in the P0 structural refactor queue after #44
(can_issue_logged_in_command dedup), #45 (poll_command_completion
extract), #46 (client/bus.rs split), #47 (bot/storage.rs split),
and #48 (bot/fsm.rs split). Branches from clean main,
independent of the other refactor PRs, so can be merged in any
order.

Upcoming: split types/entities/media_common.rs (458 lines) and
the client/backend.rs (1334 lines) + client/backend_mock.rs
(1101 lines) pair, then P1 API tweaks (jitter, StreamTypes,
SdkErrorCode, TimeoutKind, SecretString, indexed dispatch)
each with their own tests, then a big test-fill PR driven by
scripts/audit_teamtalk_coverage.py.

The pre-existing semver CI gate is expected to remain red;
release-plz handles the eventual version bump.

Link to Devin session: https://app.devin.ai/sessions/71fdd6196cb74723a2e277bb81993a9c
Requested by: @BlindMaster24


Open in Devin Review

client/hooks/builders.rs had grown to 574 lines with ~60 `on_*`
builder methods all listed in one flat file. Split by event category
per the AGENTS.md guideline (~400-600 lines or mixed responsibilities):

* builders/mod.rs - module wiring + the catch-all on_event hook.
* builders/connection.rs - connect/disconnect/max-payload/cmd-lifecycle.
* builders/session.rs - login/logout/kick/user presence + text messages.
* builders/directory.rs - channel/server/file/account/ban directory.
* builders/media.rs - audio block/video/desktop/hotkey/voice activation/
  file transfer/sound devices.
* builders/reconnect.rs - internal errors + auto-reconnect/login/join
  recovery pipeline.

Each submodule adds `impl ClientHooks` methods onto the same
ClientHooks struct defined in the parent hooks/ module. No new
public items, no re-exports needed; external call sites
(`ClientHooks::new().on_*(...)`) continue to compile unchanged.

Structural only, no semantic change. Method bodies are byte-for-byte
identical to the pre-split file.

Local verification:
* cargo fmt --all --check clean
* cargo clippy --workspace --all-targets --all-features -- -D warnings clean
* cargo test --workspace --all-features -> 287 passed / 0 failed
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown
Contributor Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@BlindMaster24 BlindMaster24 merged commit 234b706 into main Apr 24, 2026
11 of 12 checks passed
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