summaryrefslogtreecommitdiffstats
path: root/api/post.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-07-22 18:05:44 -0800
committer=Corey Hulen <corey@hulen.com>2015-07-22 18:05:44 -0800
commitc277a98b5d88c81df39f8e33ef1286f72ac04014 (patch)
tree0d96238a2ee3ab121ea576db9900311ff5a57ba6 /api/post.go
parente0bad6c03784d44210760577550be585daf513b9 (diff)
parentf4c3eaa8c091366a956fa2ab48124190f4f9082b (diff)
downloadchat-c277a98b5d88c81df39f8e33ef1286f72ac04014.tar.gz
chat-c277a98b5d88c81df39f8e33ef1286f72ac04014.tar.bz2
chat-c277a98b5d88c81df39f8e33ef1286f72ac04014.zip
Merge branch 'master' into mm-1420
Diffstat (limited to 'api/post.go')
-rw-r--r--api/post.go37
1 files changed, 34 insertions, 3 deletions
diff --git a/api/post.go b/api/post.go
index fb9fdd1ef..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"
@@ -170,16 +171,16 @@ func CreatePost(c *Context, post *model.Post, doUpdateLastViewed bool) (*model.P
continue
} else if model.PartialUrlRegex.MatchString(path) {
matches := model.PartialUrlRegex.FindAllStringSubmatch(path, -1)
- if len(matches) == 0 || len(matches[0]) < 5 {
+ if len(matches) == 0 || len(matches[0]) < 4 {
doRemove = true
}
- channelId := matches[0][2]
+ channelId := matches[0][1]
if channelId != post.ChannelId {
doRemove = true
}
- userId := matches[0][3]
+ userId := matches[0][2]
if userId != post.UserId {
doRemove = true
}
@@ -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)
}