Documentation ¶
Index ¶
- func Broadcast(event events.OutboundEvent) error
- func DisconnectClients(clients []*Client)
- func GetChatHistory() []interface{}
- func GetChatModerationHistory() []interface{}
- func GetMessagesFromUser(userID string) ([]events.UserMessageEvent, error)
- func HandleClientConnection(w http.ResponseWriter, r *http.Request)
- func SaveUserMessage(event events.UserMessageEvent)
- func SendActionToUser(userID string, text string) error
- func SendAllWelcomeMessage()
- func SendConnectedClientInfoToUser(userID string) error
- func SendFediverseAction(eventType string, userAccountName string, image *string, body string, ...) error
- func SendSystemAction(text string, ephemeral bool) error
- func SendSystemMessage(text string, ephemeral bool) error
- func SendSystemMessageToClient(clientID uint, text string)
- func SetMessageVisibilityForUserID(userID string, visible bool) error
- func SetMessagesVisibility(messageIDs []string, visibility bool) error
- func Start(getStatusFunc func() models.Status) error
- type Client
- type Server
- func (s *Server) Addclient(conn *websocket.Conn, user *user.User, accessToken string, userAgent string, ...) *Client
- func (s *Server) Broadcast(payload events.EventPayload) error
- func (s *Server) DisconnectClients(clients []*Client)
- func (s *Server) HandleClientConnection(w http.ResponseWriter, r *http.Request)
- func (s *Server) Run()
- func (s *Server) Send(payload events.EventPayload, client *Client)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Broadcast ¶ added in v0.0.8
func Broadcast(event events.OutboundEvent) error
Broadcast will send all connected clients the outbound object provided.
func DisconnectClients ¶ added in v0.0.12
func DisconnectClients(clients []*Client)
DisconnectClients will forcefully disconnect all clients belonging to a user by ID.
func GetChatHistory ¶ added in v0.0.8
func GetChatHistory() []interface{}
GetChatHistory will return all the chat messages suitable for returning as user-facing chat history.
func GetChatModerationHistory ¶ added in v0.0.8
func GetChatModerationHistory() []interface{}
GetChatModerationHistory will return all the chat messages suitable for moderation purposes.
func GetMessagesFromUser ¶ added in v0.1.0
func GetMessagesFromUser(userID string) ([]events.UserMessageEvent, error)
GetMessagesFromUser returns chat messages that were sent by a specific user.
func HandleClientConnection ¶ added in v0.0.8
func HandleClientConnection(w http.ResponseWriter, r *http.Request)
HandleClientConnection handles a single inbound websocket connection.
func SaveUserMessage ¶ added in v0.0.8
func SaveUserMessage(event events.UserMessageEvent)
SaveUserMessage will save a single chat event to the messages database.
func SendActionToUser ¶ added in v0.0.11
SendActionToUser will send system action text to all connected clients assigned to a user ID.
func SendAllWelcomeMessage ¶ added in v0.0.8
func SendAllWelcomeMessage()
SendAllWelcomeMessage will send the chat message to all connected clients.
func SendConnectedClientInfoToUser ¶ added in v0.0.11
SendConnectedClientInfoToUser will find all the connected clients assigned to a user and re-send each the connected client info.
func SendFediverseAction ¶ added in v0.0.11
func SendFediverseAction(eventType string, userAccountName string, image *string, body string, link string) error
SendFediverseAction will send a message indicating some Fediverse engagement took place.
func SendSystemAction ¶ added in v0.0.8
SendSystemAction will send a system action string as an action event to all clients.
func SendSystemMessage ¶ added in v0.0.8
SendSystemMessage will send a message string as a system message to all clients.
func SendSystemMessageToClient ¶ added in v0.0.9
SendSystemMessageToClient will send a single message to a single connected chat client.
func SetMessageVisibilityForUserID ¶ added in v0.0.9
SetMessageVisibilityForUserID will bulk change the visibility of messages for a user and then send out visibility changed events to chat clients.
func SetMessagesVisibility ¶ added in v0.0.5
SetMessagesVisibility will set the visibility of multiple messages by ID.
Types ¶
type Client ¶
type Client struct { ConnectedAt time.Time `json:"connectedAt"` User *user.User `json:"user"` Geo *geoip.GeoDetails `json:"geo"` IPAddress string `json:"-"` UserAgent string `json:"userAgent"` MessageCount int `json:"messageCount"` Id uint `json:"-"` // contains filtered or unexported fields }
Client represents a single chat client.
func FindClientByID ¶ added in v0.0.9
FindClientByID will return a single connected client by ID.
func GetClients ¶ added in v0.0.8
func GetClients() []*Client
GetClients will return all the current chat clients connected.
func GetClientsForUser ¶ added in v0.0.8
GetClientsForUser will return chat connections that are owned by a specific user.
type Server ¶ added in v0.0.9
type Server struct {
// contains filtered or unexported fields
}
Server represents an instance of the chat server.
func NewChat ¶ added in v0.0.8
func NewChat() *Server
NewChat will return a new instance of the chat server.
func (*Server) Addclient ¶ added in v0.0.9
func (s *Server) Addclient(conn *websocket.Conn, user *user.User, accessToken string, userAgent string, ipAddress string) *Client
Addclient registers new connection as a User.
func (*Server) Broadcast ¶ added in v0.0.9
func (s *Server) Broadcast(payload events.EventPayload) error
Broadcast sends message to all connected clients.
func (*Server) DisconnectClients ¶ added in v0.0.12
DisconnectClients will forcefully disconnect all clients belonging to a user by ID.
func (*Server) HandleClientConnection ¶ added in v0.0.9
func (s *Server) HandleClientConnection(w http.ResponseWriter, r *http.Request)
HandleClientConnection is fired when a single client connects to the websocket.