cloutier--bird.makeup/src/BirdsiteLive/Component/NodeInfoViewComponent.cs

61 lines
2.3 KiB
C#
Raw Normal View History

2021-02-17 20:49:17 -05:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
2021-02-18 21:48:52 -05:00
using BirdsiteLive.DAL.Contracts;
2021-02-18 21:30:13 -05:00
using BirdsiteLive.Domain.Repository;
2021-02-24 00:27:16 -05:00
using BirdsiteLive.Services;
2021-02-18 21:48:52 -05:00
using BirdsiteLive.Statistics.Domain;
2021-02-17 20:49:17 -05:00
using Microsoft.AspNetCore.Mvc;
2021-02-18 22:04:47 -05:00
using Microsoft.AspNetCore.Razor.Language.Intermediate;
2021-02-17 20:49:17 -05:00
namespace BirdsiteLive.Component
{
public class NodeInfoViewComponent : ViewComponent
{
2021-02-18 21:30:13 -05:00
private readonly IModerationRepository _moderationRepository;
2021-02-24 00:27:16 -05:00
private readonly ICachedStatisticsService _cachedStatisticsService;
2021-02-18 21:30:13 -05:00
#region Ctor
2021-02-24 00:27:16 -05:00
public NodeInfoViewComponent(IModerationRepository moderationRepository, ICachedStatisticsService cachedStatisticsService)
2021-02-18 21:30:13 -05:00
{
_moderationRepository = moderationRepository;
2021-02-24 00:27:16 -05:00
_cachedStatisticsService = cachedStatisticsService;
2021-02-18 21:30:13 -05:00
}
#endregion
2021-02-18 21:48:52 -05:00
public async Task<IViewComponentResult> InvokeAsync()
2021-02-17 20:49:17 -05:00
{
2021-02-18 21:30:13 -05:00
var followerPolicy = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.Follower);
var twitterAccountPolicy = _moderationRepository.GetModerationType(ModerationEntityTypeEnum.TwitterAccount);
2021-02-24 00:27:16 -05:00
var statistics = await _cachedStatisticsService.GetStatisticsAsync();
2021-02-18 21:48:52 -05:00
2021-02-18 21:30:13 -05:00
var viewModel = new NodeInfoViewModel
{
BlacklistingEnabled = followerPolicy == ModerationTypeEnum.BlackListing ||
twitterAccountPolicy == ModerationTypeEnum.BlackListing,
WhitelistingEnabled = followerPolicy == ModerationTypeEnum.WhiteListing ||
twitterAccountPolicy == ModerationTypeEnum.WhiteListing,
2023-01-11 19:40:11 -05:00
SyncLag = statistics.SyncLag
2021-02-18 21:30:13 -05:00
};
2021-02-18 21:48:52 -05:00
//viewModel = new NodeInfoViewModel
//{
// BlacklistingEnabled = false,
// WhitelistingEnabled = false,
// InstanceSaturation = 175
//};
2021-02-18 21:30:13 -05:00
return View(viewModel);
2021-02-17 20:49:17 -05:00
}
}
2021-02-18 21:30:13 -05:00
public class NodeInfoViewModel
{
public bool BlacklistingEnabled { get; set; }
public bool WhitelistingEnabled { get; set; }
public int InstanceSaturation { get; set; }
2023-01-11 19:40:11 -05:00
public TimeSpan SyncLag { get; set; }
2021-02-18 21:30:13 -05:00
}
2021-02-17 20:49:17 -05:00
}