79 lines
2.6 KiB
Dart
79 lines
2.6 KiB
Dart
import 'package:friendly_map/modules/platform/platform.dart';
|
|
import 'package:friendly_map/modules/storage/storage.dart';
|
|
|
|
import 'change_bus.dart';
|
|
import 'friend_service.dart' show hideAllKey;
|
|
|
|
/// 설정과 별도 저장(보관) 관리.
|
|
class SettingsService {
|
|
SettingsService(this._storage, this._clock, DeviceStorageProbe probe, this._bus)
|
|
: _archive = ArchiveService(
|
|
messages: _storage.messages,
|
|
settings: _storage.settings,
|
|
clock: _clock,
|
|
probe: probe,
|
|
);
|
|
|
|
final Storage _storage;
|
|
final Clock _clock;
|
|
final ArchiveService _archive;
|
|
final ChangeBus _bus;
|
|
|
|
Future<AppSettings> load() => _storage.settings.load();
|
|
|
|
Future<void> save(AppSettings s) async {
|
|
await _storage.settings.save(s, _clock.now());
|
|
_bus.notify();
|
|
}
|
|
|
|
/// 값 하나만 바꾼다.
|
|
Future<AppSettings> update({
|
|
int? separateTextBytes,
|
|
int? storageUsagePercent,
|
|
String? exchangeMode,
|
|
int? recoveryShares,
|
|
int? recoveryThreshold,
|
|
}) async {
|
|
final s = await load();
|
|
var shares = recoveryShares ?? s.recoveryShares;
|
|
var need = recoveryThreshold ?? s.recoveryThreshold;
|
|
shares = shares.clamp(2, 9);
|
|
need = need.clamp(2, shares);
|
|
final next = AppSettings(
|
|
separateTextBytes: (separateTextBytes ?? s.separateTextBytes).clamp(64 * 1024, 512 * 1024 * 1024),
|
|
storageUsagePercent: (storageUsagePercent ?? s.storageUsagePercent).clamp(50, 95),
|
|
exchangeMode: exchangeMode ?? s.exchangeMode,
|
|
recoveryShares: shares,
|
|
recoveryThreshold: need,
|
|
);
|
|
await save(next);
|
|
return next;
|
|
}
|
|
|
|
/// "모든 정보 숨기기": 켜면 모르는 사람의 친구 요청을 받지 않는다.
|
|
Future<bool> hideAll() async => (await _storage.settings.getText(hideAllKey)) == 'true';
|
|
|
|
Future<void> setHideAll(bool value) async {
|
|
await _storage.settings.putText(hideAllKey, value ? 'true' : 'false', _clock.now());
|
|
_bus.notify();
|
|
}
|
|
|
|
/// 이 방을 별도 저장으로 나누라고 권할 만한지.
|
|
Future<ArchiveAdvice> adviseRoom(String roomId) => _archive.adviseRoom(roomId);
|
|
|
|
/// 별도 저장으로 나눌 수 있는 범위 (처음~끝). 대화가 없으면 null.
|
|
Future<(int, int)?> selectableSpan(String roomId) => _archive.selectableSpan(roomId);
|
|
|
|
Future<int> archiveRange(String roomId, int from, int to) async {
|
|
final n = await _archive.archiveRange(roomId, from, to);
|
|
_bus.notify();
|
|
return n;
|
|
}
|
|
|
|
Future<int> restoreRange(String roomId, int from, int to) async {
|
|
final n = await _archive.restoreRange(roomId, from, to);
|
|
_bus.notify();
|
|
return n;
|
|
}
|
|
}
|