selfprivacy.org.app/lib/logic/models/hive/user.dart

80 lines
1.8 KiB
Dart
Raw Normal View History

2020-12-03 18:52:53 +02:00
import 'dart:ui';
import 'package:equatable/equatable.dart';
2021-01-06 19:35:57 +02:00
import 'package:hive/hive.dart';
2022-09-04 14:29:05 +03:00
import 'package:selfprivacy/logic/api_maps/graphql_maps/schema/schema.graphql.dart';
2022-09-04 13:45:03 +03:00
import 'package:selfprivacy/logic/api_maps/graphql_maps/schema/users.graphql.dart';
import 'package:selfprivacy/utils/color_utils.dart';
2020-12-03 18:52:53 +02:00
2021-01-06 19:35:57 +02:00
part 'user.g.dart';
@HiveType(typeId: 1)
2020-12-03 18:52:53 +02:00
class User extends Equatable {
2022-05-24 21:55:39 +03:00
const User({
2021-03-15 17:39:44 +02:00
required this.login,
2022-09-04 14:29:05 +03:00
required this.type,
this.password,
this.sshKeys = const [],
this.isFoundOnServer = true,
this.note,
2020-12-03 18:52:53 +02:00
});
2022-09-04 13:45:03 +03:00
User.fromGraphQL(final Fragment$userFields user)
: this(
login: user.username,
2022-09-04 14:29:05 +03:00
type: UserType.fromGraphQL(user.userType),
2022-09-04 13:45:03 +03:00
sshKeys: user.sshKeys,
isFoundOnServer: true,
);
2021-01-06 19:35:57 +02:00
@HiveField(0)
2020-12-03 18:52:53 +02:00
final String login;
2021-03-15 17:39:44 +02:00
2021-01-06 19:35:57 +02:00
@HiveField(1)
final String? password;
2022-05-24 21:55:39 +03:00
@HiveField(2, defaultValue: [])
final List<String> sshKeys;
@HiveField(3, defaultValue: true)
final bool isFoundOnServer;
@HiveField(4)
final String? note;
2020-12-03 18:52:53 +02:00
2022-09-04 14:29:05 +03:00
@HiveField(5, defaultValue: UserType.normal)
final UserType type;
2020-12-03 18:52:53 +02:00
@override
List<Object?> get props => [login, password, sshKeys, isFoundOnServer, note];
2020-12-03 18:52:53 +02:00
Color get color => stringToColor(login);
2021-01-06 19:35:57 +02:00
2022-05-24 21:55:39 +03:00
@override
2022-09-05 07:34:47 +03:00
String toString() =>
'$login, ${isFoundOnServer ? 'found' : 'not found'}, ${sshKeys.length} ssh keys, note: $note';
2020-12-03 18:52:53 +02:00
}
2022-09-04 14:29:05 +03:00
@HiveType(typeId: 102)
enum UserType {
@HiveField(0)
root,
@HiveField(1)
primary,
@HiveField(2)
normal;
factory UserType.fromGraphQL(final Enum$UserType type) {
switch (type) {
case Enum$UserType.ROOT:
return root;
case Enum$UserType.PRIMARY:
return primary;
case Enum$UserType.NORMAL:
return normal;
case Enum$UserType.$unknown:
return normal;
}
}
}