chat

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

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

func SendActionToUser(userID string, text string) error

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

func SendConnectedClientInfoToUser(userID string) error

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

func SendSystemAction(text string, ephemeral bool) error

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

func SendSystemMessage added in v0.0.8

func SendSystemMessage(text string, ephemeral bool) error

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

func SendSystemMessageToClient added in v0.0.9

func SendSystemMessageToClient(clientID uint, text string)

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

func SetMessageVisibilityForUserID added in v0.0.9

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 added in v0.0.5

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 {
	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

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

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

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

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

func (s *Server) DisconnectClients(clients []*Client)

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.

func (*Server) Run added in v0.0.9

func (s *Server) Run()

Run will start the chat server.

func (*Server) Send added in v0.0.9

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