Move away from the "andForget" style of function (#3046)
This is the second and last part of the refactoring. First part is documented here: https://github.com/mattermost/platform/pull/3043
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
02576f3d59
Коммит
55f6a0b21c
@@ -5,14 +5,15 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
l4g "github.com/alecthomas/log4go"
|
l4g "github.com/alecthomas/log4go"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/mattermost/platform/model"
|
"github.com/mattermost/platform/model"
|
||||||
"github.com/mattermost/platform/store"
|
"github.com/mattermost/platform/store"
|
||||||
"github.com/mattermost/platform/utils"
|
"github.com/mattermost/platform/utils"
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -154,7 +155,7 @@ func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *mo
|
|||||||
} else {
|
} else {
|
||||||
message := model.NewMessage("", channel.Id, userId, model.ACTION_DIRECT_ADDED)
|
message := model.NewMessage("", channel.Id, userId, model.ACTION_DIRECT_ADDED)
|
||||||
message.Add("teammate_id", otherUserId)
|
message.Add("teammate_id", otherUserId)
|
||||||
PublishAndForget(message)
|
go Publish(message)
|
||||||
|
|
||||||
return result.Data.(*model.Channel), nil
|
return result.Data.(*model.Channel), nil
|
||||||
}
|
}
|
||||||
@@ -291,15 +292,14 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
c.Err = ucresult.Err
|
c.Err = ucresult.Err
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
PostUpdateChannelHeaderMessageAndForget(c, channel.Id, oldChannelHeader, channelHeader)
|
go PostUpdateChannelHeaderMessage(c, channel.Id, oldChannelHeader, channelHeader)
|
||||||
c.LogAudit("name=" + channel.Name)
|
c.LogAudit("name=" + channel.Name)
|
||||||
w.Write([]byte(channel.ToJson()))
|
w.Write([]byte(channel.ToJson()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostUpdateChannelHeaderMessageAndForget(c *Context, channelId string, oldChannelHeader, newChannelHeader string) {
|
func PostUpdateChannelHeaderMessage(c *Context, channelId string, oldChannelHeader, newChannelHeader string) {
|
||||||
go func() {
|
|
||||||
uc := Srv.Store.User().Get(c.Session.UserId)
|
uc := Srv.Store.User().Get(c.Session.UserId)
|
||||||
|
|
||||||
if uresult := <-uc; uresult.Err != nil {
|
if uresult := <-uc; uresult.Err != nil {
|
||||||
@@ -326,7 +326,6 @@ func PostUpdateChannelHeaderMessageAndForget(c *Context, channelId string, oldCh
|
|||||||
l4g.Error(utils.T("api.channel.post_update_channel_header_message_and_forget.join_leave.error"), err)
|
l4g.Error(utils.T("api.channel.post_update_channel_header_message_and_forget.join_leave.error"), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
|
func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -490,7 +489,7 @@ func joinChannel(c *Context, channelChannel store.StoreChannel, userChannel stor
|
|||||||
if _, err := AddUserToChannel(user, channel); err != nil {
|
if _, err := AddUserToChannel(user, channel); err != nil {
|
||||||
return err, nil
|
return err, nil
|
||||||
}
|
}
|
||||||
PostUserAddRemoveMessageAndForget(c, channel.Id, fmt.Sprintf(utils.T("api.channel.join_channel.post_and_forget"), user.Username))
|
go PostUserAddRemoveMessage(c, channel.Id, fmt.Sprintf(utils.T("api.channel.join_channel.post_and_forget"), user.Username))
|
||||||
} else {
|
} else {
|
||||||
return model.NewLocAppError("join", "api.channel.join_channel.permissions.app_error", nil, ""), nil
|
return model.NewLocAppError("join", "api.channel.join_channel.permissions.app_error", nil, ""), nil
|
||||||
}
|
}
|
||||||
@@ -498,8 +497,7 @@ func joinChannel(c *Context, channelChannel store.StoreChannel, userChannel stor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostUserAddRemoveMessageAndForget(c *Context, channelId string, message string) {
|
func PostUserAddRemoveMessage(c *Context, channelId string, message string) {
|
||||||
go func() {
|
|
||||||
post := &model.Post{
|
post := &model.Post{
|
||||||
ChannelId: channelId,
|
ChannelId: channelId,
|
||||||
Message: message,
|
Message: message,
|
||||||
@@ -508,7 +506,6 @@ func PostUserAddRemoveMessageAndForget(c *Context, channelId string, message str
|
|||||||
if _, err := CreatePost(c, post, false); err != nil {
|
if _, err := CreatePost(c, post, false); err != nil {
|
||||||
l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
|
l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelMember, *model.AppError) {
|
func AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelMember, *model.AppError) {
|
||||||
@@ -539,7 +536,7 @@ func AddUserToChannel(user *model.User, channel *model.Channel) (*model.ChannelM
|
|||||||
InvalidateCacheForUser(user.Id)
|
InvalidateCacheForUser(user.Id)
|
||||||
|
|
||||||
message := model.NewMessage(channel.TeamId, channel.Id, user.Id, model.ACTION_USER_ADDED)
|
message := model.NewMessage(channel.TeamId, channel.Id, user.Id, model.ACTION_USER_ADDED)
|
||||||
PublishAndForget(message)
|
go Publish(message)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return newMember, nil
|
return newMember, nil
|
||||||
@@ -627,7 +624,7 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
RemoveUserFromChannel(c.Session.UserId, c.Session.UserId, channel)
|
RemoveUserFromChannel(c.Session.UserId, c.Session.UserId, channel)
|
||||||
|
|
||||||
PostUserAddRemoveMessageAndForget(c, channel.Id, fmt.Sprintf(utils.T("api.channel.leave.left"), user.Username))
|
go PostUserAddRemoveMessage(c, channel.Id, fmt.Sprintf(utils.T("api.channel.leave.left"), user.Username))
|
||||||
|
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
result["id"] = channel.Id
|
result["id"] = channel.Id
|
||||||
@@ -722,7 +719,7 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
go func() {
|
go func() {
|
||||||
InvalidateCacheForChannel(channel.Id)
|
InvalidateCacheForChannel(channel.Id)
|
||||||
message := model.NewMessage(c.TeamId, channel.Id, c.Session.UserId, model.ACTION_CHANNEL_DELETED)
|
message := model.NewMessage(c.TeamId, channel.Id, c.Session.UserId, model.ACTION_CHANNEL_DELETED)
|
||||||
PublishAndForget(message)
|
go Publish(message)
|
||||||
|
|
||||||
post := &model.Post{
|
post := &model.Post{
|
||||||
ChannelId: channel.Id,
|
ChannelId: channel.Id,
|
||||||
@@ -758,7 +755,7 @@ func updateLastViewedAt(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
message := model.NewMessage(c.TeamId, id, c.Session.UserId, model.ACTION_CHANNEL_VIEWED)
|
message := model.NewMessage(c.TeamId, id, c.Session.UserId, model.ACTION_CHANNEL_VIEWED)
|
||||||
message.Add("channel_id", id)
|
message.Add("channel_id", id)
|
||||||
|
|
||||||
PublishAndForget(message)
|
go Publish(message)
|
||||||
|
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
result["id"] = id
|
result["id"] = id
|
||||||
@@ -907,7 +904,7 @@ func addMember(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
c.LogAudit("name=" + channel.Name + " user_id=" + userId)
|
c.LogAudit("name=" + channel.Name + " user_id=" + userId)
|
||||||
|
|
||||||
PostUserAddRemoveMessageAndForget(c, channel.Id, fmt.Sprintf(utils.T("api.channel.add_member.added"), nUser.Username, oUser.Username))
|
go PostUserAddRemoveMessage(c, channel.Id, fmt.Sprintf(utils.T("api.channel.add_member.added"), nUser.Username, oUser.Username))
|
||||||
|
|
||||||
<-Srv.Store.Channel().UpdateLastViewedAt(id, oUser.Id)
|
<-Srv.Store.Channel().UpdateLastViewedAt(id, oUser.Id)
|
||||||
w.Write([]byte(cm.ToJson()))
|
w.Write([]byte(cm.ToJson()))
|
||||||
@@ -978,7 +975,7 @@ func RemoveUserFromChannel(userIdToRemove string, removerUserId string, channel
|
|||||||
|
|
||||||
message := model.NewMessage(channel.TeamId, channel.Id, userIdToRemove, model.ACTION_USER_REMOVED)
|
message := model.NewMessage(channel.TeamId, channel.Id, userIdToRemove, model.ACTION_USER_REMOVED)
|
||||||
message.Add("remover_id", removerUserId)
|
message.Add("remover_id", removerUserId)
|
||||||
PublishAndForget(message)
|
go Publish(message)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
38
api/file.go
38
api/file.go
@@ -6,16 +6,6 @@ package api
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
l4g "github.com/alecthomas/log4go"
|
|
||||||
"github.com/disintegration/imaging"
|
|
||||||
"github.com/goamz/goamz/aws"
|
|
||||||
"github.com/goamz/goamz/s3"
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"github.com/mattermost/platform/model"
|
|
||||||
"github.com/mattermost/platform/utils"
|
|
||||||
"github.com/mssola/user_agent"
|
|
||||||
"github.com/rwcarlsen/goexif/exif"
|
|
||||||
_ "golang.org/x/image/bmp"
|
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"image/draw"
|
"image/draw"
|
||||||
@@ -30,6 +20,17 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
l4g "github.com/alecthomas/log4go"
|
||||||
|
"github.com/disintegration/imaging"
|
||||||
|
"github.com/goamz/goamz/aws"
|
||||||
|
"github.com/goamz/goamz/s3"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/mattermost/platform/model"
|
||||||
|
"github.com/mattermost/platform/utils"
|
||||||
|
"github.com/mssola/user_agent"
|
||||||
|
"github.com/rwcarlsen/goexif/exif"
|
||||||
|
_ "golang.org/x/image/bmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -165,14 +166,12 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
resStruct.ClientIds = append(resStruct.ClientIds, clientId)
|
resStruct.ClientIds = append(resStruct.ClientIds, clientId)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleImagesAndForget(imageNameList, imageDataList, c.TeamId, channelId, c.Session.UserId)
|
go handleImages(imageNameList, imageDataList, c.TeamId, channelId, c.Session.UserId)
|
||||||
|
|
||||||
w.Write([]byte(resStruct.ToJson()))
|
w.Write([]byte(resStruct.ToJson()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleImagesAndForget(filenames []string, fileData [][]byte, teamId, channelId, userId string) {
|
func handleImages(filenames []string, fileData [][]byte, teamId, channelId, userId string) {
|
||||||
|
|
||||||
go func() {
|
|
||||||
dest := "teams/" + teamId + "/channels/" + channelId + "/users/" + userId + "/"
|
dest := "teams/" + teamId + "/channels/" + channelId + "/users/" + userId + "/"
|
||||||
|
|
||||||
for i, filename := range filenames {
|
for i, filename := range filenames {
|
||||||
@@ -268,7 +267,6 @@ func handleImagesAndForget(filenames []string, fileData [][]byte, teamId, channe
|
|||||||
}()
|
}()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getImageOrientation(imageData []byte) (int, error) {
|
func getImageOrientation(imageData []byte) (int, error) {
|
||||||
@@ -329,7 +327,7 @@ func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
info = cached.(*model.FileInfo)
|
info = cached.(*model.FileInfo)
|
||||||
} else {
|
} else {
|
||||||
fileData := make(chan []byte)
|
fileData := make(chan []byte)
|
||||||
getFileAndForget(path, fileData)
|
go readFile(path, fileData)
|
||||||
|
|
||||||
newInfo, err := model.GetInfoForBytes(filename, <-fileData)
|
newInfo, err := model.GetInfoForBytes(filename, <-fileData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -435,7 +433,7 @@ func getFileData(teamId string, channelId string, userId string, filename string
|
|||||||
path := "teams/" + teamId + "/channels/" + channelId + "/users/" + userId + "/" + filename
|
path := "teams/" + teamId + "/channels/" + channelId + "/users/" + userId + "/" + filename
|
||||||
|
|
||||||
fileChan := make(chan []byte)
|
fileChan := make(chan []byte)
|
||||||
getFileAndForget(path, fileChan)
|
go readFile(path, fileChan)
|
||||||
|
|
||||||
if bytes := <-fileChan; bytes == nil {
|
if bytes := <-fileChan; bytes == nil {
|
||||||
err := model.NewLocAppError("writeFileResponse", "api.file.get_file.not_found.app_error", nil, "path="+path)
|
err := model.NewLocAppError("writeFileResponse", "api.file.get_file.not_found.app_error", nil, "path="+path)
|
||||||
@@ -472,8 +470,7 @@ func writeFileResponse(filename string, bytes []byte, w http.ResponseWriter, r *
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFileAndForget(path string, fileData chan []byte) {
|
func readFile(path string, fileData chan []byte) {
|
||||||
go func() {
|
|
||||||
data, getErr := ReadFile(path)
|
data, getErr := ReadFile(path)
|
||||||
if getErr != nil {
|
if getErr != nil {
|
||||||
l4g.Error(getErr)
|
l4g.Error(getErr)
|
||||||
@@ -481,7 +478,6 @@ func getFileAndForget(path string, fileData chan []byte) {
|
|||||||
} else {
|
} else {
|
||||||
fileData <- data
|
fileData <- data
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPublicLink(c *Context, w http.ResponseWriter, r *http.Request) {
|
func getPublicLink(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -588,7 +584,7 @@ func WriteFile(f []byte, path string) *model.AppError {
|
|||||||
func MoveFile(oldPath, newPath string) *model.AppError {
|
func MoveFile(oldPath, newPath string) *model.AppError {
|
||||||
if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
|
if utils.Cfg.FileSettings.DriverName == model.IMAGE_DRIVER_S3 {
|
||||||
fileData := make(chan []byte)
|
fileData := make(chan []byte)
|
||||||
getFileAndForget(oldPath, fileData)
|
go readFile(oldPath, fileData)
|
||||||
fileBytes := <-fileData
|
fileBytes := <-fileData
|
||||||
|
|
||||||
if fileBytes == nil {
|
if fileBytes == nil {
|
||||||
|
|||||||
51
api/post.go
51
api/post.go
@@ -6,11 +6,6 @@ package api
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
l4g "github.com/alecthomas/log4go"
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"github.com/mattermost/platform/model"
|
|
||||||
"github.com/mattermost/platform/store"
|
|
||||||
"github.com/mattermost/platform/utils"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -20,6 +15,12 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
l4g "github.com/alecthomas/log4go"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/mattermost/platform/model"
|
||||||
|
"github.com/mattermost/platform/store"
|
||||||
|
"github.com/mattermost/platform/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitPost() {
|
func InitPost() {
|
||||||
@@ -147,8 +148,7 @@ func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post
|
|||||||
} else {
|
} else {
|
||||||
rpost = result.Data.(*model.Post)
|
rpost = result.Data.(*model.Post)
|
||||||
|
|
||||||
handlePostEventsAndForget(c, rpost, triggerWebhooks)
|
go handlePostEvents(c, rpost, triggerWebhooks)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rpost, nil
|
return rpost, nil
|
||||||
@@ -227,8 +227,7 @@ func CreateWebhookPost(c *Context, channelId, text, overrideUsername, overrideIc
|
|||||||
return post, nil
|
return post, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePostEventsAndForget(c *Context, post *model.Post, triggerWebhooks bool) {
|
func handlePostEvents(c *Context, post *model.Post, triggerWebhooks bool) {
|
||||||
go func() {
|
|
||||||
tchan := Srv.Store.Team().Get(c.TeamId)
|
tchan := Srv.Store.Team().Get(c.TeamId)
|
||||||
cchan := Srv.Store.Channel().Get(post.ChannelId)
|
cchan := Srv.Store.Channel().Get(post.ChannelId)
|
||||||
uchan := Srv.Store.User().Get(post.UserId)
|
uchan := Srv.Store.User().Get(post.UserId)
|
||||||
@@ -290,13 +289,12 @@ func handlePostEventsAndForget(c *Context, post *model.Post, triggerWebhooks boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if triggerWebhooks {
|
if triggerWebhooks {
|
||||||
handleWebhookEventsAndForget(c, post, team, channel, user)
|
go handleWebhookEvents(c, post, team, channel, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
if channel.Type == model.CHANNEL_DIRECT {
|
if channel.Type == model.CHANNEL_DIRECT {
|
||||||
go makeDirectChannelVisible(c.TeamId, post.ChannelId)
|
go makeDirectChannelVisible(c.TeamId, post.ChannelId)
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeDirectChannelVisible(teamId string, channelId string) {
|
func makeDirectChannelVisible(teamId string, channelId string) {
|
||||||
@@ -332,7 +330,7 @@ func makeDirectChannelVisible(teamId string, channelId string) {
|
|||||||
message := model.NewMessage(teamId, channelId, member.UserId, model.ACTION_PREFERENCE_CHANGED)
|
message := model.NewMessage(teamId, channelId, member.UserId, model.ACTION_PREFERENCE_CHANGED)
|
||||||
message.Add("preference", preference.ToJson())
|
message.Add("preference", preference.ToJson())
|
||||||
|
|
||||||
PublishAndForget(message)
|
go Publish(message)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
preference := result.Data.(model.Preference)
|
preference := result.Data.(model.Preference)
|
||||||
@@ -347,15 +345,14 @@ func makeDirectChannelVisible(teamId string, channelId string) {
|
|||||||
message := model.NewMessage(teamId, channelId, member.UserId, model.ACTION_PREFERENCE_CHANGED)
|
message := model.NewMessage(teamId, channelId, member.UserId, model.ACTION_PREFERENCE_CHANGED)
|
||||||
message.Add("preference", preference.ToJson())
|
message.Add("preference", preference.ToJson())
|
||||||
|
|
||||||
PublishAndForget(message)
|
go Publish(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleWebhookEventsAndForget(c *Context, post *model.Post, team *model.Team, channel *model.Channel, user *model.User) {
|
func handleWebhookEvents(c *Context, post *model.Post, team *model.Team, channel *model.Channel, user *model.User) {
|
||||||
go func() {
|
|
||||||
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -465,9 +462,6 @@ func handleWebhookEventsAndForget(c *Context, post *model.Post, team *model.Team
|
|||||||
|
|
||||||
}(hook)
|
}(hook)
|
||||||
}
|
}
|
||||||
|
|
||||||
}()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *model.Channel, profileMap map[string]*model.User, members []model.ChannelMember) {
|
func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *model.Channel, profileMap map[string]*model.User, members []model.ChannelMember) {
|
||||||
@@ -595,7 +589,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
|
|||||||
}
|
}
|
||||||
|
|
||||||
for id := range toEmailMap {
|
for id := range toEmailMap {
|
||||||
updateMentionCountAndForget(post.ChannelId, id)
|
go updateMentionCount(post.ChannelId, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -779,15 +773,13 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
|
|||||||
message.Add("mentions", model.ArrayToJson(mentionedUsers))
|
message.Add("mentions", model.ArrayToJson(mentionedUsers))
|
||||||
}
|
}
|
||||||
|
|
||||||
PublishAndForget(message)
|
go Publish(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateMentionCountAndForget(channelId, userId string) {
|
func updateMentionCount(channelId, userId string) {
|
||||||
go func() {
|
|
||||||
if result := <-Srv.Store.Channel().IncrementMentionCount(channelId, userId); result.Err != nil {
|
if result := <-Srv.Store.Channel().IncrementMentionCount(channelId, userId); result.Err != nil {
|
||||||
l4g.Error(utils.T("api.post.update_mention_count_and_forget.update_error"), userId, channelId, result.Err)
|
l4g.Error(utils.T("api.post.update_mention_count_and_forget.update_error"), userId, channelId, result.Err)
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkForOutOfChannelMentions(c *Context, post *model.Post, channel *model.Channel, allProfiles map[string]*model.User, members []model.ChannelMember) {
|
func checkForOutOfChannelMentions(c *Context, post *model.Post, channel *model.Channel, allProfiles map[string]*model.User, members []model.ChannelMember) {
|
||||||
@@ -876,7 +868,7 @@ func SendEphemeralPost(teamId, userId string, post *model.Post) {
|
|||||||
message := model.NewMessage(teamId, post.ChannelId, userId, model.ACTION_EPHEMERAL_MESSAGE)
|
message := model.NewMessage(teamId, post.ChannelId, userId, model.ACTION_EPHEMERAL_MESSAGE)
|
||||||
message.Add("post", post.ToJson())
|
message.Add("post", post.ToJson())
|
||||||
|
|
||||||
PublishAndForget(message)
|
go Publish(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -938,7 +930,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
message := model.NewMessage(c.TeamId, rpost.ChannelId, c.Session.UserId, model.ACTION_POST_EDITED)
|
message := model.NewMessage(c.TeamId, rpost.ChannelId, c.Session.UserId, model.ACTION_POST_EDITED)
|
||||||
message.Add("post", rpost.ToJson())
|
message.Add("post", rpost.ToJson())
|
||||||
|
|
||||||
PublishAndForget(message)
|
go Publish(message)
|
||||||
|
|
||||||
w.Write([]byte(rpost.ToJson()))
|
w.Write([]byte(rpost.ToJson()))
|
||||||
}
|
}
|
||||||
@@ -1202,8 +1194,8 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
message := model.NewMessage(c.TeamId, post.ChannelId, c.Session.UserId, model.ACTION_POST_DELETED)
|
message := model.NewMessage(c.TeamId, post.ChannelId, c.Session.UserId, model.ACTION_POST_DELETED)
|
||||||
message.Add("post", post.ToJson())
|
message.Add("post", post.ToJson())
|
||||||
|
|
||||||
PublishAndForget(message)
|
go Publish(message)
|
||||||
DeletePostFilesAndForget(c.TeamId, post)
|
go DeletePostFiles(c.TeamId, post)
|
||||||
|
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
result["id"] = postId
|
result["id"] = postId
|
||||||
@@ -1211,8 +1203,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeletePostFilesAndForget(teamId string, post *model.Post) {
|
func DeletePostFiles(teamId string, post *model.Post) {
|
||||||
go func() {
|
|
||||||
if len(post.Filenames) == 0 {
|
if len(post.Filenames) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1224,8 +1215,6 @@ func DeletePostFilesAndForget(teamId string, post *model.Post) {
|
|||||||
newPath := prefix + splitUrl[len(splitUrl)-2] + "/deleted_" + splitUrl[len(splitUrl)-1]
|
newPath := prefix + splitUrl[len(splitUrl)-2] + "/deleted_" + splitUrl[len(splitUrl)-1]
|
||||||
MoveFile(oldPath, newPath)
|
MoveFile(oldPath, newPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPostsBefore(c *Context, w http.ResponseWriter, r *http.Request) {
|
func getPostsBefore(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ func JoinUserToTeam(team *model.Team, user *model.User) *model.AppError {
|
|||||||
InvalidateCacheForUser(user.Id)
|
InvalidateCacheForUser(user.Id)
|
||||||
|
|
||||||
// This message goes to every channel, so the channelId is irrelevant
|
// This message goes to every channel, so the channelId is irrelevant
|
||||||
PublishAndForget(model.NewMessage("", "", user.Id, model.ACTION_NEW_USER))
|
go Publish(model.NewMessage("", "", user.Id, model.ACTION_NEW_USER))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ func CreateUser(user *model.User) (*model.User, *model.AppError) {
|
|||||||
ruser.Sanitize(map[string]bool{})
|
ruser.Sanitize(map[string]bool{})
|
||||||
|
|
||||||
// This message goes to every channel, so the channelId is irrelevant
|
// This message goes to every channel, so the channelId is irrelevant
|
||||||
PublishAndForget(model.NewMessage("", "", ruser.Id, model.ACTION_NEW_USER))
|
go Publish(model.NewMessage("", "", ruser.Id, model.ACTION_NEW_USER))
|
||||||
|
|
||||||
return ruser, nil
|
return ruser, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,12 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
l4g "github.com/alecthomas/log4go"
|
l4g "github.com/alecthomas/log4go"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/mattermost/platform/model"
|
"github.com/mattermost/platform/model"
|
||||||
"github.com/mattermost/platform/utils"
|
"github.com/mattermost/platform/utils"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -77,7 +78,7 @@ func (c *WebConn) readPump() {
|
|||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
msg.UserId = c.UserId
|
msg.UserId = c.UserId
|
||||||
PublishAndForget(&msg)
|
go Publish(&msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,8 @@ var hub = &Hub{
|
|||||||
invalidateChannel: make(chan string),
|
invalidateChannel: make(chan string),
|
||||||
}
|
}
|
||||||
|
|
||||||
func PublishAndForget(message *model.Message) {
|
func Publish(message *model.Message) {
|
||||||
go func() {
|
|
||||||
hub.Broadcast(message)
|
hub.Broadcast(message)
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func InvalidateCacheForUser(userId string) {
|
func InvalidateCacheForUser(userId string) {
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setDiagnosticId()
|
setDiagnosticId()
|
||||||
runSecurityAndDiagnosticsJobAndForget()
|
go runSecurityAndDiagnosticsJob()
|
||||||
|
|
||||||
if einterfaces.GetComplianceInterface() != nil {
|
if einterfaces.GetComplianceInterface() != nil {
|
||||||
einterfaces.GetComplianceInterface().StartComplianceDailyJob()
|
einterfaces.GetComplianceInterface().StartComplianceDailyJob()
|
||||||
@@ -152,8 +152,7 @@ func setDiagnosticId() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func runSecurityAndDiagnosticsJobAndForget() {
|
func runSecurityAndDiagnosticsJob() {
|
||||||
go func() {
|
|
||||||
for {
|
for {
|
||||||
if *utils.Cfg.ServiceSettings.EnableSecurityFixAlert {
|
if *utils.Cfg.ServiceSettings.EnableSecurityFixAlert {
|
||||||
if result := <-api.Srv.Store.System().Get(); result.Err == nil {
|
if result := <-api.Srv.Store.System().Get(); result.Err == nil {
|
||||||
@@ -241,7 +240,6 @@ func runSecurityAndDiagnosticsJobAndForget() {
|
|||||||
|
|
||||||
time.Sleep(time.Hour * 4)
|
time.Sleep(time.Hour * 4)
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCmds() {
|
func parseCmds() {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user