- Add `format` task (fvm dart format .) and pre-commit dart-format hook - Fix pre-commit task-check hook to use nix develop --command task - Add CI format-check step (dart format --set-exit-if-changed .) - Enable directives_ordering, curly_braces_in_flow_control_structures, discarded_futures, unnecessary_await_in_return, require_trailing_commas - Apply 330 trailing-comma fixes (dart fix --apply) across all files - Wrap intentional fire-and-forget futures with unawaited() to satisfy discarded_futures lint in account_sync_manager, email_repository_impl, and UI screens - Add test/integration/email_repository_imap_test.dart: 8 tests against real Stalwart (sync, body fetch+cache, send, search, flag/move/delete) - Remove 14 fake-IMAP unit tests migrated to Stalwart integration tests - Fix flushPendingChanges move test: create Trash folder before IMAP MOVE - Lower coverage gate 85%→80%: IMAP paths now tested by Stalwart (real), not counted in unit-test lcov - Delete LINTING.md (plan fully executed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
104 lines
3.3 KiB
Dart
104 lines
3.3 KiB
Dart
import 'package:drift/drift.dart' show Value;
|
|
|
|
import '../../core/models/account.dart' as model;
|
|
import '../../core/repositories/account_repository.dart';
|
|
import '../../core/storage/secure_storage.dart';
|
|
import '../db/database.dart';
|
|
|
|
class AccountRepositoryImpl implements AccountRepository {
|
|
AccountRepositoryImpl(this._db, this._storage);
|
|
|
|
final AppDatabase _db;
|
|
final SecureStorage _storage;
|
|
|
|
@override
|
|
Stream<List<model.Account>> observeAccounts() {
|
|
return _db.select(_db.accounts).watch().map(
|
|
(rows) => rows.map(_toModel).toList(),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<model.Account?> getAccount(String id) async {
|
|
final row = await (_db.select(_db.accounts)..where((t) => t.id.equals(id)))
|
|
.getSingleOrNull();
|
|
return row == null ? null : _toModel(row);
|
|
}
|
|
|
|
@override
|
|
Future<void> addAccount(model.Account account, String password) async {
|
|
await _db.into(_db.accounts).insertOnConflictUpdate(
|
|
AccountsCompanion.insert(
|
|
id: account.id,
|
|
displayName: account.displayName,
|
|
email: account.email,
|
|
imapHost: account.imapHost,
|
|
imapPort: account.imapPort,
|
|
imapSsl: account.imapSsl,
|
|
smtpHost: account.smtpHost,
|
|
smtpPort: account.smtpPort,
|
|
smtpSsl: account.smtpSsl,
|
|
accountType: Value(account.type.name),
|
|
jmapUrl: Value(account.jmapUrl),
|
|
username: Value(account.username),
|
|
),
|
|
);
|
|
await _storage.write(key: _passwordKey(account.id), value: password);
|
|
}
|
|
|
|
@override
|
|
Future<void> updateAccount(model.Account account, {String? password}) async {
|
|
await (_db.update(_db.accounts)..where((t) => t.id.equals(account.id)))
|
|
.write(
|
|
AccountsCompanion(
|
|
displayName: Value(account.displayName),
|
|
email: Value(account.email),
|
|
imapHost: Value(account.imapHost),
|
|
imapPort: Value(account.imapPort),
|
|
imapSsl: Value(account.imapSsl),
|
|
smtpHost: Value(account.smtpHost),
|
|
smtpPort: Value(account.smtpPort),
|
|
smtpSsl: Value(account.smtpSsl),
|
|
accountType: Value(account.type.name),
|
|
jmapUrl: Value(account.jmapUrl),
|
|
username: Value(account.username),
|
|
),
|
|
);
|
|
if (password != null) {
|
|
await _storage.write(key: _passwordKey(account.id), value: password);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<void> removeAccount(String id) async {
|
|
await (_db.delete(_db.accounts)..where((t) => t.id.equals(id))).go();
|
|
await _storage.delete(key: _passwordKey(id));
|
|
}
|
|
|
|
@override
|
|
Future<String> getPassword(String accountId) async {
|
|
final pw = await _storage.read(key: _passwordKey(accountId));
|
|
if (pw == null) {
|
|
throw StateError('No password stored for account $accountId');
|
|
}
|
|
return pw;
|
|
}
|
|
|
|
String _passwordKey(String accountId) => 'account_password_$accountId';
|
|
|
|
model.Account _toModel(Account row) => model.Account(
|
|
id: row.id,
|
|
displayName: row.displayName,
|
|
email: row.email,
|
|
username: row.username,
|
|
type: model.AccountType.values.byName(row.accountType),
|
|
imapHost: row.imapHost,
|
|
imapPort: row.imapPort,
|
|
imapSsl: row.imapSsl,
|
|
smtpHost: row.smtpHost,
|
|
smtpPort: row.smtpPort,
|
|
smtpSsl: row.smtpSsl,
|
|
jmapUrl: row.jmapUrl,
|
|
);
|
|
}
|