1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-29 08:16:28 +00:00
comunicmobile/lib/models/user.dart

71 lines
2.4 KiB
Dart

import 'dart:convert';
import 'package:comunic/enums/user_page_visibility.dart';
import 'package:comunic/helpers/database/database_contract.dart';
import 'package:comunic/lists/custom_emojies_list.dart';
import 'package:comunic/models/cache_model.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:meta/meta.dart';
/// Single user information
///
/// @author Pierre HUBERT
class User extends CacheModel {
final String firstName;
final String lastName;
final UserPageVisibility pageVisibility;
final String virtualDirectory;
final String accountImageURL;
final CustomEmojiesList customEmojies;
const User({
@required int id,
@required this.firstName,
@required this.lastName,
@required this.pageVisibility,
@required this.virtualDirectory,
@required this.accountImageURL,
@required this.customEmojies,
}) : assert(id != null),
assert(firstName != null),
assert(lastName != null),
assert(pageVisibility != null),
assert(accountImageURL != null),
assert(customEmojies != null),
super(id: id);
/// 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;
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,
UserTableContract.C_CUSTOM_EMOJIES:
jsonEncode(customEmojies.toSerializableList()),
};
}
User.fromMap(Map<String, dynamic> map)
: this.firstName = map[UserTableContract.C_FIRST_NAME],
this.lastName = map[UserTableContract.C_LAST_NAME],
this.pageVisibility =
userPageVisibilityFromString(map[UserTableContract.C_VISIBILITY]),
this.virtualDirectory = map[UserTableContract.C_VIRTUAL_DIRECTORY],
this.accountImageURL = map[UserTableContract.C_ACCOUNT_IMAGE_URL],
this.customEmojies = CustomEmojiesList.fromSerializedList(
jsonDecode(map[UserTableContract.C_CUSTOM_EMOJIES])),
super.fromMap(map);
}