mirror of
https://github.com/bitwarden/server.git
synced 2025-05-20 02:54:32 -05:00
apple data for push notifications
This commit is contained in:
parent
00d79d0fff
commit
731e1bcf46
@ -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)
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user