mirror of
https://github.com/owncast/owncast.git
synced 2024-11-26 23:24:29 +03:00
9c484efd36
* add public func to lookup a ChatClient by its clientId * add facility to send a system message directly to a user * add clientId field to UserEvent * implement simple http endpoint to send a message to a user * let mux handle new directSystemMessageToUser endpoint * add ClientId to UserEvents across the codebase * render body of system-message to client * add clientId to Chat-Message * add tests showing how url-parsing should work * add simple rest endpoint helpers for parameter-parsing and easy routing * use newly added rest-endpoint helper to rout to Client-Messaging controller * use safe "ReadRestUrlParameter" to parse ClientId * remove empty HandleFunc in router * set Header directly to prevent built-in (platform-dependent) canonicalization to kick in * fix typo in "Parameter" message * remove debug-logging of HTTP headers in REST-helpers * convert to uint32 to prevent overruns when converting to wraptype uint later on * resolve linter-ouchies * resolve linter potential nil-deref warning * document the SendSystemMessageToClient endpoint in swaggerdoc * remove clientId assignment causing potential nil dereference in userDisabledEvent-case as the clientId isn't relevant here anyway * make findClientById private, so its not accessible outside of core/chat * remove redundant string type hint * Update PR based on linter requirements Co-authored-by: Raffael Rehberger <raffael@rtrace.io> Co-authored-by: Gabe Kangas <gabek@real-ity.com>
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package webhooks
|
|
|
|
import (
|
|
"github.com/owncast/owncast/core/chat/events"
|
|
"github.com/owncast/owncast/models"
|
|
)
|
|
|
|
// SendChatEvent will send a chat event to webhook destinations.
|
|
func SendChatEvent(chatEvent *events.UserMessageEvent) {
|
|
webhookEvent := WebhookEvent{
|
|
Type: chatEvent.GetMessageType(),
|
|
EventData: &WebhookChatMessage{
|
|
User: chatEvent.User,
|
|
Body: chatEvent.Body,
|
|
ClientID: chatEvent.ClientID,
|
|
RawBody: chatEvent.RawBody,
|
|
ID: chatEvent.ID,
|
|
Visible: chatEvent.HiddenAt == nil,
|
|
Timestamp: &chatEvent.Timestamp,
|
|
},
|
|
}
|
|
|
|
SendEventToWebhooks(webhookEvent)
|
|
}
|
|
|
|
// SendChatEventUsernameChanged will send a username changed event to webhook destinations.
|
|
func SendChatEventUsernameChanged(event events.NameChangeEvent) {
|
|
webhookEvent := WebhookEvent{
|
|
Type: models.UserNameChanged,
|
|
EventData: event,
|
|
}
|
|
|
|
SendEventToWebhooks(webhookEvent)
|
|
}
|
|
|
|
// SendChatEventUserJoined sends a webhook notifying that a user has joined.
|
|
func SendChatEventUserJoined(event events.UserJoinedEvent) {
|
|
webhookEvent := WebhookEvent{
|
|
Type: models.UserJoined,
|
|
EventData: event,
|
|
}
|
|
|
|
SendEventToWebhooks(webhookEvent)
|
|
}
|