diff --git a/Yavsc/src/Controllers/CommandController.cs b/Yavsc/src/Controllers/CommandController.cs index a6e7d32e..8bac6f85 100644 --- a/Yavsc/src/Controllers/CommandController.cs +++ b/Yavsc/src/Controllers/CommandController.cs @@ -133,9 +133,9 @@ namespace Yavsc.Controllers _context.SaveChanges(); if (command.PerformerProfile.AcceptNotifications && command.PerformerProfile.AcceptPublicContact - && command.PerformerProfile.Performer.GoogleRegId!=null) { + && command.PerformerProfile.Performer.Devices.Select(d=>d.RegistrationId)!=null) { grep = await _GCMSender.NotifyAsync(_googleSettings, - command.PerformerProfile.Performer.GoogleRegId, + command.PerformerProfile.Performer.Devices.Select(d=>d.RegistrationId), yaev ); } diff --git a/Yavsc/src/Controllers/UserFilesController.cs b/Yavsc/src/Controllers/UserFilesController.cs index 9435197b..8b8e444f 100644 --- a/Yavsc/src/Controllers/UserFilesController.cs +++ b/Yavsc/src/Controllers/UserFilesController.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Hosting; -using Microsoft.AspNet.Http; using Microsoft.AspNet.Mvc; using Microsoft.Extensions.Logging; using Microsoft.Extensions.OptionsModel; diff --git a/Yavsc/src/Helpers/GoogleHelpers.cs b/Yavsc/src/Helpers/GoogleHelpers.cs index 2cc3ec31..ad31ce59 100644 --- a/Yavsc/src/Helpers/GoogleHelpers.cs +++ b/Yavsc/src/Helpers/GoogleHelpers.cs @@ -49,45 +49,36 @@ namespace Yavsc.Helpers //send a MessageWithPayload to circle members // receive MessageWithPayloadResponse // "https://gcm-http.googleapis.com/gcm/send" - var request = new HttpRequestMessage(HttpMethod.Get, Constants.GCMNotificationUrl); - request.Headers.Authorization = new AuthenticationHeaderValue("Key", googleSettings.ApiKey); var regids = new List (); - var to = new List (); foreach (var c in evpub.Circles) foreach (var u in c.Members) { - if (u.Member.GoogleRegId == null) - to.Add (u.Member.Email); - else - regids.Add ((string)u.Member.GoogleRegId); + regids.AddRange (u.Member.Devices.Select(d=>d.RegistrationId)); } - - if (regids.Count == 0) - throw new InvalidOperationException - ("No recipient where found for this circle list"); - + if (regids.Count>0) return null; + var request = new HttpRequestMessage(HttpMethod.Get, Constants.GCMNotificationUrl); + request.Headers.Authorization = new AuthenticationHeaderValue("Key", googleSettings.ApiKey); var msg = new MessageWithPayload () { notification = new Notification() { title = evpub.Title, body = evpub.Description, icon = "event" }, data = evpub , registration_ids = regids.ToArray() }; - - var response = await channel.SendAsync(request); - var payload = JObject.Parse(await response.Content.ReadAsStringAsync()); - return payload.Value(); + var response = await channel.SendAsync(request); + var payload = JObject.Parse(await response.Content.ReadAsStringAsync()); + return payload.Value(); } public static async Task NotifyEvent - (this HttpClient channel, GoogleAuthSettings googleSettings, string regid, Event ev) + (this HttpClient channel, GoogleAuthSettings googleSettings, IEnumerable regids, Event ev) where Event : YaEvent { - if (regid == null) - throw new NotImplementedException ("Notify & No GCM reg id"); + if (regids == null) + throw new NotImplementedException ("Notify & No GCM reg ids"); var request = new HttpRequestMessage(HttpMethod.Get, Constants.GCMNotificationUrl); request.Headers.Authorization = new AuthenticationHeaderValue("Key", googleSettings.ApiKey); var msg = new MessageWithPayload () { notification = new Notification() { title = ev.Title, body = ev.Description + ev.Comment==null? "":"("+ev.Comment+")", icon = "icon" }, - data = ev, registration_ids = new string[] { regid } }; + data = ev, registration_ids = regids.ToArray() }; var response = await channel.SendAsync(request); var payload = JObject.Parse(await response.Content.ReadAsStringAsync()); diff --git a/Yavsc/src/Model/Identity/ApplicationUser.cs b/Yavsc/src/Model/Identity/ApplicationUser.cs index 34cfbe6b..d34e8a7b 100644 --- a/Yavsc/src/Model/Identity/ApplicationUser.cs +++ b/Yavsc/src/Model/Identity/ApplicationUser.cs @@ -10,7 +10,6 @@ namespace Yavsc.Models // Add profile data for application users by adding properties to the ApplicationUser class public class ApplicationUser : IdentityUser { - public string GoogleRegId { get; set; } [Display(Name="AccountBalance")] public virtual AccountBalance AccountBalance { get; set; } diff --git a/Yavsc/src/Services/IGoogleCloudMessageSender.cs b/Yavsc/src/Services/IGoogleCloudMessageSender.cs index 65e42016..b4db0123 100644 --- a/Yavsc/src/Services/IGoogleCloudMessageSender.cs +++ b/Yavsc/src/Services/IGoogleCloudMessageSender.cs @@ -1,4 +1,5 @@ +using System.Collections.Generic; using System.Threading.Tasks; using Yavsc.Models.Google.Messaging; using Yavsc.Models.Messaging; @@ -7,6 +8,6 @@ namespace Yavsc.Services { public interface IGoogleCloudMessageSender { - Task NotifyAsync(GoogleAuthSettings googlesettings, string registrationId, YaEvent ev); + Task NotifyAsync(GoogleAuthSettings googlesettings, IEnumerable registrationId, YaEvent ev); } }