* Create the system console setting and send to webapp

* MI-1145: Add custom status APIs

* MI-1145 Add slash commands to set and clear status

* Add validation for custom status API

* Trim custom status message

* Code refactoring

- Run gofmt

- Rename constants

* Remove sendUserUpdated webhook event

* Fix recent custom status length

* Update error conditions

* Disable /status slash command when config setting is off

* MI-1155: Create the feature flag for custom status APIs and slash commands

* Move recent custom statuses to user preferences (#7)

* Move recent custom statuses to user preferences

* Code refactoring and feedback changes

* Update slash command text and emoji regex

* Make the custom status feature flag off by default

* Update SetCustomStatus, handle recents not set better

* Update status codes

* Update slash command handling

* Add telementry settings

* Fix i18n order

* Revert "Fix i18n order"

This reverts commit 499f7eaca8180336f5bcca360cc0133365899e08.

* Update i18n strings
Этот коммит содержится в:
Chetanya Kandhari
2021-02-18 16:38:01 +05:30
коммит произвёл GitHub
родитель 22308ea21c
Коммит 7585e16d84
15 изменённых файлов: 509 добавлений и 0 удалений

Просмотреть файл

@@ -6,6 +6,7 @@ package app
import (
"errors"
"net/http"
"strings"
"github.com/mattermost/mattermost-server/v5/mlog"
"github.com/mattermost/mattermost-server/v5/model"
@@ -363,3 +364,86 @@ func (a *App) GetStatus(userID string) (*model.Status, *model.AppError) {
func (a *App) IsUserAway(lastActivityAt int64) bool {
return model.GetMillis()-lastActivityAt >= *a.Config().TeamSettings.UserStatusAwayTimeout*1000
}
func (a *App) SetCustomStatus(userID string, cs *model.CustomStatus) *model.AppError {
user, err := a.GetUser(userID)
if err != nil {
return err
}
user.SetCustomStatus(cs)
_, updateErr := a.UpdateUser(user, true)
if updateErr != nil {
return err
}
if err := a.addRecentCustomStatus(userID, cs); err != nil {
a.Log().Error("Can't add recent custom status for", mlog.String("userID", userID), mlog.Err(err))
}
return nil
}
func (a *App) RemoveCustomStatus(userID string) *model.AppError {
user, err := a.GetUser(userID)
if err != nil {
return err
}
user.ClearCustomStatus()
_, updateErr := a.UpdateUser(user, true)
if updateErr != nil {
return err
}
return nil
}
func (a *App) addRecentCustomStatus(userID string, status *model.CustomStatus) *model.AppError {
var newRCS *model.RecentCustomStatuses
pref, err := a.GetPreferenceByCategoryAndNameForUser(userID, model.PREFERENCE_CATEGORY_CUSTOM_STATUS, model.PREFERENCE_NAME_RECENT_CUSTOM_STATUSES)
if err != nil || pref.Value == "" {
newRCS = &model.RecentCustomStatuses{*status}
} else {
existingRCS := model.RecentCustomStatusesFromJson(strings.NewReader(pref.Value))
newRCS = existingRCS.Add(status)
}
pref = &model.Preference{
UserId: userID,
Category: model.PREFERENCE_CATEGORY_CUSTOM_STATUS,
Name: model.PREFERENCE_NAME_RECENT_CUSTOM_STATUSES,
Value: newRCS.ToJson(),
}
if err := a.UpdatePreferences(userID, model.Preferences{*pref}); err != nil {
return err
}
return nil
}
func (a *App) RemoveRecentCustomStatus(userID string, status *model.CustomStatus) *model.AppError {
pref, err := a.GetPreferenceByCategoryAndNameForUser(userID, model.PREFERENCE_CATEGORY_CUSTOM_STATUS, model.PREFERENCE_NAME_RECENT_CUSTOM_STATUSES)
if err != nil {
return err
}
if pref.Value == "" {
return model.NewAppError("RemoveRecentCustomStatus", "api.custom_status.recent_custom_statuses.delete.app_error", nil, "", http.StatusBadRequest)
}
existingRCS := model.RecentCustomStatusesFromJson(strings.NewReader(pref.Value))
if !existingRCS.Contains(status) {
return model.NewAppError("RemoveRecentCustomStatus", "api.custom_status.recent_custom_statuses.delete.app_error", nil, "", http.StatusBadRequest)
}
newRCS := existingRCS.Remove(status)
pref.Value = newRCS.ToJson()
if err := a.UpdatePreferences(userID, model.Preferences{*pref}); err != nil {
return err
}
return nil
}