Skip to content

Bug #90: AI buttons visible when consent off #17

@lllyys

Description

@lllyys

Bug #90: AI buttons visible when consent is off

Severity: Medium

Repro

  1. Open Settings → AI → toggle "Allow AI data sharing" OFF (revoke consent)
  2. Open any book in the reader
  3. Observe the toolbar

Expected

AI buttons (sparkles icon) should be hidden or show a consent prompt when tapped.

Actual

AI buttons remain visible in the toolbar. Tapping them opens the AI panel, which then fails at request time with a consent error.

Root Cause

AIReaderAvailability.isAvailable() only checks two gates:

  1. Feature flag: featureFlags.aiAssistant
  2. API key presence: KeychainService.readString(forAccount: AIService.apiKeyAccount)

It does not check AIConsentManager.hasConsent. Consent is only checked at request time inside AIService.sendRequest()/streamRequest(), which throws AIError.consentRequired.

This means the button appears even when the user has explicitly revoked consent. The user sees the panel, tries an action, and only then gets the consent prompt — a confusing UX.

Proper Fix

Add consent check to AIReaderAvailability.isAvailable():

static func isAvailable(...) -> Bool {
    featureFlags.aiAssistant
    && hasAPIKey(keychainService: keychainService)
    && AIConsentManager().hasConsent  // ← add this
}

Or: keep buttons visible but show consent prompt immediately on panel open (before any tab action).

Files

  • vreader/Services/AI/AIReaderAvailability.swift — availability check (missing consent gate)
  • vreader/Services/AI/AIConsentManager.swift — consent state in UserDefaults
  • vreader/Views/Reader/ReaderAICoordinator.swiftisAIAvailable computed property
  • vreader/Views/Reader/ReaderChromeBar.swift — conditional button rendering

Refs #6

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingseverity:mediumMedium severity

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions