2023-06-04 10:27:18 -04:00
|
|
|
import 'package:collection/collection.dart';
|
2023-10-03 13:00:59 -04:00
|
|
|
import 'package:recon/apis/session_api.dart';
|
|
|
|
import 'package:recon/clients/api_client.dart';
|
|
|
|
import 'package:recon/clients/settings_client.dart';
|
|
|
|
import 'package:recon/models/session.dart';
|
2023-06-04 10:27:18 -04:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
|
|
|
|
class SessionClient extends ChangeNotifier {
|
|
|
|
final ApiClient apiClient;
|
2023-07-11 12:44:20 -04:00
|
|
|
final SettingsClient settingsClient;
|
2023-06-04 10:27:18 -04:00
|
|
|
|
|
|
|
Future<List<Session>>? _sessionsFuture;
|
|
|
|
|
|
|
|
SessionFilterSettings _filterSettings = SessionFilterSettings.empty();
|
|
|
|
|
2023-07-11 12:44:20 -04:00
|
|
|
SessionClient({required this.apiClient, required this.settingsClient}) {
|
|
|
|
_filterSettings = SessionFilterSettings(
|
|
|
|
name: "",
|
|
|
|
hostName: "",
|
|
|
|
includeEnded: settingsClient.currentSettings.sessionViewLastIncludeEnded.valueOrDefault,
|
|
|
|
includeIncompatible: settingsClient.currentSettings.sessionViewLastIncludeIncompatible.valueOrDefault,
|
|
|
|
minActiveUsers: settingsClient.currentSettings.sessionViewLastMinimumUsers.valueOrDefault,
|
|
|
|
includeEmptyHeadless: settingsClient.currentSettings.sessionViewLastIncludeEmpty.valueOrDefault,
|
|
|
|
);
|
|
|
|
}
|
2023-06-04 10:27:18 -04:00
|
|
|
|
|
|
|
SessionFilterSettings get filterSettings => _filterSettings;
|
|
|
|
|
|
|
|
Future<List<Session>>? get sessionsFuture => _sessionsFuture;
|
|
|
|
|
|
|
|
set filterSettings(value) {
|
|
|
|
_filterSettings = value;
|
|
|
|
reloadSessions();
|
|
|
|
}
|
|
|
|
|
2023-07-11 12:44:20 -04:00
|
|
|
void initSessions() {
|
2023-06-04 10:27:18 -04:00
|
|
|
_sessionsFuture = SessionApi.getSessions(apiClient, filterSettings: _filterSettings).then(
|
2023-07-11 12:44:20 -04:00
|
|
|
(value) => value.sorted(
|
|
|
|
(a, b) => b.sessionUsers.length.compareTo(a.sessionUsers.length),
|
2023-06-04 10:27:18 -04:00
|
|
|
),
|
|
|
|
);
|
2023-07-11 12:44:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void reloadSessions() {
|
|
|
|
initSessions();
|
2023-06-04 10:27:18 -04:00
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
}
|