TF-2182 Add event actions for google event
(cherry picked from commit 3ca22fdda072ad1fe29378b3d733cef74aa1ab5f)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
|
||||
import 'package:collection/collection.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';
|
||||
@@ -23,14 +22,7 @@ class LocalCalendarEventDataSourceImpl extends CalendarEventDataSource {
|
||||
@override
|
||||
Future<List<EventAction>> getListEventAction(String emailContents) {
|
||||
return Future.sync(() async {
|
||||
final listLink = await _htmlAnalyzer.getListLinkCalendarEvent(emailContents);
|
||||
if (listLink.length >= EventActionType.values.length) {
|
||||
return EventActionType.values
|
||||
.mapIndexed((index, type) => EventAction(type, listLink[index]))
|
||||
.toList();
|
||||
} else {
|
||||
return <EventAction>[];
|
||||
}
|
||||
return await _htmlAnalyzer.getListEventAction(emailContents);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/html_transform.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:html/parser.dart';
|
||||
import 'package:model/email/email_content.dart';
|
||||
import 'package:model/email/email_content_type.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/event_action.dart';
|
||||
|
||||
class HtmlAnalyzer {
|
||||
|
||||
@@ -36,14 +38,55 @@ class HtmlAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<String>> getListLinkCalendarEvent(String emailContents) async {
|
||||
final document = parse(emailContents);
|
||||
final linkElements = document.querySelectorAll('a.part-button');
|
||||
final listLink = linkElements
|
||||
.map((element) => element.attributes['href'])
|
||||
.whereNotNull()
|
||||
.toList();
|
||||
return listLink;
|
||||
Future<List<EventAction>> getListEventAction(String emailContents) async {
|
||||
try {
|
||||
final document = parse(emailContents);
|
||||
|
||||
final openPaasLinkElements = document.querySelectorAll('a.part-button');
|
||||
if (openPaasLinkElements.isNotEmpty) {
|
||||
final listEventAction = openPaasLinkElements
|
||||
.mapIndexed((index, element) {
|
||||
final hrefLink = element.attributes['href'] ?? '';
|
||||
if (hrefLink.isNotEmpty) {
|
||||
if (index == 0) {
|
||||
return EventAction(EventActionType.yes, hrefLink);
|
||||
} else if (index == 1) {
|
||||
return EventAction(EventActionType.maybe, hrefLink);
|
||||
} else if (index == 2) {
|
||||
return EventAction(EventActionType.no, hrefLink);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.whereNotNull()
|
||||
.toList();
|
||||
log('HtmlAnalyzer::getListEventAction:OPEN_PAAS::listEventAction: $listEventAction');
|
||||
return listEventAction;
|
||||
} else {
|
||||
final googleLinkElements = document.querySelectorAll('a.grey-button-text');
|
||||
final listEventAction = googleLinkElements
|
||||
.mapIndexed((index, element) {
|
||||
final hrefLink = element.attributes['href'] ?? '';
|
||||
if (hrefLink.isNotEmpty) {
|
||||
if (index == 0) {
|
||||
return EventAction(EventActionType.yes, hrefLink);
|
||||
} else if (index == 1) {
|
||||
return EventAction(EventActionType.no, hrefLink);
|
||||
} else if (index == 2) {
|
||||
return EventAction(EventActionType.maybe, hrefLink);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
})
|
||||
.whereNotNull()
|
||||
.toList();
|
||||
log('HtmlAnalyzer::getListEventAction:GOOGLE::listEventAction: $listEventAction');
|
||||
return listEventAction;
|
||||
}
|
||||
} catch(e) {
|
||||
logError('HtmlAnalyzer::getListEventAction:Exception: $e');
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> transformHtmlEmailContent(
|
||||
|
||||
Reference in New Issue
Block a user