mirror of
https://github.com/owncast/owncast.git
synced 2024-11-21 20:28:15 +03:00
implement custom welcome message (#820)
* implement custom welcome message This change adds logic for handling custom welcome messages. * trim welcome message string on POST Instead of trimming the welcome message every time we are going to send to send a welcome message, we just trim once when the message is posted from the admin.
This commit is contained in:
parent
0024ee2fb3
commit
80579c5e7e
7 changed files with 60 additions and 13 deletions
|
@ -4,12 +4,13 @@ import "github.com/owncast/owncast/models"
|
|||
|
||||
// Defaults will hold default configuration values.
|
||||
type Defaults struct {
|
||||
Name string
|
||||
Title string
|
||||
Summary string
|
||||
Logo string
|
||||
Tags []string
|
||||
PageBodyContent string
|
||||
Name string
|
||||
Title string
|
||||
Summary string
|
||||
ServerWelcomeMessage string
|
||||
Logo string
|
||||
Tags []string
|
||||
PageBodyContent string
|
||||
|
||||
DatabaseFilePath string
|
||||
WebServerPort int
|
||||
|
@ -27,10 +28,11 @@ type Defaults struct {
|
|||
// GetDefaults will return default configuration values.
|
||||
func GetDefaults() Defaults {
|
||||
return Defaults{
|
||||
Name: "Owncast",
|
||||
Title: "My Owncast Server",
|
||||
Summary: "This is brief summary of whom you are or what your stream is. You can edit this description in the admin.",
|
||||
Logo: "logo.svg",
|
||||
Name: "Owncast",
|
||||
Title: "My Owncast Server",
|
||||
Summary: "This is brief summary of whom you are or what your stream is. You can edit this description in the admin.",
|
||||
ServerWelcomeMessage: "",
|
||||
Logo: "logo.svg",
|
||||
Tags: []string{
|
||||
"owncast",
|
||||
"streaming",
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"net/http"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/owncast/owncast/controllers"
|
||||
"github.com/owncast/owncast/core"
|
||||
|
@ -120,6 +121,25 @@ func SetServerSummary(w http.ResponseWriter, r *http.Request) {
|
|||
controllers.WriteSimpleResponse(w, true, "changed")
|
||||
}
|
||||
|
||||
// SetServerWelcomeMessage will handle the web config request to set the welcome message text.
|
||||
func SetServerWelcomeMessage(w http.ResponseWriter, r *http.Request) {
|
||||
if !requirePOST(w, r) {
|
||||
return
|
||||
}
|
||||
|
||||
configValue, success := getValueFromRequest(w, r)
|
||||
if !success {
|
||||
return
|
||||
}
|
||||
|
||||
if err := data.SetServerWelcomeMessage(strings.TrimSpace(configValue.Value.(string))); err != nil {
|
||||
controllers.WriteSimpleResponse(w, false, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
controllers.WriteSimpleResponse(w, true, "changed")
|
||||
}
|
||||
|
||||
// SetExtraPageContent will handle the web config request to set the page markdown content.
|
||||
func SetExtraPageContent(w http.ResponseWriter, r *http.Request) {
|
||||
if !requirePOST(w, r) {
|
||||
|
|
|
@ -35,6 +35,7 @@ func GetServerConfig(w http.ResponseWriter, r *http.Request) {
|
|||
Tags: data.GetServerMetadataTags(),
|
||||
ExtraPageContent: data.GetExtraPageBodyContent(),
|
||||
StreamTitle: data.GetStreamTitle(),
|
||||
WelcomeMessage: data.GetServerWelcomeMessage(),
|
||||
Logo: data.GetLogoPath(),
|
||||
SocialHandles: data.GetSocialHandles(),
|
||||
NSFW: data.GetNSFW(),
|
||||
|
@ -85,6 +86,7 @@ type videoSettings struct {
|
|||
type webConfigResponse struct {
|
||||
Name string `json:"name"`
|
||||
Summary string `json:"summary"`
|
||||
WelcomeMessage string `json:"welcomeMessage"`
|
||||
Logo string `json:"logo"`
|
||||
Tags []string `json:"tags"`
|
||||
Version string `json:"version"`
|
||||
|
|
|
@ -182,8 +182,10 @@ func (s *server) sendWelcomeMessageToClient(c *Client) {
|
|||
// Add an artificial delay so people notice this message come in.
|
||||
time.Sleep(7 * time.Second)
|
||||
|
||||
initialChatMessageText := fmt.Sprintf("Welcome to %s! %s", data.GetServerName(), data.GetServerSummary())
|
||||
initialMessage := models.ChatEvent{ClientID: "owncast-server", Author: data.GetServerName(), Body: initialChatMessageText, ID: "initial-message-1", MessageType: "SYSTEM", Visible: true, Timestamp: time.Now()}
|
||||
c.write(initialMessage)
|
||||
welcomeMessage := data.GetServerWelcomeMessage()
|
||||
if welcomeMessage != "" {
|
||||
initialMessage := models.ChatEvent{ClientID: "owncast-server", Author: data.GetServerName(), Body: welcomeMessage, ID: "initial-message-1", MessageType: "SYSTEM", Visible: true, Timestamp: time.Now()}
|
||||
c.write(initialMessage)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ const streamTitleKey = "stream_title"
|
|||
const streamKeyKey = "stream_key"
|
||||
const logoPathKey = "logo_path"
|
||||
const serverSummaryKey = "server_summary"
|
||||
const serverWelcomeMessageKey = "server_welcome_message"
|
||||
const serverNameKey = "server_name"
|
||||
const serverURLKey = "server_url"
|
||||
const httpPortNumberKey = "http_port_number"
|
||||
|
@ -119,6 +120,22 @@ func SetServerSummary(summary string) error {
|
|||
return _datastore.SetString(serverSummaryKey, summary)
|
||||
}
|
||||
|
||||
// GetServerWelcomeMessage will return the server welcome message text.
|
||||
func GetServerWelcomeMessage() string {
|
||||
welcomeMessage, err := _datastore.GetString(serverWelcomeMessageKey)
|
||||
if err != nil {
|
||||
log.Debugln(serverWelcomeMessageKey, err)
|
||||
return config.GetDefaults().ServerWelcomeMessage
|
||||
}
|
||||
|
||||
return welcomeMessage
|
||||
}
|
||||
|
||||
// SetServerWelcomeMessage will set the server welcome message text.
|
||||
func SetServerWelcomeMessage(welcomeMessage string) error {
|
||||
return _datastore.SetString(serverWelcomeMessageKey, welcomeMessage)
|
||||
}
|
||||
|
||||
// GetServerName will return the server name text.
|
||||
func GetServerName() string {
|
||||
name, err := _datastore.GetString(serverNameKey)
|
||||
|
|
|
@ -28,6 +28,7 @@ func PopulateDefaults() {
|
|||
_ = SetLogoPath(defaults.Logo)
|
||||
_ = SetServerMetadataTags([]string{"owncast", "streaming"})
|
||||
_ = SetServerSummary("Welcome to your new Owncast server! This description can be changed in the admin")
|
||||
_ = SetServerWelcomeMessage("")
|
||||
_ = SetServerName("Owncast")
|
||||
_ = SetStreamKey(defaults.StreamKey)
|
||||
_ = SetExtraPageBodyContent("This is your page's content that can be edited in the admin.")
|
||||
|
|
|
@ -109,6 +109,9 @@ func Start() error {
|
|||
// Server summary
|
||||
http.HandleFunc("/api/admin/config/serversummary", middleware.RequireAdminAuth(admin.SetServerSummary))
|
||||
|
||||
// Server welcome message
|
||||
http.HandleFunc("/api/admin/config/welcomemessage", middleware.RequireAdminAuth(admin.SetServerWelcomeMessage))
|
||||
|
||||
// Disable chat
|
||||
http.HandleFunc("/api/admin/config/chat/disable", middleware.RequireAdminAuth(admin.SetChatDisabled))
|
||||
|
||||
|
|
Loading…
Reference in a new issue