Remove LoginAPI, because it does not belongs to JMAP server

This commit is contained in:
Dat PHAM HOANG
2021-09-16 16:21:51 +07:00
committed by Dat H. Pham
parent 5fd305d102
commit afe6095c7e
20 changed files with 22 additions and 345 deletions
-10
View File
@@ -1,10 +0,0 @@
import 'package:equatable/equatable.dart';
class UserId with EquatableMixin {
final String id;
UserId(this.id);
@override
List<Object?> get props => [id];
}
+4 -74
View File
@@ -1,85 +1,15 @@
import 'package:equatable/equatable.dart';
import 'package:model/account/account_type.dart';
import 'package:model/account/presentation_account.dart';
import 'package:model/user/avatar_id.dart';
import 'package:model/user/user_id.dart';
class UserProfile with EquatableMixin {
final UserId id;
final String firstName;
final String lastName;
final String jobTitle;
final String service;
final String buildingLocation;
final String officeLocation;
final String mainPhone;
final String description;
final AvatarId currentAvatar;
final List<AvatarId> avatars;
final List<PresentationAccount> accounts;
final String email;
UserProfile(
this.id,
this.firstName,
this.lastName,
this.jobTitle,
this.service,
this.buildingLocation,
this.officeLocation,
this.mainPhone,
this.description,
this.currentAvatar,
this.avatars,
this.accounts,
);
String? getEmailAddress() {
try {
final accountEmail = accounts.firstWhere((account) => account.type == AccountType.email);
if (accountEmail.emails.isNotEmpty) {
final preferredEmailIndex = accountEmail.preferredEmailIndex < 0 ? 0 : accountEmail.preferredEmailIndex;
return accountEmail.emails[preferredEmailIndex].email;
}
return '';
} catch(e) {
return '';
}
}
String getFullName() => '$firstName $lastName';
String getNameDisplay() {
if (getFullName().trim().isEmpty) {
return getEmailAddress() != null ? getEmailAddress()! : '';
}
return getFullName();
}
bool isUserEmpty() => getFullName().trim().isEmpty || getEmailAddress() == null || getEmailAddress()!.isEmpty;
UserProfile(this.email);
String getAvatarText() {
if (getFullName().trim().isNotEmpty) {
return getFullName().substring(0, 1).toUpperCase();
} else if (getEmailAddress() != null && getEmailAddress()!.isNotEmpty) {
return getEmailAddress()![0].toUpperCase();
}
return '';
return email[0].toUpperCase();
}
@override
List<Object> get props => [
id,
firstName,
lastName,
jobTitle,
service,
buildingLocation,
officeLocation,
mainPhone,
description,
currentAvatar,
avatars,
accounts,
];
List<Object> get props => [email];
}
+4 -61
View File
@@ -4,80 +4,23 @@ import 'package:model/model.dart';
part 'user_profile_response.g.dart';
@AvatarIdNullableConverter()
@AvatarIdConverter()
@UserIdConverter()
@JsonSerializable()
class UserProfileResponse with EquatableMixin {
@JsonKey(name: Attribute.id, includeIfNull: false)
final UserId id;
@JsonKey(name: Attribute.firstname, includeIfNull: false)
final String? firstName;
@JsonKey(name: Attribute.lastname, includeIfNull: false)
final String? lastName;
@JsonKey(name: Attribute.job_title, includeIfNull: false)
final String? jobTitle;
@JsonKey(includeIfNull: false)
final String? service;
@JsonKey(name: Attribute.building_location, includeIfNull: false)
final String? buildingLocation;
@JsonKey(name: Attribute.office_location, includeIfNull: false)
final String? officeLocation;
@JsonKey(name: Attribute.main_phone, includeIfNull: false)
final String? mainPhone;
@JsonKey(includeIfNull: false)
final String? description;
@JsonKey(includeIfNull: false)
final AvatarId? currentAvatar;
@JsonKey(includeIfNull: false)
final List<AvatarId>? avatars;
@JsonKey(includeIfNull: false)
final List<PresentationAccountResponse>? accounts;
final String email;
UserProfileResponse(
this.id,
this.firstName,
this.lastName,
this.jobTitle,
this.service,
this.buildingLocation,
this.officeLocation,
this.mainPhone,
this.description,
this.currentAvatar,
this.avatars,
this.accounts
);
UserProfileResponse(this.email);
factory UserProfileResponse.fromJson(Map<String, dynamic> json) => _$UserProfileResponseFromJson(json);
Map<String, dynamic> toJson() => _$UserProfileResponseToJson(this);
@override
List<Object?> get props => [
id,
firstName,
lastName,
accounts,
];
List<Object?> get props => [email];
}
extension UserProfileResponseExtension on UserProfileResponse {
UserProfile toUserProfile() {
return UserProfile(
id,
firstName ?? '',
lastName ?? '',
jobTitle ?? '',
service ?? '',
buildingLocation ?? '',
officeLocation ?? '',
mainPhone ?? '',
description ?? '',
currentAvatar ?? AvatarId.initial(),
avatars ?? [],
accounts != null ? accounts!.map((account) => account.toPresentationAccount()).toList() : []
);
return UserProfile(email);
}
}