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/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart';
|
import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart';
|
||||||
@@ -23,14 +22,7 @@ class LocalCalendarEventDataSourceImpl extends CalendarEventDataSource {
|
|||||||
@override
|
@override
|
||||||
Future<List<EventAction>> getListEventAction(String emailContents) {
|
Future<List<EventAction>> getListEventAction(String emailContents) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final listLink = await _htmlAnalyzer.getListLinkCalendarEvent(emailContents);
|
return await _htmlAnalyzer.getListEventAction(emailContents);
|
||||||
if (listLink.length >= EventActionType.values.length) {
|
|
||||||
return EventActionType.values
|
|
||||||
.mapIndexed((index, type) => EventAction(type, listLink[index]))
|
|
||||||
.toList();
|
|
||||||
} else {
|
|
||||||
return <EventAction>[];
|
|
||||||
}
|
|
||||||
}).catchError(_exceptionThrower.throwException);
|
}).catchError(_exceptionThrower.throwException);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/html_transform.dart';
|
import 'package:core/presentation/utils/html_transformer/html_transform.dart';
|
||||||
import 'package:core/presentation/utils/html_transformer/transform_configuration.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:html/parser.dart';
|
||||||
import 'package:model/email/email_content.dart';
|
import 'package:model/email/email_content.dart';
|
||||||
import 'package:model/email/email_content_type.dart';
|
import 'package:model/email/email_content_type.dart';
|
||||||
|
import 'package:tmail_ui_user/features/email/domain/model/event_action.dart';
|
||||||
|
|
||||||
class HtmlAnalyzer {
|
class HtmlAnalyzer {
|
||||||
|
|
||||||
@@ -36,14 +38,55 @@ class HtmlAnalyzer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<String>> getListLinkCalendarEvent(String emailContents) async {
|
Future<List<EventAction>> getListEventAction(String emailContents) async {
|
||||||
final document = parse(emailContents);
|
try {
|
||||||
final linkElements = document.querySelectorAll('a.part-button');
|
final document = parse(emailContents);
|
||||||
final listLink = linkElements
|
|
||||||
.map((element) => element.attributes['href'])
|
final openPaasLinkElements = document.querySelectorAll('a.part-button');
|
||||||
.whereNotNull()
|
if (openPaasLinkElements.isNotEmpty) {
|
||||||
.toList();
|
final listEventAction = openPaasLinkElements
|
||||||
return listLink;
|
.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(
|
Future<String> transformHtmlEmailContent(
|
||||||
|
|||||||
Reference in New Issue
Block a user