From 65d5e2cf121938a8c20188f5e71b2b597beac803 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Fri, 22 Nov 2024 14:40:47 -0600 Subject: [PATCH] refine --- .../Services/ConversationStateService.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index 8ee4c662..152b74ca 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -1,5 +1,4 @@ using BotSharp.Abstraction.Conversations.Enums; -using BotSharp.Abstraction.Users.Enums; namespace BotSharp.Core.Conversations.Services; @@ -21,13 +20,14 @@ public class ConversationStateService : IConversationStateService, IDisposable /// private ConversationState _historyStates; - public ConversationStateService(ILogger logger, + public ConversationStateService( IServiceProvider services, - IBotSharpRepository db) + IBotSharpRepository db, + ILogger logger) { - _logger = logger; _services = services; _db = db; + _logger = logger; _curStates = new ConversationState(); _historyStates = new ConversationState(); } @@ -125,8 +125,13 @@ public class ConversationStateService : IConversationStateService, IDisposable var curMsgId = routingCtx.MessageId; _historyStates = _db.GetConversationStates(conversationId); + + var endNodes = new Dictionary(); + + if (_historyStates.IsNullOrEmpty()) return endNodes; + var dialogs = _db.GetConversationDialogs(conversationId); - var userDialogs = dialogs.Where(x => x.MetaData?.Role == AgentRole.User || x.MetaData?.Role == UserRole.User) + var userDialogs = dialogs.Where(x => x.MetaData?.Role == AgentRole.User) .GroupBy(x => x.MetaData?.MessageId) .Select(g => g.First()) .OrderBy(x => x.MetaData?.CreateTime) @@ -134,9 +139,6 @@ public class ConversationStateService : IConversationStateService, IDisposable var curMsgIndex = userDialogs.FindIndex(x => !string.IsNullOrEmpty(curMsgId) && x.MetaData?.MessageId == curMsgId); curMsgIndex = curMsgIndex < 0 ? userDialogs.Count() : curMsgIndex; - var endNodes = new Dictionary(); - if (_historyStates.IsNullOrEmpty()) return endNodes; - foreach (var state in _historyStates) { var key = state.Key;