修复聊天消息不显示最新数据:所有列表查询排序从 created_at DESC 改为 id DESC,记录创建函数显式设置 CreatedAt,后端 v1.2.1 / 前端 v0.3.1
This commit is contained in:
@@ -416,8 +416,9 @@ func (s *Service) recordOutboundDirectMessage(bot *storepkg.BotNodeRecord, msg *
|
|||||||
BotMessageID: botMessageID,
|
BotMessageID: botMessageID,
|
||||||
CreatedBy: createdByPtr,
|
CreatedBy: createdByPtr,
|
||||||
PublishedAt: msg.PublishedAt,
|
PublishedAt: msg.PublishedAt,
|
||||||
// 出向消息从产生那一刻起就视为“已读”,未读计数只关心 inbound。
|
// 出向消息从产生那一刻起就视为"已读",未读计数只关心 inbound。
|
||||||
ReadAt: &now,
|
ReadAt: &now,
|
||||||
|
CreatedAt: now,
|
||||||
}
|
}
|
||||||
if err := s.store.InsertBotDirectMessage(dm); err != nil {
|
if err := s.store.InsertBotDirectMessage(dm); err != nil {
|
||||||
printJSON(map[string]any{
|
printJSON(map[string]any{
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ func (s *Store) ListBotDirectMessagesByConversation(opts BotDirectMessageListOpt
|
|||||||
var rows []BotDirectMessageRecord
|
var rows []BotDirectMessageRecord
|
||||||
q := s.db.Model(&BotDirectMessageRecord{}).
|
q := s.db.Model(&BotDirectMessageRecord{}).
|
||||||
Where("bot_id = ? AND peer_node_num = ?", opts.BotID, opts.PeerNodeNum).
|
Where("bot_id = ? AND peer_node_num = ?", opts.BotID, opts.PeerNodeNum).
|
||||||
Order("created_at DESC").
|
|
||||||
Order("id DESC").
|
Order("id DESC").
|
||||||
Limit(opts.Limit).
|
Limit(opts.Limit).
|
||||||
Offset(opts.Offset)
|
Offset(opts.Offset)
|
||||||
@@ -159,7 +158,6 @@ func (s *Store) ListBotDirectConversations(botID uint64, opts ListOptions) ([]Bo
|
|||||||
q := s.db.Table("(?) AS agg", subLast).
|
q := s.db.Table("(?) AS agg", subLast).
|
||||||
Select("agg.bot_id AS bot_id, agg.peer_node_id AS peer_node_id, agg.peer_node_num AS peer_node_num, m.created_at AS last_message_at, m.text AS last_text, m.direction AS last_direction, agg.unread_count AS unread_count, agg.total_count AS total_count").
|
Select("agg.bot_id AS bot_id, agg.peer_node_id AS peer_node_id, agg.peer_node_num AS peer_node_num, m.created_at AS last_message_at, m.text AS last_text, m.direction AS last_direction, agg.unread_count AS unread_count, agg.total_count AS total_count").
|
||||||
Joins("JOIN bot_direct_messages m ON m.id = agg.last_id").
|
Joins("JOIN bot_direct_messages m ON m.id = agg.last_id").
|
||||||
Order("m.created_at DESC").
|
|
||||||
Order("m.id DESC").
|
Order("m.id DESC").
|
||||||
Limit(opts.Limit).
|
Limit(opts.Limit).
|
||||||
Offset(opts.Offset)
|
Offset(opts.Offset)
|
||||||
@@ -284,6 +282,7 @@ func insertInboundBotDirectMessage(s *Store, record map[string]any, clientInfo M
|
|||||||
Status: BotMessageStatusPublished,
|
Status: BotMessageStatusPublished,
|
||||||
ReceivedAt: &now,
|
ReceivedAt: &now,
|
||||||
ContentJSON: contentPtr,
|
ContentJSON: contentPtr,
|
||||||
|
CreatedAt: now,
|
||||||
}
|
}
|
||||||
if err := s.InsertBotDirectMessage(dm); err != nil {
|
if err := s.InsertBotDirectMessage(dm); err != nil {
|
||||||
return fmt.Errorf("insert bot direct message from %s: %w", peerNodeID, err)
|
return fmt.Errorf("insert bot direct message from %s: %w", peerNodeID, err)
|
||||||
|
|||||||
@@ -211,7 +211,6 @@ func (s *Store) ListBotMessages(opts BotMessageListOptions) ([]BotMessageRecord,
|
|||||||
opts.ListOptions = NormalizeListOptions(opts.ListOptions)
|
opts.ListOptions = NormalizeListOptions(opts.ListOptions)
|
||||||
var rows []BotMessageRecord
|
var rows []BotMessageRecord
|
||||||
q := applyBotMessageFilters(s.db.Model(&BotMessageRecord{}), opts).
|
q := applyBotMessageFilters(s.db.Model(&BotMessageRecord{}), opts).
|
||||||
Order("created_at DESC").
|
|
||||||
Order("id DESC").
|
Order("id DESC").
|
||||||
Limit(opts.Limit).
|
Limit(opts.Limit).
|
||||||
Offset(opts.Offset)
|
Offset(opts.Offset)
|
||||||
|
|||||||
@@ -1291,6 +1291,7 @@ func textMessageFromRecord(record map[string]any, clientInfo MQTTClientInfo) (*T
|
|||||||
MQTTRemoteHost: clientFields.MQTTRemoteHost,
|
MQTTRemoteHost: clientFields.MQTTRemoteHost,
|
||||||
MQTTRemotePort: clientFields.MQTTRemotePort,
|
MQTTRemotePort: clientFields.MQTTRemotePort,
|
||||||
ContentJSON: common.ContentJSON,
|
ContentJSON: common.ContentJSON,
|
||||||
|
CreatedAt: time.Now(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1401,6 +1402,7 @@ func AppendPacketFieldsFromRecord(record map[string]any, wantType string, client
|
|||||||
DecryptSuccess: nullableBool(record["decrypt_success"]),
|
DecryptSuccess: nullableBool(record["decrypt_success"]),
|
||||||
DecryptStatus: NullableString(record["decrypt_status"]),
|
DecryptStatus: NullableString(record["decrypt_status"]),
|
||||||
ContentJSON: string(contentJSON),
|
ContentJSON: string(contentJSON),
|
||||||
|
CreatedAt: time.Now(),
|
||||||
}, MQTTClientRecordFields{
|
}, MQTTClientRecordFields{
|
||||||
MQTTClientID: NullableString(clientInfo.ClientID),
|
MQTTClientID: NullableString(clientInfo.ClientID),
|
||||||
MQTTUsername: NullableString(clientInfo.Username),
|
MQTTUsername: NullableString(clientInfo.Username),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Store) InsertDiscardDetails(record map[string]any, raw []byte, clientInfo MQTTClientInfo) error {
|
func (s *Store) InsertDiscardDetails(record map[string]any, raw []byte, clientInfo MQTTClientInfo) error {
|
||||||
@@ -34,6 +35,7 @@ func discardDetailsFromRecord(record map[string]any, raw []byte, clientInfo MQTT
|
|||||||
MQTTRemoteAddr: NullableStringValue(clientInfo.RemoteAddr),
|
MQTTRemoteAddr: NullableStringValue(clientInfo.RemoteAddr),
|
||||||
MQTTRemoteHost: NullableStringValue(clientInfo.RemoteHost),
|
MQTTRemoteHost: NullableStringValue(clientInfo.RemoteHost),
|
||||||
MQTTRemotePort: NullableStringValue(clientInfo.RemotePort),
|
MQTTRemotePort: NullableStringValue(clientInfo.RemotePort),
|
||||||
|
CreatedAt: time.Now(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -369,6 +369,7 @@ func (s *Store) EnqueueLLMMessage(input LLMMessageQueueInput) (*LLMMessageQueueR
|
|||||||
Status: LLMMessageStatusPending,
|
Status: LLMMessageStatusPending,
|
||||||
ReceivedAt: now,
|
ReceivedAt: now,
|
||||||
ContentJSON: input.ContentJSON,
|
ContentJSON: input.ContentJSON,
|
||||||
|
CreatedAt: now,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.db.Create(record).Error; err != nil {
|
if err := s.db.Create(record).Error; err != nil {
|
||||||
@@ -396,7 +397,7 @@ func (s *Store) ListLLMMessages(opts ListOptions, botID uint64, includeDeleted b
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 排序和分页
|
// 排序和分页
|
||||||
query = query.Order("created_at DESC")
|
query = query.Order("id DESC")
|
||||||
if opts.Limit > 0 {
|
if opts.Limit > 0 {
|
||||||
query = query.Limit(opts.Limit)
|
query = query.Limit(opts.Limit)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
package store
|
package store
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
func (s *Store) InsertLoginLog(log LoginLogRecord) error {
|
func (s *Store) InsertLoginLog(log LoginLogRecord) error {
|
||||||
|
if log.CreatedAt.IsZero() {
|
||||||
|
log.CreatedAt = time.Now()
|
||||||
|
}
|
||||||
return s.db.Create(&log).Error
|
return s.db.Create(&log).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) ListLoginLogs(opts ListOptions) ([]LoginLogRecord, error) {
|
func (s *Store) ListLoginLogs(opts ListOptions) ([]LoginLogRecord, error) {
|
||||||
opts = NormalizeListOptions(opts)
|
opts = NormalizeListOptions(opts)
|
||||||
var rows []LoginLogRecord
|
var rows []LoginLogRecord
|
||||||
q := s.db.Order("created_at DESC").Order("id DESC").Limit(opts.Limit).Offset(opts.Offset)
|
q := s.db.Order("id DESC").Limit(opts.Limit).Offset(opts.Offset)
|
||||||
if opts.Since != nil {
|
if opts.Since != nil {
|
||||||
q = q.Where("created_at >= ?", *opts.Since)
|
q = q.Where("created_at >= ?", *opts.Since)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -316,7 +316,6 @@ func (s *Store) ListDiscardDetails(opts ListOptions) ([]DiscardDetailsRecord, er
|
|||||||
opts = NormalizeListOptions(opts)
|
opts = NormalizeListOptions(opts)
|
||||||
var rows []DiscardDetailsRecord
|
var rows []DiscardDetailsRecord
|
||||||
q := applyDiscardDetailsFilters(s.db.Model(&DiscardDetailsRecord{}), opts).
|
q := applyDiscardDetailsFilters(s.db.Model(&DiscardDetailsRecord{}), opts).
|
||||||
Order("created_at DESC").
|
|
||||||
Order("id DESC").
|
Order("id DESC").
|
||||||
Limit(opts.Limit).
|
Limit(opts.Limit).
|
||||||
Offset(opts.Offset)
|
Offset(opts.Offset)
|
||||||
@@ -385,7 +384,7 @@ func (s *Store) ListTraceroute(opts ListOptions) ([]TracerouteRecord, error) {
|
|||||||
|
|
||||||
func (s *Store) listAppendRows(opts ListOptions, dest any) *gorm.DB {
|
func (s *Store) listAppendRows(opts ListOptions, dest any) *gorm.DB {
|
||||||
opts = NormalizeListOptions(opts)
|
opts = NormalizeListOptions(opts)
|
||||||
q := s.db.Order("created_at DESC").Order("id DESC").Limit(opts.Limit).Offset(opts.Offset)
|
q := s.db.Order("id DESC").Limit(opts.Limit).Offset(opts.Offset)
|
||||||
if opts.NodeID != "" {
|
if opts.NodeID != "" {
|
||||||
q = q.Where("from_id = ?", opts.NodeID)
|
q = q.Where("from_id = ?", opts.NodeID)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -84,7 +84,7 @@ func NewRouter(cfg configpkg.WebConfig, consoleLog bool, store *storepkg.Store,
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
const BackendVersion = "1.2.0"
|
const BackendVersion = "1.2.1"
|
||||||
|
|
||||||
var CommitVersion = "dev"
|
var CommitVersion = "dev"
|
||||||
|
|
||||||
|
|||||||
@@ -257,8 +257,7 @@ function toChronological(items: TextMessage[]): TextMessage[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function compareMessages(a: TextMessage, b: TextMessage): number {
|
function compareMessages(a: TextMessage, b: TextMessage): number {
|
||||||
const timeDiff = Date.parse(a.created_at) - Date.parse(b.created_at)
|
return a.id - b.id
|
||||||
return timeDiff !== 0 ? timeDiff : a.id - b.id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeMessages(existing: TextMessage[], incoming: TextMessage[]): TextMessage[] {
|
function mergeMessages(existing: TextMessage[], incoming: TextMessage[]): TextMessage[] {
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export const FRONTEND_VERSION = '0.3.0'
|
export const FRONTEND_VERSION = '0.3.1'
|
||||||
Reference in New Issue
Block a user