TF-832 Add data layer for delete recipient in forwarding

This commit is contained in:
dab246
2022-08-19 11:56:42 +07:00
committed by Dat H. Pham
parent 3f32b71f95
commit d4ed43a65f
4 changed files with 51 additions and 0 deletions
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:forward/forward/forward_id.dart';
import 'package:forward/forward/get/get_forward_method.dart';
import 'package:forward/forward/get/get_forward_response.dart';
import 'package:forward/forward/set/set_forward_method.dart';
import 'package:forward/forward/tmail_forward.dart';
import 'package:jmap_dart_client/http/http_client.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
@@ -260,4 +261,35 @@ class ManageAccountAPI {
return resultList?.list ?? <VacationResponse>[];
}
Future<TMailForward> updateForward(AccountId accountId, TMailForward forward) async {
final setForwardMethod = SetForwardMethod(accountId)
..addUpdatesSingleton({
ForwardIdSingleton.forwardIdSingleton.id : forward
});
final processingInvocation = ProcessingInvocation();
final requestBuilder = JmapRequestBuilder(_httpClient, processingInvocation)
..invocation(setForwardMethod);
final getForwardMethod = GetForwardMethod(accountId)
..addIds({ForwardIdSingleton.forwardIdSingleton.id});
final getForwardInvocation = requestBuilder.invocation(getForwardMethod);
final response = await (requestBuilder
..usings(setForwardMethod.requiredCapabilities))
.build()
.execute();
final getForwardResponse = response.parse<GetForwardResponse>(
getForwardInvocation.methodCallId,
GetForwardResponse.deserialize);
final newForward = getForwardResponse?.list.first;
if (newForward == null) {
throw NotFoundForwardException();
}
return newForward;
}
}