1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-24 22:09:21 +00:00
comunicmobile/lib/models/user.dart

67 lines
2.1 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';
/// 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;
final UserPageVisibility pageVisibility;
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;
const User({
2022-03-10 19:36:55 +00:00
required this.id,
required this.firstName,
required this.lastName,
required this.pageVisibility,
required this.virtualDirectory,
2022-03-10 19:36:55 +00:00
required this.accountImageURL,
required this.customEmojies,
2022-03-10 19:36:55 +00:00
}) : assert(id > 0);
/// 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
/// 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;
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);
}