Skip to content

Feat/user discovery - #6

Merged
DanielJohn17 merged 6 commits into
mainfrom
feat/user-discovery
Oct 5, 2026
Merged

DanielJohn17 merged 6 commits into
mainfrom
feat/user-discovery

Conversation

@nathanaelcheramlak

Copy link
Copy Markdown
Collaborator

Summary
Adds username discovery and server-backed direct messaging, replacing the TUI’s local-only “New DM” placeholder.
Users can now press n, search by username prefix, select a person, and open their existing conversation or create a new one.
Changes

  • Adds authenticated GET /api/v1/users/search?q=... with case-insensitive prefix matching, query validation, rate limiting, and a 20-result limit.
  • Returns only public fields (id, name, username) and excludes the requesting user.
  • Treats SQL wildcard characters literally and ranks exact username matches first.
  • Connects the TUI to the existing conversation-creation endpoint, using real conversation and recipient IDs.
  • Adds debounced search, keyboard selection, loading/error/empty states, cancellation, and stale-response protection.
  • Prevents duplicate submissions and reuses existing conversations without duplicating sidebar entries or overwriting live chat metadata.
  • Fixes the existing SQL visibility/conflict-handling bug affecting first-time and concurrent DM creation.
  • Documents the discovery workflow and database integration-test requirements.
    User Flow
  1. Press Esc to leave typing mode, then n.
  2. Enter at least two characters of a username.
  3. Select a result with the up/down arrows.
  4. Press Enter to open or create the conversation.
  5. Press i to start typing, or Esc to cancel discovery.
    Testing
  • Each code commit passed make test against an isolated staged snapshot.
  • Final verification passed make fmt, make test GOFLAGS=-race, and make vet.
  • Both binaries built successfully using an explicit verification-only shared secret.
  • PostgreSQL integration tests passed during implementation, covering search ordering, literal wildcard matching, password-free column access, first-time creation, conversation reuse, and concurrent creation resolving to a single DM.
  • Added HTTP client and TUI model tests for cancellation, stale sessions/replies, duplicate submission prevention, error handling, and responsive rendering.

nathanaelcheramlak and others added 6 commits October 3, 2026 00:02
Return participants on first creation and reuse the winning conversation during concurrent inserts. Add PostgreSQL integration coverage for creation, reuse, and uniqueness.
Expose bounded, case-insensitive username-prefix search with public profile fields, literal wildcard matching, self-exclusion, and rate limiting. Cover validation, authorization, and SQL behavior.
Add context-aware search and conversation requests with session validation and recipient mapping. Keep cache updates in the app and cover HTTP errors, cancellation, and stale sessions.
Replace placeholder DMs with debounced search and real conversation creation. Guard stale results and duplicate submissions, preserve chat metadata, and cover selection, cancellation, and responsive layout.
Explain the New DM search flow, API scope, and disposable PostgreSQL requirements for integration coverage.
@DanielJohn17

Copy link
Copy Markdown
Owner

Added migration 20261005212029_add_idx_users_lower_username_pattern.sql creating a functional index on users (LOWER(username) text_pattern_ops).

This enables PostgreSQL to perform fast (\log N)$ B-Tree index range scans for LOWER(username) LIKE LOWER(...) ESCAPE '\' prefix queries instead of running a full table scan on every search keystroke.

@DanielJohn17
DanielJohn17 merged commit a77a2d0 into main Oct 5, 2026
1 check passed
@DanielJohn17
DanielJohn17 deleted the feat/user-discovery branch October 5, 2026 22:32
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.

2 participants