fetchInterviewStatuses static method

Future<FetchResult> fetchInterviewStatuses(
  1. List<String> studyIds
)

Reads the per-participant InterviewStatus of one or more studies so the host can render in-app screens (offers, a resume affordance, a review state).

Asynchronous — the authoritative state lives in the Fireside backend and is read by the native SDK. Resolves a sealed FetchResult — the same result-channel shape as present — and never throws. On a successful read it carries FetchStatuses: a total map keyed by studyId where every requested id has an entry (a requested study that is not valid for this key and environment resolves to InterviewStatus.unknownStudy, not omission; a recognized study whose status this SDK version does not know decodes to InterviewStatus.unknown).

Otherwise it resolves FetchFailed carrying the shared FailureReason — never disguising the failure as data (no empty map for the not-ready states). Calling before init, or before identify set a valid userId, folds into FetchFailed with FailureReason.integrationError in every build, with the cause named on the debug-only guidance log; a reachability failure is FailureReason.networkIssue.

The returned Future completes on the main isolate, so the host may update UI directly from its result.

Implementation

static Future<FetchResult> fetchInterviewStatuses(
  List<String> studyIds,
) async {
  if (!_initialized) {
    _debugLog('Fireside.fetchInterviewStatuses called before init');
    return const FetchFailed(FailureReason.integrationError);
  }
  try {
    final tokens = await _bridge.fetchInterviewStatuses(studyIds);
    return FetchStatuses(resolveStatuses(tokens));
  } on PlatformException catch (e) {
    return FetchFailed(_fetchFailureReason(e.code));
  } catch (_) {
    // Never-throws contract: a MissingPluginException or malformed native payload
    // resolves to the unexpected sink, not an escaping Future.
    return const FetchFailed(FailureReason.unexpected);
  }
}