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:
@@ -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})";
|
||||
|
||||
Reference in New Issue
Block a user