2021-01-07 18:57:02 +00:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Jellyfin.Data.Events.Users;
|
|
|
|
|
using Jellyfin.Plugin.Webhook.Destinations;
|
|
|
|
|
using Jellyfin.Plugin.Webhook.Helpers;
|
2021-11-11 15:22:12 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
2021-01-07 18:57:02 +00:00
|
|
|
|
using MediaBrowser.Controller.Events;
|
|
|
|
|
|
2022-10-10 14:06:59 +00:00
|
|
|
|
namespace Jellyfin.Plugin.Webhook.Notifiers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// User created notifier.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class UserCreatedNotifier : IEventConsumer<UserCreatedEventArgs>
|
2021-01-07 18:57:02 +00:00
|
|
|
|
{
|
2022-10-10 14:06:59 +00:00
|
|
|
|
private readonly IServerApplicationHost _applicationHost;
|
|
|
|
|
private readonly IWebhookSender _webhookSender;
|
|
|
|
|
|
2021-01-07 18:57:02 +00:00
|
|
|
|
/// <summary>
|
2022-10-10 14:06:59 +00:00
|
|
|
|
/// Initializes a new instance of the <see cref="UserCreatedNotifier"/> class.
|
2021-01-07 18:57:02 +00:00
|
|
|
|
/// </summary>
|
2022-10-10 14:06:59 +00:00
|
|
|
|
/// <param name="applicationHost">Instance of the <see cref="IServerApplicationHost"/> interface.</param>
|
|
|
|
|
/// <param name="webhookSender">Instance of the <see cref="IWebhookSender"/> interface.</param>
|
|
|
|
|
public UserCreatedNotifier(
|
|
|
|
|
IServerApplicationHost applicationHost,
|
|
|
|
|
IWebhookSender webhookSender)
|
2021-01-07 18:57:02 +00:00
|
|
|
|
{
|
2022-10-10 14:06:59 +00:00
|
|
|
|
_applicationHost = applicationHost;
|
|
|
|
|
_webhookSender = webhookSender;
|
|
|
|
|
}
|
2021-01-07 18:57:02 +00:00
|
|
|
|
|
2022-10-10 14:06:59 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task OnEvent(UserCreatedEventArgs eventArgs)
|
|
|
|
|
{
|
|
|
|
|
var dataObject = DataObjectHelpers
|
|
|
|
|
.GetBaseDataObject(_applicationHost, NotificationType.UserCreated)
|
|
|
|
|
.AddUserData(eventArgs.Argument);
|
2021-01-07 18:57:02 +00:00
|
|
|
|
|
2022-10-10 14:06:59 +00:00
|
|
|
|
await _webhookSender.SendNotification(NotificationType.UserCreated, dataObject)
|
|
|
|
|
.ConfigureAwait(false);
|
2021-01-07 18:57:02 +00:00
|
|
|
|
}
|
2021-11-11 15:22:12 +00:00
|
|
|
|
}
|