[MM-16751] golint model (#17896)
Этот коммит содержится в:
коммит произвёл
Claudio Costa
родитель
953eebdef4
Коммит
97ccf0bdf6
186
model/post.go
186
model/post.go
@@ -18,56 +18,58 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
POST_SYSTEM_MESSAGE_PREFIX = "system_"
|
||||
POST_DEFAULT = ""
|
||||
POST_SLACK_ATTACHMENT = "slack_attachment"
|
||||
POST_SYSTEM_GENERIC = "system_generic"
|
||||
POST_JOIN_LEAVE = "system_join_leave" // Deprecated, use POST_JOIN_CHANNEL or POST_LEAVE_CHANNEL instead
|
||||
POST_JOIN_CHANNEL = "system_join_channel"
|
||||
POST_GUEST_JOIN_CHANNEL = "system_guest_join_channel"
|
||||
POST_LEAVE_CHANNEL = "system_leave_channel"
|
||||
POST_JOIN_TEAM = "system_join_team"
|
||||
POST_LEAVE_TEAM = "system_leave_team"
|
||||
POST_AUTO_RESPONDER = "system_auto_responder"
|
||||
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_GUEST_TO_CHANNEL = "system_add_guest_to_chan"
|
||||
POST_REMOVE_FROM_CHANNEL = "system_remove_from_channel"
|
||||
POST_MOVE_CHANNEL = "system_move_channel"
|
||||
POST_ADD_TO_TEAM = "system_add_to_team"
|
||||
POST_REMOVE_FROM_TEAM = "system_remove_from_team"
|
||||
POST_HEADER_CHANGE = "system_header_change"
|
||||
POST_DISPLAYNAME_CHANGE = "system_displayname_change"
|
||||
POST_CONVERT_CHANNEL = "system_convert_channel"
|
||||
POST_PURPOSE_CHANGE = "system_purpose_change"
|
||||
POST_CHANNEL_DELETED = "system_channel_deleted"
|
||||
POST_CHANNEL_RESTORED = "system_channel_restored"
|
||||
POST_EPHEMERAL = "system_ephemeral"
|
||||
POST_CHANGE_CHANNEL_PRIVACY = "system_change_chan_privacy"
|
||||
POST_ADD_BOT_TEAMS_CHANNELS = "add_bot_teams_channels"
|
||||
POST_FILEIDS_MAX_RUNES = 300
|
||||
POST_FILENAMES_MAX_RUNES = 4000
|
||||
POST_HASHTAGS_MAX_RUNES = 1000
|
||||
POST_MESSAGE_MAX_RUNES_V1 = 4000
|
||||
POST_MESSAGE_MAX_BYTES_V2 = 65535 // Maximum size of a TEXT column in MySQL
|
||||
POST_MESSAGE_MAX_RUNES_V2 = POST_MESSAGE_MAX_BYTES_V2 / 4 // Assume a worst-case representation
|
||||
POST_PROPS_MAX_RUNES = 8000
|
||||
POST_PROPS_MAX_USER_RUNES = POST_PROPS_MAX_RUNES - 400 // Leave some room for system / pre-save modifications
|
||||
POST_CUSTOM_TYPE_PREFIX = "custom_"
|
||||
POST_ME = "me"
|
||||
PROPS_ADD_CHANNEL_MEMBER = "add_channel_member"
|
||||
PostSystemMessagePrefix = "system_"
|
||||
PostTypeDefault = ""
|
||||
PostTypeSlackAttachment = "slack_attachment"
|
||||
PostTypeSystemGeneric = "system_generic"
|
||||
PostTypeJoinLeave = "system_join_leave" // Deprecated, use PostJoinChannel or PostLeaveChannel instead
|
||||
PostTypeJoinChannel = "system_join_channel"
|
||||
PostTypeGuestJoinChannel = "system_guest_join_channel"
|
||||
PostTypeLeaveChannel = "system_leave_channel"
|
||||
PostTypeJoinTeam = "system_join_team"
|
||||
PostTypeLeaveTeam = "system_leave_team"
|
||||
PostTypeAutoResponder = "system_auto_responder"
|
||||
PostTypeAddRemove = "system_add_remove" // Deprecated, use PostAddToChannel or PostRemoveFromChannel instead
|
||||
PostTypeAddToChannel = "system_add_to_channel"
|
||||
PostTypeAddGuestToChannel = "system_add_guest_to_chan"
|
||||
PostTypeRemoveFromChannel = "system_remove_from_channel"
|
||||
PostTypeMoveChannel = "system_move_channel"
|
||||
PostTypeAddToTeam = "system_add_to_team"
|
||||
PostTypeRemoveFromTeam = "system_remove_from_team"
|
||||
PostTypeHeaderChange = "system_header_change"
|
||||
PostTypeDisplaynameChange = "system_displayname_change"
|
||||
PostTypeConvertChannel = "system_convert_channel"
|
||||
PostTypePurposeChange = "system_purpose_change"
|
||||
PostTypeChannelDeleted = "system_channel_deleted"
|
||||
PostTypeChannelRestored = "system_channel_restored"
|
||||
PostTypeEphemeral = "system_ephemeral"
|
||||
PostTypeChangeChannelPrivacy = "system_change_chan_privacy"
|
||||
PostTypeAddBotTeamsChannels = "add_bot_teams_channels"
|
||||
PostTypeSystemWarnMetricStatus = "warn_metric_status"
|
||||
PostTypeMe = "me"
|
||||
PostCustomTypePrefix = "custom_"
|
||||
|
||||
POST_PROPS_ADDED_USER_ID = "addedUserId"
|
||||
POST_PROPS_DELETE_BY = "deleteBy"
|
||||
POST_PROPS_OVERRIDE_ICON_URL = "override_icon_url"
|
||||
POST_PROPS_OVERRIDE_ICON_EMOJI = "override_icon_emoji"
|
||||
PostFileidsMaxRunes = 300
|
||||
PostFilenamesMaxRunes = 4000
|
||||
PostHashtagsMaxRunes = 1000
|
||||
PostMessageMaxRunesV1 = 4000
|
||||
PostMessageMaxBytesV2 = 65535 // Maximum size of a TEXT column in MySQL
|
||||
PostMessageMaxRunesV2 = PostMessageMaxBytesV2 / 4 // Assume a worst-case representation
|
||||
PostPropsMaxRunes = 8000
|
||||
PostPropsMaxUserRunes = PostPropsMaxRunes - 400 // Leave some room for system / pre-save modifications
|
||||
|
||||
POST_PROPS_MENTION_HIGHLIGHT_DISABLED = "mentionHighlightDisabled"
|
||||
POST_PROPS_GROUP_HIGHLIGHT_DISABLED = "disable_group_highlight"
|
||||
POST_SYSTEM_WARN_METRIC_STATUS = "warn_metric_status"
|
||||
PropsAddChannelMember = "add_channel_member"
|
||||
|
||||
PostPropsAddedUserId = "addedUserId"
|
||||
PostPropsDeleteBy = "deleteBy"
|
||||
PostPropsOverrideIconUrl = "override_icon_url"
|
||||
PostPropsOverrideIconEmoji = "override_icon_emoji"
|
||||
|
||||
PostPropsMentionHighlightDisabled = "mentionHighlightDisabled"
|
||||
PostPropsGroupHighlightDisabled = "disable_group_highlight"
|
||||
)
|
||||
|
||||
var AT_MENTION_PATTEN = regexp.MustCompile(`\B@`)
|
||||
var AtMentionPattern = regexp.MustCompile(`\B@`)
|
||||
|
||||
type Post struct {
|
||||
Id string `json:"id"`
|
||||
@@ -316,54 +318,54 @@ func (o *Post) IsValid(maxPostSize int) *AppError {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.msg.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(o.Hashtags) > POST_HASHTAGS_MAX_RUNES {
|
||||
if utf8.RuneCountInString(o.Hashtags) > PostHashtagsMaxRunes {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.hashtags.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
switch o.Type {
|
||||
case
|
||||
POST_DEFAULT,
|
||||
POST_SYSTEM_GENERIC,
|
||||
POST_JOIN_LEAVE,
|
||||
POST_AUTO_RESPONDER,
|
||||
POST_ADD_REMOVE,
|
||||
POST_JOIN_CHANNEL,
|
||||
POST_GUEST_JOIN_CHANNEL,
|
||||
POST_LEAVE_CHANNEL,
|
||||
POST_JOIN_TEAM,
|
||||
POST_LEAVE_TEAM,
|
||||
POST_ADD_TO_CHANNEL,
|
||||
POST_ADD_GUEST_TO_CHANNEL,
|
||||
POST_REMOVE_FROM_CHANNEL,
|
||||
POST_MOVE_CHANNEL,
|
||||
POST_ADD_TO_TEAM,
|
||||
POST_REMOVE_FROM_TEAM,
|
||||
POST_SLACK_ATTACHMENT,
|
||||
POST_HEADER_CHANGE,
|
||||
POST_PURPOSE_CHANGE,
|
||||
POST_DISPLAYNAME_CHANGE,
|
||||
POST_CONVERT_CHANNEL,
|
||||
POST_CHANNEL_DELETED,
|
||||
POST_CHANNEL_RESTORED,
|
||||
POST_CHANGE_CHANNEL_PRIVACY,
|
||||
POST_ME,
|
||||
POST_ADD_BOT_TEAMS_CHANNELS,
|
||||
POST_SYSTEM_WARN_METRIC_STATUS:
|
||||
PostTypeDefault,
|
||||
PostTypeSystemGeneric,
|
||||
PostTypeJoinLeave,
|
||||
PostTypeAutoResponder,
|
||||
PostTypeAddRemove,
|
||||
PostTypeJoinChannel,
|
||||
PostTypeGuestJoinChannel,
|
||||
PostTypeLeaveChannel,
|
||||
PostTypeJoinTeam,
|
||||
PostTypeLeaveTeam,
|
||||
PostTypeAddToChannel,
|
||||
PostTypeAddGuestToChannel,
|
||||
PostTypeRemoveFromChannel,
|
||||
PostTypeMoveChannel,
|
||||
PostTypeAddToTeam,
|
||||
PostTypeRemoveFromTeam,
|
||||
PostTypeSlackAttachment,
|
||||
PostTypeHeaderChange,
|
||||
PostTypePurposeChange,
|
||||
PostTypeDisplaynameChange,
|
||||
PostTypeConvertChannel,
|
||||
PostTypeChannelDeleted,
|
||||
PostTypeChannelRestored,
|
||||
PostTypeChangeChannelPrivacy,
|
||||
PostTypeAddBotTeamsChannels,
|
||||
PostTypeSystemWarnMetricStatus,
|
||||
PostTypeMe:
|
||||
default:
|
||||
if !strings.HasPrefix(o.Type, POST_CUSTOM_TYPE_PREFIX) {
|
||||
if !strings.HasPrefix(o.Type, PostCustomTypePrefix) {
|
||||
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)) > PostFilenamesMaxRunes {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.filenames.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(ArrayToJson(o.FileIds)) > POST_FILEIDS_MAX_RUNES {
|
||||
if utf8.RuneCountInString(ArrayToJson(o.FileIds)) > PostFileidsMaxRunes {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.file_ids.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(StringInterfaceToJson(o.GetProps())) > POST_PROPS_MAX_RUNES {
|
||||
if utf8.RuneCountInString(StringInterfaceToJson(o.GetProps())) > PostPropsMaxRunes {
|
||||
return NewAppError("Post.IsValid", "model.post.is_valid.props.app_error", nil, "id="+o.Id, http.StatusBadRequest)
|
||||
}
|
||||
|
||||
@@ -375,7 +377,7 @@ func (o *Post) SanitizeProps() {
|
||||
return
|
||||
}
|
||||
membersToSanitize := []string{
|
||||
PROPS_ADD_CHANNEL_MEMBER,
|
||||
PropsAddChannelMember,
|
||||
}
|
||||
|
||||
for _, member := range membersToSanitize {
|
||||
@@ -469,7 +471,7 @@ func (o *Post) GetProp(key string) interface{} {
|
||||
}
|
||||
|
||||
func (o *Post) IsSystemMessage() bool {
|
||||
return len(o.Type) >= len(POST_SYSTEM_MESSAGE_PREFIX) && o.Type[:len(POST_SYSTEM_MESSAGE_PREFIX)] == POST_SYSTEM_MESSAGE_PREFIX
|
||||
return len(o.Type) >= len(PostSystemMessagePrefix) && o.Type[:len(PostSystemMessagePrefix)] == PostSystemMessagePrefix
|
||||
}
|
||||
|
||||
// IsRemote returns true if the post originated on a remote cluster.
|
||||
@@ -486,16 +488,16 @@ func (o *Post) GetRemoteID() string {
|
||||
}
|
||||
|
||||
func (o *Post) IsJoinLeaveMessage() bool {
|
||||
return o.Type == POST_JOIN_LEAVE ||
|
||||
o.Type == POST_ADD_REMOVE ||
|
||||
o.Type == POST_JOIN_CHANNEL ||
|
||||
o.Type == POST_LEAVE_CHANNEL ||
|
||||
o.Type == POST_JOIN_TEAM ||
|
||||
o.Type == POST_LEAVE_TEAM ||
|
||||
o.Type == POST_ADD_TO_CHANNEL ||
|
||||
o.Type == POST_REMOVE_FROM_CHANNEL ||
|
||||
o.Type == POST_ADD_TO_TEAM ||
|
||||
o.Type == POST_REMOVE_FROM_TEAM
|
||||
return o.Type == PostTypeJoinLeave ||
|
||||
o.Type == PostTypeAddRemove ||
|
||||
o.Type == PostTypeJoinChannel ||
|
||||
o.Type == PostTypeLeaveChannel ||
|
||||
o.Type == PostTypeJoinTeam ||
|
||||
o.Type == PostTypeLeaveTeam ||
|
||||
o.Type == PostTypeAddToChannel ||
|
||||
o.Type == PostTypeRemoveFromChannel ||
|
||||
o.Type == PostTypeAddToTeam ||
|
||||
o.Type == PostTypeRemoveFromTeam
|
||||
}
|
||||
|
||||
func (o *Post) Patch(patch *PostPatch) {
|
||||
@@ -568,7 +570,7 @@ func (o *Post) ChannelMentions() []string {
|
||||
func (o *Post) DisableMentionHighlights() string {
|
||||
mention, hasMentions := findAtChannelMention(o.Message)
|
||||
if hasMentions {
|
||||
o.AddProp(POST_PROPS_MENTION_HIGHLIGHT_DISABLED, true)
|
||||
o.AddProp(PostPropsMentionHighlightDisabled, true)
|
||||
}
|
||||
return mention
|
||||
}
|
||||
@@ -582,7 +584,7 @@ func (o *PostPatch) DisableMentionHighlights() {
|
||||
if o.Props == nil {
|
||||
o.Props = &StringInterface{}
|
||||
}
|
||||
(*o.Props)[POST_PROPS_MENTION_HIGHLIGHT_DISABLED] = true
|
||||
(*o.Props)[PostPropsMentionHighlightDisabled] = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user