mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-30 00:36:28 +00:00
74 lines
2.3 KiB
Dart
74 lines
2.3 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:comunic/enums/user_page_visibility.dart';
|
|
import 'package:comunic/helpers/serialization/base_serialization_helper.dart';
|
|
import 'package:comunic/lists/custom_emojies_list.dart';
|
|
import 'package:comunic/utils/account_utils.dart';
|
|
import 'package:comunic/utils/ui_utils.dart';
|
|
import 'package:meta/meta.dart';
|
|
|
|
/// Single user information
|
|
///
|
|
/// @author Pierre HUBERT
|
|
|
|
class User implements SerializableElement<User> {
|
|
final int id;
|
|
final String firstName;
|
|
final String lastName;
|
|
final UserPageVisibility pageVisibility;
|
|
final String virtualDirectory;
|
|
final String accountImageURL;
|
|
final CustomEmojiesList customEmojies;
|
|
|
|
const User({
|
|
@required this.id,
|
|
@required this.firstName,
|
|
@required this.lastName,
|
|
@required this.pageVisibility,
|
|
@required this.virtualDirectory,
|
|
@required this.accountImageURL,
|
|
@required this.customEmojies,
|
|
}) : assert(id != null),
|
|
assert(id > 0),
|
|
assert(firstName != null),
|
|
assert(lastName != null),
|
|
assert(pageVisibility != null),
|
|
assert(accountImageURL != null),
|
|
assert(customEmojies != null);
|
|
|
|
/// Get user full name
|
|
String get fullName => firstName + " " + lastName;
|
|
|
|
/// Get user display name
|
|
String get displayName => htmlDecodeCharacters(fullName);
|
|
|
|
bool get hasVirtualDirectory =>
|
|
virtualDirectory != null && virtualDirectory.length > 0;
|
|
|
|
bool get isCurrentUser => id == userID();
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
"id": id,
|
|
"firstName": firstName,
|
|
"lastName": lastName,
|
|
"pageVisibility": pageVisibility.toString(),
|
|
"virtualDirectory": virtualDirectory,
|
|
"accountImageURL": accountImageURL,
|
|
"customEmojies": customEmojies.toSerializableList()
|
|
};
|
|
|
|
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"],
|
|
this.customEmojies = CustomEmojiesList.fromSerializedList(
|
|
jsonDecode(map["customEmojies"]));
|
|
|
|
@override
|
|
int compareTo(User other) => id.compareTo(other.id);
|
|
}
|