Skip to content

Commit

Permalink
Add ability to mark a message as ephemeral and set it with title changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gabek committed Feb 23, 2021
1 parent 8f1681c commit 4f833be
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions controllers/admin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@ func SetStreamTitle(w http.ResponseWriter, r *http.Request) {
return
}
if value != "" {
sendSystemChatAction(fmt.Sprintf("Stream title changed to **%s**", value))
sendSystemChatAction(fmt.Sprintf("Stream title changed to **%s**", value), true)
}
controllers.WriteSimpleResponse(w, true, "changed")
}

func sendSystemChatAction(messageText string) {
func sendSystemChatAction(messageText string, ephemeral bool) {
message := models.ChatEvent{}
message.Body = messageText
message.MessageType = models.ChatActionSent
message.ClientID = "internal-server"
message.Ephemeral = ephemeral
message.SetDefaults()

if err := core.SendMessageToChat(message); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion core/chat/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ func (s *server) Listen() {

// Store in the message history
msg.SetDefaults()
addMessage(msg)
if !msg.Ephemeral {
addMessage(msg)
}

// Send webhooks
go webhooks.SendChatEvent(msg)
Expand Down
1 change: 1 addition & 0 deletions models/chatMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type ChatEvent struct {
MessageType EventType `json:"type"`
Visible bool `json:"visible"`
Timestamp time.Time `json:"timestamp,omitempty"`
Ephemeral bool `json:"ephemeral,omitempty"`
}

// Valid checks to ensure the message is valid.
Expand Down

0 comments on commit 4f833be

Please sign in to comment.