diff options
author | JoramWilander <jwawilander@gmail.com> | 2017-05-12 08:00:28 -0400 |
---|---|---|
committer | JoramWilander <jwawilander@gmail.com> | 2017-05-12 08:00:28 -0400 |
commit | 9d109b070037951fcd0832b785eba8a3db9a157c (patch) | |
tree | 5d109da2e9e088f16eff0ad1421876a3d3da412e /app | |
parent | b1c39204a63a87d2cbc57f66cf9db50c938b2ee5 (diff) | |
parent | a21a06afd9907e9911dcb166d902cba9f405c7cb (diff) | |
download | chat-9d109b070037951fcd0832b785eba8a3db9a157c.tar.gz chat-9d109b070037951fcd0832b785eba8a3db9a157c.tar.bz2 chat-9d109b070037951fcd0832b785eba8a3db9a157c.zip |
Merge branch 'release-3.9' into merge-3.9
Diffstat (limited to 'app')
-rw-r--r-- | app/channel.go | 14 | ||||
-rw-r--r-- | app/login.go | 2 | ||||
-rw-r--r-- | app/notification.go | 2 | ||||
-rw-r--r-- | app/post_test.go | 44 | ||||
-rw-r--r-- | app/session.go | 14 | ||||
-rw-r--r-- | app/status.go | 17 | ||||
-rw-r--r-- | app/web_conn.go | 5 | ||||
-rw-r--r-- | app/websocket_router.go | 5 |
8 files changed, 89 insertions, 14 deletions
diff --git a/app/channel.go b/app/channel.go index f39a57839..4164b37ce 100644 --- a/app/channel.go +++ b/app/channel.go @@ -218,7 +218,7 @@ func WaitForChannelMembership(channelId string, userId string) { } } -func CreateGroupChannel(userIds []string) (*model.Channel, *model.AppError) { +func CreateGroupChannel(userIds []string, creatorId string) (*model.Channel, *model.AppError) { if len(userIds) > model.CHANNEL_GROUP_MAX_USERS || len(userIds) < model.CHANNEL_GROUP_MIN_USERS { return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_size.app_error", nil, "", http.StatusBadRequest) } @@ -261,6 +261,10 @@ func CreateGroupChannel(userIds []string) (*model.Channel, *model.AppError) { return nil, result.Err } + if user.Id == creatorId { + WaitForChannelMembership(group.Id, creatorId) + } + InvalidateCacheForUser(user.Id) } @@ -1021,9 +1025,13 @@ func GetNumberOfChannelsOnTeam(teamId string) (int, *model.AppError) { func SetActiveChannel(userId string, channelId string) *model.AppError { status, err := GetStatus(userId) + + oldStatus := model.STATUS_OFFLINE + if err != nil { status = &model.Status{UserId: userId, Status: model.STATUS_ONLINE, Manual: false, LastActivityAt: model.GetMillis(), ActiveChannel: channelId} } else { + oldStatus = status.Status status.ActiveChannel = channelId if !status.Manual { status.Status = model.STATUS_ONLINE @@ -1033,6 +1041,10 @@ func SetActiveChannel(userId string, channelId string) *model.AppError { AddStatusCache(status) + if status.Status != oldStatus { + BroadcastStatus(status) + } + return nil } diff --git a/app/login.go b/app/login.go index 4f9284140..2528f9367 100644 --- a/app/login.go +++ b/app/login.go @@ -138,7 +138,7 @@ func DoLogin(w http.ResponseWriter, r *http.Request, user *model.User, deviceId } func GetProtocol(r *http.Request) string { - if r.Header.Get(model.HEADER_FORWARDED_PROTO) == "https" { + if r.Header.Get(model.HEADER_FORWARDED_PROTO) == "https" || r.TLS != nil { return "https" } else { return "http" diff --git a/app/notification.go b/app/notification.go index c48465003..0f59fae21 100644 --- a/app/notification.go +++ b/app/notification.go @@ -83,7 +83,7 @@ func SendNotifications(post *model.Post, team *model.Team, channel *model.Channe for _, threadPost := range list.Posts { profile := profileMap[threadPost.UserId] - if profile.NotifyProps["comments"] == "any" || (profile.NotifyProps["comments"] == "root" && threadPost.Id == list.Order[0]) { + if profile != nil && (profile.NotifyProps["comments"] == "any" || (profile.NotifyProps["comments"] == "root" && threadPost.Id == list.Order[0])) { mentionedUserIds[threadPost.UserId] = true } } diff --git a/app/post_test.go b/app/post_test.go new file mode 100644 index 000000000..9bc5ee742 --- /dev/null +++ b/app/post_test.go @@ -0,0 +1,44 @@ +// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package app + +import ( + "testing" + + "github.com/mattermost/platform/model" + "fmt" +) + +func TestPostReplyToPostWhereRootPosterLeftChannel(t *testing.T) { + // This test ensures that when replying to a root post made by a user who has since left the channel, the reply + // post completes successfully. This is a regression test for PLT-6523. + th := Setup().InitBasic() + + channel := th.BasicChannel + userInChannel := th.BasicUser2 + userNotInChannel := th.BasicUser + rootPost := th.BasicPost + + if _, err := AddUserToChannel(userInChannel, channel); err != nil { + t.Fatal(err) + } + + if err := RemoveUserFromChannel(userNotInChannel.Id, "", channel); err != nil { + t.Fatal(err) + } + + replyPost := model.Post{ + Message: "asd", + ChannelId: channel.Id, + RootId: rootPost.Id, + ParentId: rootPost.Id, + PendingPostId: model.NewId() + ":" + fmt.Sprint(model.GetMillis()), + UserId: userInChannel.Id, + CreateAt: 0, + } + + if _, err := CreatePostAsUser(&replyPost); err != nil { + t.Fatal(err) + } +} diff --git a/app/session.go b/app/session.go index 89244d780..7290bfd88 100644 --- a/app/session.go +++ b/app/session.go @@ -181,3 +181,17 @@ func AttachDeviceId(sessionId string, deviceId string, expiresAt int64) *model.A return nil } + +func UpdateLastActivityAtIfNeeded(session model.Session) { + now := model.GetMillis() + if now-session.LastActivityAt < model.SESSION_ACTIVITY_TIMEOUT { + return + } + + if result := <-Srv.Store.Session().UpdateLastActivityAt(session.Id, now); result.Err != nil { + l4g.Error(utils.T("api.status.last_activity.error", session.UserId, session.Id)) + } + + session.LastActivityAt = now + AddSessionToCache(&session) +} diff --git a/app/status.go b/app/status.go index dd57b82b2..868e57563 100644 --- a/app/status.go +++ b/app/status.go @@ -195,7 +195,6 @@ func SetStatusOnline(userId string, sessionId string, manual bool) { // Only update the database if the status has changed, the status has been manually set, // or enough time has passed since the previous action if status.Status != oldStatus || status.Manual != oldManual || status.LastActivityAt-oldTime > model.STATUS_MIN_UPDATE_TIME { - achan := Srv.Store.Session().UpdateLastActivityAt(sessionId, status.LastActivityAt) var schan store.StoreChannel if broadcast { @@ -204,23 +203,23 @@ func SetStatusOnline(userId string, sessionId string, manual bool) { schan = Srv.Store.Status().UpdateLastActivityAt(status.UserId, status.LastActivityAt) } - if result := <-achan; result.Err != nil { - l4g.Error(utils.T("api.status.last_activity.error"), userId, sessionId, result.Err) - } - if result := <-schan; result.Err != nil { l4g.Error(utils.T("api.status.save_status.error"), userId, result.Err) } } if broadcast { - event := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_STATUS_CHANGE, "", "", status.UserId, nil) - event.Add("status", model.STATUS_ONLINE) - event.Add("user_id", status.UserId) - go Publish(event) + BroadcastStatus(status) } } +func BroadcastStatus(status *model.Status) { + event := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_STATUS_CHANGE, "", "", status.UserId, nil) + event.Add("status", status.Status) + event.Add("user_id", status.UserId) + go Publish(event) +} + func SetStatusOffline(userId string, manual bool) { if !*utils.Cfg.ServiceSettings.EnableUserStatuses { return diff --git a/app/web_conn.go b/app/web_conn.go index 2c1913e2b..1ebed9fa5 100644 --- a/app/web_conn.go +++ b/app/web_conn.go @@ -43,7 +43,10 @@ type WebConn struct { func NewWebConn(ws *websocket.Conn, session model.Session, t goi18n.TranslateFunc, locale string) *WebConn { if len(session.UserId) > 0 { - go SetStatusOnline(session.UserId, session.Id, false) + go func() { + SetStatusOnline(session.UserId, session.Id, false) + UpdateLastActivityAtIfNeeded(session) + }() } return &WebConn{ diff --git a/app/websocket_router.go b/app/websocket_router.go index 84806b5cf..80773eb9d 100644 --- a/app/websocket_router.go +++ b/app/websocket_router.go @@ -53,7 +53,10 @@ func (wr *WebSocketRouter) ServeWebSocket(conn *WebConn, r *model.WebSocketReque if err != nil { conn.WebSocket.Close() } else { - go SetStatusOnline(session.UserId, session.Id, false) + go func() { + SetStatusOnline(session.UserId, session.Id, false) + UpdateLastActivityAtIfNeeded(*session) + }() conn.SessionToken = session.Token conn.UserId = session.UserId |