From dca5d138267f80149eaf4b0f9cbdce8bd26f2abf Mon Sep 17 00:00:00 2001 From: Jamie Date: Thu, 2 Nov 2017 14:56:26 +0000 Subject: [PATCH] Fixed telegram !wip --- src/Ombi.Api/Api.cs | 7 ++++--- src/Ombi.DependencyInjection/IocExtensions.cs | 1 + .../Agents/ITelegramNotification.cs | 6 ++++++ .../Agents/TelegramNotification.cs | 2 +- .../Controllers/External/TesterController.cs | 18 ++++++++++-------- src/Ombi/Controllers/SettingsController.cs | 5 +---- 6 files changed, 23 insertions(+), 16 deletions(-) create mode 100644 src/Ombi.Notifications/Agents/ITelegramNotification.cs diff --git a/src/Ombi.Api/Api.cs b/src/Ombi.Api/Api.cs index 034250178..15a02ed4d 100644 --- a/src/Ombi.Api/Api.cs +++ b/src/Ombi.Api/Api.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Net.Http; +using System.Security.Authentication; using System.Threading.Tasks; using System.Xml.Serialization; using Microsoft.Extensions.Caching.Memory; @@ -36,7 +37,7 @@ namespace Ombi.Api { return new HttpClientHandler { - ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true + ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true, }; } return new HttpClientHandler(); @@ -49,9 +50,9 @@ namespace Ombi.Api public async Task Request(Request request) { - using (var httpClient = new HttpClient(await GetHandler())) + using(var handler = await GetHandler()) + using (var httpClient = new HttpClient(handler)) { - using (var httpRequestMessage = new HttpRequestMessage(request.HttpMethod, request.FullUri)) { // Add the Json Body diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index 5ae9e7bd5..b65ac3d3c 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -134,6 +134,7 @@ namespace Ombi.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } diff --git a/src/Ombi.Notifications/Agents/ITelegramNotification.cs b/src/Ombi.Notifications/Agents/ITelegramNotification.cs new file mode 100644 index 000000000..4385d6e4b --- /dev/null +++ b/src/Ombi.Notifications/Agents/ITelegramNotification.cs @@ -0,0 +1,6 @@ +namespace Ombi.Notifications.Agents +{ + public interface ITelegramNotification : INotification + { + } +} \ No newline at end of file diff --git a/src/Ombi.Notifications/Agents/TelegramNotification.cs b/src/Ombi.Notifications/Agents/TelegramNotification.cs index 9b42f865c..92c46ab89 100644 --- a/src/Ombi.Notifications/Agents/TelegramNotification.cs +++ b/src/Ombi.Notifications/Agents/TelegramNotification.cs @@ -14,7 +14,7 @@ using Ombi.Api.Telegram; namespace Ombi.Notifications.Agents { - public class TelegramNotification : BaseNotification + public class TelegramNotification : BaseNotification, ITelegramNotification { public TelegramNotification(ITelegramApi api, ISettingsService sn, ILogger log, INotificationTemplatesRepository r, IMovieRequestRepository m, ITvRequestRepository t, ISettingsService s) : base(sn, r, m, t,s) { diff --git a/src/Ombi/Controllers/External/TesterController.cs b/src/Ombi/Controllers/External/TesterController.cs index 47dd1ea93..c85f248cf 100644 --- a/src/Ombi/Controllers/External/TesterController.cs +++ b/src/Ombi/Controllers/External/TesterController.cs @@ -51,7 +51,7 @@ namespace Ombi.Controllers.External public TesterController(INotificationService service, IDiscordNotification notification, IEmailNotification emailN, IPushbulletNotification pushbullet, ISlackNotification slack, IPushoverNotification po, IMattermostNotification mm, IPlexApi plex, IEmbyApi emby, IRadarrApi radarr, ISonarrApi sonarr, ILogger log, IEmailProvider provider, - ICouchPotatoApi cpApi) + ICouchPotatoApi cpApi, ITelegramNotification telegram) { Service = service; DiscordNotification = notification; @@ -67,6 +67,7 @@ namespace Ombi.Controllers.External Log = log; EmailProvider = provider; CouchPotatoApi = cpApi; + TelegramNotification = telegram; } private INotificationService Service { get; } @@ -83,6 +84,7 @@ namespace Ombi.Controllers.External private ICouchPotatoApi CouchPotatoApi { get; } private ILogger Log { get; } private IEmailProvider EmailProvider { get; } + private ITelegramNotification TelegramNotification { get; } /// @@ -299,14 +301,14 @@ namespace Ombi.Controllers.External /// /// The settings. /// - //[HttpPost("telegram")] - //public async Task Telegram([FromBody] TelegramSettings settings) - //{ - // settings.Enabled = true; - // await TelegramApi.Send("This is a test ") + [HttpPost("telegram")] + public async Task Telegram([FromBody] TelegramSettings settings) + { + settings.Enabled = true; + await TelegramNotification.NotifyAsync(new NotificationOptions { NotificationType = NotificationType.Test, RequestId = -1 }, settings); - // return true; - //} + return true; + } } } \ No newline at end of file diff --git a/src/Ombi/Controllers/SettingsController.cs b/src/Ombi/Controllers/SettingsController.cs index 2097aa606..7cfcd4134 100644 --- a/src/Ombi/Controllers/SettingsController.cs +++ b/src/Ombi/Controllers/SettingsController.cs @@ -43,14 +43,12 @@ namespace Ombi.Controllers /// The mapper. /// The templateRepo. /// The embyApi. - /// The embyCacher. /// The radarrCacher. /// The memory cache. public SettingsController(ISettingsResolver resolver, IMapper mapper, INotificationTemplatesRepository templateRepo, IEmbyApi embyApi, - IEmbyContentCacher embyCacher, IRadarrCacher radarrCacher, IMemoryCache memCache) { @@ -58,7 +56,6 @@ namespace Ombi.Controllers Mapper = mapper; TemplateRepository = templateRepo; _embyApi = embyApi; - _embyContentCacher = embyCacher; _radarrCacher = radarrCacher; _cache = memCache; } @@ -67,7 +64,6 @@ namespace Ombi.Controllers private IMapper Mapper { get; } private INotificationTemplatesRepository TemplateRepository { get; } private readonly IEmbyApi _embyApi; - private readonly IEmbyContentCacher _embyContentCacher; private readonly IRadarrCacher _radarrCacher; private readonly IMemoryCache _cache; @@ -90,6 +86,7 @@ namespace Ombi.Controllers public async Task OmbiSettings([FromBody]OmbiSettings ombi) { ombi.Wizard = true; + _cache.Remove(CacheKeys.OmbiSettings); return await Save(ombi); }