44 lines
1.7 KiB
Dart
44 lines
1.7 KiB
Dart
import 'package:friendly_map/modules/platform/platform.dart';
|
|
|
|
import 'archive_advice.dart';
|
|
import 'clock.dart';
|
|
import 'repos/interfaces.dart';
|
|
import 'settings_store.dart';
|
|
|
|
/// 대화가 많을 때 별도 저장을 권하고, 사용자가 고른 범위를 별도 저장으로 나눈다.
|
|
/// 지우지 않고 표시만 바꾸므로 언제든 되돌릴 수 있다.
|
|
class ArchiveService {
|
|
ArchiveService({
|
|
required MessageRepo messages,
|
|
required SettingsStore settings,
|
|
required Clock clock,
|
|
required DeviceStorageProbe probe,
|
|
}) : _messages = messages,
|
|
_settings = settings,
|
|
_clock = clock,
|
|
_probe = probe;
|
|
|
|
final MessageRepo _messages;
|
|
final SettingsStore _settings;
|
|
final Clock _clock;
|
|
final DeviceStorageProbe _probe;
|
|
|
|
/// 한 방에 대해 별도 저장을 권할지 본다.
|
|
Future<ArchiveAdvice> adviseRoom(String roomId) async => adviseArchive(
|
|
textBytes: await _messages.textBytes(roomId),
|
|
usedPercent: await _probe.usedPercent(),
|
|
settings: await _settings.load(),
|
|
);
|
|
|
|
/// 사용자가 고를 수 있는 전체 범위 (아직 나누지 않은 대화의 처음~끝). 대화가 없으면 null.
|
|
Future<(int, int)?> selectableSpan(String roomId) => _messages.span(roomId);
|
|
|
|
/// 고른 범위의 대화를 별도 저장으로 나눈다. 나눈 건수를 돌려준다.
|
|
Future<int> archiveRange(String roomId, int from, int to) =>
|
|
_messages.setArchivedBetween(roomId, from, to, _clock.now());
|
|
|
|
/// 고른 범위의 대화를 일반 저장으로 되돌린다.
|
|
Future<int> restoreRange(String roomId, int from, int to) =>
|
|
_messages.setArchivedBetween(roomId, from, to, _clock.now(), archived: false);
|
|
}
|