fix: listByConversation 在 conversation 不存在时返回空列表而非抛异常

This commit is contained in:
2026-06-28 22:40:13 +08:00
parent caaeb94477
commit e3eb1afbb0
3 changed files with 95 additions and 3 deletions
@@ -38,8 +38,15 @@ public class ScriptMessageServiceImpl implements ScriptMessageService {
public List<MessageResponse> listByConversation(String conversationId, boolean includeVersions) {
String currentUserId = UserContextHolder.getCurrentUserId();
Conversation conversation = conversationService.getById(conversationId);
if (conversation == null || !conversation.getUserId().equals(currentUserId)) {
throw new IllegalStateException("对话不存在或无权限");
// 对话不存在:视为"尚无消息",返回空列表(前端用临时 ID 查询时走这条分支)
if (conversation == null) {
return java.util.Collections.emptyList();
}
// 对话存在但归属他人:权限问题,必须暴露
if (!conversation.getUserId().equals(currentUserId)) {
throw new IllegalStateException("无权限访问该对话");
}
LambdaQueryWrapper<Message> wrapper = new LambdaQueryWrapper<>();