Skip to content

Commit

Permalink
fixup! TF-2901 Implement caching composer on log out
Browse files Browse the repository at this point in the history
  • Loading branch information
tddang-linagora committed Jul 3, 2024
1 parent 0bd2506 commit 4289c09
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/composer/domain/repository/composer_repository.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/create_email_request.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/screen_display_mode.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/composer_cache_repository.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/save_composer_cache_state.dart';

Expand All @@ -20,7 +21,8 @@ class SaveComposerCacheOnWebInteractor {
Future<Either<Failure, Success>> execute(
CreateEmailRequest createEmailRequest,
AccountId accountId,
UserName userName
UserName userName,
{required ScreenDisplayMode displayMode}
) async {
try {
final emailCreated = await _composerRepository.generateEmail(createEmailRequest);
Expand All @@ -29,6 +31,7 @@ class SaveComposerCacheOnWebInteractor {
emailCreated,
accountId: accountId,
userName: userName,
displayMode: displayMode,
identity: identity,
readReceipentEnabled: createEmailRequest.isRequestReadReceipt);
return Right(SaveComposerCacheSuccess());
Expand Down
5 changes: 4 additions & 1 deletion lib/features/composer/presentation/composer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ class ComposerController extends BaseController with DragDropFileMixin implement
await _saveComposerCacheOnWebInteractor.execute(
createEmailRequest,
mailboxDashBoardController.accountId.value!,
mailboxDashBoardController.sessionCurrent!.username);
mailboxDashBoardController.sessionCurrent!.username,
displayMode: screenDisplayMode.value);
}

Future<CreateEmailRequest?> _generateCreateEmailRequest() async {
Expand Down Expand Up @@ -604,6 +605,8 @@ class ComposerController extends BaseController with DragDropFileMixin implement
case EmailActionType.reopenComposerBrowser:
if (!PlatformInfo.isWeb) return;

screenDisplayMode.value = arguments.displayMode;

_initEmailAddress(
presentationEmail: arguments.presentationEmail!,
actionType: EmailActionType.reopenComposerBrowser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,18 @@
enum ScreenDisplayMode {
fullScreen,
minimize,
normal
normal;

factory ScreenDisplayMode.fromJson(String value) {
switch (value) {
case 'fullScreen':
return ScreenDisplayMode.fullScreen;
case 'minimize':
return ScreenDisplayMode.minimize;
default:
return ScreenDisplayMode.normal;
}
}

String toJson() => name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,9 @@ import 'package:tmail_ui_user/features/email/presentation/model/composer_argumen
extension ComposerArgumentsExtension on ComposerArguments {

ComposerArguments withIdentity({List<Identity>? identities, Identity? selectedIdentity}) {
return ComposerArguments(
emailActionType: emailActionType,
presentationEmail: presentationEmail,
emailContents: emailContents,
attachments: attachments,
mailboxRole: mailboxRole,
listEmailAddress: listEmailAddress,
listSharedMediaFile: listSharedMediaFile,
sendingEmail: sendingEmail,
subject: subject,
body: body,
messageId: messageId,
references: references,
previousEmailId: previousEmailId,
return copyWith(
identities: identities,
selectedIdentity: selectedIdentity,
inlineImages: inlineImages,
readRecepientEnabled: readRecepientEnabled
);
}
}
6 changes: 6 additions & 0 deletions lib/features/email/presentation/model/composer_arguments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
import 'package:model/model.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';

import 'package:tmail_ui_user/features/composer/presentation/model/screen_display_mode.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/composer_cache.dart';
import 'package:tmail_ui_user/features/sending_queue/domain/model/sending_email.dart';
import 'package:tmail_ui_user/features/sending_queue/presentation/model/sending_email_action_type.dart';
Expand All @@ -29,6 +30,7 @@ class ComposerArguments extends RouterArguments {
final Identity? selectedIdentity;
final List<Attachment>? inlineImages;
final bool? readRecepientEnabled;
final ScreenDisplayMode displayMode;

ComposerArguments({
this.emailActionType = EmailActionType.compose,
Expand All @@ -48,6 +50,7 @@ class ComposerArguments extends RouterArguments {
this.selectedIdentity,
this.inlineImages,
this.readRecepientEnabled,
this.displayMode = ScreenDisplayMode.normal
});

factory ComposerArguments.fromSendingEmail(SendingEmail sendingEmail) =>
Expand Down Expand Up @@ -99,6 +102,7 @@ class ComposerArguments extends RouterArguments {
selectedIdentity: composerCache.identity,
inlineImages: composerCache.email?.attachmentsWithCid,
readRecepientEnabled: composerCache.readReceipentEnabled,
displayMode: composerCache.displayMode,
);

factory ComposerArguments.replyEmail({
Expand Down Expand Up @@ -201,6 +205,7 @@ class ComposerArguments extends RouterArguments {
Identity? selectedIdentity,
List<Attachment>? inlineImages,
bool? readRecepientEnabled,
ScreenDisplayMode? displayMode,
}) {
return ComposerArguments(
emailActionType: emailActionType ?? this.emailActionType,
Expand All @@ -220,6 +225,7 @@ class ComposerArguments extends RouterArguments {
selectedIdentity: selectedIdentity ?? this.selectedIdentity,
inlineImages: inlineImages ?? this.inlineImages,
readRecepientEnabled: readRecepientEnabled ?? this.readRecepientEnabled,
displayMode: displayMode ?? this.displayMode,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:jmap_dart_client/jmap/identities/identity.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/screen_display_mode.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/composer_cache.dart';

abstract class SessionStorageComposerDatasource {
Expand All @@ -11,6 +12,7 @@ abstract class SessionStorageComposerDatasource {
{
required AccountId accountId,
required UserName userName,
required ScreenDisplayMode displayMode,
Identity? identity,
bool? readReceipentEnabled,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:jmap_dart_client/jmap/identities/identity.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:model/model.dart';
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/screen_display_mode.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/data/datasource/session_storage_composer_datasource.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/composer_cache.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
Expand Down Expand Up @@ -54,6 +55,7 @@ class SessionStorageComposerDatasourceImpl
{
required AccountId accountId,
required UserName userName,
required ScreenDisplayMode displayMode,
Identity? identity,
bool? readReceipentEnabled
}
Expand All @@ -65,9 +67,10 @@ class SessionStorageComposerDatasourceImpl
userName.value).toString();
Map<String, String> entries = {
composerCacheKey: jsonEncode(ComposerCache(
displayMode: displayMode,
email: email,
identity: identity,
readReceipentEnabled: readReceipentEnabled
readReceipentEnabled: readReceipentEnabled,
).toJson())
};
html.window.sessionStorage.addAll(entries);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import 'package:equatable/equatable.dart';
import 'package:jmap_dart_client/jmap/identities/identity.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/screen_display_mode.dart';

class ComposerCache with EquatableMixin {

final Email? email;
final Identity? identity;
final bool? readReceipentEnabled;
final ScreenDisplayMode displayMode;

ComposerCache({
required this.displayMode,
this.email,
this.identity,
this.readReceipentEnabled,
Expand All @@ -25,12 +28,14 @@ class ComposerCache with EquatableMixin {
return <String, dynamic>{
'email': email?.toJson(),
'identity': identity?.toJson(),
'readReceipentEnabled': readReceipentEnabled
'readReceipentEnabled': readReceipentEnabled,
'displayMode': displayMode.toJson()
};
}

factory ComposerCache.fromJson(Map<String, dynamic> map) {
return ComposerCache(
displayMode: ScreenDisplayMode.fromJson(map['displayMode'] ?? ''),
email: map['email'] != null ? Email.fromJson(map['email']) : null,
identity: map['identity'] != null ? Identity.fromJson(map['identity']) : null,
readReceipentEnabled: map['readReceipentEnabled'] as bool?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:jmap_dart_client/jmap/identities/identity.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/screen_display_mode.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/data/datasource/session_storage_composer_datasource.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/composer_cache.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/composer_cache_repository.dart';
Expand Down Expand Up @@ -32,6 +33,7 @@ class ComposerCacheRepositoryImpl extends ComposerCacheRepository {
{
required AccountId accountId,
required UserName userName,
required ScreenDisplayMode displayMode,
Identity? identity,
bool? readReceipentEnabled
}
Expand All @@ -40,6 +42,7 @@ class ComposerCacheRepositoryImpl extends ComposerCacheRepository {
email,
accountId: accountId,
userName: userName,
displayMode: displayMode,
identity: identity,
readReceipentEnabled: readReceipentEnabled);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:jmap_dart_client/jmap/identities/identity.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/screen_display_mode.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/data/model/composer_cache.dart';

abstract class ComposerCacheRepository {
Expand All @@ -11,6 +12,7 @@ abstract class ComposerCacheRepository {
{
required AccountId accountId,
required UserName userName,
required ScreenDisplayMode displayMode,
Identity? identity,
bool? readReceipentEnabled
}
Expand Down

0 comments on commit 4289c09

Please sign in to comment.