mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 14:34:23 +01:00
Pkzipping Notification blobs to keep with convention
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user