chat

package
v0.1.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Broadcast

func Broadcast(event events.OutboundEvent) error

Broadcast will send all connected clients the outbound object provided.

func DisconnectUser

func DisconnectUser(userID string)

DisconnectUser will forcefully disconnect all clients belonging to a user by ID.

func GetChatHistory

func GetChatHistory() []events.UserMessageEvent

GetChatHistory will return all the chat messages suitable for returning as user-facing chat history.

func GetChatModerationHistory

func GetChatModerationHistory() []events.UserMessageEvent

GetChatModerationHistory will return all the chat messages suitable for moderation purposes.

func HandleClientConnection

func HandleClientConnection(w http.ResponseWriter, r *http.Request)

HandleClientConnection handles a single inbound websocket connection.

func SaveUserMessage

func SaveUserMessage(event events.UserMessageEvent)

SaveUserMessage will save a single chat event to the messages database.

func SendAllWelcomeMessage

func SendAllWelcomeMessage()

SendAllWelcomeMessage will send the chat message to all connected clients.

func SendSystemAction

func SendSystemAction(text string, ephemeral bool) error

SendSystemAction will send a system action string as an action event to all clients.

func SendSystemMessage

func SendSystemMessage(text string, ephemeral bool) error

SendSystemMessage will send a message string as a system message to all clients.

func SendSystemMessageToClient

func SendSystemMessageToClient(clientID uint, text string)

SendSystemMessageToClient will send a single message to a single connected chat client.

func SetMessageVisibilityForUserID

func SetMessageVisibilityForUserID(userID string, visible bool) error

SetMessageVisibilityForUserID will bulk change the visibility of messages for a user and then send out visibility changed events to chat clients.

func SetMessagesVisibility

func SetMessagesVisibility(messageIDs []string, visibility bool) error

SetMessagesVisibility will set the visibility of multiple messages by ID.

func Start

func Start(getStatusFunc func() models.Status) error

Start begins the chat server.

Types

type Client

type Client struct {
	User *user.User `json:"user"`

	Geo          *geoip.GeoDetails `json:"geo"`
	MessageCount int               `json:"messageCount"`
	UserAgent    string            `json:"userAgent"`
	ConnectedAt  time.Time         `json:"connectedAt"`
	// contains filtered or unexported fields
}

Client represents a single chat client.

func FindClientByID

func FindClientByID(clientID uint) (*Client, bool)

FindClientByID will return a single connected client by ID.

func GetClients

func GetClients() []*Client

GetClients will return all the current chat clients connected.

func GetClientsForUser

func GetClientsForUser(userID string) ([]*Client, error)

GetClientsForUser will return chat connections that are owned by a specific user.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents an instance of the chat server.

func NewChat

func NewChat() *Server

NewChat will return a new instance of the chat server.

func (*Server) Addclient

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

func (s *Server) Broadcast(payload events.EventPayload) error

Broadcast sends message to all connected clients.

func (*Server) ClientClosed

func (s *Server) ClientClosed(c *Client)

ClientClosed is fired when a client disconnects or connection is dropped.

func (*Server) DisconnectUser

func (s *Server) DisconnectUser(userID string)

DisconnectUser will forcefully disconnect all clients belonging to a user by ID.

func (*Server) HandleClientConnection

func (s *Server) HandleClientConnection(w http.ResponseWriter, r *http.Request)

HandleClientConnection is fired when a single client connects to the websocket.

func (*Server) Run

func (s *Server) Run()

Run will start the chat server.

func (*Server) Send

func (s *Server) Send(payload events.EventPayload, client *Client)

Send will send a single payload to a single connected client.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL