Documentation
¶
Index ¶
- Constants
- Variables
- func ChannelMessageRemove(ctx context.Context, pool *pgxpool.Pool, stream Stream, ...) (*ChannelMessageAck, *ChannelMessage, error)
- func ChannelMessageSend(ctx context.Context, pool *pgxpool.Pool, stream Stream, ...) (*ChannelMessageAck, *ChannelMessage, error)
- func ChannelMessageUpdate(ctx context.Context, pool *pgxpool.Pool, stream Stream, ...) (*ChannelMessageAck, *ChannelMessage, error)
- func SaveMessage(ctx context.Context, pool *pgxpool.Pool, msg *Message) error
- func StreamKey(stream Stream) presence.StreamKey
- func StreamToChannelId(stream Stream) (string, error)
- type ChannelMessage
- type ChannelMessageAck
- type ChannelMessageList
- type Message
- type MessageRouter
- type Stream
Constants ¶
const ( ChannelJoinUnspecified = 0 ChannelJoinRoom = 1 ChannelJoinDM = 2 ChannelJoinGroup = 3 )
Join types for channel_join.type (reference-aligned).
const ( StreamModeChannel = presence.StreamModeChannel // 2 room StreamModeGroup = presence.StreamModeGroup // 3 group StreamModeDM = presence.StreamModeDM // 4 DM )
Stream modes (DB + channel ID prefix) — aligned with presence / ADR-0009 / ADR-0013.
const ( MessageCodeChat int16 = 0 MessageCodeChatUpdate int16 = 1 MessageCodeChatRemove int16 = 2 MessageCodeGroupJoin int16 = 3 MessageCodeGroupAdd int16 = 4 MessageCodeGroupLeave int16 = 5 MessageCodeGroupKick int16 = 6 MessageCodeGroupPromote int16 = 7 MessageCodeGroupBan int16 = 8 MessageCodeGroupDemote int16 = 9 )
Message type codes.
const NotificationCodeDmRequest int16 = -1
NotificationCodeDmRequest is sent when a user newly joins a DM and the other party is absent.
Variables ¶
var ( ErrChannelIDInvalid = errors.New("invalid channel id") ErrInvalidChannelTarget = errors.New("invalid channel target") ErrInvalidChannelType = errors.New("invalid channel type") ErrChannelMessageNotFound = errors.New("channel message not found") ErrChannelCursorInvalid = errors.New("channel cursor invalid") ErrChannelGroupNotFound = errors.New("channel group not found") )
Functions ¶
func ChannelMessageRemove ¶
func ChannelMessageRemove(ctx context.Context, pool *pgxpool.Pool, stream Stream, channelID, messageID, senderID, senderUsername string, persist bool) (*ChannelMessageAck, *ChannelMessage, error)
ChannelMessageRemove deletes a message (sender-only when persist) and returns remove broadcast payload.
func ChannelMessageSend ¶
func ChannelMessageSend(ctx context.Context, pool *pgxpool.Pool, stream Stream, channelID, content, senderID, senderUsername string, persist bool) (*ChannelMessageAck, *ChannelMessage, error)
ChannelMessageSend persists (optional) and returns an ack payload for the sender.
func ChannelMessageUpdate ¶
func ChannelMessageUpdate(ctx context.Context, pool *pgxpool.Pool, stream Stream, channelID, messageID, content, senderID, senderUsername string, persist bool) (*ChannelMessageAck, *ChannelMessage, error)
ChannelMessageUpdate updates a message (sender-only when persist).
func SaveMessage ¶
SaveMessage persists a chat message to PostgreSQL.
func StreamToChannelId ¶
StreamToChannelId encodes a stream as a four-part channel ID.
Types ¶
type ChannelMessage ¶
type ChannelMessage struct {
ChannelID string `json:"channel_id"`
MessageID string `json:"message_id"`
Code int16 `json:"code"`
SenderID string `json:"sender_id"`
Username string `json:"username"`
Content string `json:"content"`
CreateTime time.Time `json:"create_time"`
UpdateTime time.Time `json:"update_time"`
Persistent bool `json:"persistent"`
RoomName string `json:"room_name,omitempty"`
GroupID string `json:"group_id,omitempty"`
UserIDOne string `json:"user_id_one,omitempty"`
UserIDTwo string `json:"user_id_two,omitempty"`
}
ChannelMessage is the wire-facing message payload.
type ChannelMessageAck ¶
type ChannelMessageAck struct {
ChannelID string `json:"channel_id"`
MessageID string `json:"message_id"`
Code int16 `json:"code"`
Username string `json:"username"`
CreateTime time.Time `json:"create_time"`
UpdateTime time.Time `json:"update_time"`
Persistent bool `json:"persistent"`
RoomName string `json:"room_name,omitempty"`
GroupID string `json:"group_id,omitempty"`
UserIDOne string `json:"user_id_one,omitempty"`
UserIDTwo string `json:"user_id_two,omitempty"`
}
ChannelMessageAck is the send/update/remove confirmation to the originator.
type ChannelMessageList ¶
type ChannelMessageList struct {
Messages []ChannelMessage `json:"messages"`
NextCursor string `json:"next_cursor,omitempty"`
PrevCursor string `json:"prev_cursor,omitempty"`
CacheableCursor string `json:"cacheable_cursor,omitempty"`
}
ChannelMessageList is a paginated history response.
func ChannelMessagesList ¶
func ChannelMessagesList(ctx context.Context, pool *pgxpool.Pool, caller string, stream Stream, channelID string, limit int, forward bool, cursor string) (*ChannelMessageList, error)
ChannelMessagesList lists history. caller empty skips authorization (runtime/server-side).
type Message ¶
type Message struct {
ID string `json:"id"`
Code int16 `json:"code"`
SenderID string `json:"sender_id"`
Username string `json:"username"`
StreamMode int16 `json:"stream_mode"`
StreamSubject string `json:"stream_subject"`
StreamDescriptor string `json:"stream_descriptor"`
StreamLabel string `json:"stream_label"`
Content string `json:"content"`
CreateTime time.Time `json:"create_time"`
UpdateTime time.Time `json:"update_time"`
}
Message represents a chat message stored in the database.
type MessageRouter ¶
type MessageRouter interface {
BroadcastChannelMessage(channelID string, msg *ChannelMessage)
}
MessageRouter broadcasts channel messages to local WebSocket subscribers.
var DefaultRouter MessageRouter
DefaultRouter is set by the socket gateway at startup.
type Stream ¶
type Stream struct {
Mode int16
Subject string // UUID string or empty → uuid.Nil in DB
Subcontext string
Label string
}
Stream is the presence/stream identity for a channel.
func BuildChannelId ¶
func BuildChannelId(ctx context.Context, pool *pgxpool.Pool, userID, target string, joinType int) (string, Stream, error)
BuildChannelId builds a channel ID and stream from join type + target. userID may be empty (uuid.Nil semantics) for authoritative runtime calls that skip ACL.
func ChannelIdToStream ¶
ChannelIdToStream parses a four-part channel ID.