Skip to content

Commit

Permalink
[MM-387] Review fixes: Create constant and update name
Browse files Browse the repository at this point in the history
  • Loading branch information
ayusht2810 committed Jul 1, 2024
1 parent 9878691 commit ca1edd6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions server/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// UserHasBeenCreated is invoked after a user was created.
func (p *Plugin) UserHasBeenCreated(c *plugin.Context, user *model.User) {
data := p.constructGlobalMessageTemplate(user.Id)
data := p.getGlobalMessageTemplateData(user.Id)
if data == nil {
return
}
Expand All @@ -25,7 +25,7 @@ func (p *Plugin) UserHasBeenCreated(c *plugin.Context, user *model.User) {
}

if len(message.GlobalWelcomeMessage) > 0 {
tmpMsg, _ := template.New("Response").Parse(strings.Join(message.GlobalWelcomeMessage, "\n"))
tmpMsg, _ := template.New(templateNameResponse).Parse(strings.Join(message.GlobalWelcomeMessage, "\n"))
var message bytes.Buffer
err := tmpMsg.Execute(&message, data)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const (
botDisplayName = "Welcomebot"
botDescription = "A bot account created by the Welcomebot plugin."

templateNameResponse = "Response"

welcomebotChannelWelcomeKey = "chanmsg_"
)

Expand Down
6 changes: 3 additions & 3 deletions server/welcomebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (p *Plugin) constructMessageTemplate(userID, teamID string) *MessageTemplat
return data
}

func (p *Plugin) constructGlobalMessageTemplate(userID string) *GloablMessageTemplate {
func (p *Plugin) getGlobalMessageTemplateData(userID string) *GloablMessageTemplate {
data := &GloablMessageTemplate{}
var err *model.AppError

Expand Down Expand Up @@ -156,7 +156,7 @@ func (p *Plugin) renderWelcomeMessage(messageTemplate MessageTemplate, configMes
}
}

tmpMsg, _ := template.New("Response").Parse(strings.Join(configMessage.Message, "\n"))
tmpMsg, _ := template.New(templateNameResponse).Parse(strings.Join(configMessage.Message, "\n"))
var message bytes.Buffer
err := tmpMsg.Execute(&message, messageTemplate)
if err != nil {
Expand Down Expand Up @@ -225,7 +225,7 @@ func (p *Plugin) processActionMessage(messageTemplate MessageTemplate, action *A
p.joinChannel(action, channelName)
}

tmpMsg, _ := template.New("Response").Parse(strings.Join(configMessageAction.ActionSuccessfulMessage, "\n"))
tmpMsg, _ := template.New(templateNameResponse).Parse(strings.Join(configMessageAction.ActionSuccessfulMessage, "\n"))
var message bytes.Buffer
err := tmpMsg.Execute(&message, messageTemplate)
if err != nil {
Expand Down

0 comments on commit ca1edd6

Please sign in to comment.