mirror of
https://github.com/bitwarden/server.git
synced 2026-02-03 23:53:19 +08:00
27 lines
1.0 KiB
C#
27 lines
1.0 KiB
C#
|
|
using Microsoft.Azure.NotificationHubs;
|
|||
|
|
|
|||
|
|
namespace Bit.Core.NotificationHub;
|
|||
|
|
|
|||
|
|
public class NotificationHubClientProxy : INotificationHubProxy
|
|||
|
|
{
|
|||
|
|
private readonly IEnumerable<INotificationHubClient> _clients;
|
|||
|
|
|
|||
|
|
public NotificationHubClientProxy(IEnumerable<INotificationHubClient> clients)
|
|||
|
|
{
|
|||
|
|
_clients = clients;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private async Task<(INotificationHubClient, T)[]> ApplyToAllClientsAsync<T>(Func<INotificationHubClient, Task<T>> action)
|
|||
|
|
{
|
|||
|
|
var tasks = _clients.Select(async c => (c, await action(c)));
|
|||
|
|
return await Task.WhenAll(tasks);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// partial proxy of INotificationHubClient implementation
|
|||
|
|
// Note: Any other methods that are needed can simply be delegated as done here.
|
|||
|
|
public async Task<(INotificationHubClient Client, NotificationOutcome Outcome)[]> SendTemplateNotificationAsync(IDictionary<string, string> properties, string tagExpression)
|
|||
|
|
{
|
|||
|
|
return await ApplyToAllClientsAsync(async c => await c.SendTemplateNotificationAsync(properties, tagExpression));
|
|||
|
|
}
|
|||
|
|
}
|