[PLT-4341] add dnd command (#7694)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
f632232862
Коммит
62b3569025
@@ -84,6 +84,8 @@ func updateUserStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
c.App.SetStatusOffline(c.Params.UserId, true)
|
c.App.SetStatusOffline(c.Params.UserId, true)
|
||||||
case "away":
|
case "away":
|
||||||
c.App.SetStatusAwayIfNeeded(c.Params.UserId, true)
|
c.App.SetStatusAwayIfNeeded(c.Params.UserId, true)
|
||||||
|
case "dnd":
|
||||||
|
c.App.SetStatusDoNotDisturb(c.Params.UserId)
|
||||||
default:
|
default:
|
||||||
c.SetInvalidParam("status")
|
c.SetInvalidParam("status")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -31,6 +31,13 @@ func TestGetUserStatus(t *testing.T) {
|
|||||||
t.Fatal("Should return away status")
|
t.Fatal("Should return away status")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
th.App.SetStatusDoNotDisturb(th.BasicUser.Id)
|
||||||
|
userStatus, resp = Client.GetUserStatus(th.BasicUser.Id, "")
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
if userStatus.Status != "dnd" {
|
||||||
|
t.Fatal("Should return dnd status")
|
||||||
|
}
|
||||||
|
|
||||||
th.App.SetStatusOffline(th.BasicUser.Id, true)
|
th.App.SetStatusOffline(th.BasicUser.Id, true)
|
||||||
userStatus, resp = Client.GetUserStatus(th.BasicUser.Id, "")
|
userStatus, resp = Client.GetUserStatus(th.BasicUser.Id, "")
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
@@ -93,6 +100,16 @@ func TestGetUsersStatusesByIds(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
th.App.SetStatusDoNotDisturb(th.BasicUser.Id)
|
||||||
|
th.App.SetStatusDoNotDisturb(th.BasicUser2.Id)
|
||||||
|
usersStatuses, resp = Client.GetUsersStatusesByIds(usersIds)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
for _, userStatus := range usersStatuses {
|
||||||
|
if userStatus.Status != "dnd" {
|
||||||
|
t.Fatal("Status should be offline")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Client.Logout()
|
Client.Logout()
|
||||||
|
|
||||||
_, resp = Client.GetUsersStatusesByIds(usersIds)
|
_, resp = Client.GetUsersStatusesByIds(usersIds)
|
||||||
@@ -118,6 +135,13 @@ func TestUpdateUserStatus(t *testing.T) {
|
|||||||
t.Fatal("Should return away status")
|
t.Fatal("Should return away status")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toUpdateUserStatus.Status = "dnd"
|
||||||
|
updateUserStatus, resp = Client.UpdateUserStatus(th.BasicUser.Id, toUpdateUserStatus)
|
||||||
|
CheckNoError(t, resp)
|
||||||
|
if updateUserStatus.Status != "dnd" {
|
||||||
|
t.Fatal("Should return dnd status")
|
||||||
|
}
|
||||||
|
|
||||||
toUpdateUserStatus.Status = "offline"
|
toUpdateUserStatus.Status = "offline"
|
||||||
updateUserStatus, resp = Client.UpdateUserStatus(th.BasicUser.Id, toUpdateUserStatus)
|
updateUserStatus, resp = Client.UpdateUserStatus(th.BasicUser.Id, toUpdateUserStatus)
|
||||||
CheckNoError(t, resp)
|
CheckNoError(t, resp)
|
||||||
|
|||||||
49
app/command_dnd.go
Обычный файл
49
app/command_dnd.go
Обычный файл
@@ -0,0 +1,49 @@
|
|||||||
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mattermost/mattermost-server/model"
|
||||||
|
goi18n "github.com/nicksnyder/go-i18n/i18n"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DndProvider struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
CMD_DND = "dnd"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterCommandProvider(&DndProvider{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (me *DndProvider) GetTrigger() string {
|
||||||
|
return CMD_DND
|
||||||
|
}
|
||||||
|
|
||||||
|
func (me *DndProvider) GetCommand(T goi18n.TranslateFunc) *model.Command {
|
||||||
|
return &model.Command{
|
||||||
|
Trigger: CMD_DND,
|
||||||
|
AutoComplete: true,
|
||||||
|
AutoCompleteDesc: T("api.command_dnd.desc"),
|
||||||
|
DisplayName: T("api.command_dnd.name"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (me *DndProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||||
|
status, err := a.GetStatus(args.UserId)
|
||||||
|
if err != nil {
|
||||||
|
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_dnd.error")}
|
||||||
|
} else {
|
||||||
|
if status.Status == "dnd" {
|
||||||
|
a.SetStatusOnline(args.UserId, args.Session.Id, true)
|
||||||
|
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_dnd.disabled")}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
a.SetStatusDoNotDisturb(args.UserId)
|
||||||
|
|
||||||
|
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, Text: args.T("api.command_dnd.success")}
|
||||||
|
}
|
||||||
@@ -993,6 +993,8 @@ func DoesStatusAllowPushNotification(userNotifyProps model.StringMap, status *mo
|
|||||||
return true
|
return true
|
||||||
} else if pushStatus == model.STATUS_OFFLINE && status.Status == model.STATUS_OFFLINE {
|
} else if pushStatus == model.STATUS_OFFLINE && status.Status == model.STATUS_OFFLINE {
|
||||||
return true
|
return true
|
||||||
|
} else if status.Status == model.STATUS_DND {
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -295,6 +295,34 @@ func (a *App) SetStatusAwayIfNeeded(userId string, manual bool) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) SetStatusDoNotDisturb(userId string) {
|
||||||
|
if !*a.Config().ServiceSettings.EnableUserStatuses {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
status, err := a.GetStatus(userId)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
status = &model.Status{UserId: userId, Status: model.STATUS_OFFLINE, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
|
||||||
|
}
|
||||||
|
|
||||||
|
status.Status = model.STATUS_DND
|
||||||
|
status.Manual = true
|
||||||
|
|
||||||
|
a.AddStatusCache(status)
|
||||||
|
|
||||||
|
if result := <-a.Srv.Store.Status().SaveOrUpdate(status); result.Err != nil {
|
||||||
|
l4g.Error(utils.T("api.status.save_status.error"), userId, result.Err)
|
||||||
|
}
|
||||||
|
|
||||||
|
event := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_STATUS_CHANGE, "", "", status.UserId, nil)
|
||||||
|
event.Add("status", model.STATUS_DND)
|
||||||
|
event.Add("user_id", status.UserId)
|
||||||
|
a.Go(func() {
|
||||||
|
a.Publish(event)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func GetStatusFromCache(userId string) *model.Status {
|
func GetStatusFromCache(userId string) *model.Status {
|
||||||
if result, ok := statusCache.Get(userId); ok {
|
if result, ok := statusCache.Get(userId); ok {
|
||||||
status := result.(*model.Status)
|
status := result.(*model.Status)
|
||||||
|
|||||||
20
i18n/en.json
20
i18n/en.json
@@ -499,6 +499,26 @@
|
|||||||
"id": "api.command_away.success",
|
"id": "api.command_away.success",
|
||||||
"translation": "You are now away"
|
"translation": "You are now away"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.command_dnd.error",
|
||||||
|
"translation": "Error to retrieve the user status."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "api.command_dnd.disabled",
|
||||||
|
"translation": "Do Not Disturb is disabled."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "api.command_dnd.success",
|
||||||
|
"translation": "Do Not Disturb is enabled. You will not receive desktop or mobile push notifications until Do Not Disturb is turned off."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "api.command_dnd.desc",
|
||||||
|
"translation": "Do not disturb disables desktop and mobile push notifications."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "api.command_dnd.name",
|
||||||
|
"translation": "dnd"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.command_channel_header.channel.app_error",
|
"id": "api.command_channel_header.channel.app_error",
|
||||||
"translation": "Error to retrieve the current channel."
|
"translation": "Error to retrieve the current channel."
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
STATUS_OFFLINE = "offline"
|
STATUS_OFFLINE = "offline"
|
||||||
STATUS_AWAY = "away"
|
STATUS_AWAY = "away"
|
||||||
|
STATUS_DND = "dnd"
|
||||||
STATUS_ONLINE = "online"
|
STATUS_ONLINE = "online"
|
||||||
STATUS_CACHE_SIZE = SESSION_CACHE_SIZE
|
STATUS_CACHE_SIZE = SESSION_CACHE_SIZE
|
||||||
STATUS_CHANNEL_TIMEOUT = 20000 // 20 seconds
|
STATUS_CHANNEL_TIMEOUT = 20000 // 20 seconds
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user