events

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: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderAndSanitize

func RenderAndSanitize(raw string) string

RenderAndSanitize will turn markdown into HTML, sanitize raw user-supplied HTML and standardize the message into something safe and renderable for clients.

func RenderMarkdown

func RenderMarkdown(raw string) string

RenderMarkdown will return HTML rendered from the string body of a chat message.

Types

type ActionEvent

type ActionEvent struct {
	Event
	MessageEvent
}

ActionEvent represents an action that took place, not a chat message.

func (*ActionEvent) GetBroadcastPayload

func (e *ActionEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

func (*ActionEvent) GetMessageType

func (e *ActionEvent) GetMessageType() EventType

GetMessageType will return the type of message.

type ColorChangeEvent added in v0.1.0

type ColorChangeEvent struct {
	Event
	UserEvent
	NewColor int `json:"newColor"`
}

ColorChangeEvent is received when a user changes their chat display color.

type ConnectedClientInfo added in v0.0.11

type ConnectedClientInfo struct {
	User *user.User `json:"user"`
	Event
}

ConnectedClientInfo represents the information about a connected client.

type Event

type Event struct {
	Timestamp time.Time `json:"timestamp"`
	Type      EventType `json:"type,omitempty"`
	ID        string    `json:"id"`
}

Event is any kind of event. A type is required to be specified.

func (*Event) SetDefaults

func (e *Event) SetDefaults()

SetDefaults will set default properties of all inbound events.

type EventPayload

type EventPayload map[string]interface{}

EventPayload is a generic key/value map for sending out to chat clients.

type EventType

type EventType = string

EventType is the type of a websocket event.

const (
	// MessageSent is the event sent when a chat event takes place.
	MessageSent EventType = "CHAT"
	// UserJoined is the event sent when a chat user join action takes place.
	UserJoined EventType = "USER_JOINED"
	// UserParted is the event sent when a chat user part action takes place.
	UserParted EventType = "USER_PARTED"
	// UserNameChanged is the event sent when a chat username change takes place.
	UserNameChanged EventType = "NAME_CHANGE"
	// UserColorChanged is the event sent when a chat user color change takes place.
	UserColorChanged EventType = "COLOR_CHANGE"
	// VisibiltyUpdate is the event sent when a chat message's visibility changes.
	VisibiltyUpdate EventType = "VISIBILITY-UPDATE"
	// PING is a ping message.
	PING EventType = "PING"
	// PONG is a pong message.
	PONG EventType = "PONG"
	// StreamStarted represents a stream started event.
	StreamStarted EventType = "STREAM_STARTED"
	// StreamStopped represents a stream stopped event.
	StreamStopped EventType = "STREAM_STOPPED"
	// StreamTitleUpdated is the event sent when a stream's title changes.
	StreamTitleUpdated EventType = "STREAM_TITLE_UPDATED"
	// SystemMessageSent is the event sent when a system message is sent.
	SystemMessageSent EventType = "SYSTEM"
	// ChatDisabled is when a user is explicitly disabled and blocked from using chat.
	ChatDisabled EventType = "CHAT_DISABLED"
	// ConnectedUserInfo is a private event to a user letting them know their user details.
	ConnectedUserInfo EventType = "CONNECTED_USER_INFO"
	// ChatActionSent is a generic chat action that can be used for anything that doesn't need specific handling or formatting.
	ChatActionSent EventType = "CHAT_ACTION"
	// ErrorNeedsRegistration is an error returned when the client needs to perform registration.
	ErrorNeedsRegistration EventType = "ERROR_NEEDS_REGISTRATION" // nolint:gosec
	// ErrorMaxConnectionsExceeded is an error returned when the server determined it should not handle more connections.
	ErrorMaxConnectionsExceeded EventType = "ERROR_MAX_CONNECTIONS_EXCEEDED"
	// ErrorUserDisabled is an error returned when the connecting user has been previously banned/disabled.
	ErrorUserDisabled EventType = "ERROR_USER_DISABLED"
	// FediverseEngagementFollow is an event representing a follow action that took place on the fediverse.
	FediverseEngagementFollow EventType = "FEDIVERSE_ENGAGEMENT_FOLLOW"
	// FediverseEngagementLike is an event representing a like action that took place on the fediverse.
	FediverseEngagementLike EventType = "FEDIVERSE_ENGAGEMENT_LIKE"
	// FediverseEngagementRepost is an event representing a re-post action that took place on the fediverse.
	FediverseEngagementRepost EventType = "FEDIVERSE_ENGAGEMENT_REPOST"
)

type FediverseEngagementEvent added in v0.0.11

type FediverseEngagementEvent struct {
	Event
	MessageEvent
	Image           *string `json:"image"`
	Link            string  `json:"link"`
	UserAccountName string  `json:"title"`
}

FediverseEngagementEvent is a message displayed in chat on representing an action on the Fediverse.

func (*FediverseEngagementEvent) GetBroadcastPayload added in v0.0.11

func (e *FediverseEngagementEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

func (*FediverseEngagementEvent) GetMessageType added in v0.0.11

func (e *FediverseEngagementEvent) GetMessageType() EventType

GetMessageType will return the event type for this message.

type MessageEvent

type MessageEvent struct {
	OutboundEvent `json:"-"`
	Body          string `json:"body"`
	RawBody       string `json:"-"`
}

MessageEvent is an event that has a message body.

func (*MessageEvent) Empty

func (m *MessageEvent) Empty() bool

Empty will return if this message's contents is empty.

func (*MessageEvent) RenderAndSanitizeMessageBody

func (m *MessageEvent) RenderAndSanitizeMessageBody()

RenderAndSanitizeMessageBody will turn markdown into HTML, sanitize raw user-supplied HTML and standardize the message into something safe and renderable for clients.

func (*MessageEvent) RenderBody

func (m *MessageEvent) RenderBody()

RenderBody will render markdown to html without any sanitization.

type NameChangeBroadcast

type NameChangeBroadcast struct {
	Event
	OutboundEvent
	UserEvent
	Oldname string `json:"oldName"`
}

NameChangeBroadcast represents a user changing their chat display name.

func (*NameChangeBroadcast) GetBroadcastPayload

func (e *NameChangeBroadcast) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

type NameChangeEvent

type NameChangeEvent struct {
	Event
	UserEvent
	NewName string `json:"newName"`
}

NameChangeEvent is received when a user changes their chat display name.

type OutboundEvent

type OutboundEvent interface {
	GetBroadcastPayload() EventPayload
	GetMessageType() EventType
}

OutboundEvent represents an event that is sent out to all listeners of the chat server.

type SetMessageVisibilityEvent added in v0.0.11

type SetMessageVisibilityEvent struct {
	Event
	UserMessageEvent
	MessageIDs []string
	Visible    bool
}

SetMessageVisibilityEvent is the event fired when one or more message visibilities are changed.

func (*SetMessageVisibilityEvent) GetBroadcastPayload added in v0.0.11

func (e *SetMessageVisibilityEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

func (*SetMessageVisibilityEvent) GetMessageType added in v0.0.11

func (e *SetMessageVisibilityEvent) GetMessageType() EventType

GetMessageType will return the event type for this message.

type SystemActionEvent

type SystemActionEvent struct {
	Event
	MessageEvent
}

SystemActionEvent is an event that represents an action that took place, not a chat message.

type SystemMessageEvent

type SystemMessageEvent struct {
	Event
	MessageEvent
}

SystemMessageEvent is a message displayed in chat on behalf of the server.

func (*SystemMessageEvent) GetBroadcastPayload

func (e *SystemMessageEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

func (*SystemMessageEvent) GetMessageType

func (e *SystemMessageEvent) GetMessageType() EventType

GetMessageType will return the event type for this message.

type UserDisabledEvent

type UserDisabledEvent struct {
	Event
	UserEvent
}

UserDisabledEvent is the event fired when a user is banned/blocked and disconnected from chat.

func (*UserDisabledEvent) GetBroadcastPayload

func (e *UserDisabledEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

type UserEvent

type UserEvent struct {
	User     *user.User `json:"user"`
	HiddenAt *time.Time `json:"hiddenAt,omitempty"`
	ClientID uint       `json:"clientId,omitempty"`
}

UserEvent is an event with an associated user.

type UserJoinedEvent

type UserJoinedEvent struct {
	Event
	UserEvent
}

UserJoinedEvent is the event fired when a user joins chat.

func (*UserJoinedEvent) GetBroadcastPayload

func (e *UserJoinedEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

type UserMessageEvent

type UserMessageEvent struct {
	Event
	UserEvent
	MessageEvent
}

UserMessageEvent is an inbound message from a user.

func (*UserMessageEvent) GetBroadcastPayload

func (e *UserMessageEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

func (*UserMessageEvent) GetMessageType

func (e *UserMessageEvent) GetMessageType() EventType

GetMessageType will return the event type for this message.

func (*UserMessageEvent) SetDefaults

func (e *UserMessageEvent) SetDefaults()

SetDefaults will set default properties of all inbound events.

type UserPartEvent added in v0.1.2

type UserPartEvent struct {
	Event
	UserEvent
}

UserPartEvent is the event fired when a user leaves chat.

func (*UserPartEvent) GetBroadcastPayload added in v0.1.2

func (e *UserPartEvent) GetBroadcastPayload() EventPayload

GetBroadcastPayload will return the object to send to all chat users.

Jump to

Keyboard shortcuts

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