From 1fdb78b05dffb85d10a49b87f509656ddab383a4 Mon Sep 17 00:00:00 2001 From: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Date: Sat, 29 Mar 2025 12:01:19 +0530 Subject: [PATCH] rebase: convert string ids to byte uuids --- mobile/lib/extensions/string_extensions.dart | 8 ++++++++ .../repositories/sync_stream.repository.dart | 15 ++++++++------- mobile/pubspec.lock | 2 +- mobile/pubspec.yaml | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/mobile/lib/extensions/string_extensions.dart b/mobile/lib/extensions/string_extensions.dart index 67411013ee..293618df0b 100644 --- a/mobile/lib/extensions/string_extensions.dart +++ b/mobile/lib/extensions/string_extensions.dart @@ -1,3 +1,7 @@ +import 'dart:typed_data'; + +import 'package:uuid/parsing.dart'; + extension StringExtension on String { String capitalize() { return split(" ") @@ -29,3 +33,7 @@ extension DurationExtension on String { return int.parse(this); } } + +extension UUIDExtension on String { + Uint8List toUuidByte() => UuidParsing.parseAsByteList(this); +} diff --git a/mobile/lib/infrastructure/repositories/sync_stream.repository.dart b/mobile/lib/infrastructure/repositories/sync_stream.repository.dart index a765315452..f85b50c220 100644 --- a/mobile/lib/infrastructure/repositories/sync_stream.repository.dart +++ b/mobile/lib/infrastructure/repositories/sync_stream.repository.dart @@ -1,5 +1,6 @@ import 'package:drift/drift.dart'; import 'package:immich_mobile/domain/interfaces/sync_stream.interface.dart'; +import 'package:immich_mobile/extensions/string_extensions.dart'; import 'package:immich_mobile/infrastructure/entities/partner.entity.drift.dart'; import 'package:immich_mobile/infrastructure/entities/user.entity.drift.dart'; import 'package:immich_mobile/infrastructure/repositories/db.repository.dart'; @@ -17,7 +18,7 @@ class DriftSyncStreamRepository extends DriftDatabaseRepository Future deleteUsersV1(SyncUserDeleteV1 data) async { try { await _db.managers.userEntity - .filter((row) => row.id.equals(data.userId)) + .filter((row) => row.id.equals(data.userId.toUuidByte())) .delete(); return true; } catch (e, s) { @@ -35,7 +36,7 @@ class DriftSyncStreamRepository extends DriftDatabaseRepository try { await _db.userEntity.insertOne( - companion.copyWith(id: Value(data.id)), + companion.copyWith(id: Value(data.id.toUuidByte())), onConflict: DoUpdate((_) => companion), ); return true; @@ -51,8 +52,8 @@ class DriftSyncStreamRepository extends DriftDatabaseRepository await _db.managers.partnerEntity .filter( (row) => - row.sharedById.id.equals(data.sharedById) & - row.sharedWithId.id.equals(data.sharedWithId), + row.sharedById.id.equals(data.sharedById.toUuidByte()) & + row.sharedWithId.id.equals(data.sharedWithId.toUuidByte()), ) .delete(); return true; @@ -70,14 +71,14 @@ class DriftSyncStreamRepository extends DriftDatabaseRepository try { await _db.partnerEntity.insertOne( companion.copyWith( - sharedById: Value(data.sharedById), - sharedWithId: Value(data.sharedWithId), + sharedById: Value(data.sharedById.toUuidByte()), + sharedWithId: Value(data.sharedWithId.toUuidByte()), ), onConflict: DoUpdate((_) => companion), ); return true; } catch (e, s) { - _logger.severe('Error while processing SyncUserV1', e, s); + _logger.severe('Error while processing SyncPartnerV1', e, s); return false; } } diff --git a/mobile/pubspec.lock b/mobile/pubspec.lock index 7c8348726f..b82308e979 100644 --- a/mobile/pubspec.lock +++ b/mobile/pubspec.lock @@ -1798,7 +1798,7 @@ packages: source: hosted version: "3.1.4" uuid: - dependency: transitive + dependency: "direct main" description: name: uuid sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff diff --git a/mobile/pubspec.yaml b/mobile/pubspec.yaml index 73f60d9337..c9723b980d 100644 --- a/mobile/pubspec.yaml +++ b/mobile/pubspec.yaml @@ -60,6 +60,7 @@ dependencies: thumbhash: 0.1.0+1 timezone: ^0.9.4 url_launcher: ^6.3.1 + uuid: ^4.5.1 wakelock_plus: ^1.2.10 native_video_player: