Доработан менеджер состояний.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user