From ac8e1fe97ed83d2fda23490cfd2ffcf4b42e4f42 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Fri, 19 Jun 2015 08:08:54 -0400 Subject: fix a bug where mentions wouldn't update for words after a new line --- api/post.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'api') diff --git a/api/post.go b/api/post.go index 36607c231..f8125a442 100644 --- a/api/post.go +++ b/api/post.go @@ -302,10 +302,11 @@ func fireAndForgetNotifications(post *model.Post, teamId, teamUrl string) { // Build a map as a list of unique user_ids that are mentioned in this post splitF := func(c rune) bool { - return c == ',' || c == ' ' || c == '.' || c == '!' || c == '?' || c == ':' || c == '<' || c == '>' + return c == ',' || c == ' ' || c == '.' || c == '!' || c == '?' || c == ':' || c == '<' || c == '>' || c == '\n' } splitMessage := strings.FieldsFunc(strings.Replace(post.Message, "
", " ", -1), splitF) for _, word := range splitMessage { + l4g.Debug(word) // Non-case-sensitive check for regular keys userIds1, keyMatch := keywordMap[strings.ToLower(word)] -- cgit v1.2.3-1-g7c22 From 6051b01cdfbf426a6d069aa57cb612c1813a8c3f Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Fri, 19 Jun 2015 08:09:35 -0400 Subject: remove logging --- api/post.go | 1 - 1 file changed, 1 deletion(-) (limited to 'api') diff --git a/api/post.go b/api/post.go index f8125a442..0e521034d 100644 --- a/api/post.go +++ b/api/post.go @@ -306,7 +306,6 @@ func fireAndForgetNotifications(post *model.Post, teamId, teamUrl string) { } splitMessage := strings.FieldsFunc(strings.Replace(post.Message, "
", " ", -1), splitF) for _, word := range splitMessage { - l4g.Debug(word) // Non-case-sensitive check for regular keys userIds1, keyMatch := keywordMap[strings.ToLower(word)] -- cgit v1.2.3-1-g7c22 From 09c4089c95ed8f4306f0005918677bdbaa18a486 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Fri, 19 Jun 2015 08:25:47 -0400 Subject: improved split function --- api/post.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api') diff --git a/api/post.go b/api/post.go index 0e521034d..3acc95551 100644 --- a/api/post.go +++ b/api/post.go @@ -302,7 +302,7 @@ func fireAndForgetNotifications(post *model.Post, teamId, teamUrl string) { // Build a map as a list of unique user_ids that are mentioned in this post splitF := func(c rune) bool { - return c == ',' || c == ' ' || c == '.' || c == '!' || c == '?' || c == ':' || c == '<' || c == '>' || c == '\n' + return model.SplitRunes[c] } splitMessage := strings.FieldsFunc(strings.Replace(post.Message, "
", " ", -1), splitF) for _, word := range splitMessage { -- cgit v1.2.3-1-g7c22 From 3d6d71cc0b5d893923a8f67bfe8ccb2c48731e8e Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Fri, 19 Jun 2015 11:19:51 -0400 Subject: profile image now generates on each call if S3 is not configured --- api/user.go | 68 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 31 deletions(-) (limited to 'api') diff --git a/api/user.go b/api/user.go index 83e29b28e..6af737df3 100644 --- a/api/user.go +++ b/api/user.go @@ -567,7 +567,7 @@ func getAudits(c *Context, w http.ResponseWriter, r *http.Request) { } } -func createProfileImage(username string, userId string) *image.RGBA { +func createProfileImage(username string, userId string) ([]byte, *model.AppError) { colors := []color.NRGBA{ {197, 8, 126, 255}, @@ -634,16 +634,17 @@ func createProfileImage(username string, userId string) *image.RGBA { gc.Translate(width, height) gc.SetFillColor(image.White) gc.FillString(initials) - return i -} -func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { - if !utils.IsS3Configured() { - c.Err = model.NewAppError("getProfileImage", "Unable to get image. Amazon S3 not configured. ", "") - c.Err.StatusCode = http.StatusNotImplemented - return + buf := new(bytes.Buffer) + + if imgErr := png.Encode(buf, i); imgErr != nil { + return nil, model.NewAppError("getProfileImage", "Could not encode default profile image", imgErr.Error()) + } else { + return buf.Bytes(), nil } +} +func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) id := params["id"] @@ -651,36 +652,41 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { c.Err = result.Err return } else { - var auth aws.Auth - auth.AccessKey = utils.Cfg.AWSSettings.S3AccessKeyId - auth.SecretKey = utils.Cfg.AWSSettings.S3SecretAccessKey + var img []byte + var err *model.AppError + + if !utils.IsS3Configured() { + img, err = createProfileImage(result.Data.(*model.User).Username, id) + if err != nil { + c.Err = err + return + } + } else { + var auth aws.Auth + auth.AccessKey = utils.Cfg.AWSSettings.S3AccessKeyId + auth.SecretKey = utils.Cfg.AWSSettings.S3SecretAccessKey - s := s3.New(auth, aws.Regions[utils.Cfg.AWSSettings.S3Region]) - bucket := s.Bucket(utils.Cfg.AWSSettings.S3Bucket) + s := s3.New(auth, aws.Regions[utils.Cfg.AWSSettings.S3Region]) + bucket := s.Bucket(utils.Cfg.AWSSettings.S3Bucket) - path := "teams/" + c.Session.TeamId + "/users/" + id + "/profile.png" + path := "teams/" + c.Session.TeamId + "/users/" + id + "/profile.png" - var img []byte + if data, getErr := bucket.Get(path); getErr != nil { + img, err = createProfileImage(result.Data.(*model.User).Username, id) + if err != nil { + c.Err = err + return + } - if data, getErr := bucket.Get(path); getErr != nil { - rawImg := createProfileImage(result.Data.(*model.User).Username, id) - buf := new(bytes.Buffer) + options := s3.Options{} + if err := bucket.Put(path, img, "image", s3.Private, options); err != nil { + c.Err = model.NewAppError("getImage", "Couldn't upload default profile image", err.Error()) + return + } - if imgErr := png.Encode(buf, rawImg); imgErr != nil { - c.Err = model.NewAppError("getProfileImage", "Could not encode default profile image", imgErr.Error()) - return } else { - img = buf.Bytes() - } - - options := s3.Options{} - if err := bucket.Put(path, buf.Bytes(), "image", s3.Private, options); err != nil { - c.Err = model.NewAppError("getImage", "Couldn't upload default profile image", err.Error()) - return + img = data } - - } else { - img = data } if c.Session.UserId == id { -- cgit v1.2.3-1-g7c22 From a76ee16480aea34d13331490a661e8622f6eb508 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Fri, 19 Jun 2015 11:34:48 -0400 Subject: update unit tests for new createProfileImage func --- api/user_test.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'api') diff --git a/api/user_test.go b/api/user_test.go index 4d5d2b3f0..92ab216aa 100644 --- a/api/user_test.go +++ b/api/user_test.go @@ -10,6 +10,7 @@ import ( "github.com/goamz/goamz/s3" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" + "image" "image/color" "io" "mime/multipart" @@ -324,14 +325,20 @@ func TestGetAudits(t *testing.T) { func TestUserCreateImage(t *testing.T) { Setup() - i := createProfileImage("Corey Hulen", "eo1zkdr96pdj98pjmq8zy35wba") - if i == nil { - t.Fatal("Failed to gen image") + b, err := createProfileImage("Corey Hulen", "eo1zkdr96pdj98pjmq8zy35wba") + if err != nil { + t.Fatal(err) + } + + rdr := bytes.NewReader(b) + img, _, err2 := image.Decode(rdr) + if err2 != nil { + t.Fatal(err) } colorful := color.RGBA{116, 49, 196, 255} - if i.RGBAAt(1, 1) != colorful { + if img.At(1, 1) != colorful { t.Fatal("Failed to create correct color") } -- cgit v1.2.3-1-g7c22