TF-2078 Implement get calendar event action in domain & data layer
(cherry picked from commit 6c372d57cfebf31e776f071b514e71c637b44257)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
enum EventActionType {
|
||||
yes,
|
||||
maybe,
|
||||
no;
|
||||
|
||||
String getLabelButton(BuildContext context) {
|
||||
switch(this) {
|
||||
case EventActionType.yes:
|
||||
return AppLocalizations.of(context).yes;
|
||||
case EventActionType.maybe:
|
||||
return AppLocalizations.of(context).maybe;
|
||||
case EventActionType.no:
|
||||
return AppLocalizations.of(context).no;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class EventAction with EquatableMixin {
|
||||
final EventActionType actionType;
|
||||
final String link;
|
||||
|
||||
EventAction(this.actionType, this.link);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [actionType, link];
|
||||
}
|
||||
@@ -1,17 +1,19 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/event_action.dart';
|
||||
|
||||
class ParseCalendarEventLoading extends LoadingState {}
|
||||
|
||||
class ParseCalendarEventSuccess extends UIState {
|
||||
|
||||
final List<CalendarEvent> calendarEventList;
|
||||
final List<EventAction> eventActionList;
|
||||
|
||||
ParseCalendarEventSuccess(this.calendarEventList);
|
||||
ParseCalendarEventSuccess(this.calendarEventList, this.eventActionList);
|
||||
|
||||
@override
|
||||
List<Object> get props => [calendarEventList];
|
||||
List<Object> get props => [calendarEventList, eventActionList];
|
||||
}
|
||||
|
||||
class ParseCalendarEventFailure extends FeatureFailure {
|
||||
|
||||
@@ -3,6 +3,8 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/event_action.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/calendar_event_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/parse_calendar_event_state.dart';
|
||||
|
||||
@@ -11,11 +13,26 @@ class ParseCalendarEventInteractor {
|
||||
|
||||
ParseCalendarEventInteractor(this._calendarEventRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, Set<Id> blobIds) async* {
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
AccountId accountId,
|
||||
Set<Id> blobIds,
|
||||
String emailContents
|
||||
) async* {
|
||||
try {
|
||||
yield Right(ParseCalendarEventLoading());
|
||||
final calendarEventList = await _calendarEventRepository.parse(accountId, blobIds);
|
||||
yield Right(ParseCalendarEventSuccess(calendarEventList));
|
||||
|
||||
final result = await Future.wait(
|
||||
[
|
||||
_calendarEventRepository.parse(accountId, blobIds),
|
||||
_calendarEventRepository.getListEventAction(emailContents),
|
||||
],
|
||||
eagerError: true
|
||||
);
|
||||
|
||||
final calendarEventList = result.first as List<CalendarEvent>;
|
||||
final eventActionList = result.last as List<EventAction>;
|
||||
|
||||
yield Right(ParseCalendarEventSuccess(calendarEventList, eventActionList));
|
||||
} catch (e) {
|
||||
yield Left(ParseCalendarEventFailure(e));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user