Fix inconsistencies in variable names for struct methods (#13561)

Этот коммит содержится в:
Jesús Espino
2020-01-07 10:47:03 +01:00
коммит произвёл GitHub
родитель d8ac09b302
Коммит 092e53ace2
22 изменённых файлов: 391 добавлений и 391 удалений

Просмотреть файл

@@ -738,31 +738,31 @@ func (n *PostNotification) GetSenderName(userNameFormat string, overridesAllowed
}
// checkForMention checks if there is a mention to a specific user or to the keywords here / channel / all
func (e *ExplicitMentions) checkForMention(word string, keywords map[string][]string) bool {
func (m *ExplicitMentions) checkForMention(word string, keywords map[string][]string) bool {
var mentionType MentionType
switch strings.ToLower(word) {
case "@here":
e.HereMentioned = true
m.HereMentioned = true
mentionType = ChannelMention
case "@channel":
e.ChannelMentioned = true
m.ChannelMentioned = true
mentionType = ChannelMention
case "@all":
e.AllMentioned = true
m.AllMentioned = true
mentionType = ChannelMention
default:
mentionType = KeywordMention
}
if ids, match := keywords[strings.ToLower(word)]; match {
e.addMentions(ids, mentionType)
m.addMentions(ids, mentionType)
return true
}
// Case-sensitive check for first name
if ids, match := keywords[word]; match {
e.addMentions(ids, mentionType)
m.addMentions(ids, mentionType)
return true
}
@@ -791,7 +791,7 @@ func isKeywordMultibyte(keywords map[string][]string, word string) ([]string, bo
}
// Processes text to filter mentioned users and other potential mentions
func (e *ExplicitMentions) processText(text string, keywords map[string][]string) {
func (m *ExplicitMentions) processText(text string, keywords map[string][]string) {
systemMentions := map[string]bool{"@here": true, "@channel": true, "@all": true}
for _, word := range strings.FieldsFunc(text, func(c rune) bool {
@@ -805,7 +805,7 @@ func (e *ExplicitMentions) processText(text string, keywords map[string][]string
word = strings.TrimLeft(word, ":.-_")
if e.checkForMention(word, keywords) {
if m.checkForMention(word, keywords) {
continue
}
@@ -814,7 +814,7 @@ func (e *ExplicitMentions) processText(text string, keywords map[string][]string
for len(wordWithoutSuffix) > 0 && strings.LastIndexAny(wordWithoutSuffix, ".-:_") == (len(wordWithoutSuffix)-1) {
wordWithoutSuffix = wordWithoutSuffix[0 : len(wordWithoutSuffix)-1]
if e.checkForMention(wordWithoutSuffix, keywords) {
if m.checkForMention(wordWithoutSuffix, keywords) {
foundWithoutSuffix = true
break
}
@@ -825,7 +825,7 @@ func (e *ExplicitMentions) processText(text string, keywords map[string][]string
}
if _, ok := systemMentions[word]; !ok && strings.HasPrefix(word, "@") {
e.OtherPotentialMentions = append(e.OtherPotentialMentions, word[1:])
m.OtherPotentialMentions = append(m.OtherPotentialMentions, word[1:])
} else if strings.ContainsAny(word, ".-:") {
// This word contains a character that may be the end of a sentence, so split further
splitWords := strings.FieldsFunc(word, func(c rune) bool {
@@ -833,17 +833,17 @@ func (e *ExplicitMentions) processText(text string, keywords map[string][]string
})
for _, splitWord := range splitWords {
if e.checkForMention(splitWord, keywords) {
if m.checkForMention(splitWord, keywords) {
continue
}
if _, ok := systemMentions[splitWord]; !ok && strings.HasPrefix(splitWord, "@") {
e.OtherPotentialMentions = append(e.OtherPotentialMentions, splitWord[1:])
m.OtherPotentialMentions = append(m.OtherPotentialMentions, splitWord[1:])
}
}
}
if ids, match := isKeywordMultibyte(keywords, word); match {
e.addMentions(ids, KeywordMention)
m.addMentions(ids, KeywordMention)
}
}
}

Просмотреть файл

@@ -24,17 +24,17 @@ func (a *App) ProcessSlackText(text string) string {
// can be found in the text attribute, or in the pretext, text, title and value
// attributes of the attachment structure. The Slack attachment structure is
// documented here: https://api.slack.com/docs/attachments
func (app *App) ProcessSlackAttachments(a []*model.SlackAttachment) []*model.SlackAttachment {
var nonNilAttachments = model.StringifySlackFieldValue(a)
for _, attachment := range a {
attachment.Pretext = app.ProcessSlackText(attachment.Pretext)
attachment.Text = app.ProcessSlackText(attachment.Text)
attachment.Title = app.ProcessSlackText(attachment.Title)
func (a *App) ProcessSlackAttachments(attachments []*model.SlackAttachment) []*model.SlackAttachment {
var nonNilAttachments = model.StringifySlackFieldValue(attachments)
for _, attachment := range attachments {
attachment.Pretext = a.ProcessSlackText(attachment.Pretext)
attachment.Text = a.ProcessSlackText(attachment.Text)
attachment.Title = a.ProcessSlackText(attachment.Title)
for _, field := range attachment.Fields {
if field.Value != nil {
// Ensure the value is set to a string if it is set
field.Value = app.ProcessSlackText(fmt.Sprintf("%v", field.Value))
field.Value = a.ProcessSlackText(fmt.Sprintf("%v", field.Value))
}
}
}

Просмотреть файл

@@ -80,60 +80,60 @@ func (wc *WebConn) Close() {
<-wc.pumpFinished
}
func (c *WebConn) GetSessionExpiresAt() int64 {
return atomic.LoadInt64(&c.sessionExpiresAt)
func (wc *WebConn) GetSessionExpiresAt() int64 {
return atomic.LoadInt64(&wc.sessionExpiresAt)
}
func (c *WebConn) SetSessionExpiresAt(v int64) {
atomic.StoreInt64(&c.sessionExpiresAt, v)
func (wc *WebConn) SetSessionExpiresAt(v int64) {
atomic.StoreInt64(&wc.sessionExpiresAt, v)
}
func (c *WebConn) GetSessionToken() string {
return c.sessionToken.Load().(string)
func (wc *WebConn) GetSessionToken() string {
return wc.sessionToken.Load().(string)
}
func (c *WebConn) SetSessionToken(v string) {
c.sessionToken.Store(v)
func (wc *WebConn) SetSessionToken(v string) {
wc.sessionToken.Store(v)
}
func (c *WebConn) GetSession() *model.Session {
return c.session.Load().(*model.Session)
func (wc *WebConn) GetSession() *model.Session {
return wc.session.Load().(*model.Session)
}
func (c *WebConn) SetSession(v *model.Session) {
func (wc *WebConn) SetSession(v *model.Session) {
if v != nil {
v = v.DeepCopy()
}
c.session.Store(v)
wc.session.Store(v)
}
func (c *WebConn) Pump() {
func (wc *WebConn) Pump() {
ch := make(chan struct{})
go func() {
c.writePump()
wc.writePump()
close(ch)
}()
c.readPump()
c.closeOnce.Do(func() {
close(c.endWritePump)
wc.readPump()
wc.closeOnce.Do(func() {
close(wc.endWritePump)
})
<-ch
c.App.HubUnregister(c)
close(c.pumpFinished)
wc.App.HubUnregister(wc)
close(wc.pumpFinished)
}
func (c *WebConn) readPump() {
func (wc *WebConn) readPump() {
defer func() {
c.WebSocket.Close()
wc.WebSocket.Close()
}()
c.WebSocket.SetReadLimit(model.SOCKET_MAX_MESSAGE_SIZE_KB)
c.WebSocket.SetReadDeadline(time.Now().Add(PONG_WAIT))
c.WebSocket.SetPongHandler(func(string) error {
c.WebSocket.SetReadDeadline(time.Now().Add(PONG_WAIT))
if c.IsAuthenticated() {
c.App.Srv.Go(func() {
c.App.SetStatusAwayIfNeeded(c.UserId, false)
wc.WebSocket.SetReadLimit(model.SOCKET_MAX_MESSAGE_SIZE_KB)
wc.WebSocket.SetReadDeadline(time.Now().Add(PONG_WAIT))
wc.WebSocket.SetPongHandler(func(string) error {
wc.WebSocket.SetReadDeadline(time.Now().Add(PONG_WAIT))
if wc.IsAuthenticated() {
wc.App.Srv.Go(func() {
wc.App.SetStatusAwayIfNeeded(wc.UserId, false)
})
}
return nil
@@ -141,49 +141,49 @@ func (c *WebConn) readPump() {
for {
var req model.WebSocketRequest
if err := c.WebSocket.ReadJSON(&req); err != nil {
if err := wc.WebSocket.ReadJSON(&req); err != nil {
// browsers will appear as CloseNoStatusReceived
if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseNoStatusReceived) {
mlog.Debug("websocket.read: client side closed socket", mlog.String("user_id", c.UserId))
mlog.Debug("websocket.read: client side closed socket", mlog.String("user_id", wc.UserId))
} else {
mlog.Debug("websocket.read: closing websocket", mlog.String("user_id", c.UserId), mlog.Err(err))
mlog.Debug("websocket.read: closing websocket", mlog.String("user_id", wc.UserId), mlog.Err(err))
}
return
}
c.App.Srv.WebSocketRouter.ServeWebSocket(c, &req)
wc.App.Srv.WebSocketRouter.ServeWebSocket(wc, &req)
}
}
func (c *WebConn) writePump() {
func (wc *WebConn) writePump() {
ticker := time.NewTicker(PING_PERIOD)
authTicker := time.NewTicker(AUTH_TIMEOUT)
defer func() {
ticker.Stop()
authTicker.Stop()
c.WebSocket.Close()
wc.WebSocket.Close()
}()
for {
select {
case msg, ok := <-c.Send:
case msg, ok := <-wc.Send:
if !ok {
c.WebSocket.SetWriteDeadline(time.Now().Add(WRITE_WAIT))
c.WebSocket.WriteMessage(websocket.CloseMessage, []byte{})
wc.WebSocket.SetWriteDeadline(time.Now().Add(WRITE_WAIT))
wc.WebSocket.WriteMessage(websocket.CloseMessage, []byte{})
return
}
evt, evtOk := msg.(*model.WebSocketEvent)
skipSend := false
if len(c.Send) >= SEND_SLOW_WARN {
if len(wc.Send) >= SEND_SLOW_WARN {
// When the pump starts to get slow we'll drop non-critical messages
if msg.EventType() == model.WEBSOCKET_EVENT_TYPING ||
msg.EventType() == model.WEBSOCKET_EVENT_STATUS_CHANGE ||
msg.EventType() == model.WEBSOCKET_EVENT_CHANNEL_VIEWED {
mlog.Info(
"websocket.slow: dropping message",
mlog.String("user_id", c.UserId),
mlog.String("user_id", wc.UserId),
mlog.String("type", msg.EventType()),
mlog.String("channel_id", evt.GetBroadcast().ChannelId),
)
@@ -194,18 +194,18 @@ func (c *WebConn) writePump() {
if !skipSend {
var msgBytes []byte
if evtOk {
cpyEvt := evt.SetSequence(c.Sequence)
cpyEvt := evt.SetSequence(wc.Sequence)
msgBytes = []byte(cpyEvt.ToJson())
c.Sequence++
wc.Sequence++
} else {
msgBytes = []byte(msg.ToJson())
}
if len(c.Send) >= SEND_DEADLOCK_WARN {
if len(wc.Send) >= SEND_DEADLOCK_WARN {
if evtOk {
mlog.Warn(
"websocket.full",
mlog.String("user_id", c.UserId),
mlog.String("user_id", wc.UserId),
mlog.String("type", msg.EventType()),
mlog.String("channel_id", evt.GetBroadcast().ChannelId),
mlog.Int("size", len(msg.ToJson())),
@@ -213,49 +213,49 @@ func (c *WebConn) writePump() {
} else {
mlog.Warn(
"websocket.full",
mlog.String("user_id", c.UserId),
mlog.String("user_id", wc.UserId),
mlog.String("type", msg.EventType()),
mlog.Int("size", len(msg.ToJson())),
)
}
}
c.WebSocket.SetWriteDeadline(time.Now().Add(WRITE_WAIT))
if err := c.WebSocket.WriteMessage(websocket.TextMessage, msgBytes); err != nil {
wc.WebSocket.SetWriteDeadline(time.Now().Add(WRITE_WAIT))
if err := wc.WebSocket.WriteMessage(websocket.TextMessage, msgBytes); err != nil {
// browsers will appear as CloseNoStatusReceived
if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseNoStatusReceived) {
mlog.Debug("websocket.send: client side closed socket", mlog.String("user_id", c.UserId))
mlog.Debug("websocket.send: client side closed socket", mlog.String("user_id", wc.UserId))
} else {
mlog.Debug("websocket.send: closing websocket", mlog.String("user_id", c.UserId), mlog.Err(err))
mlog.Debug("websocket.send: closing websocket", mlog.String("user_id", wc.UserId), mlog.Err(err))
}
return
}
if c.App.Metrics != nil {
c.App.Srv.Go(func() {
c.App.Metrics.IncrementWebSocketBroadcast(msg.EventType())
if wc.App.Metrics != nil {
wc.App.Srv.Go(func() {
wc.App.Metrics.IncrementWebSocketBroadcast(msg.EventType())
})
}
}
case <-ticker.C:
c.WebSocket.SetWriteDeadline(time.Now().Add(WRITE_WAIT))
if err := c.WebSocket.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
wc.WebSocket.SetWriteDeadline(time.Now().Add(WRITE_WAIT))
if err := wc.WebSocket.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
// browsers will appear as CloseNoStatusReceived
if websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseNoStatusReceived) {
mlog.Debug("websocket.ticker: client side closed socket", mlog.String("user_id", c.UserId))
mlog.Debug("websocket.ticker: client side closed socket", mlog.String("user_id", wc.UserId))
} else {
mlog.Debug("websocket.ticker: closing websocket", mlog.String("user_id", c.UserId), mlog.Err(err))
mlog.Debug("websocket.ticker: closing websocket", mlog.String("user_id", wc.UserId), mlog.Err(err))
}
return
}
case <-c.endWritePump:
case <-wc.endWritePump:
return
case <-authTicker.C:
if c.GetSessionToken() == "" {
mlog.Debug("websocket.authTicker: did not authenticate", mlog.Any("ip_address", c.WebSocket.RemoteAddr()))
if wc.GetSessionToken() == "" {
mlog.Debug("websocket.authTicker: did not authenticate", mlog.Any("ip_address", wc.WebSocket.RemoteAddr()))
return
}
authTicker.Stop()
@@ -263,43 +263,43 @@ func (c *WebConn) writePump() {
}
}
func (webCon *WebConn) InvalidateCache() {
webCon.AllChannelMembers = nil
webCon.LastAllChannelMembersTime = 0
webCon.SetSession(nil)
webCon.SetSessionExpiresAt(0)
func (wc *WebConn) InvalidateCache() {
wc.AllChannelMembers = nil
wc.LastAllChannelMembersTime = 0
wc.SetSession(nil)
wc.SetSessionExpiresAt(0)
}
func (webCon *WebConn) IsAuthenticated() bool {
func (wc *WebConn) IsAuthenticated() bool {
// Check the expiry to see if we need to check for a new session
if webCon.GetSessionExpiresAt() < model.GetMillis() {
if webCon.GetSessionToken() == "" {
if wc.GetSessionExpiresAt() < model.GetMillis() {
if wc.GetSessionToken() == "" {
return false
}
session, err := webCon.App.GetSession(webCon.GetSessionToken())
session, err := wc.App.GetSession(wc.GetSessionToken())
if err != nil {
mlog.Error("Invalid session.", mlog.Err(err))
webCon.SetSessionToken("")
webCon.SetSession(nil)
webCon.SetSessionExpiresAt(0)
wc.SetSessionToken("")
wc.SetSession(nil)
wc.SetSessionExpiresAt(0)
return false
}
webCon.SetSession(session)
webCon.SetSessionExpiresAt(session.ExpiresAt)
wc.SetSession(session)
wc.SetSessionExpiresAt(session.ExpiresAt)
}
return true
}
func (webCon *WebConn) SendHello() {
msg := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_HELLO, "", "", webCon.UserId, nil)
msg.Add("server_version", fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, model.BuildNumber, webCon.App.ClientConfigHash(), webCon.App.License() != nil))
webCon.Send <- msg
func (wc *WebConn) SendHello() {
msg := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_HELLO, "", "", wc.UserId, nil)
msg.Add("server_version", fmt.Sprintf("%v.%v.%v.%v", model.CurrentVersion, model.BuildNumber, wc.App.ClientConfigHash(), wc.App.License() != nil))
wc.Send <- msg
}
func (webCon *WebConn) shouldSendEventToGuest(msg *model.WebSocketEvent) bool {
func (wc *WebConn) shouldSendEventToGuest(msg *model.WebSocketEvent) bool {
var userId string
var canSee bool
@@ -312,7 +312,7 @@ func (webCon *WebConn) shouldSendEventToGuest(msg *model.WebSocketEvent) bool {
return true
}
canSee, err := webCon.App.UserCanSeeOtherUser(webCon.UserId, userId)
canSee, err := wc.App.UserCanSeeOtherUser(wc.UserId, userId)
if err != nil {
mlog.Error("webhub.shouldSendEvent.", mlog.Err(err))
return false
@@ -321,9 +321,9 @@ func (webCon *WebConn) shouldSendEventToGuest(msg *model.WebSocketEvent) bool {
return canSee
}
func (webCon *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
func (wc *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
// IMPORTANT: Do not send event if WebConn does not have a session
if !webCon.IsAuthenticated() {
if !wc.IsAuthenticated() {
return false
}
@@ -331,7 +331,7 @@ func (webCon *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
// see sensitive data. Prevents admin clients from receiving events with bad data
var hasReadPrivateDataPermission *bool
if msg.GetBroadcast().ContainsSanitizedData {
hasReadPrivateDataPermission = model.NewBool(webCon.App.RolesGrantPermission(webCon.GetSession().GetUserRoles(), model.PERMISSION_MANAGE_SYSTEM.Id))
hasReadPrivateDataPermission = model.NewBool(wc.App.RolesGrantPermission(wc.GetSession().GetUserRoles(), model.PERMISSION_MANAGE_SYSTEM.Id))
if *hasReadPrivateDataPermission {
return false
@@ -341,7 +341,7 @@ func (webCon *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
// If the event contains sensitive data, only send to users with permission to see it
if msg.GetBroadcast().ContainsSensitiveData {
if hasReadPrivateDataPermission == nil {
hasReadPrivateDataPermission = model.NewBool(webCon.App.RolesGrantPermission(webCon.GetSession().GetUserRoles(), model.PERMISSION_MANAGE_SYSTEM.Id))
hasReadPrivateDataPermission = model.NewBool(wc.App.RolesGrantPermission(wc.GetSession().GetUserRoles(), model.PERMISSION_MANAGE_SYSTEM.Id))
}
if !*hasReadPrivateDataPermission {
@@ -351,34 +351,34 @@ func (webCon *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
// If the event is destined to a specific user
if len(msg.GetBroadcast().UserId) > 0 {
return webCon.UserId == msg.GetBroadcast().UserId
return wc.UserId == msg.GetBroadcast().UserId
}
// if the user is omitted don't send the message
if len(msg.GetBroadcast().OmitUsers) > 0 {
if _, ok := msg.GetBroadcast().OmitUsers[webCon.UserId]; ok {
if _, ok := msg.GetBroadcast().OmitUsers[wc.UserId]; ok {
return false
}
}
// Only report events to users who are in the channel for the event
if len(msg.GetBroadcast().ChannelId) > 0 {
if model.GetMillis()-webCon.LastAllChannelMembersTime > WEBCONN_MEMBER_CACHE_TIME {
webCon.AllChannelMembers = nil
webCon.LastAllChannelMembersTime = 0
if model.GetMillis()-wc.LastAllChannelMembersTime > WEBCONN_MEMBER_CACHE_TIME {
wc.AllChannelMembers = nil
wc.LastAllChannelMembersTime = 0
}
if webCon.AllChannelMembers == nil {
result, err := webCon.App.Srv.Store.Channel().GetAllChannelMembersForUser(webCon.UserId, true, false)
if wc.AllChannelMembers == nil {
result, err := wc.App.Srv.Store.Channel().GetAllChannelMembersForUser(wc.UserId, true, false)
if err != nil {
mlog.Error("webhub.shouldSendEvent.", mlog.Err(err))
return false
}
webCon.AllChannelMembers = result
webCon.LastAllChannelMembersTime = model.GetMillis()
wc.AllChannelMembers = result
wc.LastAllChannelMembersTime = model.GetMillis()
}
if _, ok := webCon.AllChannelMembers[msg.GetBroadcast().ChannelId]; ok {
if _, ok := wc.AllChannelMembers[msg.GetBroadcast().ChannelId]; ok {
return true
}
return false
@@ -386,26 +386,26 @@ func (webCon *WebConn) ShouldSendEvent(msg *model.WebSocketEvent) bool {
// Only report events to users who are in the team for the event
if len(msg.GetBroadcast().TeamId) > 0 {
return webCon.IsMemberOfTeam(msg.GetBroadcast().TeamId)
return wc.IsMemberOfTeam(msg.GetBroadcast().TeamId)
}
if webCon.GetSession().Props[model.SESSION_PROP_IS_GUEST] == "true" {
return webCon.shouldSendEventToGuest(msg)
if wc.GetSession().Props[model.SESSION_PROP_IS_GUEST] == "true" {
return wc.shouldSendEventToGuest(msg)
}
return true
}
func (webCon *WebConn) IsMemberOfTeam(teamId string) bool {
currentSession := webCon.GetSession()
func (wc *WebConn) IsMemberOfTeam(teamId string) bool {
currentSession := wc.GetSession()
if currentSession == nil || len(currentSession.Token) == 0 {
session, err := webCon.App.GetSession(webCon.GetSessionToken())
session, err := wc.App.GetSession(wc.GetSessionToken())
if err != nil {
mlog.Error("Invalid session.", mlog.Err(err))
return false
}
webCon.SetSession(session)
wc.SetSession(session)
currentSession = session
}