TF-802 Show message when enable/disable vacation responder
This commit is contained in:
+56
-2
@@ -3,8 +3,10 @@ import 'package:core/utils/app_logger.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/utc_date.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/vacation/vacation_response.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/vacation/vacation_presentation.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/presentation/model/vacation/vacation_responder_status.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
extension VacationResponseExtension on VacationResponse {
|
||||
|
||||
@@ -26,14 +28,48 @@ extension VacationResponseExtension on VacationResponse {
|
||||
);
|
||||
}
|
||||
|
||||
bool get vacationResponderIsValid {
|
||||
return vacationResponderIsReady && !vacationResponderIsStopped;
|
||||
}
|
||||
|
||||
bool get vacationResponderIsReady {
|
||||
if (isEnabled == true) {
|
||||
final currentDate = DateTime.now().toUtc();
|
||||
log('VacationResponseExtension::vacationResponderEnabled(): currentDate: $currentDate');
|
||||
final startDate = fromDate?.value.toUtc();
|
||||
log('VacationResponseExtension::vacationResponderEnabled(): startDate: $startDate');
|
||||
if (startDate?.isBefore(currentDate) == true ||
|
||||
startDate?.isAtSameMomentAs(currentDate) == true) {
|
||||
if (startDate != null && (startDate.isBefore(currentDate) ||
|
||||
startDate.isAtSameMomentAs(currentDate))) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get vacationResponderIsWaiting {
|
||||
if (isEnabled == true) {
|
||||
final currentDate = DateTime.now().toUtc();
|
||||
log('VacationResponseExtension::vacationResponderIsWaiting(): currentDate: $currentDate');
|
||||
final startDate = fromDate?.value.toUtc();
|
||||
log('VacationResponseExtension::vacationResponderIsWaiting(): startDate: $startDate');
|
||||
if (startDate != null && startDate.isAfter(currentDate)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get vacationResponderIsStopped {
|
||||
if (isEnabled == true) {
|
||||
final currentDate = DateTime.now().toUtc();
|
||||
log('VacationResponseExtension::vacationResponderIsStopped(): currentDate: $currentDate');
|
||||
final endDate = toDate?.value.toUtc();
|
||||
log('VacationResponseExtension::vacationResponderIsStopped(): endDate: $endDate');
|
||||
if (endDate != null && endDate.isBefore(currentDate)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -59,4 +95,22 @@ extension VacationResponseExtension on VacationResponse {
|
||||
htmlBody: htmlBody ?? this.htmlBody
|
||||
);
|
||||
}
|
||||
|
||||
String getNotificationMessage(BuildContext context) {
|
||||
if (vacationResponderIsValid) {
|
||||
return AppLocalizations.of(context).yourVacationResponderIsEnabled;
|
||||
} else if (vacationResponderIsWaiting) {
|
||||
return AppLocalizations.of(context).messageEnableVacationResponderAutomatically(
|
||||
fromDate.formatDate(
|
||||
pattern: 'MMM d, y h:mm a',
|
||||
locale: Localizations.localeOf(context).toLanguageTag()));
|
||||
} else if (vacationResponderIsStopped) {
|
||||
return AppLocalizations.of(context).messageDisableVacationResponderAutomatically(
|
||||
toDate.formatDate(
|
||||
pattern: 'MMM d, y h:mm a',
|
||||
locale: Localizations.localeOf(context).toLanguageTag()));
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user