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/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/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/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/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/main/localizations/app_localizations.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
@@ -217,9 +217,7 @@ class ComposerController extends BaseController {
|
||||
final generateEmailId = EmailId(Id(_uuid.v1()));
|
||||
final outboxMailboxId = composerArguments.value!.mapMailboxId[PresentationMailbox.roleOutbox];
|
||||
final listFromEmailAddress = {
|
||||
EmailAddress(
|
||||
composerArguments.value!.userProfile.getNameDisplay(),
|
||||
composerArguments.value!.userProfile.getEmailAddress())
|
||||
EmailAddress(null, composerArguments.value!.userProfile.email)
|
||||
};
|
||||
final generatePartId = PartId(_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:jmap_dart_client/jmap/mail/email/email_address.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/main/localizations/app_localizations.dart';
|
||||
|
||||
typedef OnOpenExpandAddressActionClick = void Function();
|
||||
typedef OnSuggestionEmailAddress = Future<List<EmailAddress>> Function(String word);
|
||||
@@ -88,14 +88,10 @@ class EmailAddressComposerWidgetBuilder {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (_userProfile?.getFullName().isNotEmpty == true)
|
||||
Text(
|
||||
'${_userProfile?.getFullName()}',
|
||||
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))
|
||||
Text(
|
||||
'<${_userProfile?.email}>',
|
||||
style: TextStyle(fontSize: 14, color: AppColor.nameUserColor)
|
||||
)
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,20 +1,14 @@
|
||||
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/network/login_api.dart';
|
||||
|
||||
class AuthenticationDataSourceImpl extends AuthenticationDataSource {
|
||||
|
||||
final LoginAPI loginAPI;
|
||||
|
||||
AuthenticationDataSourceImpl(this.loginAPI);
|
||||
AuthenticationDataSourceImpl();
|
||||
|
||||
@override
|
||||
Future<UserProfile> authenticationUser(Uri baseUrl, UserName userName, Password password) {
|
||||
return Future.sync(() async {
|
||||
final userProfileResponse = await loginAPI.authenticationUser(baseUrl, AccountRequest(userName, password));
|
||||
return userProfileResponse.toUserProfile();
|
||||
}).catchError((error) {
|
||||
throw error;
|
||||
return Future.sync(() {
|
||||
return UserProfile(userName.userName);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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: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/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/credential_repository_impl.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 {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut(() => AuthenticationDataSourceImpl(Get.find<LoginAPI>()));
|
||||
Get.lazyPut(() => AuthenticationDataSourceImpl());
|
||||
Get.lazyPut<AuthenticationDataSource>(() => Get.find<AuthenticationDataSourceImpl>());
|
||||
|
||||
Get.lazyPut(() => CredentialRepositoryImpl(Get.find<SharedPreferences>()));
|
||||
|
||||
@@ -42,21 +42,11 @@ class UserInformationWidgetBuilder {
|
||||
title: Transform(
|
||||
transform: Matrix4.translationValues(0.0, 0.0, 0.0),
|
||||
child: Text(
|
||||
_userProfile != null ? _userProfile!.getNameDisplay() : '',
|
||||
_userProfile != null ? _userProfile!.email : '',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
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(
|
||||
transform: Matrix4.translationValues(0.0, 0.0, 0.0),
|
||||
child: IconButton(
|
||||
|
||||
@@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:get/get.dart';
|
||||
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/login/data/network/login_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/thread/data/network/thread_api.dart';
|
||||
@@ -46,7 +45,6 @@ class NetworkBindings extends Bindings {
|
||||
void _bindingApi() {
|
||||
Get.put(DioClient(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(SessionAPI(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 {
|
||||
UserProfileResponse toUserProfileResponse() {
|
||||
return UserProfileResponse(
|
||||
id,
|
||||
firstName,
|
||||
lastName,
|
||||
jobTitle,
|
||||
service,
|
||||
buildingLocation,
|
||||
officeLocation,
|
||||
mainPhone,
|
||||
description,
|
||||
currentAvatar,
|
||||
avatars,
|
||||
accounts.map((account) => account.toPresentationAccountResponse()).toList()
|
||||
);
|
||||
return UserProfileResponse(email);
|
||||
}
|
||||
}
|
||||
@@ -4,15 +4,10 @@ library model;
|
||||
export 'account/user_name.dart';
|
||||
export 'account/password.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';
|
||||
|
||||
// User
|
||||
export 'user/user_id.dart';
|
||||
export 'user/user_profile.dart';
|
||||
export 'user/avatar_id.dart';
|
||||
export 'user/user_profile_response.dart';
|
||||
|
||||
// Mailbox
|
||||
@@ -35,14 +30,7 @@ export 'extensions/list_email_address_extension.dart';
|
||||
export 'extensions/session_extension.dart';
|
||||
export 'extensions/utc_date_extension.dart';
|
||||
export 'extensions/email_extension.dart';
|
||||
export 'extensions/presentation_account_extension.dart';
|
||||
export 'extensions/user_profile_extension.dart';
|
||||
export 'extensions/presentation_email_extension.dart';
|
||||
export 'extensions/keyword_identifier_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: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,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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user