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 _channels; public ChannelManager(UserStore users, Database database, Serilog.ILogger logger) { _users = users; _database = database; _logger = logger; _channels = new ConcurrentDictionary(); } 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; } } }