veilidchat/lib/entities/user_login.dart

43 lines
1.4 KiB
Dart
Raw Normal View History

2023-07-26 18:20:29 +00:00
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
2023-07-09 04:07:21 +00:00
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:veilid/veilid.dart';
part 'user_login.freezed.dart';
part 'user_login.g.dart';
// Represents a currently logged in account
// User logins are stored in the user_logins tablestore table
// indexed by the accountMasterKey
@freezed
class UserLogin with _$UserLogin {
const factory UserLogin({
2023-07-22 01:25:27 +00:00
// Master record key for the user used to index the local accounts table
2023-07-23 03:29:10 +00:00
required TypedKey accountMasterRecordKey,
2023-07-09 04:07:21 +00:00
// The identity secret as unlocked from the local accounts table
2023-07-23 03:29:10 +00:00
required TypedSecret identitySecret,
2023-07-09 04:07:21 +00:00
// The time this login was most recently used
required Timestamp lastActive,
}) = _UserLogin;
2023-07-25 05:04:34 +00:00
factory UserLogin.fromJson(dynamic json) =>
_$UserLoginFromJson(json as Map<String, dynamic>);
2023-07-09 04:07:21 +00:00
}
// Represents a set of user logins
// and the currently selected account
@freezed
class ActiveLogins with _$ActiveLogins {
const factory ActiveLogins({
// The list of current logged in accounts
required IList<UserLogin> userLogins,
2023-07-22 01:25:27 +00:00
// The current selected account indexed by master record key
2023-07-09 04:07:21 +00:00
TypedKey? activeUserLogin,
}) = _ActiveLogins;
factory ActiveLogins.empty() =>
const ActiveLogins(userLogins: IListConst([]));
2023-07-25 05:04:34 +00:00
factory ActiveLogins.fromJson(dynamic json) =>
_$ActiveLoginsFromJson(json as Map<String, dynamic>);
2023-07-09 04:07:21 +00:00
}