38 Commits

  • Merge upstream gramsrv/main into FromGram.
    Bring in configurable branding, premium stars, grammY store bot, admin
    localization, broadcast/gif catalog features, and related protocol sync.
    Preserve FromGram branding defaults, login notices, and broadcast bot.
    
    Co-authored-by: Cursor <cursoragent@cursor.com>
  • Ship FromGram WIP after upstream merges: branding, Stars subscriptions, and service inbox.
    Point public defaults at t.fromchat.ru, harden service-notification delivery, add Stars paid-invite subscriptions plus StarsTestBot, demote blank text_color emoji thumbs, and expose live OTP codes in the admin panel.
  • Merge upstream gramsrv/main into FromGram.
    Bring in approximate last-seen, multi-username toggles/reorder, Telegram Login, auth/privacy/PTS hardening, and related upstream fixes while keeping FromGram branding defaults where they do not conflict.
    
    Co-authored-by: Cursor <cursoragent@cursor.com>
  • feat: real multi-username collectible usernames (issue new, not tag existing) + Fake badge
    Per the real Telegram API (usernames: vector<Username>, editable/active
    flags), a collectible username is a brand-new SECOND username, never a
    relabeling of the account's existing one. Rebuilt around that:
    
    - collectible_usernames: added owner_user_id + active columns.
    - CollectibleUsername store: Issue() atomically claims the new
      username in the shared peer_usernames registry AND records pricing
      metadata, in one transaction; fails with ErrUsernameOccupied if
      taken. SetActive() lets the owner switch which of their usernames
      (editable or collectible) is active. ByOwners() batch-loads for
      serialization.
    - domain.User: CollectibleUsername/CollectibleUsernameActive fields,
      populated in users.Service.loadBaseUsersByIDs -- the one choke
      point all user loading goes through, so tgUser/tgSelfUser (which
      take domain.User by value, no DB access) pick it up for free
      without touching the dozens of call sites across the RPC layer.
    - tgUsernames/tgActiveUsername (convert_users.go): build the real
      usernames[] vector with correct editable/active flags, and the
      legacy top-level Username field mirrors whichever is active.
    - account.toggleUsername: implemented for real (previously only
      channels/bots had it, and only as no-op stubs) -- lets an owner
      switch their active username; only their own collectible username
      can be toggled.
    - admin.SetCollectibleUsername -> IssueCollectibleUsername: takes a
      recipient (user_id/username/phone) + NewUsername, not an existing
      username to tag.
    - New Fake badge (tg.User.fake): admin.SetFake, backed by a small
      standalone user_flags table (not a users table column, to avoid
      touching sqlc-generated code) and the same load-time enrichment
      pattern as the collectible username.
    - adminapi + web admin panel (proxy handlers, routes, account-page
      form) updated for the new issue/revoke shape and the Fake toggle.
    - cmd/telesrv-admin/readstore.go: AccountDetail gains Fake via a
      LEFT JOIN against user_flags (this read path is raw SQL, separate
      from sqlc, so no codegen involved there either).
    
    Verified: frontend builds clean (tsc + vite build). Go side gofmt
    only across every changed file -- same toolchain limitation as prior
    commits (go.mod needs 1.25, unavailable in the sandbox). This is the
    largest, most cross-cutting change of the session (new RPC method,
    DI wiring through main.go, user-serialization path) -- build and
    test thoroughly before deploying:
      go build ./...
      go test ./internal/rpc/... ./internal/admin/... ./internal/adminapi/... \
        ./internal/app/users/... ./internal/store/postgres/... ./cmd/telesrv-admin/...
  • feat: supply limits and released-by for plain (non-collectible) gifts
    Previously ImportStarGift (custom, non-official gifts) always set
    Limited=false and AvailabilityTotal/Remains=0 -- there was no way to
    give a plain gift a limited supply at all; only the official-import
    path (with IncludeCollectible) supported that.
    
    - ImportStarGiftRequest: new SupplyTotal (0 = unlimited; an unlimited
      gift can't later be upgraded to a collectible -- that stays a
      separate CreateCollectibleRevision step for supply-limited gifts),
      ReleasedByType/ReleasedByID (optional).
    - resolveReleasedByPeer: validates a 'released by' user or channel
      and requires it to already have a username, since clients always
      render 'Released by @username'.
    - Wired into StarGiftCatalogWrite: Limited = SupplyTotal > 0,
      AvailabilityTotal/AvailabilityRemains = SupplyTotal, ReleasedBy =
      the validated peer. The store layer already persisted and served
      these fields for other gift types -- this was purely an admin-layer
      gap.
    - Web panel: supply + released-by (user/channel + ID) fields on the
      custom gift upload form.
    
    Verified: frontend builds clean (tsc + vite build). Go side gofmt
    only, same toolchain limitation as prior commits -- test locally:
      go test ./internal/admin/...
  • feat: implement fragment.getCollectibleInfo (collectible/NFT usernames)
    Previously the server had zero support for collectible usernames --
    only the TL types existed (unused) in the vendored td library, and
    the Android client's Fragment-username UI had nothing to talk to.
    
    - deploy/migrations: new collectible_usernames table.
    - internal/domain/collectible_username.go: CollectibleUsername type.
    - internal/store/postgres/collectible_username.go: Get/Set/Delete.
    - internal/rpc/fragment.go: fragment.getCollectibleInfo RPC handler,
      registered in router.go. Ordinary (non-collectible) usernames
      return COLLECTIBLE_INFO_INVALID, which is the expected/normal case
      -- the client simply doesn't show the collectible badge then.
    - internal/rpc/deps.go: new CollectibleUsernameService dependency.
    - internal/admin/service.go: SetCollectibleUsername /
      RemoveCollectibleUsername admin actions. Currency/Amount (e.g.
      YUT/1000) and CryptoCurrency/CryptoAmount are purely
      informational display fields -- nothing is charged; this only
      changes what fragment.getCollectibleInfo reports to clients.
    - internal/adminapi/server.go: POST /v1/usernames/set-collectible
      and /v1/usernames/remove-collectible.
    - cmd/telesrv/main.go: wires CollectibleUsernameStore into both
      rpc.Deps and admin.Dependencies.
    - cmd/telesrv-admin: web panel proxy handlers + routes, and a
      currency/amount form with set/remove buttons on the account page
      (web/dist rebuilt since it's go:embed'd into the binary).
    
    Verification: frontend fully builds ('npx tsc --noEmit' and
    'npm run build' both pass). The Go side could NOT be compiled in the
    authoring sandbox -- go.mod requires go 1.25, only 1.22/1.23 were
    installable via apt, and building go1.25 from source in-sandbox kept
    getting killed between tool calls before finishing. All new Go code
    was gofmt-verified and manually cross-checked line-by-line against
    the actual vendored github.com/iamxvbaba/td source (exact struct/
    field names, semantic method constant, existing registerRPC call
    patterns) rather than written from memory. Still: build and test
    this locally before deploying --
    
      go build ./...
      go test ./internal/rpc/... ./internal/admin/... ./internal/adminapi/... ./internal/store/postgres/... ./cmd/telesrv-admin/...
    
    -- this is meaningfully more new/untested surface area (new DB
    table, new RPC method, cross-cutting DI wiring in main.go) than the
    previous two commits.
  • feat: add grant-star-gift to admin web panel
    Wires the new backend endpoint (POST /v1/accounts/grant-star-gift,
    added in 6fe4dc9) into the telesrv-admin web UI:
    
    - cmd/telesrv-admin/server.go: proxy handler at
      POST /api/actions/grant-star-gift, mirroring the existing
      grant-stars/grant-premium handlers.
    - AccountDetailPage.tsx: gift ID + optional price-label (info-only,
      never charged) fields and a Grant gift button on the account page.
    - i18n.tsx: en/zh/ru strings for the new fields.
    - web/dist: rebuilt bundle, since the Go binary embeds this
      directory at compile time (go:embed web/dist) -- without
      rebuilding, the running admin panel would keep the old UI even
      after a server rebuild.
    
    Verified: 'npx tsc --noEmit' and 'npm run build' both pass cleanly
    in web/. The Go side (server.go) is only gofmt-checked, not
    compiled -- same toolchain limitation as the previous commit,
    build/test it locally before deploying.
  • feat: add NFT usernames and bot verification (#22)
    Implements collectible usernames, official verification workflows, and third-party bot verification after maintainer protocol and migration review.
    
    The composite activity/moderation rating remains an admin-only read model; Telegram Stars Rating wire fields stay unset pending a dedicated official-semantics implementation.
    
    Reviewed-Head: 2796345775ea0f908fb7734601e5e1dee4b653b9
    Original-Head: fa082b892fd5180c9c9bc53c81c21cf5d250a75b
    
    Co-authored-by: Egor Egorov <business.egor.sg@gmail.com>
  • fix(admin): close PR review blockers
    Keep bot credentials out of durable command results, fail bot deletion closed when session revocation fails, reject invalid scam/fake states at every write boundary, and make direct collectible grants a single replayable PostgreSQL aggregate.
    
    Also lock admin gift sender/message limits and add regression coverage for rollback, replay, moderation constraints, and credential redaction.
  • fix(admin): resolve moderation, gift, and admin-panel bugs from QA
    - scam/fake: enforce mutual exclusivity (scam precedence) at TL conversion, admin command, and UI toggles; both flags could render as neither
    - scam/fake flicker: persist scam/fake in the Redis user base cache so cache hits no longer drop the flags
    - getSavedStarGifts: hidden (unsaved) gifts are now force-excluded for non-owner viewers; same guard for get-by-ref
    - convertStarGift: map already-upgraded/owner-invalid/unavailable to a clean client error instead of 500
    - channel force-settings: send only changed fields (partial patch) and re-sync toggles after reload, so one setting no longer resets another
    - give gifts: removed custom collectible numbers (auto sequential only); locked sender to the system account 777000
    - give gifts UI: fixed picker card spacing/right gap; static (hover-play) Lottie previews on emoji + picker to stop render lag; fixed emoji ID field overflow
  • admin: gift granting, collectible attribute/number control, and Layer 228 moderation tools
    Admin console additions (Layer 228):
    - Give Gifts: dedicated tab with sorted Lottie/TGS gift picker + inline form; grant any catalog gift to a user/channel from 777000 (no charge)
    - Upgraded/collectible delivery: mint a unique gift with admin-selected model/pattern/backdrop and custom number, or random/auto (DB FK + UNIQUE(gift_id,num) enforce invariants)
    - SCAM/FAKE flags for users/channels (migration 0136) with configurable profile warning (TELESRV_SCAM_WARNING/TELESRV_FAKE_WARNING)
    - Support toggle, force channel settings incl. gigagroup (migration 0137), username management, cosmetic color/emoji-status
    - Emoji admin tab (custom emoji list + document IDs + Lottie/TGS preview)
    - Bot management; soft UI / dark theme
    Wired through Router -> admin.Service -> adminapi -> BFF -> React panel (en/zh/ru).
  • feat(admin): bot management (list, verify, create, delete)
    - Add a Bots admin tab: list/search bots with a dedicated read query
      (users.is_bot, excluded from the accounts list), showing owner and
      system-vs-user type
    - Create system bots from the admin via a new bot.create command that
      reuses the existing bot provisioning flow; the token is shown once
    - Delete user-created bots via a new bot.delete command backed by a
      dedicated Postgres DeleteBotAccount (revokes sessions, purges private
      state, releases username, drops the bots row, tombstones the user);
      system service bots are rejected
    - Verified badge toggling reuses the existing set-verified command
    - All write paths go through the dry-run/confirm + audit command pipeline
    - Rebuild dist bundle
  • feat(admin-ui): softer pre-material styling and dark theme
    - Rebuild admin console styling on semantic CSS variables (light + dark palettes)
    - Soften palette, shadows and corner radii for a calmer pre-material look
    - Add theme provider with light/dark toggle in the topbar and login header
    - Respect prefers-color-scheme and persist choice, with anti-FOUC inline script
    - Polish Russian translations (yo letters, consistent 'Звёзды' currency, wording)
    - Rebuild dist bundle to match the updated source
  • feat: sync visible product branding
    Sync telesrv c779c48 (feat(branding): unify visible product naming).
    
    Skipped private www files and preserved public README files; mapped orange appearance seed names to public default names.
  • feat: sync official star gift lifecycle tooling
    Sync telesrv 4c0e2d9 (feat: complete official star gift lifecycle and admin tooling).
    
    Public adjustments: skipped private docs/deploy-nginx/README source changes, kept iamxvbaba/td public dependency, replaced local/private sample IP and orange seed label.
  • Refactor admin config to use centralized config package
    - Import and use internal/config.Load() in telesrv-admin instead of manual env parsing
    - Remove envOr() helper function (now consolidated in config package)
    - Add comprehensive .env.example documentation for Admin API/UI settings including:
      - TELESRV_ADMIN_API_TOKEN
      - TELESRV_ADMIN_UI_PASSWORD and TELESRV_ADMIN_UI_TOKEN
      - TELESRV_ADMIN_SESSION_KEY with security guidance
      - Optional address configuration parameters
    - Improve config validation error handling