Custom status feature (#16835)
* 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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
22308ea21c
Коммит
7585e16d84
85
app/slashcommands/command_custom_status.go
Обычный файл
85
app/slashcommands/command_custom_status.go
Обычный файл
@@ -0,0 +1,85 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package slashcommands
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
goi18n "github.com/mattermost/go-i18n/i18n"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
type CustomStatusProvider struct {
|
||||
}
|
||||
|
||||
const (
|
||||
CmdCustomStatus = app.CmdCustomStatusTrigger
|
||||
CmdCustomStatusClear = "clear"
|
||||
|
||||
DefaultCustomStatusEmoji = "speech_balloon"
|
||||
)
|
||||
|
||||
func init() {
|
||||
app.RegisterCommandProvider(&CustomStatusProvider{})
|
||||
}
|
||||
|
||||
func (*CustomStatusProvider) GetTrigger() string {
|
||||
return CmdCustomStatus
|
||||
}
|
||||
|
||||
func (*CustomStatusProvider) GetCommand(a *app.App, T goi18n.TranslateFunc) *model.Command {
|
||||
return &model.Command{
|
||||
Trigger: CmdCustomStatus,
|
||||
AutoComplete: true,
|
||||
AutoCompleteDesc: T("api.command_custom_status.desc"),
|
||||
AutoCompleteHint: T("api.command_custom_status.hint"),
|
||||
DisplayName: T("api.command_custom_status.name"),
|
||||
}
|
||||
}
|
||||
|
||||
func (*CustomStatusProvider) DoCommand(a *app.App, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
if !a.Config().FeatureFlags.CustomUserStatuses || !*a.Config().TeamSettings.EnableCustomUserStatuses {
|
||||
return nil
|
||||
}
|
||||
|
||||
if message == CmdCustomStatusClear {
|
||||
if err := a.RemoveCustomStatus(args.UserId); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
return &model.CommandResponse{Text: args.T("api.command_custom_status.clear.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
return &model.CommandResponse{
|
||||
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
|
||||
Text: args.T("api.command_custom_status.clear.success"),
|
||||
}
|
||||
}
|
||||
|
||||
customStatus := &model.CustomStatus{
|
||||
Emoji: DefaultCustomStatusEmoji,
|
||||
Text: message,
|
||||
}
|
||||
firstEmojiLocations := model.ALL_EMOJI_PATTERN.FindIndex([]byte(message))
|
||||
if len(firstEmojiLocations) > 0 && firstEmojiLocations[0] == 0 {
|
||||
// emoji found at starting index
|
||||
customStatus.Emoji = message[firstEmojiLocations[0]+1 : firstEmojiLocations[1]-1]
|
||||
customStatus.Text = strings.TrimSpace(message[firstEmojiLocations[1]:])
|
||||
}
|
||||
|
||||
customStatus.TrimMessage()
|
||||
if err := a.SetCustomStatus(args.UserId, customStatus); err != nil {
|
||||
mlog.Error(err.Error())
|
||||
return &model.CommandResponse{Text: args.T("api.command_custom_status.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||
}
|
||||
|
||||
return &model.CommandResponse{
|
||||
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL,
|
||||
Text: args.T("api.command_custom_status.success", map[string]interface{}{
|
||||
"EmojiName": ":" + customStatus.Emoji + ":",
|
||||
"StatusMessage": customStatus.Text,
|
||||
}),
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user