Google Registration+ device info

This commit is contained in:
2016-07-03 23:57:33 +02:00
parent 5b3ed5f5ff
commit 1a7cd378ad
6 changed files with 25 additions and 32 deletions

View File

@ -3,34 +3,18 @@ using System.ComponentModel.DataAnnotations.Schema;
using Yavsc.Models; using Yavsc.Models;
public class GoogleCloudMobileDeclaration { public class GoogleCloudMobileDeclaration {
[Key]
public string RegistrationId { get; set; } public string GCMRegistrationId { get; set; }
public string DeviceOwnerId { 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")] [ForeignKeyAttribute("DeviceOwnerId")]
public virtual ApplicationUser DeviceOwner { get; set; } 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();
}
} }

View File

@ -16,7 +16,12 @@ public class GCMController : Controller {
_logger = loggerFactory.CreateLogger<GCMController>(); _logger = loggerFactory.CreateLogger<GCMController>();
_context = context; _context = context;
} }
/// <summary>
/// This is not a method supporting user creation.
/// It only registers Google Clood Messaging id.
/// </summary>
/// <param name="declaration"></param>
/// <returns></returns>
public IActionResult Register (GoogleCloudMobileDeclaration declaration) public IActionResult Register (GoogleCloudMobileDeclaration declaration)
{ {
if (declaration.DeviceOwnerId!=null) if (declaration.DeviceOwnerId!=null)
@ -25,9 +30,9 @@ public class GCMController : Controller {
new { error = "you're not allowed to register for another user" }  new { error = "you're not allowed to register for another user" } 
); );
declaration.DeviceOwnerId = User.GetUserId(); 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 // Assert alreadyRegisteredDevice != null
if (alreadyRegisteredDevice != declaration) { if (alreadyRegisteredDevice != declaration) {
_context.GCMDevices.Update(declaration); _context.GCMDevices.Update(declaration);

View File

@ -53,7 +53,7 @@ namespace Yavsc.Helpers
var regids = new List<string> (); var regids = new List<string> ();
foreach (var c in evpub.Circles) foreach (var c in evpub.Circles)
foreach (var u in c.Members) { 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; if (regids.Count>0) return null;
var request = new HttpRequestMessage(HttpMethod.Get, Constants.GCMNotificationUrl); var request = new HttpRequestMessage(HttpMethod.Get, Constants.GCMNotificationUrl);

View File

@ -1,7 +1,6 @@
using System; using System;
using Microsoft.Data.Entity; using Microsoft.Data.Entity;
using Microsoft.Data.Entity.Infrastructure; using Microsoft.Data.Entity.Infrastructure;
using Microsoft.Data.Entity.Metadata;
using Microsoft.Data.Entity.Migrations; using Microsoft.Data.Entity.Migrations;
using Yavsc.Models; using Yavsc.Models;

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using Microsoft.Data.Entity.Migrations; using Microsoft.Data.Entity.Migrations;
namespace Yavsc.Migrations namespace Yavsc.Migrations

View File

@ -17,13 +17,19 @@ namespace Yavsc.Migrations
modelBuilder.Entity("GoogleCloudMobileDeclaration", b => modelBuilder.Entity("GoogleCloudMobileDeclaration", b =>
{ {
b.Property<string>("RegistrationId"); b.Property<string>("DeviceId");
b.Property<string>("DeviceOwnerId"); b.Property<string>("DeviceOwnerId");
b.Property<string>("Name"); b.Property<string>("GCMRegistrationId");
b.HasKey("RegistrationId"); b.Property<string>("Model");
b.Property<string>("Platform");
b.Property<string>("Version");
b.HasKey("DeviceId");
}); });
modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRole", b => modelBuilder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRole", b =>