From 1a7cd378ad236cb98bcb0689b6ec1cf45abc7d87 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 3 Jul 2016 23:57:33 +0200 Subject: [PATCH] Google Registration+ device info --- .../Model/Identity/MobileAppDeclaration.cs | 30 +++++-------------- Yavsc/ApiController/GCMController.cs | 11 +++++-- Yavsc/Helpers/GoogleHelpers.cs | 2 +- .../20160614010545_bookquery.Designer.cs | 1 - Yavsc/Migrations/20160614010545_bookquery.cs | 1 - .../ApplicationDbContextModelSnapshot.cs | 12 ++++++-- 6 files changed, 25 insertions(+), 32 deletions(-) diff --git a/Yavsc.Api/Model/Identity/MobileAppDeclaration.cs b/Yavsc.Api/Model/Identity/MobileAppDeclaration.cs index 313575cb..e53db50c 100644 --- a/Yavsc.Api/Model/Identity/MobileAppDeclaration.cs +++ b/Yavsc.Api/Model/Identity/MobileAppDeclaration.cs @@ -3,34 +3,18 @@ using System.ComponentModel.DataAnnotations.Schema; using Yavsc.Models; public class GoogleCloudMobileDeclaration { - [Key] - public string RegistrationId { get; set; } + public string GCMRegistrationId { get; set; } public string DeviceOwnerId { get; set; } + + [Key] + public string DeviceId { get; set; } - public string Name { get; set; } + public string Model { get; set; } + public string Platform { get; set; } + public string Version { get; set; } [ForeignKeyAttribute("DeviceOwnerId")] public virtual ApplicationUser DeviceOwner { get; set; } - - // override object.Equals - public override bool Equals (object obj) - { - if (obj == null || GetType() != obj.GetType()) - { - return false; - } - - var other = obj as GoogleCloudMobileDeclaration; - return RegistrationId == other.RegistrationId - && Name == other.Name; - } - - // override object.GetHashCode - public override int GetHashCode() - { - return (RegistrationId+Name).GetHashCode(); - } - } diff --git a/Yavsc/ApiController/GCMController.cs b/Yavsc/ApiController/GCMController.cs index 85aede96..a7b7e4e2 100644 --- a/Yavsc/ApiController/GCMController.cs +++ b/Yavsc/ApiController/GCMController.cs @@ -16,7 +16,12 @@ public class GCMController : Controller { _logger = loggerFactory.CreateLogger(); _context = context; } - + /// + /// This is not a method supporting user creation. + /// It only registers Google Clood Messaging id. + /// + /// + /// public IActionResult Register (GoogleCloudMobileDeclaration declaration) { if (declaration.DeviceOwnerId!=null) @@ -25,9 +30,9 @@ public class GCMController : Controller { new { error = "you're not allowed to register for another user" }  ); declaration.DeviceOwnerId = User.GetUserId(); - if (_context.GCMDevices.Any(d => d.RegistrationId == declaration.RegistrationId)) + if (_context.GCMDevices.Any(d => d.DeviceId == declaration.DeviceId)) { - var alreadyRegisteredDevice = _context.GCMDevices.FirstOrDefault(d => d.RegistrationId == declaration.RegistrationId); + var alreadyRegisteredDevice = _context.GCMDevices.FirstOrDefault(d => d.DeviceId == declaration.DeviceId); // Assert alreadyRegisteredDevice != null if (alreadyRegisteredDevice != declaration) { _context.GCMDevices.Update(declaration); diff --git a/Yavsc/Helpers/GoogleHelpers.cs b/Yavsc/Helpers/GoogleHelpers.cs index ad31ce59..eca1e91b 100644 --- a/Yavsc/Helpers/GoogleHelpers.cs +++ b/Yavsc/Helpers/GoogleHelpers.cs @@ -53,7 +53,7 @@ namespace Yavsc.Helpers var regids = new List (); foreach (var c in evpub.Circles) foreach (var u in c.Members) { - regids.AddRange (u.Member.Devices.Select(d=>d.RegistrationId)); + regids.AddRange (u.Member.Devices.Select(d=>d.GCMRegistrationId)); } if (regids.Count>0) return null; var request = new HttpRequestMessage(HttpMethod.Get, Constants.GCMNotificationUrl); diff --git a/Yavsc/Migrations/20160614010545_bookquery.Designer.cs b/Yavsc/Migrations/20160614010545_bookquery.Designer.cs index b000df2e..7c12d44c 100644 --- a/Yavsc/Migrations/20160614010545_bookquery.Designer.cs +++ b/Yavsc/Migrations/20160614010545_bookquery.Designer.cs @@ -1,7 +1,6 @@ using System; using Microsoft.Data.Entity; using Microsoft.Data.Entity.Infrastructure; -using Microsoft.Data.Entity.Metadata; using Microsoft.Data.Entity.Migrations; using Yavsc.Models; diff --git a/Yavsc/Migrations/20160614010545_bookquery.cs b/Yavsc/Migrations/20160614010545_bookquery.cs index 4e33216b..0e90975b 100644 --- a/Yavsc/Migrations/20160614010545_bookquery.cs +++ b/Yavsc/Migrations/20160614010545_bookquery.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using Microsoft.Data.Entity.Migrations; namespace Yavsc.Migrations diff --git a/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs b/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs index 21362a2c..60c4ea2b 100644 --- a/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Yavsc/Migrations/ApplicationDbContextModelSnapshot.cs @@ -17,13 +17,19 @@ namespace Yavsc.Migrations modelBuilder.Entity("GoogleCloudMobileDeclaration", b => { - b.Property("RegistrationId"); + b.Property("DeviceId"); b.Property("DeviceOwnerId"); - b.Property("Name"); + b.Property("GCMRegistrationId"); + + b.Property("Model"); + + b.Property("Platform"); + + b.Property("Version"); - b.HasKey("RegistrationId"); + b.HasKey("DeviceId"); }); modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRole", b =>