diff --git a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs
index 5663e9a5..de26ef5b 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Conversations/IConversationStateService.cs
@@ -17,6 +17,6 @@ public interface IConversationStateService
int activeRounds = -1, string valueType = StateDataType.String, string source = StateSource.User, bool readOnly = false);
void SaveStateByArgs(JsonDocument args);
bool RemoveState(string name);
- void CleanStates(params string[] keepStates);
+ void CleanStates(params string[] excludedStates);
void Save();
}
diff --git a/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs b/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs
index d11752f6..92e3eacb 100644
--- a/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs
+++ b/src/Infrastructure/BotSharp.Abstraction/Utilities/Pagination.cs
@@ -26,6 +26,16 @@ public class Pagination
}
}
+ ///
+ /// Sort by field
+ ///
+ public string? Sort { get; set; }
+
+ ///
+ /// Sort order: asc or desc
+ ///
+ public string Order { get; set; } = "asc";
+
public int Offset
{
get { return (Page - 1) * Size; }
diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs
index 4901a7c6..57f09c71 100644
--- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs
+++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs
@@ -270,7 +270,7 @@ public class ConversationStateService : IConversationStateService, IDisposable
return true;
}
- public void CleanStates(params string[] keepStates)
+ public void CleanStates(params string[] excludedStates)
{
var routingCtx = _services.GetRequiredService();
var curMsgId = routingCtx.MessageId;
@@ -279,7 +279,7 @@ public class ConversationStateService : IConversationStateService, IDisposable
foreach (var key in _curStates.Keys)
{
// skip state
- if (keepStates.Contains(key))
+ if (excludedStates.Contains(key))
{
continue;
}
diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs
index 38f47f9f..5ccd3777 100644
--- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs
+++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs
@@ -481,7 +481,7 @@ namespace BotSharp.Core.Repository
// Handle truncated breakpoints
var breakpointDir = Path.Combine(convDir, BREAKPOINT_FILE);
var breakpoints = CollectConversationBreakpoints(breakpointDir);
- isSaved = HandleTruncatedBreakpoints(breakpointDir, breakpoints, messageId);
+ isSaved = HandleTruncatedBreakpoints(breakpointDir, breakpoints, refTime);
// Remove logs
if (cleanLog)
@@ -585,10 +585,9 @@ namespace BotSharp.Core.Repository
return isSaved;
}
- private bool HandleTruncatedBreakpoints(string breakpointDir, List breakpoints, string refMessageId)
+ private bool HandleTruncatedBreakpoints(string breakpointDir, List breakpoints, DateTime refTime)
{
- var targetIdx = breakpoints.FindIndex(x => x.MessageId == refMessageId);
- var truncatedBreakpoints = breakpoints?.Where((x, idx) => idx < targetIdx)?
+ var truncatedBreakpoints = breakpoints?.Where(x => x.CreatedTime < refTime)?
.ToList() ?? new List();
var isSaved = SaveTruncatedBreakpoints(breakpointDir, truncatedBreakpoints);
diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs
index cfd3199d..aefd0db5 100644
--- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs
+++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs
@@ -452,8 +452,7 @@ public partial class MongoRepository
if (!foundStates.Breakpoints.IsNullOrEmpty())
{
var breakpoints = foundStates.Breakpoints ?? new List();
- var targetIdx = breakpoints.FindIndex(x => x.MessageId == messageId);
- var truncatedBreakpoints = breakpoints.Where((x, idx) => idx < targetIdx).ToList();
+ var truncatedBreakpoints = breakpoints.Where(x => x.CreatedTime < refTime).ToList();
foundStates.Breakpoints = truncatedBreakpoints;
}