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';
|
2019-04-24 09:24:05 +00:00
|
|
|
import 'package:comunic/helpers/database/database_contract.dart';
|
2020-04-28 16:47:47 +00:00
|
|
|
import 'package:comunic/lists/custom_emojies_list.dart';
|
2019-04-24 11:56:56 +00:00
|
|
|
import 'package:comunic/models/cache_model.dart';
|
2020-04-17 12:19:38 +00:00
|
|
|
import 'package:comunic/utils/ui_utils.dart';
|
2019-04-23 15:29:58 +00:00
|
|
|
import 'package:meta/meta.dart';
|
|
|
|
|
|
|
|
/// Single user information
|
|
|
|
///
|
|
|
|
/// @author Pierre HUBERT
|
|
|
|
|
2019-04-24 11:56:56 +00:00
|
|
|
class User extends CacheModel {
|
2019-04-23 15:29:58 +00:00
|
|
|
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;
|
2019-04-23 15:29:58 +00:00
|
|
|
|
|
|
|
const User({
|
2019-04-24 11:56:56 +00:00
|
|
|
@required int id,
|
2019-04-23 15:29:58 +00:00
|
|
|
@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,
|
2019-04-23 15:29:58 +00:00
|
|
|
}) : assert(id != null),
|
|
|
|
assert(firstName != null),
|
|
|
|
assert(lastName != null),
|
|
|
|
assert(pageVisibility != null),
|
2019-04-24 11:56:56 +00:00
|
|
|
assert(accountImageURL != null),
|
2020-04-28 16:47:47 +00:00
|
|
|
assert(customEmojies != null),
|
2019-04-24 11:56:56 +00:00
|
|
|
super(id: id);
|
2019-04-23 15:29:58 +00:00
|
|
|
|
|
|
|
/// Get user full name
|
|
|
|
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 =>
|
|
|
|
virtualDirectory != null && virtualDirectory.length > 0;
|
|
|
|
|
2019-04-24 09:24:05 +00:00
|
|
|
Map<String, dynamic> toMap() {
|
|
|
|
return {
|
|
|
|
UserTableContract.C_ID: id,
|
|
|
|
UserTableContract.C_FIRST_NAME: firstName,
|
|
|
|
UserTableContract.C_LAST_NAME: lastName,
|
|
|
|
UserTableContract.C_VISIBILITY: pageVisibility.toString(),
|
|
|
|
UserTableContract.C_VIRTUAL_DIRECTORY: virtualDirectory,
|
|
|
|
UserTableContract.C_ACCOUNT_IMAGE_URL: accountImageURL,
|
2020-04-28 16:47:47 +00:00
|
|
|
UserTableContract.C_CUSTOM_EMOJIES:
|
|
|
|
jsonEncode(customEmojies.toSerializableList()),
|
2019-04-24 09:24:05 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
User.fromMap(Map<String, dynamic> map)
|
2019-04-24 11:56:56 +00:00
|
|
|
: this.firstName = map[UserTableContract.C_FIRST_NAME],
|
2019-04-24 09:24:05 +00:00
|
|
|
this.lastName = map[UserTableContract.C_LAST_NAME],
|
|
|
|
this.pageVisibility =
|
|
|
|
userPageVisibilityFromString(map[UserTableContract.C_VISIBILITY]),
|
|
|
|
this.virtualDirectory = map[UserTableContract.C_VIRTUAL_DIRECTORY],
|
2019-04-24 11:56:56 +00:00
|
|
|
this.accountImageURL = map[UserTableContract.C_ACCOUNT_IMAGE_URL],
|
2020-04-28 16:47:47 +00:00
|
|
|
this.customEmojies = CustomEmojiesList.fromSerializedList(
|
|
|
|
jsonDecode(map[UserTableContract.C_CUSTOM_EMOJIES])),
|
2019-04-24 11:56:56 +00:00
|
|
|
super.fromMap(map);
|
2019-04-23 15:29:58 +00:00
|
|
|
}
|