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:
@@ -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.")
|
||||
|
||||
Reference in New Issue
Block a user