Pkzipping Notification blobs to keep with convention

This commit is contained in:
rockstardev
2020-06-11 18:14:23 -05:00
parent 1f35534dfb
commit b53cb50a91
4 changed files with 22 additions and 17 deletions

View File

@@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BTCPayServer.Data;
using BTCPayServer.Data;
using BTCPayServer.Models.NotificationViewModels;
using ExchangeSharp;
using Newtonsoft.Json;
namespace BTCPayServer.Events.Notifications
@@ -16,7 +10,7 @@ namespace BTCPayServer.Events.Notifications
public override NotificationViewModel ToViewModel(NotificationData data)
{
var casted = JsonConvert.DeserializeObject<NewVersionNotification>(data.Blob.ToStringFromUTF8());
var casted = JsonConvert.DeserializeObject<NewVersionNotification>(ZipUtils.Unzip(data.Blob));
var obj = new NotificationViewModel
{
Id = data.Id,

View File

@@ -1,7 +1,6 @@
using System;
using BTCPayServer.Data;
using BTCPayServer.Models.NotificationViewModels;
using ExchangeSharp;
using Newtonsoft.Json;
namespace BTCPayServer.Events.Notifications
@@ -18,7 +17,7 @@ namespace BTCPayServer.Events.Notifications
{
Created = DateTimeOffset.UtcNow,
NotificationType = NotificationType,
Blob = obj.ToBytesUTF8(),
Blob = ZipUtils.Zip(obj),
Seen = false
};
return data;

View File

@@ -94,12 +94,25 @@ namespace BTCPayServer.HostedServices
if (resp.UnseenCount > 0)
{
resp.Last5 = _db.Notifications
.Where(a => a.ApplicationUserId == userId && !a.Seen)
.OrderByDescending(a => a.Created)
.Take(5)
.Select(a => a.ViewModel())
.ToList();
try
{
resp.Last5 = _db.Notifications
.Where(a => a.ApplicationUserId == userId && !a.Seen)
.OrderByDescending(a => a.Created)
.Take(5)
.Select(a => a.ViewModel())
.ToList();
}
catch (System.IO.InvalidDataException iex)
{
// invalid notifications that are not pkuzipable, burn them all
var notif = _db.Notifications.Where(a => a.ApplicationUserId == userId);
_db.Notifications.RemoveRange(notif);
_db.SaveChanges();
resp.UnseenCount = 0;
resp.Last5 = new List<NotificationViewModel>();
}
}
else
{

View File

@@ -7,7 +7,6 @@ using System.Threading.Tasks;
using BTCPayServer.Data;
using BTCPayServer.Events;
using BTCPayServer.Events.Notifications;
using ExchangeSharp;
using Newtonsoft.Json;
namespace BTCPayServer.Models.NotificationViewModels