From 44d8b772ab05c947f58e19e2d4b96c34352df29e Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Tue, 3 Jan 2017 21:39:32 +0100 Subject: [PATCH] Trying to send a live mass message, now --- Backend/CommsTransmitter.cs | 17 +++++----- Site/Pages/v5/Comms/SendMassMessage.aspx | 36 ++++++++++++--------- Site/Pages/v5/Comms/SendMassMessage.aspx.cs | 6 +++- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/Backend/CommsTransmitter.cs b/Backend/CommsTransmitter.cs index d5755c13..da441422 100644 --- a/Backend/CommsTransmitter.cs +++ b/Backend/CommsTransmitter.cs @@ -37,7 +37,7 @@ namespace Swarmops.Backend customStrings["GeographyName"] = ((IHasGeography) resolver).Geography.Name; } OutboundComm.CreateNotification(Organization.FromIdentity(comm.OrganizationId), - NotificationResource.OutboundComm_Resolved, notifyStrings, + NotificationResource.OutboundComm_Resolved, notifyStrings, customStrings, People.FromSingle(Person.FromIdentity(comm.SenderPersonId))); } @@ -76,22 +76,23 @@ namespace Swarmops.Backend { ICommsResolver resolver = FindResolver(comm); - // "Your message to[GeographyName] has been sent to all scheduled recipients.Of the[RecipientCount] planned recipients, [RecipientsSuccess] succeeded - // from Swarmops' horizon. (These can fail later for a number of reasons, from broken computers to hospitalized recipients.) - // Time spent transmitting: [TransmissionTime]." - - // TODO: CONTINUE HERE + // "Your message to [GeographyName] has been sent to all scheduled recipients. Of the [RecipientCount] planned recipients, + // [RecipientsSuccess] succeeded from Swarmops' horizon. (These can fail later for a number of reasons, from broken + // computers to hospitalized recipients.) Time spent transmitting: [TransmissionTime]." NotificationStrings notifyStrings = new NotificationStrings(); NotificationCustomStrings customStrings = new NotificationCustomStrings(); notifyStrings[NotificationString.OrganizationName] = Organization.FromIdentity(comm.OrganizationId).Name; customStrings["RecipientCount"] = comm.Recipients.Count.ToString("N0"); + customStrings["RecipientsSuccess"] = comm.RecipientsSuccess.ToString("N0"); + customStrings["TransmissionTime"] = + (comm.ClosedDateTime - comm.StartTransmitDateTime).ToString("m min ss.ff sec"); if (resolver is IHasGeography) { - customStrings["Geography"] = ((IHasGeography)resolver).Geography.Name; + customStrings["GeographyName"] = ((IHasGeography)resolver).Geography.Name; } OutboundComm.CreateNotification(Organization.FromIdentity(comm.OrganizationId), - NotificationResource.OutboundComm_Resolved, notifyStrings, + NotificationResource.OutboundComm_Sent, notifyStrings, customStrings, People.FromSingle(Person.FromIdentity(comm.SenderPersonId))); } } diff --git a/Site/Pages/v5/Comms/SendMassMessage.aspx b/Site/Pages/v5/Comms/SendMassMessage.aspx index 15b4fac5..33a3f07a 100644 --- a/Site/Pages/v5/Comms/SendMassMessage.aspx +++ b/Site/Pages/v5/Comms/SendMassMessage.aspx @@ -29,12 +29,16 @@ } function onClickSend() { - alertify.alert(SwarmopsJS.unescape('<%= this.Localized_SendMessageResult %>')); + onExecute(true); return false; } function onClickTest() { + onExecute(false); + return false; + } + function onExecute(live) { var body = $('#<%=this.TextMessage.ClientID%>').val().trim(); var subject = $('#<%=this.TextSubject.ClientID%>').val().trim(); @@ -51,22 +55,20 @@ return false; } - if (<%=this.RunningOnSandbox%> && testMessageSandboxAddress == '') - { + if (<%=this.RunningOnSandbox%> && !live && testMessageSandboxAddress == '') { // Prompt for an address to send to // This should preferably be in a mod on just Sandbox and not in code everywhere alertify.prompt("You're currently using the Sandbox. Where would you like a test message sent?", // TODO: LOC - function (evt, value) - { - testMessageSandboxAddress = value; // may need sanitation - onClickTest(); // rerun with value set - }, - function() { - alertify.log('Canceled.'); - }); + function(evt, value) { + testMessageSandboxAddress = value; // may need sanitation + onClickTest(); // rerun with value set + }, + function() { + alertify.log('Canceled.'); + }); - return false; // do not process at this time, wait for async response + return null; // do not process at this time, wait for async response } var jsonData = { @@ -82,13 +84,17 @@ SwarmopsJS.ajaxCall ("/Pages/v5/Comms/SendMassMessage.aspx/ExecuteSend", jsonData, - function (result) { + function(result) { if (result.Success) { - alertify.alert(SwarmopsJS.unescape('<%= this.Localized_TestMessageResult %>')); + if (live) { // race condition but won't probably ever trigger + alertify.alert(SwarmopsJS.unescape('<%= this.Localized_TestMessageResult %>')); + } else { + alertify.alert(SwarmopsJS.unescape('<%= this.Localized_SendMessageResult %>')); + } } }); - return false; + return null; } function onRecipientChange(oldClassIgnored, newRecipientClass) { diff --git a/Site/Pages/v5/Comms/SendMassMessage.aspx.cs b/Site/Pages/v5/Comms/SendMassMessage.aspx.cs index 936e7530..01a2427f 100644 --- a/Site/Pages/v5/Comms/SendMassMessage.aspx.cs +++ b/Site/Pages/v5/Comms/SendMassMessage.aspx.cs @@ -6,6 +6,7 @@ using System.Web.UI; using System.Web.UI.WebControls; using Resources; using Swarmops.Logic.Communications; +using Swarmops.Logic.Communications.Resolution; using Swarmops.Logic.Security; using Swarmops.Logic.Structure; using Swarmops.Logic.Support; @@ -131,7 +132,10 @@ namespace Swarmops.Frontend.Pages.Comms } else // Send live { - throw new NotImplementedException(); // TODO: Write resolver + // TODO: change resolver to match selected group + + OutboundComm.CreateParticipantMail(subject, body, authData.CurrentUser, authData.CurrentUser, authData.CurrentOrganization, Geography.FromIdentity(geographyId)); + return new AjaxCallResult { Success = true }; } }