TF-4068 Change profile (set identity as default) in setting
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/exceptions/null_session_or_accountid_exception.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/edit_identity_request.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/edit_default_identity_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/extensions/identity_extension.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/identities/identities_controller.dart';
|
||||
import 'package:tmail_ui_user/main/error/capability_validator.dart';
|
||||
|
||||
extension VerifyDefaultIdentitySupportedExtension on IdentitiesController {
|
||||
bool get isDefaultIdentitySupported {
|
||||
final accountId = accountDashBoardController.accountId.value;
|
||||
final session = accountDashBoardController.sessionCurrent;
|
||||
if (session != null && accountId != null) {
|
||||
return [CapabilityIdentifier.jamesSortOrder].isSupported(
|
||||
session,
|
||||
accountId,
|
||||
);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void changeIdentityAsDefault(Identity identity) {
|
||||
final accountId = accountDashBoardController.accountId.value;
|
||||
final session = accountDashBoardController.sessionCurrent;
|
||||
|
||||
if (session != null && accountId != null && identity.id != null) {
|
||||
editIdentityAction(
|
||||
session,
|
||||
accountId,
|
||||
EditIdentityRequest.fromIdentityWithoutPublicAssets(
|
||||
identity.asDefault(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
consumeState(
|
||||
Stream.value(
|
||||
Left(EditDefaultIdentityFailure(NullSessionOrAccountIdException())),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/identities/identity.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/identity_signature.dart';
|
||||
|
||||
extension IdentityExtension on Identity {
|
||||
@@ -16,4 +18,32 @@ extension IdentityExtension on Identity {
|
||||
IdentitySignature? toIdentitySignature() => id != null
|
||||
? IdentitySignature(identityId: id!, signature: signatureAsString)
|
||||
: null;
|
||||
|
||||
Identity asDefault() => copyWith(sortOrder: UnsignedInt(0));
|
||||
|
||||
Identity copyWith({
|
||||
IdentityId? id,
|
||||
String? description,
|
||||
String? name,
|
||||
String? email,
|
||||
Set<EmailAddress>? bcc,
|
||||
Set<EmailAddress>? replyTo,
|
||||
Signature? textSignature,
|
||||
Signature? htmlSignature,
|
||||
bool? mayDelete,
|
||||
UnsignedInt? sortOrder,
|
||||
}) {
|
||||
return Identity(
|
||||
id: id ?? this.id,
|
||||
description: description ?? this.description,
|
||||
name: name ?? this.name,
|
||||
email: email ?? this.email,
|
||||
bcc: bcc ?? this.bcc,
|
||||
replyTo: replyTo ?? this.replyTo,
|
||||
textSignature: textSignature ?? this.textSignature,
|
||||
htmlSignature: htmlSignature ?? this.htmlSignature,
|
||||
mayDelete: mayDelete ?? this.mayDelete,
|
||||
sortOrder: sortOrder ?? this.sortOrder,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user