Merge pull request #827 from trheyi/main
Enhance chat retrieval and update functionality in Xun
This commit is contained in:
commit
7137ed4e2c
1 changed files with 19 additions and 3 deletions
|
|
@ -335,7 +335,7 @@ func (conv *Xun) GetChats(sid string, filter ChatFilter) (*ChatGroupResponse, er
|
||||||
|
|
||||||
// Build base query
|
// Build base query
|
||||||
qb := conv.newQueryChat().
|
qb := conv.newQueryChat().
|
||||||
Select("chat_id", "title", "created_at").
|
Select("chat_id", "title", "created_at", "updated_at").
|
||||||
Where("sid", userID).
|
Where("sid", userID).
|
||||||
Where("chat_id", "!=", "")
|
Where("chat_id", "!=", "")
|
||||||
|
|
||||||
|
|
@ -358,7 +358,9 @@ func (conv *Xun) GetChats(sid string, filter ChatFilter) (*ChatGroupResponse, er
|
||||||
lastPage := int(math.Ceil(float64(total) / float64(filter.PageSize)))
|
lastPage := int(math.Ceil(float64(total) / float64(filter.PageSize)))
|
||||||
|
|
||||||
// Get paginated results
|
// Get paginated results
|
||||||
rows, err := qb.OrderBy("created_at", filter.Order).
|
rows, err := qb.
|
||||||
|
OrderBy("updated_at", filter.Order).
|
||||||
|
OrderBy("created_at", filter.Order).
|
||||||
Offset(offset).
|
Offset(offset).
|
||||||
Limit(filter.PageSize).
|
Limit(filter.PageSize).
|
||||||
Get()
|
Get()
|
||||||
|
|
@ -392,8 +394,13 @@ func (conv *Xun) GetChats(sid string, filter ChatFilter) (*ChatGroupResponse, er
|
||||||
"title": row.Get("title"),
|
"title": row.Get("title"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dbDatetime = row.Get("updated_at")
|
||||||
|
if dbDatetime == nil {
|
||||||
|
dbDatetime = row.Get("created_at")
|
||||||
|
}
|
||||||
|
|
||||||
var createdAt time.Time
|
var createdAt time.Time
|
||||||
switch v := row.Get("created_at").(type) {
|
switch v := dbDatetime.(type) {
|
||||||
case time.Time:
|
case time.Time:
|
||||||
createdAt = v
|
createdAt = v
|
||||||
case string:
|
case string:
|
||||||
|
|
@ -608,6 +615,15 @@ func (conv *Xun) SaveHistory(sid string, messages []map[string]interface{}, cid
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update Chat updated_at
|
||||||
|
_, err = conv.newQueryChat().
|
||||||
|
Where("chat_id", cid).
|
||||||
|
Where("sid", userID).
|
||||||
|
Update(map[string]interface{}{"updated_at": now})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue