Remove LoginAPI, because it does not belongs to JMAP server
This commit is contained in:
committed by
Dat H. Pham
parent
5fd305d102
commit
afe6095c7e
@@ -22,11 +22,11 @@ import 'package:tmail_ui_user/features/composer/domain/state/search_email_addres
|
|||||||
import 'package:tmail_ui_user/features/composer/domain/usecases/save_email_addresses_interactor.dart';
|
import 'package:tmail_ui_user/features/composer/domain/usecases/save_email_addresses_interactor.dart';
|
||||||
import 'package:tmail_ui_user/features/composer/domain/usecases/search_email_address_interactor.dart';
|
import 'package:tmail_ui_user/features/composer/domain/usecases/search_email_address_interactor.dart';
|
||||||
import 'package:tmail_ui_user/features/composer/domain/usecases/send_email_interactor.dart';
|
import 'package:tmail_ui_user/features/composer/domain/usecases/send_email_interactor.dart';
|
||||||
|
import 'package:tmail_ui_user/features/composer/presentation/extensions/email_action_type_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/constants/email_constants.dart';
|
import 'package:tmail_ui_user/features/email/presentation/constants/email_constants.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/presentation/extensions/email_content_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/model/attachment_file.dart';
|
import 'package:tmail_ui_user/features/email/presentation/model/attachment_file.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/model/composer_arguments.dart';
|
import 'package:tmail_ui_user/features/email/presentation/model/composer_arguments.dart';
|
||||||
import 'package:tmail_ui_user/features/email/presentation/extensions/email_content_extension.dart';
|
|
||||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/email_action_type_extension.dart';
|
|
||||||
import 'package:tmail_ui_user/features/email/presentation/model/message_content.dart';
|
import 'package:tmail_ui_user/features/email/presentation/model/message_content.dart';
|
||||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
@@ -217,9 +217,7 @@ class ComposerController extends BaseController {
|
|||||||
final generateEmailId = EmailId(Id(_uuid.v1()));
|
final generateEmailId = EmailId(Id(_uuid.v1()));
|
||||||
final outboxMailboxId = composerArguments.value!.mapMailboxId[PresentationMailbox.roleOutbox];
|
final outboxMailboxId = composerArguments.value!.mapMailboxId[PresentationMailbox.roleOutbox];
|
||||||
final listFromEmailAddress = {
|
final listFromEmailAddress = {
|
||||||
EmailAddress(
|
EmailAddress(null, composerArguments.value!.userProfile.email)
|
||||||
composerArguments.value!.userProfile.getNameDisplay(),
|
|
||||||
composerArguments.value!.userProfile.getEmailAddress())
|
|
||||||
};
|
};
|
||||||
final generatePartId = PartId(_uuid.v1());
|
final generatePartId = PartId(_uuid.v1());
|
||||||
final generateBlobId = Id(_uuid.v1());
|
final generateBlobId = Id(_uuid.v1());
|
||||||
|
|||||||
+5
-9
@@ -9,8 +9,8 @@ import 'package:flutter_svg/flutter_svg.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||||
import 'package:model/model.dart';
|
import 'package:model/model.dart';
|
||||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
|
||||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/prefix_email_address_extension.dart';
|
import 'package:tmail_ui_user/features/composer/presentation/extensions/prefix_email_address_extension.dart';
|
||||||
|
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||||
|
|
||||||
typedef OnOpenExpandAddressActionClick = void Function();
|
typedef OnOpenExpandAddressActionClick = void Function();
|
||||||
typedef OnSuggestionEmailAddress = Future<List<EmailAddress>> Function(String word);
|
typedef OnSuggestionEmailAddress = Future<List<EmailAddress>> Function(String word);
|
||||||
@@ -88,14 +88,10 @@ class EmailAddressComposerWidgetBuilder {
|
|||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
if (_userProfile?.getFullName().isNotEmpty == true)
|
Text(
|
||||||
Text(
|
'<${_userProfile?.email}>',
|
||||||
'${_userProfile?.getFullName()}',
|
style: TextStyle(fontSize: 14, color: AppColor.nameUserColor)
|
||||||
style: TextStyle(fontWeight: FontWeight.w500, fontSize: 14, color: AppColor.nameUserColor)),
|
)
|
||||||
if (_userProfile?.getEmailAddress()?.isNotEmpty == true)
|
|
||||||
Text(
|
|
||||||
'<${_userProfile?.getEmailAddress()}>',
|
|
||||||
style: TextStyle(fontSize: 14, color: AppColor.nameUserColor))
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,20 +1,14 @@
|
|||||||
import 'package:model/model.dart';
|
import 'package:model/model.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/datasource/authentication_datasource.dart';
|
import 'package:tmail_ui_user/features/login/data/datasource/authentication_datasource.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/network/login_api.dart';
|
|
||||||
|
|
||||||
class AuthenticationDataSourceImpl extends AuthenticationDataSource {
|
class AuthenticationDataSourceImpl extends AuthenticationDataSource {
|
||||||
|
|
||||||
final LoginAPI loginAPI;
|
AuthenticationDataSourceImpl();
|
||||||
|
|
||||||
AuthenticationDataSourceImpl(this.loginAPI);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<UserProfile> authenticationUser(Uri baseUrl, UserName userName, Password password) {
|
Future<UserProfile> authenticationUser(Uri baseUrl, UserName userName, Password password) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() {
|
||||||
final userProfileResponse = await loginAPI.authenticationUser(baseUrl, AccountRequest(userName, password));
|
return UserProfile(userName.userName);
|
||||||
return userProfileResponse.toUserProfile();
|
|
||||||
}).catchError((error) {
|
|
||||||
throw error;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:core/core.dart';
|
|
||||||
import 'package:dio/dio.dart';
|
|
||||||
import 'package:model/model.dart';
|
|
||||||
|
|
||||||
class LoginAPI {
|
|
||||||
final DioClient _dioClient;
|
|
||||||
|
|
||||||
LoginAPI(this._dioClient);
|
|
||||||
|
|
||||||
Future<UserProfileResponse> authenticationUser(Uri baseUrl, AccountRequest accountRequest) async {
|
|
||||||
final basicAuth = 'Basic ' + base64Encode(utf8.encode('${accountRequest.userName.userName}:${accountRequest.password.value}'));
|
|
||||||
final resultJson = await _dioClient.post(
|
|
||||||
Endpoint.authentication.generateAuthenticationUrl(baseUrl),
|
|
||||||
options: Options(headers: _buildHeaderRequestParam(basicAuth)),
|
|
||||||
data: accountRequest.toJson());
|
|
||||||
return UserProfileResponse.fromJson(resultJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, dynamic> _buildHeaderRequestParam(String authorizationHeader) {
|
|
||||||
final headerParam = _dioClient.getHeaders();
|
|
||||||
headerParam[HttpHeaders.authorizationHeader] = authorizationHeader;
|
|
||||||
return headerParam;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,6 @@ import 'package:get/get.dart';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/datasource/authentication_datasource.dart';
|
import 'package:tmail_ui_user/features/login/data/datasource/authentication_datasource.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/datasource_impl/authentication_datasource_impl.dart';
|
import 'package:tmail_ui_user/features/login/data/datasource_impl/authentication_datasource_impl.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/network/login_api.dart';
|
|
||||||
import 'package:tmail_ui_user/features/login/data/repository/authentication_repository_impl.dart';
|
import 'package:tmail_ui_user/features/login/data/repository/authentication_repository_impl.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/repository/credential_repository_impl.dart';
|
import 'package:tmail_ui_user/features/login/data/repository/credential_repository_impl.dart';
|
||||||
import 'package:tmail_ui_user/features/login/domain/repository/authentication_repository.dart';
|
import 'package:tmail_ui_user/features/login/domain/repository/authentication_repository.dart';
|
||||||
@@ -14,7 +13,7 @@ import 'package:tmail_ui_user/features/login/presentation/login_controller.dart'
|
|||||||
class LoginBindings extends Bindings {
|
class LoginBindings extends Bindings {
|
||||||
@override
|
@override
|
||||||
void dependencies() {
|
void dependencies() {
|
||||||
Get.lazyPut(() => AuthenticationDataSourceImpl(Get.find<LoginAPI>()));
|
Get.lazyPut(() => AuthenticationDataSourceImpl());
|
||||||
Get.lazyPut<AuthenticationDataSource>(() => Get.find<AuthenticationDataSourceImpl>());
|
Get.lazyPut<AuthenticationDataSource>(() => Get.find<AuthenticationDataSourceImpl>());
|
||||||
|
|
||||||
Get.lazyPut(() => CredentialRepositoryImpl(Get.find<SharedPreferences>()));
|
Get.lazyPut(() => CredentialRepositoryImpl(Get.find<SharedPreferences>()));
|
||||||
|
|||||||
@@ -42,21 +42,11 @@ class UserInformationWidgetBuilder {
|
|||||||
title: Transform(
|
title: Transform(
|
||||||
transform: Matrix4.translationValues(0.0, 0.0, 0.0),
|
transform: Matrix4.translationValues(0.0, 0.0, 0.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
_userProfile != null ? _userProfile!.getNameDisplay() : '',
|
_userProfile != null ? _userProfile!.email : '',
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: TextStyle(fontSize: 16, color: AppColor.nameUserColor, fontWeight: FontWeight.w500),
|
style: TextStyle(fontSize: 16, color: AppColor.nameUserColor, fontWeight: FontWeight.w500),
|
||||||
)),
|
)),
|
||||||
subtitle: (_userProfile != null && !_userProfile!.isUserEmpty())
|
|
||||||
? Transform(
|
|
||||||
transform: Matrix4.translationValues(0.0, 4.0, 0.0),
|
|
||||||
child: Text(
|
|
||||||
_userProfile!.getEmailAddress() ?? '',
|
|
||||||
maxLines: 1,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: TextStyle(fontSize: 12, color: AppColor.emailUserColor, fontWeight: FontWeight.w500),
|
|
||||||
))
|
|
||||||
: null,
|
|
||||||
trailing: Transform(
|
trailing: Transform(
|
||||||
transform: Matrix4.translationValues(0.0, 0.0, 0.0),
|
transform: Matrix4.translationValues(0.0, 0.0, 0.0),
|
||||||
child: IconButton(
|
child: IconButton(
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:jmap_dart_client/http/http_client.dart' as JmapHttpClient;
|
import 'package:jmap_dart_client/http/http_client.dart' as JmapHttpClient;
|
||||||
import 'package:tmail_ui_user/features/email/data/network/email_api.dart';
|
import 'package:tmail_ui_user/features/email/data/network/email_api.dart';
|
||||||
import 'package:tmail_ui_user/features/login/data/network/login_api.dart';
|
|
||||||
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart';
|
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart';
|
||||||
import 'package:tmail_ui_user/features/session/data/network/session_api.dart';
|
import 'package:tmail_ui_user/features/session/data/network/session_api.dart';
|
||||||
import 'package:tmail_ui_user/features/thread/data/network/thread_api.dart';
|
import 'package:tmail_ui_user/features/thread/data/network/thread_api.dart';
|
||||||
@@ -46,7 +45,6 @@ class NetworkBindings extends Bindings {
|
|||||||
void _bindingApi() {
|
void _bindingApi() {
|
||||||
Get.put(DioClient(Get.find<Dio>()));
|
Get.put(DioClient(Get.find<Dio>()));
|
||||||
Get.put(JmapHttpClient.HttpClient(Get.find<Dio>()));
|
Get.put(JmapHttpClient.HttpClient(Get.find<Dio>()));
|
||||||
Get.put(LoginAPI(Get.find<DioClient>()));
|
|
||||||
Get.put(MailboxAPI(Get.find<JmapHttpClient.HttpClient>()));
|
Get.put(MailboxAPI(Get.find<JmapHttpClient.HttpClient>()));
|
||||||
Get.put(SessionAPI(Get.find<JmapHttpClient.HttpClient>()));
|
Get.put(SessionAPI(Get.find<JmapHttpClient.HttpClient>()));
|
||||||
Get.put(ThreadAPI(Get.find<JmapHttpClient.HttpClient>()));
|
Get.put(ThreadAPI(Get.find<JmapHttpClient.HttpClient>()));
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
class Attribute {
|
|
||||||
static const id = '_id';
|
|
||||||
static const firstname = 'firstname';
|
|
||||||
static const lastname = 'lastname';
|
|
||||||
static const job_title = 'job_title';
|
|
||||||
static const building_location = 'building_location';
|
|
||||||
static const office_location = 'office_location';
|
|
||||||
static const main_phone = 'main_phone';
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:model/account/account_type.dart';
|
|
||||||
import 'package:model/email/presentation_email_address.dart';
|
|
||||||
|
|
||||||
class PresentationAccount with EquatableMixin {
|
|
||||||
final List<PresentationEmailAddress> emails;
|
|
||||||
final int preferredEmailIndex;
|
|
||||||
final AccountType type;
|
|
||||||
|
|
||||||
PresentationAccount(this.emails, this.preferredEmailIndex, this.type);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [emails];
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:json_annotation/json_annotation.dart';
|
|
||||||
import 'package:model/model.dart';
|
|
||||||
|
|
||||||
part 'presentation_account_response.g.dart';
|
|
||||||
|
|
||||||
@PresentationEmailAddressConverter()
|
|
||||||
@JsonSerializable()
|
|
||||||
class PresentationAccountResponse with EquatableMixin {
|
|
||||||
final List<PresentationEmailAddress>? emails;
|
|
||||||
final int preferredEmailIndex;
|
|
||||||
final AccountType type;
|
|
||||||
|
|
||||||
PresentationAccountResponse(this.emails, this.preferredEmailIndex, this.type);
|
|
||||||
|
|
||||||
factory PresentationAccountResponse.fromJson(Map<String, dynamic> json) => _$PresentationAccountResponseFromJson(json);
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => _$PresentationAccountResponseToJson(this);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [emails, preferredEmailIndex, type];
|
|
||||||
}
|
|
||||||
|
|
||||||
extension PresentationAccountResponseExtension on PresentationAccountResponse {
|
|
||||||
PresentationAccount toPresentationAccount() {
|
|
||||||
return PresentationAccount(emails ?? [], preferredEmailIndex, type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import 'package:json_annotation/json_annotation.dart';
|
|
||||||
import 'package:model/model.dart';
|
|
||||||
|
|
||||||
class AvatarIdConverter implements JsonConverter<AvatarId, String> {
|
|
||||||
const AvatarIdConverter();
|
|
||||||
|
|
||||||
@override
|
|
||||||
AvatarId fromJson(String json) => AvatarId(json);
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toJson(AvatarId object) => object.id;
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import 'package:json_annotation/json_annotation.dart';
|
|
||||||
import 'package:model/model.dart';
|
|
||||||
|
|
||||||
class AvatarIdNullableConverter implements JsonConverter<AvatarId?, String?> {
|
|
||||||
const AvatarIdNullableConverter();
|
|
||||||
|
|
||||||
@override
|
|
||||||
AvatarId? fromJson(String? json) => json != null ? AvatarId(json) : AvatarId.initial();
|
|
||||||
|
|
||||||
@override
|
|
||||||
String? toJson(AvatarId? object) => object?.id;
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import 'package:json_annotation/json_annotation.dart';
|
|
||||||
import 'package:model/model.dart';
|
|
||||||
|
|
||||||
class PresentationEmailAddressConverter implements JsonConverter<PresentationEmailAddress, String> {
|
|
||||||
const PresentationEmailAddressConverter();
|
|
||||||
|
|
||||||
@override
|
|
||||||
PresentationEmailAddress fromJson(String json) => PresentationEmailAddress(json);
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toJson(PresentationEmailAddress object) => object.email;
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import 'package:json_annotation/json_annotation.dart';
|
|
||||||
import 'package:model/model.dart';
|
|
||||||
|
|
||||||
class UserIdConverter implements JsonConverter<UserId, String> {
|
|
||||||
const UserIdConverter();
|
|
||||||
|
|
||||||
@override
|
|
||||||
UserId fromJson(String json) => UserId(json);
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toJson(UserId object) => object.id;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import 'package:model/model.dart';
|
|
||||||
|
|
||||||
extension PresentationAccountExtension on PresentationAccount {
|
|
||||||
PresentationAccountResponse toPresentationAccountResponse() {
|
|
||||||
return PresentationAccountResponse(emails, preferredEmailIndex, type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,19 +2,6 @@ import 'package:model/model.dart';
|
|||||||
|
|
||||||
extension UserProfileExtension on UserProfile {
|
extension UserProfileExtension on UserProfile {
|
||||||
UserProfileResponse toUserProfileResponse() {
|
UserProfileResponse toUserProfileResponse() {
|
||||||
return UserProfileResponse(
|
return UserProfileResponse(email);
|
||||||
id,
|
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
jobTitle,
|
|
||||||
service,
|
|
||||||
buildingLocation,
|
|
||||||
officeLocation,
|
|
||||||
mainPhone,
|
|
||||||
description,
|
|
||||||
currentAvatar,
|
|
||||||
avatars,
|
|
||||||
accounts.map((account) => account.toPresentationAccountResponse()).toList()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,15 +4,10 @@ library model;
|
|||||||
export 'account/user_name.dart';
|
export 'account/user_name.dart';
|
||||||
export 'account/password.dart';
|
export 'account/password.dart';
|
||||||
export 'account/account_type.dart';
|
export 'account/account_type.dart';
|
||||||
export 'account/presentation_account.dart';
|
|
||||||
export 'account/presentation_account_response.dart';
|
|
||||||
export 'account/attribute.dart';
|
|
||||||
export 'account/account_request.dart';
|
export 'account/account_request.dart';
|
||||||
|
|
||||||
// User
|
// User
|
||||||
export 'user/user_id.dart';
|
|
||||||
export 'user/user_profile.dart';
|
export 'user/user_profile.dart';
|
||||||
export 'user/avatar_id.dart';
|
|
||||||
export 'user/user_profile_response.dart';
|
export 'user/user_profile_response.dart';
|
||||||
|
|
||||||
// Mailbox
|
// Mailbox
|
||||||
@@ -35,14 +30,7 @@ export 'extensions/list_email_address_extension.dart';
|
|||||||
export 'extensions/session_extension.dart';
|
export 'extensions/session_extension.dart';
|
||||||
export 'extensions/utc_date_extension.dart';
|
export 'extensions/utc_date_extension.dart';
|
||||||
export 'extensions/email_extension.dart';
|
export 'extensions/email_extension.dart';
|
||||||
export 'extensions/presentation_account_extension.dart';
|
|
||||||
export 'extensions/user_profile_extension.dart';
|
export 'extensions/user_profile_extension.dart';
|
||||||
export 'extensions/presentation_email_extension.dart';
|
export 'extensions/presentation_email_extension.dart';
|
||||||
export 'extensions/keyword_identifier_extension.dart';
|
export 'extensions/keyword_identifier_extension.dart';
|
||||||
export 'extensions/presentation_mailbox_extension.dart';
|
export 'extensions/presentation_mailbox_extension.dart';
|
||||||
|
|
||||||
// Converter
|
|
||||||
export 'converter/avatar_id_converter.dart';
|
|
||||||
export 'converter/avatar_id_nullable_converter.dart';
|
|
||||||
export 'converter/presentation_email_address_converter.dart';
|
|
||||||
export 'converter/user_id_converter.dart';
|
|
||||||
@@ -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];
|
|
||||||
}
|
|
||||||
@@ -1,85 +1,15 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
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 {
|
class UserProfile with EquatableMixin {
|
||||||
|
|
||||||
final UserId id;
|
final String email;
|
||||||
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;
|
|
||||||
|
|
||||||
UserProfile(
|
UserProfile(this.email);
|
||||||
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;
|
|
||||||
|
|
||||||
String getAvatarText() {
|
String getAvatarText() {
|
||||||
if (getFullName().trim().isNotEmpty) {
|
return email[0].toUpperCase();
|
||||||
return getFullName().substring(0, 1).toUpperCase();
|
|
||||||
} else if (getEmailAddress() != null && getEmailAddress()!.isNotEmpty) {
|
|
||||||
return getEmailAddress()![0].toUpperCase();
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [
|
List<Object> get props => [email];
|
||||||
id,
|
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
jobTitle,
|
|
||||||
service,
|
|
||||||
buildingLocation,
|
|
||||||
officeLocation,
|
|
||||||
mainPhone,
|
|
||||||
description,
|
|
||||||
currentAvatar,
|
|
||||||
avatars,
|
|
||||||
accounts,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
@@ -4,80 +4,23 @@ import 'package:model/model.dart';
|
|||||||
|
|
||||||
part 'user_profile_response.g.dart';
|
part 'user_profile_response.g.dart';
|
||||||
|
|
||||||
@AvatarIdNullableConverter()
|
|
||||||
@AvatarIdConverter()
|
|
||||||
@UserIdConverter()
|
|
||||||
@JsonSerializable()
|
@JsonSerializable()
|
||||||
class UserProfileResponse with EquatableMixin {
|
class UserProfileResponse with EquatableMixin {
|
||||||
|
|
||||||
@JsonKey(name: Attribute.id, includeIfNull: false)
|
final String email;
|
||||||
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;
|
|
||||||
|
|
||||||
UserProfileResponse(
|
UserProfileResponse(this.email);
|
||||||
this.id,
|
|
||||||
this.firstName,
|
|
||||||
this.lastName,
|
|
||||||
this.jobTitle,
|
|
||||||
this.service,
|
|
||||||
this.buildingLocation,
|
|
||||||
this.officeLocation,
|
|
||||||
this.mainPhone,
|
|
||||||
this.description,
|
|
||||||
this.currentAvatar,
|
|
||||||
this.avatars,
|
|
||||||
this.accounts
|
|
||||||
);
|
|
||||||
|
|
||||||
factory UserProfileResponse.fromJson(Map<String, dynamic> json) => _$UserProfileResponseFromJson(json);
|
factory UserProfileResponse.fromJson(Map<String, dynamic> json) => _$UserProfileResponseFromJson(json);
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => _$UserProfileResponseToJson(this);
|
Map<String, dynamic> toJson() => _$UserProfileResponseToJson(this);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [
|
List<Object?> get props => [email];
|
||||||
id,
|
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
accounts,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension UserProfileResponseExtension on UserProfileResponse {
|
extension UserProfileResponseExtension on UserProfileResponse {
|
||||||
UserProfile toUserProfile() {
|
UserProfile toUserProfile() {
|
||||||
return UserProfile(
|
return UserProfile(email);
|
||||||
id,
|
|
||||||
firstName ?? '',
|
|
||||||
lastName ?? '',
|
|
||||||
jobTitle ?? '',
|
|
||||||
service ?? '',
|
|
||||||
buildingLocation ?? '',
|
|
||||||
officeLocation ?? '',
|
|
||||||
mainPhone ?? '',
|
|
||||||
description ?? '',
|
|
||||||
currentAvatar ?? AvatarId.initial(),
|
|
||||||
avatars ?? [],
|
|
||||||
accounts != null ? accounts!.map((account) => account.toPresentationAccount()).toList() : []
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user