always send an email, at notifying some performer

vnext
Paul Schneider 5 years ago
parent d62caa048c
commit 53fc0e26a6
1 changed files with 62 additions and 53 deletions

@ -61,9 +61,11 @@ namespace Yavsc.Services
if (raa.Length < 1)
throw new Exception("No dest id");
try {
try
{
List<MessageWithPayloadResponse.Result> results = new List<MessageWithPayloadResponse.Result>();
foreach(var userId in raa) {
foreach (var userId in raa)
{
MessageWithPayloadResponse.Result result = new MessageWithPayloadResponse.Result();
result.registration_id = userId;
@ -74,12 +76,14 @@ namespace Yavsc.Services
result.error = "no such user.";
continue;
}
if (!user.EmailConfirmed){
if (!user.EmailConfirmed)
{
response.failure++;
result.error = "user has not confirmed his email address.";
continue;
}
if (user.Email==null){
if (user.Email == null)
{
response.failure++;
result.error = "user has no legacy email address.";
continue;
@ -87,10 +91,7 @@ namespace Yavsc.Services
var body = ev.CreateBody();
var cxids = _cxManager.GetConnexionIds(user.UserName).ToArray();
if (cxids.Length==0)
{
_logger.LogDebug($"Sending to {user.UserName} <{user.Email}> : {body}");
var mailSent = await _emailSender.SendEmailAsync(
user.UserName,
@ -99,7 +100,8 @@ namespace Yavsc.Services
body + Environment.NewLine
);
if (!mailSent.Sent) {
if (!mailSent.Sent)
{
result.message_id = mailSent.MessageId;
result.error = mailSent.ErrorMessage;
response.failure++;
@ -109,11 +111,17 @@ namespace Yavsc.Services
result.message_id = mailSent.MessageId;
response.success++;
}
var cxids = _cxManager.GetConnexionIds(user.UserName).ToArray();
if (cxids.Length == 0)
{
_logger.LogDebug($"no cx to {user.UserName} <{user.Email}> ");
}
else {
else
{
_logger.LogDebug($"Sending signal to {string.Join(" ", cxids)} : " + JsonConvert.SerializeObject(ev));
foreach( var cxid in cxids) {
foreach (var cxid in cxids)
{
var hubClient = hubContext.Clients.User(cxid);
var data = new Dictionary<string, object>();
data["event"] = ev;
@ -132,7 +140,8 @@ namespace Yavsc.Services
response.results = results.ToArray();
return response;
}
catch (Exception ex) {
catch (Exception ex)
{
_logger.LogError("Quelque chose s'est mal passé à l'envoi: " + ex.Message);
throw;
}

Loading…