Expanded linting + fix warnings (#1396)
* Expand the linters and types of warnings to improve consistency and safety * Fail lint workflow if there are errors * golint has been replaced by revive * Hand-pick some of the default exclude list * Ignore error when trying to delete preview gif * Ignore linter warning opening playlist path * Rename user field Id -> ID * A bunch of renames to address linter warnings * Rename ChatClient -> Client per linter suggestion best practice * Rename ChatServer -> Server per linter suggestion best practice * More linter warning fixes * Add missing comments to all exported functions and properties
This commit is contained in:
@@ -1,20 +1,22 @@
|
||||
package events
|
||||
|
||||
// ActionEvent represents an action that took place, not a chat message.
|
||||
type ActionEvent struct {
|
||||
Event
|
||||
MessageEvent
|
||||
}
|
||||
|
||||
// ActionEvent will return the object to send to all chat users.
|
||||
// GetBroadcastPayload will return the object to send to all chat users.
|
||||
func (e *ActionEvent) GetBroadcastPayload() EventPayload {
|
||||
return EventPayload{
|
||||
"id": e.Id,
|
||||
"id": e.ID,
|
||||
"timestamp": e.Timestamp,
|
||||
"body": e.Body,
|
||||
"type": e.GetMessageType(),
|
||||
}
|
||||
}
|
||||
|
||||
// GetMessageType will return the type of message.
|
||||
func (e *ActionEvent) GetMessageType() EventType {
|
||||
return ChatActionSent
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
// EventPayload is a generic key/value map for sending out to chat clients.
|
||||
type EventPayload map[string]interface{}
|
||||
|
||||
// OutboundEvent represents an event that is sent out to all listeners of the chat server.
|
||||
type OutboundEvent interface {
|
||||
GetBroadcastPayload() EventPayload
|
||||
GetMessageType() EventType
|
||||
@@ -28,10 +29,11 @@ type OutboundEvent interface {
|
||||
// Event is any kind of event. A type is required to be specified.
|
||||
type Event struct {
|
||||
Type EventType `json:"type,omitempty"`
|
||||
Id string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
}
|
||||
|
||||
// UserEvent is an event with an associated user.
|
||||
type UserEvent struct {
|
||||
User *user.User `json:"user"`
|
||||
HiddenAt *time.Time `json:"hiddenAt,omitempty"`
|
||||
@@ -44,6 +46,7 @@ type MessageEvent struct {
|
||||
RawBody string `json:"-"`
|
||||
}
|
||||
|
||||
// SystemActionEvent is an event that represents an action that took place, not a chat message.
|
||||
type SystemActionEvent struct {
|
||||
Event
|
||||
MessageEvent
|
||||
@@ -51,13 +54,13 @@ type SystemActionEvent struct {
|
||||
|
||||
// SetDefaults will set default properties of all inbound events.
|
||||
func (e *Event) SetDefaults() {
|
||||
e.Id = shortid.MustGenerate()
|
||||
e.ID = shortid.MustGenerate()
|
||||
e.Timestamp = time.Now()
|
||||
}
|
||||
|
||||
// SetDefaults will set default properties of all inbound events.
|
||||
func (e *UserMessageEvent) SetDefaults() {
|
||||
e.Id = shortid.MustGenerate()
|
||||
e.ID = shortid.MustGenerate()
|
||||
e.Timestamp = time.Now()
|
||||
e.RenderAndSanitizeMessageBody()
|
||||
}
|
||||
@@ -92,6 +95,7 @@ func RenderAndSanitize(raw string) string {
|
||||
return strings.TrimSpace(safe)
|
||||
}
|
||||
|
||||
// RenderMarkdown will return HTML rendered from the string body of a chat message.
|
||||
func RenderMarkdown(raw string) string {
|
||||
markdown := goldmark.New(
|
||||
goldmark.WithRendererOptions(
|
||||
|
||||
@@ -27,8 +27,11 @@ const (
|
||||
// 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 EventType = "ERROR_NEEDS_REGISTRATION"
|
||||
ChatActionSent EventType = "CHAT_ACTION"
|
||||
// ErrorNeedsRegistration is an error returned when the client needs to perform registration.
|
||||
ErrorNeedsRegistration EventType = "ERROR_NEEDS_REGISTRATION"
|
||||
// ErrorMaxConnectionsExceeded is an error returned when the server determined it should not handle more connections.
|
||||
ErrorMaxConnectionsExceeded EventType = "ERROR_MAX_CONNECTIONS_EXCEEDED"
|
||||
ErrorUserDisabled EventType = "ERROR_USER_DISABLED"
|
||||
// ErrorUserDisabled is an error returned when the connecting user has been previously banned/disabled.
|
||||
ErrorUserDisabled EventType = "ERROR_USER_DISABLED"
|
||||
)
|
||||
|
||||
@@ -7,7 +7,7 @@ type NameChangeEvent struct {
|
||||
NewName string `json:"newName"`
|
||||
}
|
||||
|
||||
// NameChangeEventBroadcast is fired when a user changes their chat display name.
|
||||
// NameChangeBroadcast represents a user changing their chat display name.
|
||||
type NameChangeBroadcast struct {
|
||||
Event
|
||||
UserEvent
|
||||
@@ -17,7 +17,7 @@ type NameChangeBroadcast struct {
|
||||
// GetBroadcastPayload will return the object to send to all chat users.
|
||||
func (e *NameChangeBroadcast) GetBroadcastPayload() EventPayload {
|
||||
return EventPayload{
|
||||
"id": e.Id,
|
||||
"id": e.ID,
|
||||
"timestamp": e.Timestamp,
|
||||
"user": e.User,
|
||||
"oldName": e.Oldname,
|
||||
|
||||
@@ -8,10 +8,10 @@ type SystemMessageEvent struct {
|
||||
MessageEvent
|
||||
}
|
||||
|
||||
// SystemMessageEvent will return the object to send to all chat users.
|
||||
// GetBroadcastPayload will return the object to send to all chat users.
|
||||
func (e *SystemMessageEvent) GetBroadcastPayload() EventPayload {
|
||||
return EventPayload{
|
||||
"id": e.Id,
|
||||
"id": e.ID,
|
||||
"timestamp": e.Timestamp,
|
||||
"body": e.Body,
|
||||
"type": SystemMessageSent,
|
||||
@@ -21,6 +21,7 @@ func (e *SystemMessageEvent) GetBroadcastPayload() EventPayload {
|
||||
}
|
||||
}
|
||||
|
||||
// GetMessageType will return the event type for this message.
|
||||
func (e *SystemMessageEvent) GetMessageType() EventType {
|
||||
return SystemMessageSent
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ type UserDisabledEvent struct {
|
||||
func (e *UserDisabledEvent) GetBroadcastPayload() EventPayload {
|
||||
return EventPayload{
|
||||
"type": ErrorUserDisabled,
|
||||
"id": e.Id,
|
||||
"id": e.ID,
|
||||
"timestamp": e.Timestamp,
|
||||
"user": e.User,
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ type UserJoinedEvent struct {
|
||||
func (e *UserJoinedEvent) GetBroadcastPayload() EventPayload {
|
||||
return EventPayload{
|
||||
"type": UserJoined,
|
||||
"id": e.Id,
|
||||
"id": e.ID,
|
||||
"timestamp": e.Timestamp,
|
||||
"user": e.User,
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ type UserMessageEvent struct {
|
||||
// GetBroadcastPayload will return the object to send to all chat users.
|
||||
func (e *UserMessageEvent) GetBroadcastPayload() EventPayload {
|
||||
return EventPayload{
|
||||
"id": e.Id,
|
||||
"id": e.ID,
|
||||
"timestamp": e.Timestamp,
|
||||
"body": e.Body,
|
||||
"user": e.User,
|
||||
@@ -19,6 +19,7 @@ func (e *UserMessageEvent) GetBroadcastPayload() EventPayload {
|
||||
}
|
||||
}
|
||||
|
||||
// GetMessageType will return the event type for this message.
|
||||
func (e *UserMessageEvent) GetMessageType() EventType {
|
||||
return MessageSent
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user