fix: LoadFromDB Timestamp 赋值 + restoreContext 查20条消息
This commit is contained in:
@@ -538,13 +538,19 @@ func (t *Thinker) restoreContext() {
|
||||
if t.convStore == nil {
|
||||
return
|
||||
}
|
||||
// 从已恢复的会话历史中获取最后一条用户消息的时间
|
||||
history := t.convStore.GetHistory(t.adminSessionID, 5)
|
||||
// 从已恢复的会话历史中获取最后一条消息的时间(优先用户消息)
|
||||
history := t.convStore.GetHistory(t.adminSessionID, 20)
|
||||
var latest time.Time
|
||||
for i := len(history) - 1; i >= 0; i-- {
|
||||
if history[i].Role == model.RoleUser && !history[i].Timestamp.IsZero() {
|
||||
latest = history[i].Timestamp
|
||||
break
|
||||
if !history[i].Timestamp.IsZero() {
|
||||
if history[i].Role == model.RoleUser {
|
||||
latest = history[i].Timestamp
|
||||
break
|
||||
}
|
||||
// 回退:非 system 消息的时间也可以
|
||||
if latest.IsZero() && history[i].Role != model.RoleSystem {
|
||||
latest = history[i].Timestamp
|
||||
}
|
||||
}
|
||||
}
|
||||
if !latest.IsZero() && time.Since(latest) < 24*time.Hour {
|
||||
|
||||
Reference in New Issue
Block a user