2020-04-28 16:47:47 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2019-04-23 15:29:58 +00:00
|
|
|
import 'package:comunic/enums/user_page_visibility.dart';
|
2021-03-14 17:15:38 +00:00
|
|
|
import 'package:comunic/helpers/serialization/base_serialization_helper.dart';
|
2020-04-28 16:47:47 +00:00
|
|
|
import 'package:comunic/lists/custom_emojies_list.dart';
|
2021-03-17 16:14:53 +00:00
|
|
|
import 'package:comunic/utils/account_utils.dart';
|
2020-04-17 12:19:38 +00:00
|
|
|
import 'package:comunic/utils/ui_utils.dart';
|
2019-04-23 15:29:58 +00:00
|
|
|
|
|
|
|
/// Single user information
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
2021-03-14 17:15:38 +00:00
|
|
|
class User implements SerializableElement<User> {
|
|
|
|
final int id;
|
2022-03-10 19:36:55 +00:00
|
|
|
final String firstName;
|
|
|
|
final String lastName;
|
2019-04-23 15:29:58 +00:00
|
|
|
final UserPageVisibility pageVisibility;
|
2022-03-10 18:39:57 +00:00
|
|
|
final String? virtualDirectory;
|
2022-03-10 19:36:55 +00:00
|
|
|
final String accountImageURL;
|
2020-04-28 16:47:47 +00:00
|
|
|
final CustomEmojiesList customEmojies;
|
2019-04-23 15:29:58 +00:00
|
|
|
|
|
|
|
const User({
|
2022-03-10 19:36:55 +00:00
|
|
|
required this.id,
|
|
|
|
required this.firstName,
|
|
|
|
required this.lastName,
|
2022-03-10 18:39:57 +00:00
|
|
|
required this.pageVisibility,
|
|
|
|
required this.virtualDirectory,
|
2022-03-10 19:36:55 +00:00
|
|
|
required this.accountImageURL,
|
2022-03-10 18:39:57 +00:00
|
|
|
required this.customEmojies,
|
2022-03-10 19:36:55 +00:00
|
|
|
}) : assert(id > 0);
|
2019-04-23 15:29:58 +00:00
|
|
|
|
|
|
|
/// Get user full name
|
2022-03-11 15:21:35 +00:00
|
|
|
String get fullName => firstName + " " + lastName;
|
2019-04-24 09:24:05 +00:00
|
|
|
|
2019-05-01 15:52:41 +00:00
|
|
|
/// Get user display name
|
2020-04-17 12:19:38 +00:00
|
|
|
String get displayName => htmlDecodeCharacters(fullName);
|
2019-05-01 15:52:41 +00:00
|
|
|
|
2020-05-16 12:01:59 +00:00
|
|
|
bool get hasVirtualDirectory =>
|
2022-03-10 18:39:57 +00:00
|
|
|
virtualDirectory != null && virtualDirectory!.length > 0;
|
2020-05-16 12:01:59 +00:00
|
|
|
|
2021-03-17 16:14:53 +00:00
|
|
|
bool get isCurrentUser => id == userID();
|
|
|
|
|
2021-03-14 17:15:38 +00:00
|
|
|
Map<String, dynamic> toJson() => {
|
|
|
|
"id": id,
|
|
|
|
"firstName": firstName,
|
|
|
|
"lastName": lastName,
|
|
|
|
"pageVisibility": pageVisibility.toString(),
|
|
|
|
"virtualDirectory": virtualDirectory,
|
|
|
|
"accountImageURL": accountImageURL,
|
|
|
|
"customEmojies": customEmojies.toSerializableList()
|
|
|
|
};
|
2019-04-24 09:24:05 +00:00
|
|
|
|
2021-03-14 17:15:38 +00:00
|
|
|
User.fromJson(Map<String, dynamic> map)
|
|
|
|
: this.id = map["id"],
|
|
|
|
this.firstName = map["firstName"],
|
|
|
|
this.lastName = map["lastName"],
|
|
|
|
this.pageVisibility = UserPageVisibility.values.firstWhere(
|
|
|
|
(element) => element.toString() == map["pageVisibility"]),
|
|
|
|
this.virtualDirectory = map["virtualDirectory"],
|
|
|
|
this.accountImageURL = map["accountImageURL"],
|
2020-04-28 16:47:47 +00:00
|
|
|
this.customEmojies = CustomEmojiesList.fromSerializedList(
|
2021-03-14 17:15:38 +00:00
|
|
|
jsonDecode(map["customEmojies"]));
|
|
|
|
|
|
|
|
@override
|
2022-03-10 19:36:55 +00:00
|
|
|
int compareTo(User other) => id.compareTo(other.id);
|
2019-04-23 15:29:58 +00:00
|
|
|
}
|