问题
In outlook (website or application), before a message will be sent (click on send button), we're trying to check/adapt the "to" addresses. We want to make sure that the email addresses are adapted before the message is sent.
For this we're actually using the event item.to.getAsync() The problem is that this event is not called on sent button click and we observed that the event (item.to.getAsync()) takes to much time to be trigerred by a value change in the "to" field.
Example: After entering a recipient and clicking into the content part of the message, we need to wait 5 seconds before we get the event from Microsoft Outlook API that give us the new list of recipients.
This means, if a user clicks on the send button and the call event has not been triggered yet from microsoft api, we cannot make sure that the recipients has been adapted.
• Now the question is, how could we improve this delay? • How does the Async listener work? • Does any instant event exist to catch updates on "to" field ?
Thank you for your help!
Best Regards.
More details....
Here a pseudo code example:
var testApp = (function () {
'use strict';
var self = {};
self.lookupRate = 500;
var item = Office.context.mailbox.item;
self.initialize = function () {
setInterval(function () {
self.updateRecipients();
}, self.lookupRate);
};
self.updateRecipients = function () {
item.to.getAsync(function (asyncResult) {
self.setRecipients(asyncResult);
});
};
self.setRecipients = function () {
var hasChanged = false;
for (var i = 0; i < asyncResult.value.length; i++) {
// asyncResult.value[i].emailAddress are updated only after 5 seconds.
if(!alreadyAdaptedAndNotNew(asyncResult.value[i].emailAddress) || hasChanged)
{
hasChanged===true;
}
}
if(hasChanged)
{
// Push adapted emailaddresses are instant.
adaptEmails();
}
};
})();
Our Goal: Two times per second, we're pulling the state of the email recipients (the "to" field). We want catch to the changes on this field and adapt the emailadresses before a user sends a messsage.
Error Resume: Mailbox Api allows us to get the updated emailadresses using "asyncResult.value[i].emailAddress". The problem is, when we enter an new emailadress, the Api needs 5 seconds before an update is done on the "asyncResult.value[i].emailAddress". This means, during this 5 seconds, if a user clicks on the send button we cannot make sure that the email addresses are adapted before the message is sent. This error occurs on OWA and on OUTLOOK App.
来源:https://stackoverflow.com/questions/55532295/item-to-getasync-when-the-to-value-changed-is-trigerred-to-late