TF-934 Add interactor get email by id

This commit is contained in:
dab246
2022-11-04 21:58:55 +07:00
committed by Dat H. Pham
parent a4eb2ffbec
commit 4c9beb7526
8 changed files with 107 additions and 0 deletions
@@ -139,4 +139,29 @@ class ThreadAPI {
hasMoreChanges: resultChanges?.hasMoreChanges ?? false,
updatedProperties: propertiesUpdated);
}
Future<Email> getEmailById(AccountId accountId, EmailId emailId, {Properties? properties}) async {
final processingInvocation = ProcessingInvocation();
final jmapRequestBuilder = JmapRequestBuilder(httpClient, processingInvocation);
final getEmailMethod = GetEmailMethod(accountId)
..addIds({emailId.id});
if (properties != null) {
getEmailMethod.addProperties(properties);
}
final getEmailInvocation = jmapRequestBuilder.invocation(getEmailMethod);
final result = await (jmapRequestBuilder
..usings(getEmailMethod.requiredCapabilities))
.build()
.execute();
final resultList = result.parse<GetEmailResponse>(
getEmailInvocation.methodCallId,
GetEmailResponse.deserialize);
return resultList!.list.first;
}
}