* Adds new string post message when a user has joined a team (#6483) * Simplifies long if statement in post.go (#6483)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
617a98d6d8
Коммит
0cdf969ac7
@@ -64,7 +64,7 @@ func (a *App) JoinDefaultChannels(teamId string, user *model.User, channelRole s
|
|||||||
}
|
}
|
||||||
|
|
||||||
if requestor == nil {
|
if requestor == nil {
|
||||||
if err := a.postJoinChannelMessage(user, townSquare); err != nil {
|
if err := a.postJoinTeamMessage(user, townSquare); err != nil {
|
||||||
l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
|
l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -965,6 +965,24 @@ func (a *App) postJoinChannelMessage(user *model.User, channel *model.Channel) *
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) postJoinTeamMessage(user *model.User, channel *model.Channel) *model.AppError {
|
||||||
|
post := &model.Post{
|
||||||
|
ChannelId: channel.Id,
|
||||||
|
Message: fmt.Sprintf(utils.T("api.team.join_team.post_and_forget"), user.Username),
|
||||||
|
Type: model.POST_JOIN_TEAM,
|
||||||
|
UserId: user.Id,
|
||||||
|
Props: model.StringInterface{
|
||||||
|
"username": user.Username,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := a.CreatePost(post, channel, false); err != nil {
|
||||||
|
return model.NewAppError("postJoinTeamMessage", "api.channel.post_user_add_remove_message_and_forget.error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
|
func (a *App) LeaveChannel(channelId string, userId string) *model.AppError {
|
||||||
sc := a.Srv.Store.Channel().Get(channelId, true)
|
sc := a.Srv.Store.Channel().Get(channelId, true)
|
||||||
uc := a.Srv.Store.User().Get(userId)
|
uc := a.Srv.Store.User().Get(userId)
|
||||||
|
|||||||
@@ -2286,6 +2286,10 @@
|
|||||||
"id": "api.team.is_team_creation_allowed.domain.app_error",
|
"id": "api.team.is_team_creation_allowed.domain.app_error",
|
||||||
"translation": "Email must be from a specific domain (e.g. @example.com). Please ask your systems administrator for details."
|
"translation": "Email must be from a specific domain (e.g. @example.com). Please ask your systems administrator for details."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.team.join_team.post_and_forget",
|
||||||
|
"translation": "%v joined the team."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.team.leave.left",
|
"id": "api.team.leave.left",
|
||||||
"translation": "%v left the team."
|
"translation": "%v left the team."
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ const (
|
|||||||
POST_JOIN_LEAVE = "system_join_leave" // Deprecated, use POST_JOIN_CHANNEL or POST_LEAVE_CHANNEL instead
|
POST_JOIN_LEAVE = "system_join_leave" // Deprecated, use POST_JOIN_CHANNEL or POST_LEAVE_CHANNEL instead
|
||||||
POST_JOIN_CHANNEL = "system_join_channel"
|
POST_JOIN_CHANNEL = "system_join_channel"
|
||||||
POST_LEAVE_CHANNEL = "system_leave_channel"
|
POST_LEAVE_CHANNEL = "system_leave_channel"
|
||||||
|
POST_JOIN_TEAM = "system_join_team"
|
||||||
POST_LEAVE_TEAM = "system_leave_team"
|
POST_LEAVE_TEAM = "system_leave_team"
|
||||||
POST_ADD_REMOVE = "system_add_remove" // Deprecated, use POST_ADD_TO_CHANNEL or POST_REMOVE_FROM_CHANNEL instead
|
POST_ADD_REMOVE = "system_add_remove" // Deprecated, use POST_ADD_TO_CHANNEL or POST_REMOVE_FROM_CHANNEL instead
|
||||||
POST_ADD_TO_CHANNEL = "system_add_to_channel"
|
POST_ADD_TO_CHANNEL = "system_add_to_channel"
|
||||||
@@ -169,13 +170,27 @@ func (o *Post) IsValid() *AppError {
|
|||||||
return NewAppError("Post.IsValid", "model.post.is_valid.hashtags.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
return NewAppError("Post.IsValid", "model.post.is_valid.hashtags.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(o.Type == POST_DEFAULT || o.Type == POST_JOIN_LEAVE || o.Type == POST_ADD_REMOVE ||
|
switch o.Type {
|
||||||
o.Type == POST_JOIN_CHANNEL || o.Type == POST_LEAVE_CHANNEL || o.Type == POST_LEAVE_TEAM ||
|
case
|
||||||
o.Type == POST_REMOVE_FROM_CHANNEL || o.Type == POST_ADD_TO_CHANNEL || o.Type == POST_ADD_TO_TEAM ||
|
POST_DEFAULT,
|
||||||
o.Type == POST_SLACK_ATTACHMENT || o.Type == POST_HEADER_CHANGE || o.Type == POST_PURPOSE_CHANGE ||
|
POST_JOIN_LEAVE,
|
||||||
o.Type == POST_DISPLAYNAME_CHANGE || o.Type == POST_CHANNEL_DELETED ||
|
POST_ADD_REMOVE,
|
||||||
strings.HasPrefix(o.Type, POST_CUSTOM_TYPE_PREFIX)) {
|
POST_JOIN_CHANNEL,
|
||||||
return NewAppError("Post.IsValid", "model.post.is_valid.type.app_error", nil, "id="+o.Type, http.StatusBadRequest)
|
POST_LEAVE_CHANNEL,
|
||||||
|
POST_LEAVE_TEAM,
|
||||||
|
POST_REMOVE_FROM_CHANNEL,
|
||||||
|
POST_ADD_TO_CHANNEL,
|
||||||
|
POST_ADD_TO_TEAM,
|
||||||
|
POST_JOIN_TEAM,
|
||||||
|
POST_SLACK_ATTACHMENT,
|
||||||
|
POST_HEADER_CHANGE,
|
||||||
|
POST_PURPOSE_CHANGE,
|
||||||
|
POST_DISPLAYNAME_CHANGE,
|
||||||
|
POST_CHANNEL_DELETED:
|
||||||
|
default:
|
||||||
|
if !strings.HasPrefix(o.Type, POST_CUSTOM_TYPE_PREFIX) {
|
||||||
|
return NewAppError("Post.IsValid", "model.post.is_valid.type.app_error", nil, "id="+o.Type, http.StatusBadRequest)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if utf8.RuneCountInString(ArrayToJson(o.Filenames)) > POST_FILENAMES_MAX_RUNES {
|
if utf8.RuneCountInString(ArrayToJson(o.Filenames)) > POST_FILENAMES_MAX_RUNES {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user