Google Registration+ device info
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,12 @@ public class GCMController : Controller {
|
||||
_logger = loggerFactory.CreateLogger<GCMController>();
|
||||
_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)
|
||||
{
|
||||
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);
|
||||
|
@ -53,7 +53,7 @@ namespace Yavsc.Helpers
|
||||
var regids = new List<string> ();
|
||||
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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Data.Entity.Migrations;
|
||||
|
||||
namespace Yavsc.Migrations
|
||||
|
@ -17,13 +17,19 @@ namespace Yavsc.Migrations
|
||||
|
||||
modelBuilder.Entity("GoogleCloudMobileDeclaration", b =>
|
||||
{
|
||||
b.Property<string>("RegistrationId");
|
||||
b.Property<string>("DeviceId");
|
||||
|
||||
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 =>
|
||||
|
Reference in New Issue
Block a user