Доработан менеджер состояний.
All checks were successful
CI / build-test (push) Successful in 31s
Release / pack-and-publish (release) Successful in 1m12s

This commit is contained in:
2025-12-03 07:15:46 +03:00
parent 5feeffe6bf
commit 4aff8edbcd
14 changed files with 234 additions and 27 deletions

View File

@@ -6,17 +6,21 @@
/// </summary>
public sealed class InMemoryStateStore : IStateStore
{
private readonly Dictionary<long, UserState> _store = new();
private readonly Dictionary<(string chatClientId, long userId), UserState> _store = new();
/// <summary>
/// Получает состояние пользователя, создавая новое при отсутствии.
/// </summary>
public Task<UserState> GetAsync(long userId, CancellationToken ct)
public Task<UserState> GetAsync(string chatClientId, long userId, CancellationToken ct)
{
if (!_store.TryGetValue(userId, out var st))
if (!_store.TryGetValue((chatClientId, userId), out var st))
{
st = new UserState { UserId = userId };
_store[userId] = st;
st = new UserState
{
UserId = userId,
ChatClientId = chatClientId,
};
_store[(chatClientId, userId)] = st;
}
return Task.FromResult(st);
}
@@ -26,7 +30,7 @@
/// </summary>
public Task SaveAsync(UserState state, CancellationToken ct)
{
_store[state.UserId] = state;
_store[(state.ChatClientId, state.UserId)] = state;
return Task.CompletedTask;
}
}