Skip to content

Commit f4cc8f4

Browse files
author
Jicheng Lu
committed
refine update conv tags
1 parent 9a8f559 commit f4cc8f4

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/Infrastructure/BotSharp.Abstraction/Conversations/ConversationHookBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ public virtual Task OnBreakpointUpdated(string conversationId, bool resetStates)
7979
public virtual Task OnNotificationGenerated(RoleDialogModel message)
8080
=> Task.CompletedTask;
8181

82-
public Task OnUserDisconnected(Conversation conversation)
82+
public virtual Task OnUserDisconnected(Conversation conversation)
8383
=> Task.CompletedTask;
8484
}

src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Conversation.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ public bool UpdateConversationTags(string conversationId, List<string> toAddTags
171171
var json = File.ReadAllText(convFile);
172172
var conv = JsonSerializer.Deserialize<Conversation>(json, _options);
173173

174-
var tags = conv.Tags.Concat(toAddTags).ToList();
174+
var tags = conv.Tags ?? [];
175+
tags = tags.Concat(toAddTags).Distinct().ToList();
175176
conv.Tags = tags.Where(x => !toDeleteTags.Contains(x, StringComparer.OrdinalIgnoreCase)).ToList();
176177

177178
conv.UpdatedTime = DateTime.UtcNow;

src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Conversation.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,12 @@ public bool UpdateConversationTags(string conversationId, List<string> toAddTags
142142
var conv = _dc.Conversations.Find(filter).FirstOrDefault();
143143
if (conv == null) return false;
144144

145-
145+
var tags = conv.Tags ?? [];
146+
tags = tags.Concat(toAddTags).Distinct().ToList();
147+
tags = tags.Where(x => !toDeleteTags.Contains(x, StringComparer.OrdinalIgnoreCase)).ToList();
146148

147149
var update = Builders<ConversationDocument>.Update
148-
.Set(x => x.Tags, tags ?? new())
150+
.Set(x => x.Tags, tags)
149151
.Set(x => x.UpdatedTime, DateTime.UtcNow);
150152

151153
var res = _dc.Conversations.UpdateOne(filter, update);

0 commit comments

Comments
 (0)