Refactored CreatePost to not use context (#3813)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
9ad50d4d75
Коммит
8c2ea22892
@@ -4,11 +4,12 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"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"
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetLogs(t *testing.T) {
|
func TestGetLogs(t *testing.T) {
|
||||||
@@ -198,7 +199,7 @@ func TestGetTeamAnalyticsStandard(t *testing.T) {
|
|||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
if rows[2].Value != 1 {
|
if rows[2].Value != 3 {
|
||||||
t.Log(rows.ToJson())
|
t.Log(rows.ToJson())
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -352,8 +352,9 @@ func PostUpdateChannelHeaderMessage(c *Context, channelId string, oldChannelHead
|
|||||||
ChannelId: channelId,
|
ChannelId: channelId,
|
||||||
Message: message,
|
Message: message,
|
||||||
Type: model.POST_HEADER_CHANGE,
|
Type: model.POST_HEADER_CHANGE,
|
||||||
|
UserId: c.Session.UserId,
|
||||||
}
|
}
|
||||||
if _, err := CreatePost(c, post, false); err != nil {
|
if _, err := CreatePost(c.TeamId, post, false); err != nil {
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -543,8 +544,9 @@ func PostUserAddRemoveMessage(c *Context, channelId string, message, postType st
|
|||||||
ChannelId: channelId,
|
ChannelId: channelId,
|
||||||
Message: message,
|
Message: message,
|
||||||
Type: postType,
|
Type: postType,
|
||||||
|
UserId: c.Session.UserId,
|
||||||
}
|
}
|
||||||
if _, err := CreatePost(c, post, false); err != nil {
|
if _, err := CreatePost(c.TeamId, 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -609,6 +611,16 @@ func JoinDefaultChannels(teamId string, user *model.User, channelRole string) *m
|
|||||||
if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
|
if cmResult := <-Srv.Store.Channel().SaveMember(cm); cmResult.Err != nil {
|
||||||
err = cmResult.Err
|
err = cmResult.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
post := &model.Post{
|
||||||
|
ChannelId: result.Data.(*model.Channel).Id,
|
||||||
|
Message: fmt.Sprintf(utils.T("api.channel.join_channel.post_and_forget"), user.Username),
|
||||||
|
Type: model.POST_JOIN_LEAVE,
|
||||||
|
UserId: user.Id,
|
||||||
|
}
|
||||||
|
if _, err := CreatePost(teamId, post, false); err != nil {
|
||||||
|
l4g.Error(utils.T("api.channel.post_user_add_remove_message_and_forget.error"), err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-Srv.Store.Channel().GetByName(teamId, "off-topic"); result.Err != nil {
|
if result := <-Srv.Store.Channel().GetByName(teamId, "off-topic"); result.Err != nil {
|
||||||
@@ -780,8 +792,9 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
ChannelId: channel.Id,
|
ChannelId: channel.Id,
|
||||||
Message: fmt.Sprintf(c.T("api.channel.delete_channel.archived"), user.Username),
|
Message: fmt.Sprintf(c.T("api.channel.delete_channel.archived"), user.Username),
|
||||||
Type: model.POST_CHANNEL_DELETED,
|
Type: model.POST_CHANNEL_DELETED,
|
||||||
|
UserId: c.Session.UserId,
|
||||||
}
|
}
|
||||||
if _, err := CreatePost(c, post, false); err != nil {
|
if _, err := CreatePost(c.TeamId, post, false); err != nil {
|
||||||
l4g.Error(utils.T("api.channel.delete_channel.failed_post.error"), err)
|
l4g.Error(utils.T("api.channel.delete_channel.failed_post.error"), err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
@@ -247,7 +247,8 @@ func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandRe
|
|||||||
|
|
||||||
if response.ResponseType == model.COMMAND_RESPONSE_TYPE_IN_CHANNEL {
|
if response.ResponseType == model.COMMAND_RESPONSE_TYPE_IN_CHANNEL {
|
||||||
post.Message = response.Text
|
post.Message = response.Text
|
||||||
if _, err := CreatePost(c, post, true); err != nil {
|
post.UserId = c.Session.UserId
|
||||||
|
if _, err := CreatePost(c.TeamId, post, true); err != nil {
|
||||||
c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
|
c.Err = model.NewLocAppError("command", "api.command.execute_command.save.app_error", nil, "")
|
||||||
}
|
}
|
||||||
} else if response.ResponseType == model.COMMAND_RESPONSE_TYPE_EPHEMERAL && response.Text != "" {
|
} else if response.ResponseType == model.COMMAND_RESPONSE_TYPE_EPHEMERAL && response.Text != "" {
|
||||||
|
|||||||
@@ -77,10 +77,11 @@ func (me *EchoProvider) DoCommand(c *Context, channelId string, message string)
|
|||||||
post := &model.Post{}
|
post := &model.Post{}
|
||||||
post.ChannelId = channelId
|
post.ChannelId = channelId
|
||||||
post.Message = message
|
post.Message = message
|
||||||
|
post.UserId = c.Session.UserId
|
||||||
|
|
||||||
time.Sleep(time.Duration(delay) * time.Second)
|
time.Sleep(time.Duration(delay) * time.Second)
|
||||||
|
|
||||||
if _, err := CreatePost(c, post, true); err != nil {
|
if _, err := CreatePost(c.TeamId, post, true); err != nil {
|
||||||
l4g.Error(c.T("api.command_echo.create.app_error"), err)
|
l4g.Error(c.T("api.command_echo.create.app_error"), err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|||||||
@@ -355,8 +355,9 @@ func (me *LoadTestProvider) UrlCommand(c *Context, channelId string, message str
|
|||||||
post := &model.Post{}
|
post := &model.Post{}
|
||||||
post.Message = string(bytes[:length])
|
post.Message = string(bytes[:length])
|
||||||
post.ChannelId = channelId
|
post.ChannelId = channelId
|
||||||
|
post.UserId = c.Session.UserId
|
||||||
|
|
||||||
if _, err := CreatePost(c, post, false); err != nil {
|
if _, err := CreatePost(c.TeamId, post, false); err != nil {
|
||||||
return &model.CommandResponse{Text: "Unable to create post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
return &model.CommandResponse{Text: "Unable to create post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -390,11 +391,12 @@ func (me *LoadTestProvider) JsonCommand(c *Context, channelId string, message st
|
|||||||
|
|
||||||
post := model.PostFromJson(contents)
|
post := model.PostFromJson(contents)
|
||||||
post.ChannelId = channelId
|
post.ChannelId = channelId
|
||||||
|
post.UserId = c.Session.UserId
|
||||||
if post.Message == "" {
|
if post.Message == "" {
|
||||||
post.Message = message
|
post.Message = message
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := CreatePost(c, post, false); err != nil {
|
if _, err := CreatePost(c.TeamId, post, false); err != nil {
|
||||||
return &model.CommandResponse{Text: "Unable to create post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
return &model.CommandResponse{Text: "Unable to create post", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||||
}
|
}
|
||||||
return &model.CommandResponse{Text: "Loaded data", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
return &model.CommandResponse{Text: "Loaded data", ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||||
|
|||||||
@@ -4,8 +4,9 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mattermost/platform/model"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mattermost/platform/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type msgProvider struct {
|
type msgProvider struct {
|
||||||
@@ -83,7 +84,8 @@ func (me *msgProvider) DoCommand(c *Context, channelId string, message string) *
|
|||||||
post := &model.Post{}
|
post := &model.Post{}
|
||||||
post.Message = parsedMessage
|
post.Message = parsedMessage
|
||||||
post.ChannelId = targetChannelId
|
post.ChannelId = targetChannelId
|
||||||
if _, err := CreatePost(c, post, true); err != nil {
|
post.UserId = c.Session.UserId
|
||||||
|
if _, err := CreatePost(c.TeamId, post, true); err != nil {
|
||||||
return &model.CommandResponse{Text: c.T("api.command_msg.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
return &model.CommandResponse{Text: c.T("api.command_msg.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
96
api/post.go
96
api/post.go
@@ -56,6 +56,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
c.SetInvalidParam("createPost", "post")
|
c.SetInvalidParam("createPost", "post")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
post.UserId = c.Session.UserId
|
||||||
|
|
||||||
// Create and save post object to channel
|
// Create and save post object to channel
|
||||||
cchan := Srv.Store.Channel().CheckPermissionsTo(c.TeamId, post.ChannelId, c.Session.UserId)
|
cchan := Srv.Store.Channel().CheckPermissionsTo(c.TeamId, post.ChannelId, c.Session.UserId)
|
||||||
@@ -64,7 +65,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if rp, err := CreatePost(c, post, true); err != nil {
|
if rp, err := CreatePost(c.TeamId, post, true); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
|
|
||||||
if c.Err.Id == "api.post.create_post.root_id.app_error" ||
|
if c.Err.Id == "api.post.create_post.root_id.app_error" ||
|
||||||
@@ -83,7 +84,7 @@ func createPost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
|
func CreatePost(teamId string, post *model.Post, triggerWebhooks bool) (*model.Post, *model.AppError) {
|
||||||
var pchan store.StoreChannel
|
var pchan store.StoreChannel
|
||||||
if len(post.RootId) > 0 {
|
if len(post.RootId) > 0 {
|
||||||
pchan = Srv.Store.Post().Get(post.RootId)
|
pchan = Srv.Store.Post().Get(post.RootId)
|
||||||
@@ -116,8 +117,6 @@ func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post
|
|||||||
|
|
||||||
post.Hashtags, _ = model.ParseHashtags(post.Message)
|
post.Hashtags, _ = model.ParseHashtags(post.Message)
|
||||||
|
|
||||||
post.UserId = c.Session.UserId
|
|
||||||
|
|
||||||
if len(post.Filenames) > 0 {
|
if len(post.Filenames) > 0 {
|
||||||
doRemove := false
|
doRemove := false
|
||||||
for i := len(post.Filenames) - 1; i >= 0; i-- {
|
for i := len(post.Filenames) - 1; i >= 0; i-- {
|
||||||
@@ -157,18 +156,18 @@ func CreatePost(c *Context, post *model.Post, triggerWebhooks bool) (*model.Post
|
|||||||
} else {
|
} else {
|
||||||
rpost = result.Data.(*model.Post)
|
rpost = result.Data.(*model.Post)
|
||||||
|
|
||||||
go handlePostEvents(c, rpost, triggerWebhooks)
|
go handlePostEvents(teamId, rpost, triggerWebhooks)
|
||||||
}
|
}
|
||||||
|
|
||||||
return rpost, nil
|
return rpost, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateWebhookPost(c *Context, channelId, text, overrideUsername, overrideIconUrl string, props model.StringInterface, postType string) (*model.Post, *model.AppError) {
|
func CreateWebhookPost(userId, channelId, teamId, text, overrideUsername, overrideIconUrl string, props model.StringInterface, postType string) (*model.Post, *model.AppError) {
|
||||||
// parse links into Markdown format
|
// parse links into Markdown format
|
||||||
linkWithTextRegex := regexp.MustCompile(`<([^<\|]+)\|([^>]+)>`)
|
linkWithTextRegex := regexp.MustCompile(`<([^<\|]+)\|([^>]+)>`)
|
||||||
text = linkWithTextRegex.ReplaceAllString(text, "[${2}](${1})")
|
text = linkWithTextRegex.ReplaceAllString(text, "[${2}](${1})")
|
||||||
|
|
||||||
post := &model.Post{UserId: c.Session.UserId, ChannelId: channelId, Message: text, Type: postType}
|
post := &model.Post{UserId: userId, ChannelId: channelId, Message: text, Type: postType}
|
||||||
post.AddProp("from_webhook", "true")
|
post.AddProp("from_webhook", "true")
|
||||||
|
|
||||||
if utils.Cfg.ServiceSettings.EnablePostUsernameOverride {
|
if utils.Cfg.ServiceSettings.EnablePostUsernameOverride {
|
||||||
@@ -229,21 +228,21 @@ func CreateWebhookPost(c *Context, channelId, text, overrideUsername, overrideIc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := CreatePost(c, post, false); err != nil {
|
if _, err := CreatePost(teamId, post, false); err != nil {
|
||||||
return nil, model.NewLocAppError("CreateWebhookPost", "api.post.create_webhook_post.creating.app_error", nil, "err="+err.Message)
|
return nil, model.NewLocAppError("CreateWebhookPost", "api.post.create_webhook_post.creating.app_error", nil, "err="+err.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
return post, nil
|
return post, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePostEvents(c *Context, post *model.Post, triggerWebhooks bool) {
|
func handlePostEvents(teamId string, post *model.Post, triggerWebhooks bool) {
|
||||||
tchan := Srv.Store.Team().Get(c.TeamId)
|
tchan := Srv.Store.Team().Get(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)
|
||||||
|
|
||||||
var team *model.Team
|
var team *model.Team
|
||||||
if result := <-tchan; result.Err != nil {
|
if result := <-tchan; result.Err != nil {
|
||||||
l4g.Error(utils.T("api.post.handle_post_events_and_forget.team.error"), c.TeamId, result.Err)
|
l4g.Error(utils.T("api.post.handle_post_events_and_forget.team.error"), teamId, result.Err)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
team = result.Data.(*model.Team)
|
team = result.Data.(*model.Team)
|
||||||
@@ -257,7 +256,7 @@ func handlePostEvents(c *Context, post *model.Post, triggerWebhooks bool) {
|
|||||||
channel = result.Data.(*model.Channel)
|
channel = result.Data.(*model.Channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
go sendNotifications(c, post, team, channel)
|
go sendNotifications(teamId, post, team, channel)
|
||||||
|
|
||||||
var user *model.User
|
var user *model.User
|
||||||
if result := <-uchan; result.Err != nil {
|
if result := <-uchan; result.Err != nil {
|
||||||
@@ -268,11 +267,11 @@ func handlePostEvents(c *Context, post *model.Post, triggerWebhooks bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if triggerWebhooks {
|
if triggerWebhooks {
|
||||||
go handleWebhookEvents(c, post, team, channel, user)
|
go handleWebhookEvents(post, team, channel, user)
|
||||||
}
|
}
|
||||||
|
|
||||||
if channel.Type == model.CHANNEL_DIRECT {
|
if channel.Type == model.CHANNEL_DIRECT {
|
||||||
go makeDirectChannelVisible(c.TeamId, post.ChannelId)
|
go makeDirectChannelVisible(teamId, post.ChannelId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,7 +330,7 @@ func makeDirectChannelVisible(teamId string, channelId string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleWebhookEvents(c *Context, post *model.Post, team *model.Team, channel *model.Channel, user *model.User) {
|
func handleWebhookEvents(post *model.Post, team *model.Team, channel *model.Channel, user *model.User) {
|
||||||
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
if !utils.Cfg.ServiceSettings.EnableOutgoingWebhooks {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -340,7 +339,7 @@ func handleWebhookEvents(c *Context, post *model.Post, team *model.Team, channel
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
hchan := Srv.Store.Webhook().GetOutgoingByTeam(c.TeamId)
|
hchan := Srv.Store.Webhook().GetOutgoingByTeam(team.Id)
|
||||||
result := <-hchan
|
result := <-hchan
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.getting.error"), result.Err)
|
l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.getting.error"), result.Err)
|
||||||
@@ -414,29 +413,8 @@ func handleWebhookEvents(c *Context, post *model.Post, team *model.Team, channel
|
|||||||
}()
|
}()
|
||||||
respProps := model.MapFromJson(resp.Body)
|
respProps := model.MapFromJson(resp.Body)
|
||||||
|
|
||||||
// copy the context and create a mock session for posting the message
|
|
||||||
mockSession := model.Session{
|
|
||||||
UserId: hook.CreatorId,
|
|
||||||
TeamMembers: []*model.TeamMember{{TeamId: hook.TeamId, UserId: hook.CreatorId}},
|
|
||||||
IsOAuth: false,
|
|
||||||
}
|
|
||||||
|
|
||||||
newContext := &Context{
|
|
||||||
Session: mockSession,
|
|
||||||
RequestId: model.NewId(),
|
|
||||||
IpAddress: "",
|
|
||||||
Path: c.Path,
|
|
||||||
Err: nil,
|
|
||||||
teamURLValid: c.teamURLValid,
|
|
||||||
teamURL: c.teamURL,
|
|
||||||
siteURL: c.siteURL,
|
|
||||||
T: c.T,
|
|
||||||
Locale: c.Locale,
|
|
||||||
TeamId: hook.TeamId,
|
|
||||||
}
|
|
||||||
|
|
||||||
if text, ok := respProps["text"]; ok {
|
if text, ok := respProps["text"]; ok {
|
||||||
if _, err := CreateWebhookPost(newContext, post.ChannelId, text, respProps["username"], respProps["icon_url"], post.Props, post.Type); err != nil {
|
if _, err := CreateWebhookPost(hook.CreatorId, post.ChannelId, hook.TeamId, text, respProps["username"], respProps["icon_url"], post.Props, post.Type); err != nil {
|
||||||
l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.create_post.error"), err)
|
l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.create_post.error"), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -547,22 +525,22 @@ func getExplicitMentions(message string, keywords map[string][]string) (map[stri
|
|||||||
return mentioned, hereMentioned
|
return mentioned, hereMentioned
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *model.Channel) {
|
func sendNotifications(teamId string, post *model.Post, team *model.Team, channel *model.Channel) {
|
||||||
// get profiles for all users we could be mentioning
|
// get profiles for all users we could be mentioning
|
||||||
pchan := Srv.Store.User().GetProfiles(c.TeamId)
|
pchan := Srv.Store.User().GetProfiles(teamId)
|
||||||
dpchan := Srv.Store.User().GetDirectProfiles(c.Session.UserId)
|
dpchan := Srv.Store.User().GetDirectProfiles(post.UserId)
|
||||||
mchan := Srv.Store.Channel().GetMembers(post.ChannelId)
|
mchan := Srv.Store.Channel().GetMembers(post.ChannelId)
|
||||||
|
|
||||||
var profileMap map[string]*model.User
|
var profileMap map[string]*model.User
|
||||||
if result := <-pchan; result.Err != nil {
|
if result := <-pchan; result.Err != nil {
|
||||||
l4g.Error(utils.T("api.post.handle_post_events_and_forget.profiles.error"), c.TeamId, result.Err)
|
l4g.Error(utils.T("api.post.handle_post_events_and_forget.profiles.error"), teamId, result.Err)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
profileMap = result.Data.(map[string]*model.User)
|
profileMap = result.Data.(map[string]*model.User)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := <-dpchan; result.Err != nil {
|
if result := <-dpchan; result.Err != nil {
|
||||||
l4g.Error(utils.T("api.post.handle_post_events_and_forget.profiles.error"), c.TeamId, result.Err)
|
l4g.Error(utils.T("api.post.handle_post_events_and_forget.profiles.error"), teamId, result.Err)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
dps := result.Data.(map[string]*model.User)
|
dps := result.Data.(map[string]*model.User)
|
||||||
@@ -638,7 +616,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
go sendOutOfChannelMentions(c, post, profileMap, outOfChannelMentions)
|
go sendOutOfChannelMentions(teamId, post, profileMap, outOfChannelMentions)
|
||||||
|
|
||||||
// find which users in the channel are set up to always receive mobile notifications
|
// find which users in the channel are set up to always receive mobile notifications
|
||||||
for id := range members {
|
for id := range members {
|
||||||
@@ -658,9 +636,14 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
|
|||||||
|
|
||||||
mentionedUsersList := make([]string, 0, len(mentionedUserIds))
|
mentionedUsersList := make([]string, 0, len(mentionedUserIds))
|
||||||
|
|
||||||
|
T := utils.T
|
||||||
|
if result := <-Srv.Store.User().Get(post.UserId); result.Err == nil {
|
||||||
|
T = utils.TfuncWithFallback(result.Data.(*model.User).Locale)
|
||||||
|
}
|
||||||
|
|
||||||
senderName := ""
|
senderName := ""
|
||||||
if post.IsSystemMessage() {
|
if post.IsSystemMessage() {
|
||||||
senderName = c.T("system.message.name")
|
senderName = T("system.message.name")
|
||||||
} else if profile, ok := profileMap[post.UserId]; ok {
|
} else if profile, ok := profileMap[post.UserId]; ok {
|
||||||
senderName = profile.Username
|
senderName = profile.Username
|
||||||
}
|
}
|
||||||
@@ -681,7 +664,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
|
|||||||
}
|
}
|
||||||
|
|
||||||
if userAllowsEmails && status.Status != model.STATUS_ONLINE {
|
if userAllowsEmails && status.Status != model.STATUS_ONLINE {
|
||||||
sendNotificationEmail(c, post, profileMap[id], channel, team, senderName)
|
sendNotificationEmail(post, profileMap[id], channel, team, senderName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -733,7 +716,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message := model.NewWebSocketEvent(c.TeamId, post.ChannelId, post.UserId, model.WEBSOCKET_EVENT_POSTED)
|
message := model.NewWebSocketEvent(teamId, post.ChannelId, post.UserId, model.WEBSOCKET_EVENT_POSTED)
|
||||||
message.Add("post", post.ToJson())
|
message.Add("post", post.ToJson())
|
||||||
message.Add("channel_type", channel.Type)
|
message.Add("channel_type", channel.Type)
|
||||||
message.Add("channel_display_name", channel.DisplayName)
|
message.Add("channel_display_name", channel.DisplayName)
|
||||||
@@ -767,7 +750,7 @@ func sendNotifications(c *Context, post *model.Post, team *model.Team, channel *
|
|||||||
go Publish(message)
|
go Publish(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendNotificationEmail(c *Context, post *model.Post, user *model.User, channel *model.Channel, team *model.Team, senderName string) {
|
func sendNotificationEmail(post *model.Post, user *model.User, channel *model.Channel, team *model.Team, senderName string) {
|
||||||
// skip if inactive
|
// skip if inactive
|
||||||
if user.DeleteAt > 0 {
|
if user.DeleteAt > 0 {
|
||||||
return
|
return
|
||||||
@@ -785,7 +768,7 @@ func sendNotificationEmail(c *Context, post *model.Post, user *model.User, chann
|
|||||||
var bodyText string
|
var bodyText string
|
||||||
var subjectText string
|
var subjectText string
|
||||||
|
|
||||||
teamURL := c.GetSiteURL() + "/" + team.Name
|
teamURL := *utils.Cfg.ServiceSettings.SiteURL + "/" + team.Name
|
||||||
tm := time.Unix(post.CreateAt/1000, 0)
|
tm := time.Unix(post.CreateAt/1000, 0)
|
||||||
|
|
||||||
userLocale := utils.GetUserTranslations(user.Locale)
|
userLocale := utils.GetUserTranslations(user.Locale)
|
||||||
@@ -812,7 +795,7 @@ func sendNotificationEmail(c *Context, post *model.Post, user *model.User, chann
|
|||||||
subjectPage.Props["SiteName"] = utils.Cfg.TeamSettings.SiteName
|
subjectPage.Props["SiteName"] = utils.Cfg.TeamSettings.SiteName
|
||||||
|
|
||||||
bodyPage := utils.NewHTMLTemplate("post_body", user.Locale)
|
bodyPage := utils.NewHTMLTemplate("post_body", user.Locale)
|
||||||
bodyPage.Props["SiteURL"] = c.GetSiteURL()
|
bodyPage.Props["SiteURL"] = *utils.Cfg.ServiceSettings.SiteURL
|
||||||
bodyPage.Props["PostMessage"] = getMessageForNotification(post, userLocale)
|
bodyPage.Props["PostMessage"] = getMessageForNotification(post, userLocale)
|
||||||
bodyPage.Props["TeamLink"] = teamURL + "/pl/" + post.Id
|
bodyPage.Props["TeamLink"] = teamURL + "/pl/" + post.Id
|
||||||
bodyPage.Props["BodyText"] = bodyText
|
bodyPage.Props["BodyText"] = bodyText
|
||||||
@@ -935,7 +918,7 @@ func sendPushNotification(post *model.Post, user *model.User, channel *model.Cha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendOutOfChannelMentions(c *Context, post *model.Post, profiles map[string]*model.User, outOfChannelMentions map[string]bool) {
|
func sendOutOfChannelMentions(teamId string, post *model.Post, profiles map[string]*model.User, outOfChannelMentions map[string]bool) {
|
||||||
if len(outOfChannelMentions) == 0 {
|
if len(outOfChannelMentions) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -946,20 +929,25 @@ func sendOutOfChannelMentions(c *Context, post *model.Post, profiles map[string]
|
|||||||
}
|
}
|
||||||
sort.Strings(usernames)
|
sort.Strings(usernames)
|
||||||
|
|
||||||
|
T := utils.T
|
||||||
|
if result := <-Srv.Store.User().Get(post.UserId); result.Err == nil {
|
||||||
|
T = utils.TfuncWithFallback(result.Data.(*model.User).Locale)
|
||||||
|
}
|
||||||
|
|
||||||
var message string
|
var message string
|
||||||
if len(usernames) == 1 {
|
if len(usernames) == 1 {
|
||||||
message = c.T("api.post.check_for_out_of_channel_mentions.message.one", map[string]interface{}{
|
message = T("api.post.check_for_out_of_channel_mentions.message.one", map[string]interface{}{
|
||||||
"Username": usernames[0],
|
"Username": usernames[0],
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
message = c.T("api.post.check_for_out_of_channel_mentions.message.multiple", map[string]interface{}{
|
message = T("api.post.check_for_out_of_channel_mentions.message.multiple", map[string]interface{}{
|
||||||
"Usernames": strings.Join(usernames[:len(usernames)-1], ", "),
|
"Usernames": strings.Join(usernames[:len(usernames)-1], ", "),
|
||||||
"LastUsername": usernames[len(usernames)-1],
|
"LastUsername": usernames[len(usernames)-1],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
SendEphemeralPost(
|
SendEphemeralPost(
|
||||||
c.TeamId,
|
teamId,
|
||||||
post.UserId,
|
post.UserId,
|
||||||
&model.Post{
|
&model.Post{
|
||||||
ChannelId: post.ChannelId,
|
ChannelId: post.ChannelId,
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := CreateWebhookPost(c, channel.Id, text, overrideUsername, overrideIconUrl, parsedRequest.Props, webhookType); err != nil {
|
if _, err := CreateWebhookPost(hook.UserId, channel.Id, hook.TeamId, text, overrideUsername, overrideIconUrl, parsedRequest.Props, webhookType); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
3689
capi.out
Обычный файл
3689
capi.out
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
2091
cmodel.out
Обычный файл
2091
cmodel.out
Обычный файл
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Ссылка в новой задаче
Block a user