SYNC_INBOX 补 conversation_type、peer_id、group_id 和 last_read_msg_id。历史消息在 sender 为 0 时用 peer_id 定位对方。已读清未读时保留会话 ZSET 分数,避免被毫秒时间戳冲到游标后面。 Co-authored-by: Cursor <cursoragent@cursor.com>
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package logic
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"spark-server/internal/module/message/entity"
|
|
"spark-server/internal/pkg/reply"
|
|
)
|
|
|
|
// Item is the HTTP/TCP message view. Content is serialized JSON bytes.
|
|
type Item struct {
|
|
MsgID int64 `json:"msg_id"`
|
|
ConversationID int64 `json:"conversation_id"`
|
|
SenderID int64 `json:"sender_id"`
|
|
ReceiverID int64 `json:"receiver_id,omitempty"`
|
|
PeerID int64 `json:"peer_id,omitempty"`
|
|
GroupID int64 `json:"group_id,omitempty"`
|
|
ClientMsgID string `json:"client_msg_id,omitempty"`
|
|
MessageType entity.Type `json:"message_type"`
|
|
Kind entity.Kind `json:"kind,omitempty"`
|
|
Content json.RawMessage `json:"content"`
|
|
Status entity.Status `json:"status"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
}
|
|
|
|
func itemOf(m *entity.Message) *Item {
|
|
if m == nil {
|
|
return nil
|
|
}
|
|
return &Item{
|
|
MsgID: m.ID, ConversationID: m.ConversationID, SenderID: m.SenderID,
|
|
ReceiverID: m.ReceiverID, GroupID: m.GroupID, ClientMsgID: m.ClientMsgID,
|
|
MessageType: m.Type, Kind: m.Kind, Content: append(json.RawMessage(nil), m.Content...), Status: m.Status, CreatedAt: m.CreatedAtMS,
|
|
}
|
|
}
|
|
|
|
func pushBytes(m *entity.Message) []byte {
|
|
return reply.MustMarshal(reply.OK(itemOf(m)))
|
|
}
|
|
|
|
func controlBytes(msgID, conversationID int64) []byte {
|
|
return reply.MustMarshal(reply.OK(map[string]int64{
|
|
"msg_id": msgID, "conversation_id": conversationID,
|
|
}))
|
|
}
|
|
|
|
func previewOf(m *entity.Message) []byte {
|
|
if m == nil {
|
|
return nil
|
|
}
|
|
raw, _ := json.Marshal(map[string]any{
|
|
"msg_id": m.ID, "t": m.Type, "sender_id": m.SenderID, "status": m.Status,
|
|
})
|
|
return raw
|
|
}
|