1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-20 11:04:31 -05:00

apple data for push notifications

This commit is contained in:
Kyle Spearrin 2016-06-30 00:35:17 -04:00
parent 00d79d0fff
commit 731e1bcf46
2 changed files with 42 additions and 5 deletions

View File

@ -17,7 +17,6 @@ namespace Bit.Api.Models
FolderId = cipher.FolderId?.ToString();
Type = cipher.Type;
Favorite = cipher.Favorite;
Data = cipher.Data;
RevisionDate = cipher.RevisionDate;
switch(cipher.Type)

View File

@ -12,6 +12,7 @@ using System.Security.Cryptography.X509Certificates;
using Bit.Core.Domains;
using Bit.Core.Enums;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
namespace Bit.Core.Services
{
@ -59,11 +60,13 @@ namespace Bit.Core.Services
private async Task PushCipherAsync(Cipher cipher, PushType type)
{
var message = new
var message = new SyncCipherPushNotification
{
Type = type,
Id = cipher.Id,
UserId = cipher.UserId
UserId = cipher.UserId,
RevisionDate = cipher.RevisionDate,
Aps = new PushNotification.AppleData { ContentAvailable = 1 }
};
await PushToAllUserDevicesAsync(cipher.UserId, JObject.FromObject(message));
@ -71,10 +74,12 @@ namespace Bit.Core.Services
public async Task PushSyncCiphersAsync(Guid userId)
{
var message = new
var message = new SyncCiphersPushNotification
{
Type = PushType.SyncCiphers,
UserId = userId
UserId = userId,
Date = DateTime.UtcNow,
Aps = new PushNotification.AppleData { ContentAvailable = 1 }
};
await PushToAllUserDevicesAsync(userId, new JObject(message));
@ -277,5 +282,38 @@ namespace Bit.Core.Services
});
}
}
private class PushNotification
{
public PushType Type { get; set; }
[JsonProperty(PropertyName = "aps")]
public AppleData Aps { get; set; }
public class AppleData
{
[JsonProperty(PropertyName = "badge")]
public dynamic Badge { get; set; } = null;
[JsonProperty(PropertyName = "alert")]
public string Alert { get; set; }
[JsonProperty(PropertyName = "content-available")]
public int ContentAvailable { get; set; }
}
}
private abstract class SyncPushNotification : PushNotification
{
public Guid UserId { get; set; }
}
private class SyncCipherPushNotification : SyncPushNotification
{
public Guid Id { get; set; }
public DateTime RevisionDate { get; set; }
}
private class SyncCiphersPushNotification : SyncPushNotification
{
public DateTime Date { get; set; }
}
}
}