Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Save draft locally periodically] Grooming #3464

Open
hoangdat opened this issue Feb 4, 2025 · 0 comments
Open

[Save draft locally periodically] Grooming #3464

hoangdat opened this issue Feb 4, 2025 · 0 comments

Comments

@hoangdat
Copy link
Member

hoangdat commented Feb 4, 2025

Issue

#3358

Technical

  1. Save draft to persistent storage (Hive database)
  • Rename all ComposerCache name to LocalDraftEmail

  • Create id for LocalDraftEmail:

 final key = TupleKey(
    savedTime,
    accountId.asString,
    userName.value).toString();
  • Add DateTime savedTime and String id properties for LocalDraftEmail object. LocalDraftEmail will then be updated to:
class LocalDraftEmail with EquatableMixin {

  final String id;
  final Email email;
  final bool hasRequestReadReceipt;
  final ScreenDisplayMode displayMode;
  final DateTime savedTime;

  LocalDraftEmail(
    this.id,
    this.email,
    this.hasRequestReadReceipt,
    this.displayMode = ScreenDisplayMode.normal,
    this.savedTime,
  );
}
  • Create LocalDraftEmailClient class:
class LocalDraftEmailClient extends HiveCacheClient<String> {

  @override
  String get tableName => CachingConstants.localDraftEmailBoxName;
}
  • Create LocalDraftEmailDatasource class
abstract class LocalDraftEmailDatasource {
  Future<void> saveLocalDraftEmail(LocalDraftEmail draftEmail);

  Future<List<LocalDraftEmail>> getAllLocalDraftEmail();

  Future<void> removeLocalDraftEmail(String id);
}
  • Create TypingStatusController class to manages the typing status and automatically calls the callback function if no typing activity occurs within the specified timeout duration.
import 'dart:async';

class TypingStatusController {
  final Duration timeoutDuration;
  final VoidCallback onCallbackAction;
  Timer? _timer;

  TypingStatusController({
    required this.onCallbackAction,
    this.timeoutDuration = const Duration(seconds: 15),
  });

  /// Call this method when the user starts typing.
  void onUserTyping() {
    _resetTimer();
  }

  /// Reset the timer when the user is typing.
  void _resetTimer() {
    _timer?.cancel();
    _timer = Timer(timeoutDuration, _triggerCallbackAction);
  }

  /// Call the callback function when the timeout occurs.
  void _triggerCallbackAction() {
    onCallbackAction();
  }

  /// Cancel the timer when it's no longer needed (to avoid memory leaks).
  void dispose() {
    _timer?.cancel();
  }
}
  1. Displays the local draft email list dialog.
  • Sort email list by newest
  • Each draft email item has 3 actions: Edit, Save as draft and Delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant