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:
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
var getStatus func() models.Status
|
||||
|
||||
// Start begins the chat server.
|
||||
func Start(getStatusFunc func() models.Status) error {
|
||||
setupPersistence()
|
||||
|
||||
@@ -26,11 +27,11 @@ func Start(getStatusFunc func() models.Status) error {
|
||||
}
|
||||
|
||||
// GetClientsForUser will return chat connections that are owned by a specific user.
|
||||
func GetClientsForUser(userID string) ([]*ChatClient, error) {
|
||||
clients := map[string][]*ChatClient{}
|
||||
func GetClientsForUser(userID string) ([]*Client, error) {
|
||||
clients := map[string][]*Client{}
|
||||
|
||||
for _, client := range _server.clients {
|
||||
clients[client.User.Id] = append(clients[client.User.Id], client)
|
||||
clients[client.User.ID] = append(clients[client.User.ID], client)
|
||||
}
|
||||
|
||||
if _, exists := clients[userID]; !exists {
|
||||
@@ -40,8 +41,9 @@ func GetClientsForUser(userID string) ([]*ChatClient, error) {
|
||||
return clients[userID], nil
|
||||
}
|
||||
|
||||
func GetClients() []*ChatClient {
|
||||
clients := []*ChatClient{}
|
||||
// GetClients will return all the current chat clients connected.
|
||||
func GetClients() []*Client {
|
||||
clients := []*Client{}
|
||||
|
||||
// Convert the keyed map to a slice.
|
||||
for _, client := range _server.clients {
|
||||
@@ -55,6 +57,7 @@ func GetClients() []*ChatClient {
|
||||
return clients
|
||||
}
|
||||
|
||||
// SendSystemMessage will send a message string as a system message to all clients.
|
||||
func SendSystemMessage(text string, ephemeral bool) error {
|
||||
message := events.SystemMessageEvent{
|
||||
MessageEvent: events.MessageEvent{
|
||||
@@ -69,12 +72,13 @@ func SendSystemMessage(text string, ephemeral bool) error {
|
||||
}
|
||||
|
||||
if !ephemeral {
|
||||
saveEvent(message.Id, "system", message.Body, message.GetMessageType(), nil, message.Timestamp)
|
||||
saveEvent(message.ID, "system", message.Body, message.GetMessageType(), nil, message.Timestamp)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendSystemAction will send a system action string as an action event to all clients.
|
||||
func SendSystemAction(text string, ephemeral bool) error {
|
||||
message := events.ActionEvent{
|
||||
MessageEvent: events.MessageEvent{
|
||||
@@ -90,20 +94,23 @@ func SendSystemAction(text string, ephemeral bool) error {
|
||||
}
|
||||
|
||||
if !ephemeral {
|
||||
saveEvent(message.Id, "action", message.Body, message.GetMessageType(), nil, message.Timestamp)
|
||||
saveEvent(message.ID, "action", message.Body, message.GetMessageType(), nil, message.Timestamp)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SendAllWelcomeMessage will send the chat message to all connected clients.
|
||||
func SendAllWelcomeMessage() {
|
||||
_server.sendAllWelcomeMessage()
|
||||
}
|
||||
|
||||
// Broadcast will send all connected clients the outbound object provided.
|
||||
func Broadcast(event events.OutboundEvent) error {
|
||||
return _server.Broadcast(event.GetBroadcastPayload())
|
||||
}
|
||||
|
||||
// HandleClientConnection handles a single inbound websocket connection.
|
||||
func HandleClientConnection(w http.ResponseWriter, r *http.Request) {
|
||||
_server.HandleClientConnection(w, r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user