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 }