Skip to content

Commit 9e15374

Browse files
committed
Avoid conversation title to be updated unexpectly
1 parent d6a2f56 commit 9e15374

4 files changed

Lines changed: 21 additions & 15 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public interface IConversationService
1111
Task SetConversationId(string conversationId, List<MessageState> states, bool isReadOnly = false);
1212
Task<Conversation> GetConversation(string id, bool isLoadStates = false);
1313
Task<PagedItems<Conversation>> GetConversations(ConversationFilter filter);
14-
Task<Conversation> UpdateConversationTitle(string id, string title);
15-
Task<Conversation> UpdateConversationTitleAlias(string id, string titleAlias);
14+
Task<bool> UpdateConversationTitle(string id, string title);
15+
Task<bool> UpdateConversationTitleAlias(string id, string titleAlias);
1616
Task<bool> UpdateConversationTags(string conversationId, List<string> toAddTags, List<string> toDeleteTags);
1717
Task<bool> UpdateConversationMessage(string conversationId, UpdateMessageRequest request);
1818
Task<List<Conversation>> GetLastConversations();

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.SendMessage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ response.RichContent is RichContent<IRichMessage> template &&
153153
if (response.Instruction != null)
154154
{
155155
var conversation = _services.GetRequiredService<IConversationService>();
156-
var updatedConversation = await conversation.UpdateConversationTitle(_conversationId, response.Instruction.NextActionReason);
156+
await conversation.UpdateConversationTitle(_conversationId, response.Instruction.NextActionReason);
157157

158158
// Emit conversation ending hook
159159
if (response.Instruction.ConversationEnd)

src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationService.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,26 @@ public async Task<bool> DeleteConversations(IEnumerable<string> ids)
4343
return isDeleted;
4444
}
4545

46-
public async Task<Conversation> UpdateConversationTitle(string id, string title)
46+
public async Task<bool> UpdateConversationTitle(string id, string title)
4747
{
48-
var db = _services.GetRequiredService<IBotSharpRepository>();
49-
await db.UpdateConversationTitle(id, title);
50-
var conversation = await db.GetConversation(id);
51-
return conversation;
48+
if (!string.IsNullOrEmpty(title))
49+
{
50+
var db = _services.GetRequiredService<IBotSharpRepository>();
51+
await db.UpdateConversationTitle(id, title);
52+
}
53+
54+
return true;
5255
}
5356

54-
public async Task<Conversation> UpdateConversationTitleAlias(string id, string titleAlias)
57+
public async Task<bool> UpdateConversationTitleAlias(string id, string titleAlias)
5558
{
56-
var db = _services.GetRequiredService<IBotSharpRepository>();
57-
await db.UpdateConversationTitleAlias(id, titleAlias);
58-
var conversation = await db.GetConversation(id);
59-
return conversation;
59+
if (!string.IsNullOrEmpty(titleAlias))
60+
{
61+
var db = _services.GetRequiredService<IBotSharpRepository>();
62+
await db.UpdateConversationTitleAlias(id, titleAlias);
63+
}
64+
65+
return true;
6066
}
6167

6268
public async Task<bool> UpdateConversationTags(string conversationId, List<string> toAddTags, List<string> toDeleteTags)

src/Infrastructure/BotSharp.OpenAPI/Controllers/Conversation/ConversationController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ public async Task<bool> UpdateConversationTitle([FromRoute] string conversationI
213213
return false;
214214
}
215215

216-
var response = await conv.UpdateConversationTitle(conversationId, newTile.NewTitle);
217-
return response != null;
216+
await conv.UpdateConversationTitle(conversationId, newTile.NewTitle);
217+
return true;
218218
}
219219

220220
[HttpPut("/conversation/{conversationId}/update-title-alias")]

0 commit comments

Comments
 (0)