## Summary Closes #377 - Adds a new `ImageTrustedSenders` Drift table (schema v37) that stores email addresses for which remote images are loaded automatically (per device, not per account) - When the user taps "Load remote images", the sender's address is saved and a 3-second snackbar appears with a "Settings" hyperlink to undo the choice in preferences - Both `EmailDetailScreen` and `ThreadDetailScreen` check the trusted senders list on open and auto-load images for known senders - The Preferences screen gains a new "Trusted image senders" section listing all saved senders with individual remove buttons ## Test plan - [x] `dart run build_runner build` regenerates `database.g.dart` cleanly (schema v37) - [x] `flutter analyze` — no issues - [x] Migration test updated: checks `image_trusted_senders` table exists after upgrade and fresh install - [x] `FakeUserPreferencesRepository` updated with three new interface methods - [x] All 490 unit + widget tests pass (1 pre-existing golden test failure unrelated to this change) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Thomas SharedInbox <sharedinbox@thomas-guettler.de> Reviewed-on: https://codeberg.org/guettli/sharedinbox/pulls/378
96 lines
3.0 KiB
Dart
96 lines
3.0 KiB
Dart
import 'package:drift/drift.dart';
|
|
import 'package:sharedinbox/core/models/user_preferences.dart' as pref;
|
|
import 'package:sharedinbox/core/repositories/user_preferences_repository.dart';
|
|
import 'package:sharedinbox/data/db/database.dart';
|
|
|
|
class UserPreferencesRepositoryImpl implements UserPreferencesRepository {
|
|
UserPreferencesRepositoryImpl(this._db);
|
|
|
|
final AppDatabase _db;
|
|
static const _rowId = 1;
|
|
|
|
@override
|
|
Stream<pref.UserPreferences> observePreferences() {
|
|
return (_db.select(
|
|
_db.userPreferences,
|
|
)..where((t) => t.id.equals(_rowId)))
|
|
.watchSingleOrNull()
|
|
.map(_rowToModel);
|
|
}
|
|
|
|
@override
|
|
Future<void> updateMenuPosition(pref.MenuPosition position) async {
|
|
await _db.into(_db.userPreferences).insertOnConflictUpdate(
|
|
UserPreferencesCompanion(
|
|
id: const Value(_rowId),
|
|
menuPosition: Value(position.name),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<void> updateMailViewButtonPosition(pref.MenuPosition position) async {
|
|
await _db.into(_db.userPreferences).insertOnConflictUpdate(
|
|
UserPreferencesCompanion(
|
|
id: const Value(_rowId),
|
|
mailViewButtonPosition: Value(position.name),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<void> updateAfterMailViewAction(
|
|
pref.AfterMailViewAction action,
|
|
) async {
|
|
await _db.into(_db.userPreferences).insertOnConflictUpdate(
|
|
UserPreferencesCompanion(
|
|
id: const Value(_rowId),
|
|
afterMailViewAction: Value(action.name),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Stream<List<String>> observeTrustedImageSenders() {
|
|
return (_db.select(_db.imageTrustedSenders)
|
|
..orderBy([(t) => OrderingTerm.desc(t.addedAt)]))
|
|
.watch()
|
|
.map((rows) => rows.map((r) => r.senderEmail).toList());
|
|
}
|
|
|
|
@override
|
|
Future<void> addTrustedImageSender(String senderEmail) async {
|
|
await _db.into(_db.imageTrustedSenders).insertOnConflictUpdate(
|
|
ImageTrustedSendersCompanion(
|
|
senderEmail: Value(senderEmail.toLowerCase()),
|
|
addedAt: Value(DateTime.now()),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<void> removeTrustedImageSender(String senderEmail) async {
|
|
await (_db.delete(_db.imageTrustedSenders)
|
|
..where((t) => t.senderEmail.equals(senderEmail.toLowerCase())))
|
|
.go();
|
|
}
|
|
|
|
static pref.UserPreferences _rowToModel(UserPreferencesRow? row) {
|
|
if (row == null) return const pref.UserPreferences();
|
|
return pref.UserPreferences(
|
|
menuPosition: pref.MenuPosition.values.firstWhere(
|
|
(e) => e.name == row.menuPosition,
|
|
orElse: () => pref.MenuPosition.bottom,
|
|
),
|
|
mailViewButtonPosition: pref.MenuPosition.values.firstWhere(
|
|
(e) => e.name == row.mailViewButtonPosition,
|
|
orElse: () => pref.MenuPosition.bottom,
|
|
),
|
|
afterMailViewAction: pref.AfterMailViewAction.values.firstWhere(
|
|
(e) => e.name == row.afterMailViewAction,
|
|
orElse: () => pref.AfterMailViewAction.nextMessage,
|
|
),
|
|
);
|
|
}
|
|
}
|