diff options
author | Joram Wilander <jwawilander@gmail.com> | 2015-07-22 15:42:09 -0400 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2015-07-22 15:42:09 -0400 |
commit | ecdd160ec07aef5d309056a23eacf12c91a93193 (patch) | |
tree | 9a0fb976a216d1a7f0da64a6db88c998d9b780a6 /api | |
parent | 33c32be69bdfea8241ea696b8d387be0d8493e2f (diff) | |
parent | 156e3a94c49fa43a862d0e8de6683d9d96794447 (diff) | |
download | chat-ecdd160ec07aef5d309056a23eacf12c91a93193.tar.gz chat-ecdd160ec07aef5d309056a23eacf12c91a93193.tar.bz2 chat-ecdd160ec07aef5d309056a23eacf12c91a93193.zip |
Merge pull request #214 from hmhealey/mm1498
MM-1498 Provide a replacement message for email notifications for posts only containing files
Diffstat (limited to 'api')
-rw-r--r-- | api/post.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/api/post.go b/api/post.go index 268a9be20..f96320639 100644 --- a/api/post.go +++ b/api/post.go @@ -11,6 +11,7 @@ import ( "github.com/mattermost/platform/store" "github.com/mattermost/platform/utils" "net/http" + "net/url" "path/filepath" "strconv" "strings" @@ -407,6 +408,36 @@ func fireAndForgetNotifications(post *model.Post, teamId, siteURL string) { bodyPage.Props["PostMessage"] = model.ClearMentionTags(post.Message) bodyPage.Props["TeamLink"] = teamURL + "/channels/" + channel.Name + // attempt to fill in a message body if the post doesn't have any text + if len(strings.TrimSpace(bodyPage.Props["PostMessage"])) == 0 && len(post.Filenames) > 0 { + // extract the filenames from their paths and determine what type of files are attached + filenames := make([]string, len(post.Filenames)) + onlyImages := true + for i, filename := range post.Filenames { + var err error + if filenames[i], err = url.QueryUnescape(filepath.Base(filename)); err != nil { + // this should never error since filepath was escaped using url.QueryEscape + filenames[i] = filepath.Base(filename) + } + + ext := filepath.Ext(filename) + onlyImages = onlyImages && model.IsFileExtImage(ext) + } + filenamesString := strings.Join(filenames, ", ") + + var attachmentPrefix string + if onlyImages { + attachmentPrefix = "Image" + } else { + attachmentPrefix = "File" + } + if len(post.Filenames) > 1 { + attachmentPrefix += "s" + } + + bodyPage.Props["PostMessage"] = fmt.Sprintf("%s: %s sent", attachmentPrefix, filenamesString) + } + if err := utils.SendMail(profileMap[id].Email, subjectPage.Render(), bodyPage.Render()); err != nil { l4g.Error("Failed to send mention email successfully email=%v err=%v", profileMap[id].Email, err) } |