[MM-16751] golint model (#17896)
Этот коммит содержится в:
коммит произвёл
Claudio Costa
родитель
953eebdef4
Коммит
97ccf0bdf6
@@ -85,7 +85,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
allActivityPushUserIds := []string{}
|
||||
var allowChannelMentions bool
|
||||
var keywords map[string][]string
|
||||
if channel.Type == model.CHANNEL_DIRECT {
|
||||
if channel.Type == model.ChannelTypeDirect {
|
||||
otherUserId := channel.GetOtherUserIdForDM(post.UserId)
|
||||
|
||||
_, ok := profileMap[otherUserId]
|
||||
@@ -103,8 +103,8 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
mentions = getExplicitMentions(post, keywords, groups)
|
||||
// Add an implicit mention when a user is added to a channel
|
||||
// even if the user has set 'username mentions' to false in account settings.
|
||||
if post.Type == model.POST_ADD_TO_CHANNEL {
|
||||
addedUserId, ok := post.GetProp(model.POST_PROPS_ADDED_USER_ID).(string)
|
||||
if post.Type == model.PostTypeAddToChannel {
|
||||
addedUserId, ok := post.GetProp(model.PostPropsAddedUserId).(string)
|
||||
if ok {
|
||||
mentions.addMention(addedUserId, KeywordMention)
|
||||
}
|
||||
@@ -133,7 +133,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
if threadPost.Id == parentPostList.Order[0] && threadPost.IsFromOAuthBot() {
|
||||
continue
|
||||
}
|
||||
if profile.NotifyProps[model.COMMENTS_NOTIFY_PROP] == model.COMMENTS_NOTIFY_ANY || (profile.NotifyProps[model.COMMENTS_NOTIFY_PROP] == model.COMMENTS_NOTIFY_ROOT && threadPost.Id == parentPostList.Order[0]) {
|
||||
if profile.NotifyProps[model.CommentsNotifyProp] == model.CommentsNotifyAny || (profile.NotifyProps[model.CommentsNotifyProp] == model.CommentsNotifyRoot && threadPost.Id == parentPostList.Order[0]) {
|
||||
mentionType := ThreadMention
|
||||
if threadPost.Id == parentPostList.Order[0] {
|
||||
mentionType = CommentMention
|
||||
@@ -158,8 +158,8 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
|
||||
// find which users in the channel are set up to always receive mobile notifications
|
||||
for _, profile := range profileMap {
|
||||
if (profile.NotifyProps[model.PUSH_NOTIFY_PROP] == model.USER_NOTIFY_ALL ||
|
||||
channelMemberNotifyPropsMap[profile.Id][model.PUSH_NOTIFY_PROP] == model.CHANNEL_NOTIFY_ALL) &&
|
||||
if (profile.NotifyProps[model.PushNotifyProp] == model.UserNotifyAll ||
|
||||
channelMemberNotifyPropsMap[profile.Id][model.PushNotifyProp] == model.ChannelNotifyAll) &&
|
||||
(post.UserId != profile.Id || post.GetProp("from_webhook") == "true") &&
|
||||
!post.IsSystemMessage() {
|
||||
allActivityPushUserIds = append(allActivityPushUserIds, profile.Id)
|
||||
@@ -175,7 +175,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
var rootMentions *ExplicitMentions
|
||||
if parentPostList != nil {
|
||||
threadParticipants[parentPostList.Posts[parentPostList.Order[0]].UserId] = true
|
||||
if channel.Type != model.CHANNEL_DIRECT {
|
||||
if channel.Type != model.ChannelTypeDirect {
|
||||
rootPost := parentPostList.Posts[parentPostList.Order[0]]
|
||||
rootMentions = getExplicitMentions(rootPost, keywords, groups)
|
||||
for id := range rootMentions.Mentions {
|
||||
@@ -358,7 +358,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
var status *model.Status
|
||||
var err *model.AppError
|
||||
if status, err = a.GetStatus(id); err != nil {
|
||||
status = &model.Status{UserId: id, Status: model.STATUS_OFFLINE, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
|
||||
status = &model.Status{UserId: id, Status: model.StatusOffline, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
|
||||
}
|
||||
|
||||
if ShouldSendPushNotification(profileMap[id], channelMemberNotifyPropsMap[id], true, status, post) {
|
||||
@@ -366,9 +366,9 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
|
||||
replyToThreadType := ""
|
||||
if mentionType == ThreadMention {
|
||||
replyToThreadType = model.COMMENTS_NOTIFY_ANY
|
||||
replyToThreadType = model.CommentsNotifyAny
|
||||
} else if mentionType == CommentMention {
|
||||
replyToThreadType = model.COMMENTS_NOTIFY_ROOT
|
||||
replyToThreadType = model.CommentsNotifyRoot
|
||||
}
|
||||
|
||||
a.sendPushNotification(
|
||||
@@ -382,10 +382,10 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
// register that a notification was not sent
|
||||
a.NotificationsLog().Debug("Notification not sent",
|
||||
mlog.String("ackId", ""),
|
||||
mlog.String("type", model.PUSH_TYPE_MESSAGE),
|
||||
mlog.String("type", model.PushTypeMessage),
|
||||
mlog.String("userId", id),
|
||||
mlog.String("postId", post.Id),
|
||||
mlog.String("status", model.PUSH_NOT_SENT),
|
||||
mlog.String("status", model.PushNotSent),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -399,7 +399,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
var status *model.Status
|
||||
var err *model.AppError
|
||||
if status, err = a.GetStatus(id); err != nil {
|
||||
status = &model.Status{UserId: id, Status: model.STATUS_OFFLINE, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
|
||||
status = &model.Status{UserId: id, Status: model.StatusOffline, Manual: false, LastActivityAt: 0, ActiveChannel: ""}
|
||||
}
|
||||
|
||||
if ShouldSendPushNotification(profileMap[id], channelMemberNotifyPropsMap[id], false, status, post) {
|
||||
@@ -414,25 +414,25 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
// register that a notification was not sent
|
||||
a.NotificationsLog().Debug("Notification not sent",
|
||||
mlog.String("ackId", ""),
|
||||
mlog.String("type", model.PUSH_TYPE_MESSAGE),
|
||||
mlog.String("type", model.PushTypeMessage),
|
||||
mlog.String("userId", id),
|
||||
mlog.String("postId", post.Id),
|
||||
mlog.String("status", model.PUSH_NOT_SENT),
|
||||
mlog.String("status", model.PushNotSent),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_POSTED, "", post.ChannelId, "", nil)
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventPosted, "", post.ChannelId, "", nil)
|
||||
|
||||
// Note that PreparePostForClient should've already been called by this point
|
||||
message.Add("post", post.ToJson())
|
||||
|
||||
message.Add("channel_type", channel.Type)
|
||||
message.Add("channel_display_name", notification.GetChannelName(model.SHOW_USERNAME, ""))
|
||||
message.Add("channel_display_name", notification.GetChannelName(model.ShowUsername, ""))
|
||||
message.Add("channel_name", channel.Name)
|
||||
message.Add("sender_name", notification.GetSenderName(model.SHOW_USERNAME, *a.Config().ServiceSettings.EnablePostUsernameOverride))
|
||||
message.Add("sender_name", notification.GetSenderName(model.ShowUsername, *a.Config().ServiceSettings.EnablePostUsernameOverride))
|
||||
message.Add("team_id", team.Id)
|
||||
message.Add("set_online", setOnline)
|
||||
|
||||
@@ -461,19 +461,19 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
a.Publish(message)
|
||||
|
||||
// If this is a reply in a thread, notify participants
|
||||
if a.Config().FeatureFlags.CollapsedThreads && *a.Config().ServiceSettings.CollapsedThreads != model.COLLAPSED_THREADS_DISABLED && post.RootId != "" {
|
||||
if a.Config().FeatureFlags.CollapsedThreads && *a.Config().ServiceSettings.CollapsedThreads != model.CollapsedThreadsDisabled && post.RootId != "" {
|
||||
followers, err := a.Srv().Store.Thread().GetThreadFollowers(post.RootId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "cannot get thread %q followers", post.RootId)
|
||||
}
|
||||
for _, uid := range followers {
|
||||
sendEvent := *a.Config().ServiceSettings.CollapsedThreads == model.COLLAPSED_THREADS_DEFAULT_ON
|
||||
sendEvent := *a.Config().ServiceSettings.CollapsedThreads == model.CollapsedThreadsDefaultOn
|
||||
// check if a participant has overridden collapsed threads settings
|
||||
if preference, err := a.Srv().Store.Preference().Get(uid, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_COLLAPSED_THREADS_ENABLED); err == nil {
|
||||
if preference, err := a.Srv().Store.Preference().Get(uid, model.PreferenceCategoryDisplaySettings, model.PreferenceNameCollapsedThreadsEnabled); err == nil {
|
||||
sendEvent = preference.Value == "on"
|
||||
}
|
||||
if sendEvent {
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_THREAD_UPDATED, team.Id, "", uid, nil)
|
||||
message := model.NewWebSocketEvent(model.WebsocketEventThreadUpdated, team.Id, "", uid, nil)
|
||||
threadMembership, err := a.Srv().Store.Thread().GetMembershipForUser(uid, post.RootId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "cannot get thread membership %q for user %q", post.RootId, uid)
|
||||
@@ -496,16 +496,16 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
|
||||
}
|
||||
|
||||
func (a *App) userAllowsEmail(user *model.User, channelMemberNotificationProps model.StringMap, post *model.Post) bool {
|
||||
userAllowsEmails := user.NotifyProps[model.EMAIL_NOTIFY_PROP] != "false"
|
||||
if channelEmail, ok := channelMemberNotificationProps[model.EMAIL_NOTIFY_PROP]; ok {
|
||||
if channelEmail != model.CHANNEL_NOTIFY_DEFAULT {
|
||||
userAllowsEmails := user.NotifyProps[model.EmailNotifyProp] != "false"
|
||||
if channelEmail, ok := channelMemberNotificationProps[model.EmailNotifyProp]; ok {
|
||||
if channelEmail != model.ChannelNotifyDefault {
|
||||
userAllowsEmails = channelEmail != "false"
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the user as recipient when the user has muted the channel.
|
||||
if channelMuted, ok := channelMemberNotificationProps[model.MARK_UNREAD_NOTIFY_PROP]; ok {
|
||||
if channelMuted == model.CHANNEL_MARK_UNREAD_MENTION {
|
||||
if channelMuted, ok := channelMemberNotificationProps[model.MarkUnreadNotifyProp]; ok {
|
||||
if channelMuted == model.ChannelMarkUnreadMention {
|
||||
mlog.Debug("Channel muted for user", mlog.String("user_id", user.Id), mlog.String("channel_mute", channelMuted))
|
||||
userAllowsEmails = false
|
||||
}
|
||||
@@ -516,15 +516,15 @@ func (a *App) userAllowsEmail(user *model.User, channelMemberNotificationProps m
|
||||
if status, err = a.GetStatus(user.Id); err != nil {
|
||||
status = &model.Status{
|
||||
UserId: user.Id,
|
||||
Status: model.STATUS_OFFLINE,
|
||||
Status: model.StatusOffline,
|
||||
Manual: false,
|
||||
LastActivityAt: 0,
|
||||
ActiveChannel: "",
|
||||
}
|
||||
}
|
||||
|
||||
autoResponderRelated := status.Status == model.STATUS_OUT_OF_OFFICE || post.Type == model.POST_AUTO_RESPONDER
|
||||
emailNotificationsAllowedForStatus := status.Status != model.STATUS_ONLINE && status.Status != model.STATUS_DND
|
||||
autoResponderRelated := status.Status == model.StatusOutOfOffice || post.Type == model.PostTypeAutoResponder
|
||||
emailNotificationsAllowedForStatus := status.Status != model.StatusOnline && status.Status != model.StatusDnd
|
||||
|
||||
return userAllowsEmails && emailNotificationsAllowedForStatus && user.DeleteAt == 0 && !autoResponderRelated
|
||||
}
|
||||
@@ -577,7 +577,7 @@ func (a *App) filterOutOfChannelMentions(sender *model.User, post *model.Post, c
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
if channel.TeamId == "" || channel.Type == model.CHANNEL_DIRECT || channel.Type == model.CHANNEL_GROUP {
|
||||
if channel.TeamId == "" || channel.Type == model.ChannelTypeDirect || channel.Type == model.ChannelTypeGroup {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
@@ -669,7 +669,7 @@ func makeOutOfChannelMentionPost(sender *model.User, post *model.Post, outOfChan
|
||||
}
|
||||
|
||||
props := model.StringInterface{
|
||||
model.PROPS_ADD_CHANNEL_MEMBER: model.StringInterface{
|
||||
model.PropsAddChannelMember: model.StringInterface{
|
||||
"post_id": ephemeralPostId,
|
||||
|
||||
"usernames": allUsers.Usernames(), // Kept for backwards compatibility of mobile app.
|
||||
@@ -844,11 +844,11 @@ func getMentionsEnabledFields(post *model.Post) model.StringArray {
|
||||
|
||||
// allowChannelMentions returns whether or not the channel mentions are allowed for the given post.
|
||||
func (a *App) allowChannelMentions(post *model.Post, numProfiles int) bool {
|
||||
if !a.HasPermissionToChannel(post.UserId, post.ChannelId, model.PERMISSION_USE_CHANNEL_MENTIONS) {
|
||||
if !a.HasPermissionToChannel(post.UserId, post.ChannelId, model.PermissionUseChannelMentions) {
|
||||
return false
|
||||
}
|
||||
|
||||
if post.Type == model.POST_HEADER_CHANGE || post.Type == model.POST_PURPOSE_CHANGE {
|
||||
if post.Type == model.PostTypeHeaderChange || post.Type == model.PostTypePurposeChange {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -865,11 +865,11 @@ func (a *App) allowGroupMentions(post *model.Post) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if !a.HasPermissionToChannel(post.UserId, post.ChannelId, model.PERMISSION_USE_GROUP_MENTIONS) {
|
||||
if !a.HasPermissionToChannel(post.UserId, post.ChannelId, model.PermissionUseGroupMentions) {
|
||||
return false
|
||||
}
|
||||
|
||||
if post.Type == model.POST_HEADER_CHANGE || post.Type == model.POST_PURPOSE_CHANGE {
|
||||
if post.Type == model.PostTypeHeaderChange || post.Type == model.PostTypePurposeChange {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -990,20 +990,20 @@ func addMentionKeywordsForUser(keywords map[string][]string, profile *model.User
|
||||
}
|
||||
|
||||
// If turned on, add the user's case sensitive first name
|
||||
if profile.NotifyProps[model.FIRST_NAME_NOTIFY_PROP] == "true" && profile.FirstName != "" {
|
||||
if profile.NotifyProps[model.FirstNameNotifyProp] == "true" && profile.FirstName != "" {
|
||||
keywords[profile.FirstName] = append(keywords[profile.FirstName], profile.Id)
|
||||
}
|
||||
|
||||
// Add @channel and @all to keywords if user has them turned on and the server allows them
|
||||
if allowChannelMentions {
|
||||
// Ignore channel mentions if channel is muted and channel mention setting is default
|
||||
ignoreChannelMentions := channelNotifyProps[model.IGNORE_CHANNEL_MENTIONS_NOTIFY_PROP] == model.IGNORE_CHANNEL_MENTIONS_ON || (channelNotifyProps[model.MARK_UNREAD_NOTIFY_PROP] == model.USER_NOTIFY_MENTION && channelNotifyProps[model.IGNORE_CHANNEL_MENTIONS_NOTIFY_PROP] == model.IGNORE_CHANNEL_MENTIONS_DEFAULT)
|
||||
ignoreChannelMentions := channelNotifyProps[model.IgnoreChannelMentionsNotifyProp] == model.IgnoreChannelMentionsOn || (channelNotifyProps[model.MarkUnreadNotifyProp] == model.UserNotifyMention && channelNotifyProps[model.IgnoreChannelMentionsNotifyProp] == model.IgnoreChannelMentionsDefault)
|
||||
|
||||
if profile.NotifyProps[model.CHANNEL_MENTIONS_NOTIFY_PROP] == "true" && !ignoreChannelMentions {
|
||||
if profile.NotifyProps[model.ChannelMentionsNotifyProp] == "true" && !ignoreChannelMentions {
|
||||
keywords["@channel"] = append(keywords["@channel"], profile.Id)
|
||||
keywords["@all"] = append(keywords["@all"], profile.Id)
|
||||
|
||||
if status != nil && status.Status == model.STATUS_ONLINE {
|
||||
if status != nil && status.Status == model.StatusOnline {
|
||||
keywords["@here"] = append(keywords["@here"], profile.Id)
|
||||
}
|
||||
}
|
||||
@@ -1025,9 +1025,9 @@ type PostNotification struct {
|
||||
// channel, with an option to exclude the recipient of the message from that list.
|
||||
func (n *PostNotification) GetChannelName(userNameFormat, excludeId string) string {
|
||||
switch n.Channel.Type {
|
||||
case model.CHANNEL_DIRECT:
|
||||
case model.ChannelTypeDirect:
|
||||
return n.Sender.GetDisplayNameWithPrefix(userNameFormat, "@")
|
||||
case model.CHANNEL_GROUP:
|
||||
case model.ChannelTypeGroup:
|
||||
names := []string{}
|
||||
for _, user := range n.ProfileMap {
|
||||
if user.Id != excludeId {
|
||||
@@ -1050,7 +1050,7 @@ func (n *PostNotification) GetSenderName(userNameFormat string, overridesAllowed
|
||||
return i18n.T("system.message.name")
|
||||
}
|
||||
|
||||
if overridesAllowed && n.Channel.Type != model.CHANNEL_DIRECT {
|
||||
if overridesAllowed && n.Channel.Type != model.ChannelTypeDirect {
|
||||
if value, ok := n.Post.GetProps()["override_username"]; ok && n.Post.GetProp("from_webhook") == "true" {
|
||||
return value.(string)
|
||||
}
|
||||
@@ -1182,10 +1182,10 @@ func (m *ExplicitMentions) processText(text string, keywords map[string][]string
|
||||
|
||||
func (a *App) GetNotificationNameFormat(user *model.User) string {
|
||||
if !*a.Config().PrivacySettings.ShowFullName {
|
||||
return model.SHOW_USERNAME
|
||||
return model.ShowUsername
|
||||
}
|
||||
|
||||
data, err := a.Srv().Store.Preference().Get(user.Id, model.PREFERENCE_CATEGORY_DISPLAY_SETTINGS, model.PREFERENCE_NAME_NAME_FORMAT)
|
||||
data, err := a.Srv().Store.Preference().Get(user.Id, model.PreferenceCategoryDisplaySettings, model.PreferenceNameNameFormat)
|
||||
if err != nil {
|
||||
return *a.Config().TeamSettings.TeammateNameDisplay
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user