MM-21356: Conditionally set user status online (#13538)
* MM-21356: Conditionally set user status online Check for the set_online query param and do not set the status if it is set to false. * Fix some issues * Add a test * Log an error if an invalid value was passed * Logging a warning instead of error Co-authored-by: mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
49308e9163
Коммит
8b24b26cb0
16
api4/post.go
16
api4/post.go
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
@@ -67,7 +68,20 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
c.App.SetStatusOnline(c.App.Session.UserId, false)
|
||||
setOnline := r.URL.Query().Get("set_online")
|
||||
setOnlineBool := true // By default, always set online.
|
||||
var err2 error
|
||||
if setOnline != "" {
|
||||
setOnlineBool, err2 = strconv.ParseBool(setOnline)
|
||||
if err2 != nil {
|
||||
mlog.Warn("Failed to parse set_online URL query parameter from createPost request", mlog.Err(err2))
|
||||
setOnlineBool = true // Set online nevertheless.
|
||||
}
|
||||
}
|
||||
if setOnlineBool {
|
||||
c.App.SetStatusOnline(c.App.Session.UserId, false)
|
||||
}
|
||||
|
||||
c.App.UpdateLastActivityAtIfNeeded(c.App.Session)
|
||||
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
|
||||
Ссылка в новой задаче
Block a user