Introduced IUnsubscriptionService and replaced the usage in rendering page view model.

This commit is contained in:
Burak Kaan Köse
2024-05-02 00:21:29 +02:00
parent e8b07738a5
commit 11b652f851
4 changed files with 57 additions and 10 deletions

View File

@@ -37,6 +37,7 @@ namespace Wino.Core
services.AddTransient<IAutoDiscoveryService, AutoDiscoveryService>();
services.AddTransient<IContextMenuItemService, ContextMenuItemService>();
services.AddTransient<IFontService, FontService>();
services.AddTransient<IUnsubscriptionService, UnsubscriptionService>();
services.AddTransient<OutlookThreadingStrategy>();
services.AddTransient<GmailThreadingStrategy>();

View File

@@ -0,0 +1,36 @@
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Serilog;
using Wino.Core.Domain.Interfaces;
using Wino.Core.Domain.Models.Reader;
namespace Wino.Core.Services
{
public class UnsubscriptionService : IUnsubscriptionService
{
public async Task<bool> OneClickUnsubscribeAsync(UnsubscribeInfo info)
{
try
{
using var httpClient = new HttpClient();
var unsubscribeRequest = new HttpRequestMessage(HttpMethod.Post, info.HttpLink)
{
Content = new StringContent("List-Unsubscribe=One-Click", Encoding.UTF8, "application/x-www-form-urlencoded")
};
var result = await httpClient.SendAsync(unsubscribeRequest).ConfigureAwait(false);
return result.IsSuccessStatusCode;
}
catch (Exception ex)
{
Log.Error("Failed to unsubscribe from {HttpLink} - {Message}", info.HttpLink, ex.Message);
}
return false;
}
}
}