1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 00:22:50 -05: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

@ -15,12 +15,14 @@ namespace Bit.Api.Controllers
public class PushController : Controller
{
private readonly IPushRegistrationService _pushRegistrationService;
private readonly IPushNotificationService _pushNotificationService;
private readonly IHostingEnvironment _environment;
private readonly CurrentContext _currentContext;
private readonly GlobalSettings _globalSettings;
public PushController(
IPushRegistrationService pushRegistrationService,
IPushNotificationService pushNotificationService,
IHostingEnvironment environment,
CurrentContext currentContext,
GlobalSettings globalSettings)
@ -28,6 +30,7 @@ namespace Bit.Api.Controllers
_currentContext = currentContext;
_environment = environment;
_pushRegistrationService = pushRegistrationService;
_pushNotificationService = pushNotificationService;
_globalSettings = globalSettings;
}
@ -62,8 +65,30 @@ namespace Bit.Api.Controllers
model.DeviceIds.Select(d => Prefix(d)), Prefix(model.OrganizationId));
}
[HttpPost("send")]
public async Task PostSend(PushSendRequestModel model)
{
CheckUsage();
if(!string.IsNullOrWhiteSpace(model.UserId))
{
await _pushNotificationService.SendPayloadToUserAsync(Prefix(model.OrganizationId),
model.Type.Value, model.Payload, Prefix(model.Identifier));
}
else if(!string.IsNullOrWhiteSpace(model.OrganizationId))
{
await _pushNotificationService.SendPayloadToOrganizationAsync(Prefix(model.OrganizationId),
model.Type.Value, model.Payload, Prefix(model.Identifier));
}
}
private string Prefix(string value)
{
if(string.IsNullOrWhiteSpace(value))
{
return null;
}
return $"{_currentContext.InstallationId.Value}_{value}";
}