MM-31062: Rewrite empty string checks to be more idiomatic (#16587)
https://mattermost.atlassian.net/browse/MM-31062 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
1a131b54af
Коммит
6487d0ca91
@@ -629,7 +629,7 @@ func (a *App) CreateChannelScheme(channel *model.Channel) (*model.Scheme, *model
|
||||
|
||||
// DeleteChannelScheme deletes a channels scheme and sets its SchemeId to nil.
|
||||
func (a *App) DeleteChannelScheme(channel *model.Channel) (*model.Channel, *model.AppError) {
|
||||
if channel.SchemeId != nil && len(*channel.SchemeId) != 0 {
|
||||
if channel.SchemeId != nil && *channel.SchemeId != "" {
|
||||
if _, err := a.DeleteScheme(*channel.SchemeId); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -784,7 +784,7 @@ func (a *App) GetSchemeRolesForChannel(channelId string) (guestRoleName, userRol
|
||||
return
|
||||
}
|
||||
|
||||
if channel.SchemeId != nil && len(*channel.SchemeId) != 0 {
|
||||
if channel.SchemeId != nil && *channel.SchemeId != "" {
|
||||
var scheme *model.Scheme
|
||||
scheme, err = a.GetScheme(*channel.SchemeId)
|
||||
if err != nil {
|
||||
@@ -808,7 +808,7 @@ func (a *App) GetTeamSchemeChannelRoles(teamId string) (guestRoleName, userRoleN
|
||||
return
|
||||
}
|
||||
|
||||
if team.SchemeId != nil && len(*team.SchemeId) != 0 {
|
||||
if team.SchemeId != nil && *team.SchemeId != "" {
|
||||
var scheme *model.Scheme
|
||||
scheme, err = a.GetScheme(*team.SchemeId)
|
||||
if err != nil {
|
||||
|
||||
@@ -520,7 +520,7 @@ func (a *App) DoCommandRequest(cmd *model.Command, p url.Values) (*model.Command
|
||||
|
||||
func (a *App) HandleCommandResponse(command *model.Command, args *model.CommandArgs, response *model.CommandResponse, builtIn bool) (*model.CommandResponse, *model.AppError) {
|
||||
trigger := ""
|
||||
if len(args.Command) != 0 {
|
||||
if args.Command != "" {
|
||||
parts := strings.Split(args.Command, " ")
|
||||
trigger = parts[0][1:]
|
||||
trigger = strings.ToLower(trigger)
|
||||
@@ -561,7 +561,7 @@ func (a *App) HandleCommandResponsePost(command *model.Command, args *model.Comm
|
||||
post.Type = response.Type
|
||||
post.SetProps(response.Props)
|
||||
|
||||
if len(response.ChannelId) != 0 {
|
||||
if response.ChannelId != "" {
|
||||
_, err := a.GetChannelMember(response.ChannelId, args.UserId)
|
||||
if err != nil {
|
||||
err = model.NewAppError("HandleCommandResponsePost", "api.command.command_post.forbidden.app_error", nil, err.Error(), http.StatusForbidden)
|
||||
@@ -573,20 +573,20 @@ func (a *App) HandleCommandResponsePost(command *model.Command, args *model.Comm
|
||||
isBotPost := !builtIn
|
||||
|
||||
if *a.Config().ServiceSettings.EnablePostUsernameOverride {
|
||||
if len(command.Username) != 0 {
|
||||
if command.Username != "" {
|
||||
post.AddProp("override_username", command.Username)
|
||||
isBotPost = true
|
||||
} else if len(response.Username) != 0 {
|
||||
} else if response.Username != "" {
|
||||
post.AddProp("override_username", response.Username)
|
||||
isBotPost = true
|
||||
}
|
||||
}
|
||||
|
||||
if *a.Config().ServiceSettings.EnablePostIconOverride {
|
||||
if len(command.IconURL) != 0 {
|
||||
if command.IconURL != "" {
|
||||
post.AddProp("override_icon_url", command.IconURL)
|
||||
isBotPost = true
|
||||
} else if len(response.IconURL) != 0 {
|
||||
} else if response.IconURL != "" {
|
||||
post.AddProp("override_icon_url", response.IconURL)
|
||||
isBotPost = true
|
||||
} else {
|
||||
|
||||
@@ -122,7 +122,7 @@ func (a *App) GetUserForLogin(id, loginId string) (*model.User, *model.AppError)
|
||||
enableEmail := *a.Config().EmailSettings.EnableSignInWithEmail
|
||||
|
||||
// If we are given a userID then fail if we can't find a user with that ID
|
||||
if len(id) != 0 {
|
||||
if id != "" {
|
||||
user, err := a.GetUser(id)
|
||||
if err != nil {
|
||||
if err.Id != MISSING_ACCOUNT_ERROR {
|
||||
|
||||
@@ -780,10 +780,10 @@ func getMentionsEnabledFields(post *model.Post) model.StringArray {
|
||||
ret = append(ret, post.Message)
|
||||
for _, attachment := range post.Attachments() {
|
||||
|
||||
if len(attachment.Pretext) != 0 {
|
||||
if attachment.Pretext != "" {
|
||||
ret = append(ret, attachment.Pretext)
|
||||
}
|
||||
if len(attachment.Text) != 0 {
|
||||
if attachment.Text != "" {
|
||||
ret = append(ret, attachment.Text)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ func (a *App) generateHyperlinkForChannels(postMessage, teamName, teamURL string
|
||||
}
|
||||
|
||||
func (s *Server) GetMessageForNotification(post *model.Post, translateFunc i18n.TranslateFunc) string {
|
||||
if len(strings.TrimSpace(post.Message)) != 0 || len(post.FileIds) == 0 {
|
||||
if strings.TrimSpace(post.Message) != "" || len(post.FileIds) == 0 {
|
||||
return post.Message
|
||||
}
|
||||
|
||||
|
||||
@@ -415,11 +415,11 @@ func (a *App) newSessionUpdateToken(appName string, accessData *model.AccessData
|
||||
func (a *App) GetOAuthLoginEndpoint(w http.ResponseWriter, r *http.Request, service, teamId, action, redirectTo, loginHint string, isMobile bool) (string, *model.AppError) {
|
||||
stateProps := map[string]string{}
|
||||
stateProps["action"] = action
|
||||
if len(teamId) != 0 {
|
||||
if teamId != "" {
|
||||
stateProps["team_id"] = teamId
|
||||
}
|
||||
|
||||
if len(redirectTo) != 0 {
|
||||
if redirectTo != "" {
|
||||
stateProps["redirect_to"] = redirectTo
|
||||
}
|
||||
|
||||
@@ -436,7 +436,7 @@ func (a *App) GetOAuthLoginEndpoint(w http.ResponseWriter, r *http.Request, serv
|
||||
func (a *App) GetOAuthSignupEndpoint(w http.ResponseWriter, r *http.Request, service, teamId string) (string, *model.AppError) {
|
||||
stateProps := map[string]string{}
|
||||
stateProps["action"] = model.OAUTH_ACTION_SIGNUP
|
||||
if len(teamId) != 0 {
|
||||
if teamId != "" {
|
||||
stateProps["team_id"] = teamId
|
||||
}
|
||||
|
||||
|
||||
@@ -342,7 +342,7 @@ func (a *App) GetSchemeRolesForTeam(teamId string) (string, string, string, *mod
|
||||
return "", "", "", err
|
||||
}
|
||||
|
||||
if team.SchemeId != nil && len(*team.SchemeId) != 0 {
|
||||
if team.SchemeId != nil && *team.SchemeId != "" {
|
||||
scheme, err := a.GetScheme(*team.SchemeId)
|
||||
if err != nil {
|
||||
return "", "", "", err
|
||||
|
||||
@@ -1497,7 +1497,7 @@ func (a *App) SendPasswordReset(email string, siteURL string) (bool, *model.AppE
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if user.AuthData != nil && len(*user.AuthData) != 0 {
|
||||
if user.AuthData != nil && *user.AuthData != "" {
|
||||
return false, model.NewAppError("SendPasswordReset", "api.user.send_password_reset.sso.app_error", nil, "userId="+user.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
|
||||
@@ -264,7 +264,7 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
|
||||
}
|
||||
|
||||
if *a.Config().ServiceSettings.EnablePostUsernameOverride {
|
||||
if len(overrideUsername) != 0 {
|
||||
if overrideUsername != "" {
|
||||
post.AddProp("override_username", overrideUsername)
|
||||
} else {
|
||||
post.AddProp("override_username", model.DEFAULT_WEBHOOK_USERNAME)
|
||||
@@ -272,10 +272,10 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
|
||||
}
|
||||
|
||||
if *a.Config().ServiceSettings.EnablePostIconOverride {
|
||||
if len(overrideIconUrl) != 0 {
|
||||
if overrideIconUrl != "" {
|
||||
post.AddProp("override_icon_url", overrideIconUrl)
|
||||
}
|
||||
if len(overrideIconEmoji) != 0 {
|
||||
if overrideIconEmoji != "" {
|
||||
post.AddProp("override_icon_emoji", overrideIconEmoji)
|
||||
}
|
||||
}
|
||||
@@ -445,7 +445,7 @@ func (a *App) CreateOutgoingWebhook(hook *model.OutgoingWebhook) (*model.Outgoin
|
||||
return nil, model.NewAppError("CreateOutgoingWebhook", "api.outgoing_webhook.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if len(hook.ChannelId) != 0 {
|
||||
if hook.ChannelId != "" {
|
||||
channel, errCh := a.Srv().Store.Channel().Get(hook.ChannelId, true)
|
||||
if errCh != nil {
|
||||
var nfErr *store.ErrNotFound
|
||||
@@ -696,7 +696,7 @@ func (a *App) HandleIncomingWebhook(hookId string, req *model.IncomingWebhookReq
|
||||
var channel *model.Channel
|
||||
var cchan chan store.StoreResult
|
||||
|
||||
if len(channelName) != 0 {
|
||||
if channelName != "" {
|
||||
if channelName[0] == '@' {
|
||||
result, nErr := a.Srv().Store.User().GetByUsername(channelName[1:])
|
||||
if nErr != nil {
|
||||
|
||||
Ссылка в новой задаче
Block a user