Redid stores. Added user store. Added Channel Manager, to manage data from a single channel.

This commit is contained in:
Tom
2024-10-19 01:50:46 +00:00
parent 3f3ba63554
commit 4d0b38babd
22 changed files with 654 additions and 475 deletions

View File

@@ -0,0 +1,56 @@
using System.Collections.Concurrent;
using HermesSocketLibrary.db;
using HermesSocketServer.Models;
using HermesSocketServer.Store;
namespace HermesSocketServer.Services
{
public class ChannelManager
{
private readonly UserStore _users;
private readonly Database _database;
private readonly Serilog.ILogger _logger;
private readonly IDictionary<string, Channel> _channels;
public ChannelManager(UserStore users, Database database, Serilog.ILogger logger)
{
_users = users;
_database = database;
_logger = logger;
_channels = new ConcurrentDictionary<string, Channel>();
}
public async Task Add(string userId)
{
var user = _users.Get(userId);
if (user == null)
{
return;
}
if (_channels.ContainsKey(userId))
{
return;
}
var chatters = new ChatterStore(userId, _database, _logger);
await chatters.Load();
var channel = new Channel()
{
Id = userId,
User = user,
Chatters = chatters
};
_channels.Add(userId, channel);
}
public Channel? Get(string channelId)
{
if (_channels.TryGetValue(channelId, out var channel))
return channel;
return null;
}
}
}