1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-23 05:19:22 +00:00
comunicmobile/lib/models/user.dart

74 lines
2.3 KiB
Dart
Raw Normal View History

2020-04-28 16:47:47 +00:00
import 'dart:convert';
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';
import 'package:meta/meta.dart';
/// Single user information
///
/// @author Pierre HUBERT
2021-03-14 17:15:38 +00:00
class User implements SerializableElement<User> {
final int id;
final String firstName;
final String lastName;
final UserPageVisibility pageVisibility;
final String virtualDirectory;
final String accountImageURL;
2020-04-28 16:47:47 +00:00
final CustomEmojiesList customEmojies;
const User({
2021-03-14 17:15:38 +00:00
@required this.id,
@required this.firstName,
@required this.lastName,
@required this.pageVisibility,
@required this.virtualDirectory,
@required this.accountImageURL,
2020-04-28 16:47:47 +00:00
@required this.customEmojies,
}) : assert(id != null),
2021-03-14 17:15:38 +00:00
assert(id > 0),
assert(firstName != null),
assert(lastName != null),
assert(pageVisibility != null),
2019-04-24 11:56:56 +00:00
assert(accountImageURL != null),
2021-03-14 17:15:38 +00:00
assert(customEmojies != null);
/// Get user full name
String get fullName => firstName + " " + lastName;
2019-04-24 09:24:05 +00:00
/// Get user display name
2020-04-17 12:19:38 +00:00
String get displayName => htmlDecodeCharacters(fullName);
2020-05-16 12:01:59 +00:00
bool get hasVirtualDirectory =>
virtualDirectory != null && virtualDirectory.length > 0;
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
int compareTo(User other) => id.compareTo(other.id);
}