Merge branch 'release-3.9' into merge-3.9

Этот коммит содержится в:
JoramWilander
2017-05-12 08:00:28 -04:00
родитель b1c39204a6 a21a06afd9
Коммит 9d109b0700
66 изменённых файлов: 799 добавлений и 494 удалений

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

@@ -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
}

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

@@ -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"

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

@@ -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
}
}

44
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)
}
}

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

@@ -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)
}

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

@@ -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

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

@@ -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{

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

@@ -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