OpenContacts/lib/clients/session_client.dart

49 lines
1.6 KiB
Dart
Raw Normal View History

2023-06-04 10:27:18 -04:00
import 'package:collection/collection.dart';
2024-07-15 00:23:04 -04:00
import 'package:OpenContacts/apis/session_api.dart';
import 'package:OpenContacts/clients/api_client.dart';
import 'package:OpenContacts/clients/settings_client.dart';
import 'package:OpenContacts/models/session.dart';
2023-06-04 10:27:18 -04:00
import 'package:flutter/foundation.dart';
class SessionClient extends ChangeNotifier {
final ApiClient apiClient;
final SettingsClient settingsClient;
2023-06-04 10:27:18 -04:00
Future<List<Session>>? _sessionsFuture;
SessionFilterSettings _filterSettings = SessionFilterSettings.empty();
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();
}
void initSessions() {
2023-06-04 10:27:18 -04:00
_sessionsFuture = SessionApi.getSessions(apiClient, filterSettings: _filterSettings).then(
(value) => value.sorted(
(a, b) => b.sessionUsers.length.compareTo(a.sessionUsers.length),
2023-06-04 10:27:18 -04:00
),
);
}
void reloadSessions() {
initSessions();
2023-06-04 10:27:18 -04:00
notifyListeners();
}
}