Skip to content

Commit

Permalink
TF-2838 calendar event reject api & data source implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tddang-linagora committed Apr 29, 2024
1 parent f18357e commit e2d7286
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_accept_response.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_reject_response.dart';
import 'package:tmail_ui_user/features/email/data/datasource/calendar_event_datasource.dart';
import 'package:tmail_ui_user/features/email/data/network/calendar_event_api.dart';
import 'package:tmail_ui_user/features/email/domain/model/event_action.dart';
Expand Down Expand Up @@ -33,4 +34,11 @@ class CalendarEventDataSourceImpl extends CalendarEventDataSource {
return await _calendarEventAPI.accept(accountId, blobIds);
}).catchError(_exceptionThrower.throwException);
}

@override
Future<CalendarEventRejectResponse> rejectEventInvitation(AccountId accountId, Set<Id> blobIds) {
return Future.sync(() async {
return await _calendarEventAPI.reject(accountId, blobIds);
}).catchError(_exceptionThrower.throwException);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_accept_response.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_reject_response.dart';
import 'package:tmail_ui_user/features/email/data/datasource/calendar_event_datasource.dart';
import 'package:tmail_ui_user/features/email/data/local/html_analyzer.dart';
import 'package:tmail_ui_user/features/email/domain/model/event_action.dart';
Expand Down Expand Up @@ -31,4 +32,9 @@ class LocalCalendarEventDataSourceImpl extends CalendarEventDataSource {
Future<CalendarEventAcceptResponse> accept(AccountId accountId, Set<Id> blobIds) {
throw UnimplementedError();
}

@override
Future<CalendarEventRejectResponse> rejectEventInvitation(AccountId accountId, Set<Id> blobIds) {
throw UnimplementedError();
}
}
23 changes: 23 additions & 0 deletions lib/features/email/data/network/calendar_event_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:jmap_dart_client/jmap/mail/calendar/parse/calendar_event_parse_m
import 'package:jmap_dart_client/jmap/mail/calendar/parse/calendar_event_parse_response.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_accept_method.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_accept_response.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_reject_method.dart';
import 'package:jmap_dart_client/jmap/mail/calendar/reply/calendar_event_reject_response.dart';
import 'package:tmail_ui_user/features/email/domain/exceptions/calendar_event_exceptions.dart';

class CalendarEventAPI {
Expand Down Expand Up @@ -61,4 +63,25 @@ class CalendarEventAPI {

return calendarEventAcceptResponse;
}

Future<CalendarEventRejectResponse> reject(AccountId accountId, Set<Id> blobIds) async {
final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
final calendarEventRejectMethod = CalendarEventRejectMethod(
accountId,
blobIds: blobIds.toList());
final calendarEventRejectInvocation = requestBuilder.invocation(calendarEventRejectMethod);
final response = await (requestBuilder..usings(calendarEventRejectMethod.requiredCapabilities))
.build()
.execute();

final calendarEventRejectResponse = response.parse<CalendarEventRejectResponse>(
calendarEventRejectInvocation.methodCallId,
CalendarEventRejectResponse.deserialize);

if (calendarEventRejectResponse == null) {
throw NotRejectableCalendarEventException();
}

return calendarEventRejectResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ class NotFoundCalendarEventException implements Exception {}
class NotParsableCalendarEventException implements Exception {}

class NotAcceptableCalendarEventException implements Exception {}

class NotRejectableCalendarEventException implements Exception {}

0 comments on commit e2d7286

Please sign in to comment.