MM-23395: Add websockets support for update group (#14202)
* MM-23395: add websockets support for update group
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
94dbb09906
Коммит
6dc8eccc13
@@ -322,7 +322,6 @@ func patchChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if c.Err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
patch := model.ChannelPatchFromJson(r.Body)
|
||||
if patch == nil {
|
||||
c.SetInvalidParam("channel")
|
||||
|
||||
39
app/group.go
39
app/group.go
@@ -32,11 +32,27 @@ func (a *App) CreateGroup(group *model.Group) (*model.Group, *model.AppError) {
|
||||
}
|
||||
|
||||
func (a *App) UpdateGroup(group *model.Group) (*model.Group, *model.AppError) {
|
||||
return a.Srv().Store.Group().Update(group)
|
||||
updatedGroup, err := a.Srv().Store.Group().Update(group)
|
||||
|
||||
if err == nil {
|
||||
messageWs := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_RECEIVED_GROUP, "", "", "", nil)
|
||||
messageWs.Add("group", updatedGroup.ToJson())
|
||||
a.Publish(messageWs)
|
||||
}
|
||||
|
||||
return updatedGroup, err
|
||||
}
|
||||
|
||||
func (a *App) DeleteGroup(groupID string) (*model.Group, *model.AppError) {
|
||||
return a.Srv().Store.Group().Delete(groupID)
|
||||
deletedGroup, err := a.Srv().Store.Group().Delete(groupID)
|
||||
|
||||
if err == nil {
|
||||
messageWs := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_RECEIVED_GROUP, "", "", "", nil)
|
||||
messageWs.Add("group", deletedGroup.ToJson())
|
||||
a.Publish(messageWs)
|
||||
}
|
||||
|
||||
return deletedGroup, err
|
||||
}
|
||||
|
||||
func (a *App) GetGroupMemberUsers(groupID string) ([]*model.User, *model.AppError) {
|
||||
@@ -99,6 +115,15 @@ func (a *App) UpsertGroupSyncable(groupSyncable *model.GroupSyncable) (*model.Gr
|
||||
}
|
||||
}
|
||||
|
||||
var messageWs *model.WebSocketEvent
|
||||
if gs.Type == model.GroupSyncableTypeTeam {
|
||||
messageWs = model.NewWebSocketEvent(model.WEBSOCKET_EVENT_RECEIVED_GROUP_ASSOCIATED_TO_TEAM, gs.SyncableId, "", "", nil)
|
||||
} else {
|
||||
messageWs = model.NewWebSocketEvent(model.WEBSOCKET_EVENT_RECEIVED_GROUP_ASSOCIATED_TO_CHANNEL, "", gs.SyncableId, "", nil)
|
||||
}
|
||||
messageWs.Add("group_id", gs.GroupId)
|
||||
a.Publish(messageWs)
|
||||
|
||||
return gs, nil
|
||||
}
|
||||
|
||||
@@ -149,6 +174,16 @@ func (a *App) DeleteGroupSyncable(groupID string, syncableID string, syncableTyp
|
||||
}
|
||||
}
|
||||
|
||||
var messageWs *model.WebSocketEvent
|
||||
if gs.Type == model.GroupSyncableTypeTeam {
|
||||
messageWs = model.NewWebSocketEvent(model.WEBSOCKET_EVENT_RECEIVED_GROUP_NOT_ASSOCIATED_TO_TEAM, gs.SyncableId, "", "", nil)
|
||||
} else {
|
||||
messageWs = model.NewWebSocketEvent(model.WEBSOCKET_EVENT_RECEIVED_GROUP_NOT_ASSOCIATED_TO_CHANNEL, "", gs.SyncableId, "", nil)
|
||||
}
|
||||
|
||||
messageWs.Add("group_id", gs.GroupId)
|
||||
a.Publish(messageWs)
|
||||
|
||||
return gs, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -160,6 +160,11 @@ func (group *Group) IsValidForUpdate() *AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (group *Group) ToJson() string {
|
||||
b, _ := json.Marshal(group)
|
||||
return string(b)
|
||||
}
|
||||
|
||||
var validGroupnameChars = regexp.MustCompile(`^[a-z0-9\.\-_]+$`)
|
||||
|
||||
func (group *Group) IsValidName() *AppError {
|
||||
|
||||
@@ -57,6 +57,11 @@ const (
|
||||
WEBSOCKET_EVENT_CONFIG_CHANGED = "config_changed"
|
||||
WEBSOCKET_EVENT_OPEN_DIALOG = "open_dialog"
|
||||
WEBSOCKET_EVENT_GUESTS_DEACTIVATED = "guests_deactivated"
|
||||
WEBSOCKET_EVENT_RECEIVED_GROUP = "received_group"
|
||||
WEBSOCKET_EVENT_RECEIVED_GROUP_ASSOCIATED_TO_TEAM = "received_group_associated_to_team"
|
||||
WEBSOCKET_EVENT_RECEIVED_GROUP_NOT_ASSOCIATED_TO_TEAM = "received_group_not_associated_to_team"
|
||||
WEBSOCKET_EVENT_RECEIVED_GROUP_ASSOCIATED_TO_CHANNEL = "received_group_associated_to_channel"
|
||||
WEBSOCKET_EVENT_RECEIVED_GROUP_NOT_ASSOCIATED_TO_CHANNEL = "received_group_not_associated_to_channel"
|
||||
)
|
||||
|
||||
type WebSocketMessage interface {
|
||||
|
||||
Ссылка в новой задаче
Block a user