2022-02-03 17:06:44 +01:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:immich_mobile/shared/models/device_info.model.dart';
|
|
|
|
|
|
|
|
class AuthenticationState {
|
|
|
|
final String deviceId;
|
|
|
|
final String deviceType;
|
|
|
|
final String userId;
|
|
|
|
final String userEmail;
|
|
|
|
final bool isAuthenticated;
|
2022-05-29 05:35:45 +02:00
|
|
|
final String firstName;
|
|
|
|
final String lastName;
|
|
|
|
final bool isAdmin;
|
|
|
|
final bool isFirstLogin;
|
|
|
|
final String profileImagePath;
|
2022-02-03 17:06:44 +01:00
|
|
|
final DeviceInfoRemote deviceInfo;
|
|
|
|
|
|
|
|
AuthenticationState({
|
|
|
|
required this.deviceId,
|
|
|
|
required this.deviceType,
|
|
|
|
required this.userId,
|
|
|
|
required this.userEmail,
|
|
|
|
required this.isAuthenticated,
|
2022-05-29 05:35:45 +02:00
|
|
|
required this.firstName,
|
|
|
|
required this.lastName,
|
|
|
|
required this.isAdmin,
|
|
|
|
required this.isFirstLogin,
|
|
|
|
required this.profileImagePath,
|
2022-02-03 17:06:44 +01:00
|
|
|
required this.deviceInfo,
|
|
|
|
});
|
|
|
|
|
|
|
|
AuthenticationState copyWith({
|
|
|
|
String? deviceId,
|
|
|
|
String? deviceType,
|
|
|
|
String? userId,
|
|
|
|
String? userEmail,
|
|
|
|
bool? isAuthenticated,
|
2022-05-29 05:35:45 +02:00
|
|
|
String? firstName,
|
|
|
|
String? lastName,
|
|
|
|
bool? isAdmin,
|
|
|
|
bool? isFirstLoggedIn,
|
|
|
|
String? profileImagePath,
|
2022-02-03 17:06:44 +01:00
|
|
|
DeviceInfoRemote? deviceInfo,
|
|
|
|
}) {
|
|
|
|
return AuthenticationState(
|
|
|
|
deviceId: deviceId ?? this.deviceId,
|
|
|
|
deviceType: deviceType ?? this.deviceType,
|
|
|
|
userId: userId ?? this.userId,
|
|
|
|
userEmail: userEmail ?? this.userEmail,
|
|
|
|
isAuthenticated: isAuthenticated ?? this.isAuthenticated,
|
2022-05-29 05:35:45 +02:00
|
|
|
firstName: firstName ?? this.firstName,
|
|
|
|
lastName: lastName ?? this.lastName,
|
|
|
|
isAdmin: isAdmin ?? this.isAdmin,
|
|
|
|
isFirstLogin: isFirstLoggedIn ?? isFirstLogin,
|
|
|
|
profileImagePath: profileImagePath ?? this.profileImagePath,
|
2022-02-03 17:06:44 +01:00
|
|
|
deviceInfo: deviceInfo ?? this.deviceInfo,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
2022-05-29 05:35:45 +02:00
|
|
|
return 'AuthenticationState(deviceId: $deviceId, deviceType: $deviceType, userId: $userId, userEmail: $userEmail, isAuthenticated: $isAuthenticated, firstName: $firstName, lastName: $lastName, isAdmin: $isAdmin, isFirstLoggedIn: $isFirstLogin, profileImagePath: $profileImagePath, deviceInfo: $deviceInfo)';
|
2022-02-03 17:06:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
2022-05-29 05:35:45 +02:00
|
|
|
final result = <String, dynamic>{};
|
|
|
|
|
|
|
|
result.addAll({'deviceId': deviceId});
|
|
|
|
result.addAll({'deviceType': deviceType});
|
|
|
|
result.addAll({'userId': userId});
|
|
|
|
result.addAll({'userEmail': userEmail});
|
|
|
|
result.addAll({'isAuthenticated': isAuthenticated});
|
|
|
|
result.addAll({'firstName': firstName});
|
|
|
|
result.addAll({'lastName': lastName});
|
|
|
|
result.addAll({'isAdmin': isAdmin});
|
|
|
|
result.addAll({'isFirstLogin': isFirstLogin});
|
|
|
|
result.addAll({'profileImagePath': profileImagePath});
|
|
|
|
result.addAll({'deviceInfo': deviceInfo.toMap()});
|
|
|
|
|
|
|
|
return result;
|
2022-02-03 17:06:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
factory AuthenticationState.fromMap(Map<String, dynamic> map) {
|
|
|
|
return AuthenticationState(
|
|
|
|
deviceId: map['deviceId'] ?? '',
|
|
|
|
deviceType: map['deviceType'] ?? '',
|
|
|
|
userId: map['userId'] ?? '',
|
|
|
|
userEmail: map['userEmail'] ?? '',
|
|
|
|
isAuthenticated: map['isAuthenticated'] ?? false,
|
2022-05-29 05:35:45 +02:00
|
|
|
firstName: map['firstName'] ?? '',
|
|
|
|
lastName: map['lastName'] ?? '',
|
|
|
|
isAdmin: map['isAdmin'] ?? false,
|
|
|
|
isFirstLogin: map['isFirstLogin'] ?? false,
|
|
|
|
profileImagePath: map['profileImagePath'] ?? '',
|
2022-02-03 17:06:44 +01:00
|
|
|
deviceInfo: DeviceInfoRemote.fromMap(map['deviceInfo']),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
String toJson() => json.encode(toMap());
|
|
|
|
|
2022-06-25 22:12:47 +02:00
|
|
|
factory AuthenticationState.fromJson(String source) =>
|
|
|
|
AuthenticationState.fromMap(json.decode(source));
|
2022-02-03 17:06:44 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(Object other) {
|
|
|
|
if (identical(this, other)) return true;
|
|
|
|
|
|
|
|
return other is AuthenticationState &&
|
|
|
|
other.deviceId == deviceId &&
|
|
|
|
other.deviceType == deviceType &&
|
|
|
|
other.userId == userId &&
|
|
|
|
other.userEmail == userEmail &&
|
|
|
|
other.isAuthenticated == isAuthenticated &&
|
2022-05-29 05:35:45 +02:00
|
|
|
other.firstName == firstName &&
|
|
|
|
other.lastName == lastName &&
|
|
|
|
other.isAdmin == isAdmin &&
|
|
|
|
other.isFirstLogin == isFirstLogin &&
|
|
|
|
other.profileImagePath == profileImagePath &&
|
2022-02-03 17:06:44 +01:00
|
|
|
other.deviceInfo == deviceInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
int get hashCode {
|
|
|
|
return deviceId.hashCode ^
|
|
|
|
deviceType.hashCode ^
|
|
|
|
userId.hashCode ^
|
|
|
|
userEmail.hashCode ^
|
|
|
|
isAuthenticated.hashCode ^
|
2022-05-29 05:35:45 +02:00
|
|
|
firstName.hashCode ^
|
|
|
|
lastName.hashCode ^
|
|
|
|
isAdmin.hashCode ^
|
|
|
|
isFirstLogin.hashCode ^
|
|
|
|
profileImagePath.hashCode ^
|
2022-02-03 17:06:44 +01:00
|
|
|
deviceInfo.hashCode;
|
|
|
|
}
|
|
|
|
}
|