summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2016-12-21 05:33:04 -0800
committerJoram Wilander <jwawilander@gmail.com>2016-12-21 08:33:04 -0500
commit2c09582d89f6ff075fdfb8fce5f039b8ac5a920f (patch)
tree60834eaf32aaff004a89c75b243bac8d998971b4 /api
parent8c5744492f592a7e42603a4d9bf26af38eb48542 (diff)
downloadchat-2c09582d89f6ff075fdfb8fce5f039b8ac5a920f.tar.gz
chat-2c09582d89f6ff075fdfb8fce5f039b8ac5a920f.tar.bz2
chat-2c09582d89f6ff075fdfb8fce5f039b8ac5a920f.zip
Fixing image profiles (#4863)
* Fixing image profiles * Fixing break
Diffstat (limited to 'api')
-rw-r--r--api/user.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/api/user.go b/api/user.go
index 4413815f9..7e5a50fc4 100644
--- a/api/user.go
+++ b/api/user.go
@@ -1251,6 +1251,7 @@ func createProfileImage(username string, userId string) ([]byte, *model.AppError
func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
id := params["user_id"]
+ readFailed := false
if result := <-Srv.Store.User().Get(id); result.Err != nil {
c.Err = result.Err
@@ -1268,15 +1269,18 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
path := "users/" + id + "/profile.png"
if data, err := ReadFile(path); err != nil {
+ readFailed = true
if img, err = createProfileImage(result.Data.(*model.User).Username, id); err != nil {
c.Err = err
return
}
- if err := WriteFile(img, path); err != nil {
- c.Err = err
- return
+ if result.Data.(*model.User).LastPictureUpdate == 0 {
+ if err := WriteFile(img, path); err != nil {
+ c.Err = err
+ return
+ }
}
} else {
@@ -1284,7 +1288,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
- if c.Session.UserId == id {
+ if c.Session.UserId == id || readFailed {
w.Header().Set("Cache-Control", "max-age=300, public") // 5 mins
} else {
w.Header().Set("Cache-Control", "max-age=86400, public") // 24 hrs