Handling notifications event and rendering them through controller

This commit is contained in:
rockstardev
2020-05-28 16:19:02 -05:00
parent e834cd7595
commit 9206f0cd2e
7 changed files with 125 additions and 112 deletions

View File

@@ -3,19 +3,46 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BTCPayServer.Data;
using BTCPayServer.Events;
using BTCPayServer.Events.Notifications;
using ExchangeSharp;
using Newtonsoft.Json;
namespace BTCPayServer.Models.NotificationViewModels
{
public class IndexViewModel
{
public List<NoticeDataHolder> Items { get; set; }
public List<NotificationViewModel> Items { get; set; }
}
public class NoticeDataHolder
public class NotificationViewModel
{
public string Id { get; set; }
public DateTimeOffset Created { get; set; }
public string Body { get; set; }
public string ActionLink { get; set; }
}
public static class NotificationViewModelExt
{
public static NotificationViewModel ViewModel(this NotificationData data)
{
public int Id { get; set; }
public string Body { get; set; }
public string Level { get; set; }
public DateTime Created { get; set; }
if (data.NotificationType == nameof(NewVersionNotification))
{
var casted = JsonConvert.DeserializeObject<NewVersionNotification>(data.Blob.ToStringFromUTF8());
var obj = new NotificationViewModel
{
Id = data.Id,
Created = data.Created,
Body = $"New version {casted.Version} released!",
ActionLink = "https://github.com/btcpayserver/btcpayserver/releases/tag/v" + casted.Version
};
return obj;
}
return null;
}
}
}