fetch method

Fetch the active messages; on success, auto-show a session-start message.

Implementation

Future<List<NexusInAppMessage>> fetch() async {
  await _loadCounts();
  try {
    final res = await _http.post('/partner/inapp/active', {
      if (_id.distinctId != null) 'distinctId': _id.distinctId,
      'deviceKey': _id.deviceKey,
    });
    final list = (res?['messages'] as List?) ?? const [];
    _active = list.whereType<Map>().map((m) => NexusInAppMessage.fromJson(m.cast<String, dynamic>())).toList();
    NexusLog.debug('inapp: ${_active.length} active');
    if (_cfg.inAppAutoShow) _showNext(null);
  } catch (e) {
    NexusLog.warn('inapp fetch failed: $e');
  }
  return _active;
}