feat: Update category server version handling in createCategory and CategoryDialog

This commit is contained in:
2026-05-22 11:26:41 +02:00
parent 2069de55ae
commit a31cc12b7e
2 changed files with 10 additions and 1 deletions
+9 -1
View File
@@ -58,12 +58,20 @@ class NoteRepository {
Future<void> createCategory(Category category) async {
debugPrint('createCategory called with: ${category.name}');
final DbCategory? existingCategory = await (
_database.select(_database.categories)..where((c) => c.id.equals(category.id))
).getSingleOrNull();
final int effectiveServerVersion = math.max(
category.serverVersion,
existingCategory?.serverVersion ?? category.serverVersion,
);
await _database.upsertCategory(
CategoriesCompanion.insert(
id: category.id,
name: category.name,
updatedAt: category.updatedAt,
serverVersion: const Value(0),
serverVersion: Value(effectiveServerVersion),
isDeleted: const Value(false),
isDirty: const Value(true),
colorValue: Value<int?>(category.colorValue),