user removal functionnal
This commit is contained in:
parent
f1a7146c67
commit
25221c33e0
|
@ -3,6 +3,7 @@ using System.Linq;
|
|||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using BirdsiteLive.DAL.Contracts;
|
||||
using BirdsiteLive.DAL.Models;
|
||||
using BirdsiteLive.Moderation.Actions;
|
||||
using Terminal.Gui;
|
||||
|
||||
|
@ -13,6 +14,9 @@ namespace BSLManager
|
|||
private readonly IFollowersDal _followersDal;
|
||||
private readonly IRemoveFollowerAction _removeFollowerAction;
|
||||
|
||||
private List<string> _displayableUserList = new List<string>();
|
||||
private List<Follower> _sourceUserList = new List<Follower>();
|
||||
|
||||
#region Ctor
|
||||
public App(IFollowersDal followersDal, IRemoveFollowerAction removeFollowerAction)
|
||||
{
|
||||
|
@ -62,22 +66,10 @@ namespace BSLManager
|
|||
var n = MessageBox.Query(50, 7, "Quit BSL Manager", "Are you sure you want to quit?", "Yes", "No");
|
||||
return n == 0;
|
||||
}
|
||||
|
||||
RetrieveUserList();
|
||||
|
||||
var listData = new List<string>();
|
||||
|
||||
Application.MainLoop.Invoke(async () => {
|
||||
var followers = await _followersDal.GetAllFollowersAsync();
|
||||
var orderedFollowers = followers.OrderByDescending(x => x.Followings.Count).ToList();
|
||||
|
||||
foreach (var follower in orderedFollowers)
|
||||
{
|
||||
listData.Add($"@{follower.Acct}@{follower.Host} {follower.Followings.Count}");
|
||||
}
|
||||
|
||||
RefreshUI();
|
||||
});
|
||||
|
||||
var list = new ListView(listData)
|
||||
var list = new ListView(_displayableUserList)
|
||||
{
|
||||
X = 1,
|
||||
Y = 2,
|
||||
|
@ -104,7 +96,7 @@ namespace BSLManager
|
|||
|
||||
var dialog = new Dialog("Delete", 60, 18, cancel, ok);
|
||||
|
||||
var name = new Label($"User: {listData[el]}")
|
||||
var name = new Label($"User: {_displayableUserList[el]}")
|
||||
{
|
||||
X = 1,
|
||||
Y = 1,
|
||||
|
@ -124,8 +116,7 @@ namespace BSLManager
|
|||
|
||||
if (okpressed)
|
||||
{
|
||||
listData.RemoveAt(el);
|
||||
RefreshUI();
|
||||
DeleteAndRemoveUser(el);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -139,6 +130,37 @@ namespace BSLManager
|
|||
Application.Run();
|
||||
}
|
||||
|
||||
private void DeleteAndRemoveUser(int el)
|
||||
{
|
||||
Application.MainLoop.Invoke(async () =>
|
||||
{
|
||||
var userToDelete = _sourceUserList[el];
|
||||
|
||||
await _removeFollowerAction.ProcessAsync(userToDelete);
|
||||
|
||||
_sourceUserList.RemoveAt(el);
|
||||
_displayableUserList.RemoveAt(el);
|
||||
RefreshUI();
|
||||
});
|
||||
}
|
||||
|
||||
private void RetrieveUserList()
|
||||
{
|
||||
Application.MainLoop.Invoke(async () =>
|
||||
{
|
||||
var followers = await _followersDal.GetAllFollowersAsync();
|
||||
_sourceUserList = followers.OrderByDescending(x => x.Followings.Count).ToList();
|
||||
|
||||
_displayableUserList.Clear();
|
||||
foreach (var follower in _sourceUserList)
|
||||
{
|
||||
_displayableUserList.Add($"@{follower.Acct}@{follower.Host} {follower.Followings.Count}");
|
||||
}
|
||||
|
||||
RefreshUI();
|
||||
});
|
||||
}
|
||||
|
||||
private void RefreshUI()
|
||||
{
|
||||
typeof(Application).GetMethod("TerminalResized", BindingFlags.Static | BindingFlags.NonPublic)
|
||||
|
|
|
@ -19,4 +19,10 @@
|
|||
<ProjectReference Include="..\DataAccessLayers\BirdsiteLive.DAL.Postgres\BirdsiteLive.DAL.Postgres.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="key.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -14,12 +14,14 @@ namespace BSLManager
|
|||
{
|
||||
public class Bootstrapper
|
||||
{
|
||||
private readonly DbSettings _settings;
|
||||
private readonly DbSettings _dbSettings;
|
||||
private readonly InstanceSettings _instanceSettings;
|
||||
|
||||
#region Ctor
|
||||
public Bootstrapper(DbSettings settings)
|
||||
public Bootstrapper(DbSettings dbSettings, InstanceSettings instanceSettings)
|
||||
{
|
||||
_settings = settings;
|
||||
_dbSettings = dbSettings;
|
||||
_instanceSettings = instanceSettings;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -27,9 +29,13 @@ namespace BSLManager
|
|||
{
|
||||
var container = new Container(x =>
|
||||
{
|
||||
if (string.Equals(_settings.Type, DbTypes.Postgres, StringComparison.OrdinalIgnoreCase))
|
||||
x.For<DbSettings>().Use(x => _dbSettings);
|
||||
|
||||
x.For<InstanceSettings>().Use(x => _instanceSettings);
|
||||
|
||||
if (string.Equals(_dbSettings.Type, DbTypes.Postgres, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var connString = $"Host={_settings.Host};Username={_settings.User};Password={_settings.Password};Database={_settings.Name}";
|
||||
var connString = $"Host={_dbSettings.Host};Username={_dbSettings.User};Password={_dbSettings.Password};Database={_dbSettings.Name}";
|
||||
var postgresSettings = new PostgresSettings
|
||||
{
|
||||
ConnString = connString
|
||||
|
@ -42,7 +48,7 @@ namespace BSLManager
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException($"{_settings.Type} is not supported");
|
||||
throw new NotImplementedException($"{_dbSettings.Type} is not supported");
|
||||
}
|
||||
|
||||
var serviceProvider = new ServiceCollection().AddHttpClient().BuildServiceProvider();
|
||||
|
|
|
@ -18,23 +18,18 @@ namespace BSLManager
|
|||
{
|
||||
Console.OutputEncoding = Encoding.Default;
|
||||
|
||||
var settings = GetSettings();
|
||||
|
||||
var bootstrapper = new Bootstrapper(settings);
|
||||
var container = bootstrapper.Init();
|
||||
|
||||
var app = container.GetInstance<App>();
|
||||
app.Run();
|
||||
}
|
||||
|
||||
private static DbSettings GetSettings()
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables();
|
||||
var configuration = builder.Build();
|
||||
|
||||
var dbSettings = configuration.GetSection("Db").Get<DbSettings>();
|
||||
return dbSettings;
|
||||
var instanceSettings = configuration.GetSection("Instance").Get<InstanceSettings>();
|
||||
|
||||
var bootstrapper = new Bootstrapper(dbSettings, instanceSettings);
|
||||
var container = bootstrapper.Init();
|
||||
|
||||
var app = container.GetInstance<App>();
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue