drift(mobile): drift auth user sync
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import 'package:immich_mobile/domain/models/store.model.dart';
|
||||
import 'package:immich_mobile/domain/models/user.model.dart';
|
||||
|
||||
enum Setting<T> {
|
||||
// TODO: Remove UserDto after new store in drift
|
||||
currentUser<UserDto?>(StoreKey.currentUser, null),
|
||||
tilesPerRow<int>(StoreKey.tilesPerRow, 4),
|
||||
groupAssetsBy<int>(StoreKey.groupAssetsBy, 0),
|
||||
showStorageIndicator<bool>(StoreKey.storageIndicator, true),
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:immich_mobile/domain/models/user_metadata.model.dart';
|
||||
|
||||
// TODO: Rename to User once Isar is removed
|
||||
// TODO: Remove UserDto once Isar is removed
|
||||
class UserDto {
|
||||
final String id;
|
||||
final String email;
|
||||
@@ -44,19 +41,19 @@ class UserDto {
|
||||
@override
|
||||
String toString() {
|
||||
return '''User: {
|
||||
id: $id,
|
||||
email: $email,
|
||||
name: $name,
|
||||
isAdmin: $isAdmin,
|
||||
updatedAt: $updatedAt,
|
||||
profileImagePath: ${profileImagePath ?? '<NA>'},
|
||||
avatarColor: $avatarColor,
|
||||
memoryEnabled: $memoryEnabled,
|
||||
inTimeline: $inTimeline,
|
||||
isPartnerSharedBy: $isPartnerSharedBy,
|
||||
isPartnerSharedWith: $isPartnerSharedWith,
|
||||
quotaUsageInBytes: $quotaUsageInBytes,
|
||||
quotaSizeInBytes: $quotaSizeInBytes,
|
||||
id: $id,
|
||||
email: $email,
|
||||
name: $name,
|
||||
isAdmin: $isAdmin,
|
||||
updatedAt: $updatedAt,
|
||||
profileImagePath: ${profileImagePath ?? '<NA>'},
|
||||
avatarColor: $avatarColor,
|
||||
memoryEnabled: $memoryEnabled,
|
||||
inTimeline: $inTimeline,
|
||||
isPartnerSharedBy: $isPartnerSharedBy,
|
||||
isPartnerSharedWith: $isPartnerSharedWith,
|
||||
quotaUsageInBytes: $quotaUsageInBytes,
|
||||
quotaSizeInBytes: $quotaSizeInBytes,
|
||||
}''';
|
||||
}
|
||||
|
||||
@@ -127,80 +124,229 @@ quotaSizeInBytes: $quotaSizeInBytes,
|
||||
quotaSizeInBytes.hashCode;
|
||||
}
|
||||
|
||||
class PartnerUserDto {
|
||||
class User {
|
||||
final String id;
|
||||
final String name;
|
||||
final String email;
|
||||
final DateTime? deletedAt;
|
||||
final AvatarColor? avatarColor;
|
||||
|
||||
const User({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.email,
|
||||
this.deletedAt,
|
||||
this.avatarColor,
|
||||
});
|
||||
|
||||
User copyWith({
|
||||
String? id,
|
||||
String? name,
|
||||
String? email,
|
||||
DateTime? deletedAt,
|
||||
AvatarColor? avatarColor,
|
||||
}) {
|
||||
return User(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
email: email ?? this.email,
|
||||
deletedAt: deletedAt ?? this.deletedAt,
|
||||
avatarColor: avatarColor ?? this.avatarColor,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '''User {
|
||||
id: $id,
|
||||
name: $name,
|
||||
email: $email,
|
||||
deletedAt: ${deletedAt ?? "<NA>"},
|
||||
avatarColor: ${avatarColor ?? "<NA>"},
|
||||
}''';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(covariant User other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other.id == id &&
|
||||
other.name == name &&
|
||||
other.email == email &&
|
||||
other.deletedAt == deletedAt &&
|
||||
other.avatarColor == avatarColor;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return id.hashCode ^ name.hashCode ^ email.hashCode ^ deletedAt.hashCode ^ avatarColor.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
class AuthUser {
|
||||
final String id;
|
||||
final String name;
|
||||
final String email;
|
||||
final DateTime? deletedAt;
|
||||
final AvatarColor? avatarColor;
|
||||
final bool isAdmin;
|
||||
final String oauthId;
|
||||
final String? pinCode;
|
||||
final bool hasProfileImage;
|
||||
final DateTime profileChangedAt;
|
||||
final int? quotaSizeInBytes;
|
||||
final int quotaUsageInBytes;
|
||||
final String? storageLabel;
|
||||
|
||||
const AuthUser({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.email,
|
||||
this.deletedAt,
|
||||
this.avatarColor,
|
||||
required this.isAdmin,
|
||||
required this.oauthId,
|
||||
this.pinCode,
|
||||
required this.hasProfileImage,
|
||||
required this.profileChangedAt,
|
||||
this.quotaSizeInBytes,
|
||||
required this.quotaUsageInBytes,
|
||||
this.storageLabel,
|
||||
});
|
||||
|
||||
AuthUser copyWith({
|
||||
String? id,
|
||||
String? name,
|
||||
String? email,
|
||||
DateTime? deletedAt,
|
||||
AvatarColor? avatarColor,
|
||||
bool? isAdmin,
|
||||
String? oauthId,
|
||||
String? pinCode,
|
||||
bool? hasProfileImage,
|
||||
DateTime? profileChangedAt,
|
||||
int? quotaSizeInBytes,
|
||||
int? quotaUsageInBytes,
|
||||
String? storageLabel,
|
||||
}) {
|
||||
return AuthUser(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
email: email ?? this.email,
|
||||
deletedAt: deletedAt ?? this.deletedAt,
|
||||
avatarColor: avatarColor ?? this.avatarColor,
|
||||
isAdmin: isAdmin ?? this.isAdmin,
|
||||
oauthId: oauthId ?? this.oauthId,
|
||||
pinCode: pinCode ?? this.pinCode,
|
||||
hasProfileImage: hasProfileImage ?? this.hasProfileImage,
|
||||
profileChangedAt: profileChangedAt ?? this.profileChangedAt,
|
||||
quotaSizeInBytes: quotaSizeInBytes ?? this.quotaSizeInBytes,
|
||||
quotaUsageInBytes: quotaUsageInBytes ?? this.quotaUsageInBytes,
|
||||
storageLabel: storageLabel ?? this.storageLabel,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '''AuthUser {
|
||||
id: $id,
|
||||
name: $name,
|
||||
email: $email,
|
||||
deletedAt: ${deletedAt ?? "<NA>"},
|
||||
avatarColor: ${avatarColor ?? "<NA>"},
|
||||
isAdmin: $isAdmin,
|
||||
oauthId: $oauthId,
|
||||
pinCode: ${pinCode ?? "<NA>"},
|
||||
hasProfileImage: $hasProfileImage,
|
||||
profileChangedAt: $profileChangedAt,
|
||||
quotaSizeInBytes: ${quotaSizeInBytes ?? "<NA>"},
|
||||
quotaUsageInBytes: $quotaUsageInBytes,
|
||||
storageLabel: ${storageLabel ?? "<NA>"},
|
||||
}''';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(covariant AuthUser other) {
|
||||
if (identical(this, other)) return true;
|
||||
return other.id == id &&
|
||||
other.name == name &&
|
||||
other.email == email &&
|
||||
other.deletedAt == deletedAt &&
|
||||
other.avatarColor == avatarColor &&
|
||||
other.isAdmin == isAdmin &&
|
||||
other.oauthId == oauthId &&
|
||||
other.pinCode == pinCode &&
|
||||
other.hasProfileImage == hasProfileImage &&
|
||||
other.profileChangedAt == profileChangedAt &&
|
||||
other.quotaSizeInBytes == quotaSizeInBytes &&
|
||||
other.quotaUsageInBytes == quotaUsageInBytes &&
|
||||
other.storageLabel == storageLabel;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return id.hashCode ^
|
||||
name.hashCode ^
|
||||
email.hashCode ^
|
||||
deletedAt.hashCode ^
|
||||
avatarColor.hashCode ^
|
||||
isAdmin.hashCode ^
|
||||
oauthId.hashCode ^
|
||||
pinCode.hashCode ^
|
||||
hasProfileImage.hashCode ^
|
||||
profileChangedAt.hashCode ^
|
||||
quotaSizeInBytes.hashCode ^
|
||||
quotaUsageInBytes.hashCode ^
|
||||
storageLabel.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
class PartnerUser {
|
||||
final String id;
|
||||
final String email;
|
||||
final String name;
|
||||
final bool inTimeline;
|
||||
|
||||
final String? profileImagePath;
|
||||
|
||||
const PartnerUserDto({
|
||||
const PartnerUser({
|
||||
required this.id,
|
||||
required this.email,
|
||||
required this.name,
|
||||
required this.inTimeline,
|
||||
this.profileImagePath,
|
||||
});
|
||||
|
||||
PartnerUserDto copyWith({
|
||||
PartnerUser copyWith({
|
||||
String? id,
|
||||
String? email,
|
||||
String? name,
|
||||
bool? inTimeline,
|
||||
String? profileImagePath,
|
||||
}) {
|
||||
return PartnerUserDto(
|
||||
return PartnerUser(
|
||||
id: id ?? this.id,
|
||||
email: email ?? this.email,
|
||||
name: name ?? this.name,
|
||||
inTimeline: inTimeline ?? this.inTimeline,
|
||||
profileImagePath: profileImagePath ?? this.profileImagePath,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return <String, dynamic>{
|
||||
'id': id,
|
||||
'email': email,
|
||||
'name': name,
|
||||
'inTimeline': inTimeline,
|
||||
'profileImagePath': profileImagePath,
|
||||
};
|
||||
}
|
||||
|
||||
factory PartnerUserDto.fromMap(Map<String, dynamic> map) {
|
||||
return PartnerUserDto(
|
||||
id: map['id'] as String,
|
||||
email: map['email'] as String,
|
||||
name: map['name'] as String,
|
||||
inTimeline: map['inTimeline'] as bool,
|
||||
profileImagePath: map['profileImagePath'] != null ? map['profileImagePath'] as String : null,
|
||||
);
|
||||
}
|
||||
|
||||
String toJson() => json.encode(toMap());
|
||||
|
||||
factory PartnerUserDto.fromJson(String source) => PartnerUserDto.fromMap(json.decode(source) as Map<String, dynamic>);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PartnerUserDto(id: $id, email: $email, name: $name, inTimeline: $inTimeline, profileImagePath: $profileImagePath)';
|
||||
return '''PartnerUser {
|
||||
id: $id,
|
||||
email: $email,
|
||||
name: $name,
|
||||
inTimeline: $inTimeline,
|
||||
}''';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(covariant PartnerUserDto other) {
|
||||
bool operator ==(covariant PartnerUser other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other.id == id &&
|
||||
other.email == email &&
|
||||
other.name == name &&
|
||||
other.inTimeline == inTimeline &&
|
||||
other.profileImagePath == profileImagePath;
|
||||
return other.id == id && other.email == email && other.name == name && other.inTimeline == inTimeline;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return id.hashCode ^ email.hashCode ^ name.hashCode ^ inTimeline.hashCode ^ profileImagePath.hashCode;
|
||||
return id.hashCode ^ email.hashCode ^ name.hashCode ^ inTimeline.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,15 @@ class DriftPartnerService {
|
||||
this._partnerApiRepository,
|
||||
);
|
||||
|
||||
Future<List<PartnerUserDto>> getSharedWith(String userId) {
|
||||
Future<List<PartnerUser>> getSharedWith(String userId) {
|
||||
return _driftPartnerRepository.getSharedWith(userId);
|
||||
}
|
||||
|
||||
Future<List<PartnerUserDto>> getSharedBy(String userId) {
|
||||
Future<List<PartnerUser>> getSharedBy(String userId) {
|
||||
return _driftPartnerRepository.getSharedBy(userId);
|
||||
}
|
||||
|
||||
Future<List<PartnerUserDto>> getAvailablePartners(
|
||||
Future<List<PartnerUser>> getAvailablePartners(
|
||||
String currentUserId,
|
||||
) async {
|
||||
final otherUsers = await _driftPartnerRepository.getAvailablePartners(currentUserId);
|
||||
|
||||
@@ -108,7 +108,7 @@ class RemoteAlbumService {
|
||||
return _repository.getDateRange(albumId);
|
||||
}
|
||||
|
||||
Future<List<UserDto>> getSharedUsers(String albumId) {
|
||||
Future<List<User>> getSharedUsers(String albumId) {
|
||||
return _repository.getSharedUsers(albumId);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class SyncStreamService {
|
||||
bool get isCancelled => _cancelChecker?.call() ?? false;
|
||||
|
||||
Future<void> sync() {
|
||||
_logger.info("Remote sync request for userr");
|
||||
_logger.info("Remote sync request for user");
|
||||
DLog.log("Remote sync request for user");
|
||||
// Start the sync stream and handle events
|
||||
return _syncApiRepository.streamChanges(_handleEvents);
|
||||
@@ -120,6 +120,8 @@ class SyncStreamService {
|
||||
) async {
|
||||
_logger.fine("Processing sync data for $type of length ${data.length}");
|
||||
switch (type) {
|
||||
case SyncEntityType.authUserV1:
|
||||
return _syncStreamRepository.updateAuthUsersV1(data.cast());
|
||||
case SyncEntityType.userV1:
|
||||
return _syncStreamRepository.updateUsersV1(data.cast());
|
||||
case SyncEntityType.userDeleteV1:
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:immich_mobile/domain/models/setting.model.dart';
|
||||
import 'package:immich_mobile/domain/models/store.model.dart';
|
||||
import 'package:immich_mobile/domain/models/user.model.dart';
|
||||
import 'package:immich_mobile/domain/services/setting.service.dart';
|
||||
import 'package:immich_mobile/domain/services/store.service.dart';
|
||||
import 'package:immich_mobile/infrastructure/repositories/user.repository.dart';
|
||||
import 'package:immich_mobile/infrastructure/repositories/user_api.repository.dart';
|
||||
@@ -66,3 +68,28 @@ class UserService {
|
||||
return _isarUserRepository.deleteAll();
|
||||
}
|
||||
}
|
||||
|
||||
class DriftUserService {
|
||||
final DriftUserRepository _userRepository;
|
||||
final SettingsService _settingsService;
|
||||
|
||||
const DriftUserService(
|
||||
this._userRepository,
|
||||
this._settingsService,
|
||||
);
|
||||
|
||||
Future<User?> getMyUser() {
|
||||
// TODO: Remove UserDto after new store
|
||||
final isarCurrentUser = _settingsService.get(Setting.currentUser);
|
||||
|
||||
if (isarCurrentUser == null) {
|
||||
throw Exception('User must be login');
|
||||
}
|
||||
|
||||
return _userRepository.getById(isarCurrentUser.id);
|
||||
}
|
||||
|
||||
Future<List<User>> getAll() {
|
||||
return _userRepository.getAll();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user