1
0
mirror of https://github.com/bitwarden/server synced 2025-12-12 06:13:43 +00:00

push notification relay service and relay send api

This commit is contained in:
Kyle Spearrin
2017-08-11 10:04:59 -04:00
parent 0f37920de2
commit 6fe5e3b849
10 changed files with 487 additions and 181 deletions

View File

@@ -126,26 +126,43 @@ namespace Bit.Core.Services
private async Task SendPayloadToUserAsync(Guid userId, PushType type, object payload, bool excludeCurrentContext)
{
var tag = BuildTag($"template:payload_userId:{userId}", excludeCurrentContext);
await SendPayloadAsync(tag, type, payload);
await SendPayloadToUserAsync(userId.ToString(), type, payload, GetContextIdentifier(excludeCurrentContext));
}
private async Task SendPayloadToOrganizationAsync(Guid orgId, PushType type, object payload, bool excludeCurrentContext)
{
var tag = BuildTag($"template:payload && organizationId:{orgId}", excludeCurrentContext);
await SendPayloadToUserAsync(orgId.ToString(), type, payload, GetContextIdentifier(excludeCurrentContext));
}
public async Task SendPayloadToUserAsync(string userId, PushType type, object payload, string identifier)
{
var tag = BuildTag($"template:payload_userId:{userId}", identifier);
await SendPayloadAsync(tag, type, payload);
}
private string BuildTag(string tag, bool excludeCurrentContext)
public async Task SendPayloadToOrganizationAsync(string orgId, PushType type, object payload, string identifier)
{
if(excludeCurrentContext)
var tag = BuildTag($"template:payload && organizationId:{orgId}", identifier);
await SendPayloadAsync(tag, type, payload);
}
private string GetContextIdentifier(bool excludeCurrentContext)
{
if(!excludeCurrentContext)
{
var currentContext = _httpContextAccessor?.HttpContext?.
return null;
}
var currentContext = _httpContextAccessor?.HttpContext?.
RequestServices.GetService(typeof(CurrentContext)) as CurrentContext;
if(!string.IsNullOrWhiteSpace(currentContext?.DeviceIdentifier))
{
tag += $" && !deviceIdentifier:{currentContext.DeviceIdentifier}";
}
return currentContext?.DeviceIdentifier;
}
private string BuildTag(string tag, string identifier)
{
if(!string.IsNullOrWhiteSpace(identifier))
{
tag += $" && !deviceIdentifier:{identifier}";
}
return $"({tag})";