[MM-36318] Set bot profile image and icon only if they have changed (#18008)
* Set bot profile image and icon only if they have changed * Move equality check to the app layer * Use ioutil.ReadAll Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2982cc6f4e
Коммит
868b8d91db
14
app/user.go
14
app/user.go
@@ -12,6 +12,7 @@ import (
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -715,8 +716,7 @@ func (a *App) SetDefaultProfileImage(user *model.User) *model.AppError {
|
||||
return appErr
|
||||
}
|
||||
|
||||
path := "users/" + user.Id + "/profile.png"
|
||||
|
||||
path := getProfileImagePath(user.Id)
|
||||
if _, err := a.WriteFile(bytes.NewReader(img), path); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -787,7 +787,11 @@ func (a *App) SetProfileImageFromFile(userID string, file io.Reader) *model.AppE
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
path := "users/" + userID + "/profile.png"
|
||||
|
||||
path := getProfileImagePath(userID)
|
||||
if storedData, err := a.ReadFile(path); err == nil && bytes.Equal(storedData, buf.Bytes()) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, err := a.WriteFile(buf, path); err != nil {
|
||||
return model.NewAppError("SetProfileImage", "api.user.upload_profile_user.upload_profile.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -2310,3 +2314,7 @@ func (a *App) UpdateThreadReadForUser(userID, teamID, threadID string, timestamp
|
||||
a.Publish(message)
|
||||
return thread, nil
|
||||
}
|
||||
|
||||
func getProfileImagePath(userID string) string {
|
||||
return filepath.Join("users", userID, "profile.png")
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user