summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-10-21 01:38:26 +0800
committerGitHub <noreply@github.com>2017-10-21 01:38:26 +0800
commit18ee37586027e5672446a6f23c05a8ccb2b35896 (patch)
treed915646e73a91b0082ecdf89b7a290291c0c9451 /app
parentcbb18479e9a4c410664535f6e0f5032d4261dfff (diff)
downloadchat-18ee37586027e5672446a6f23c05a8ccb2b35896.tar.gz
chat-18ee37586027e5672446a6f23c05a8ccb2b35896.tar.bz2
chat-18ee37586027e5672446a6f23c05a8ccb2b35896.zip
[PLT-7362] Option to add user to channel if mentioned user is not currently in the channel (#7619)
* Option to add user to channel if mentioned user is not currently in the channel * instead of link from server, just add component on client side to add channel member * change implementation using post.props * do clean up and add test * sanitize post.props['add_channel_member'] on post creation * move sanitize to app.CreatePost and also apply to app.UpdatePost
Diffstat (limited to 'app')
-rw-r--r--app/notification.go33
-rw-r--r--app/post.go4
2 files changed, 33 insertions, 4 deletions
diff --git a/app/notification.go b/app/notification.go
index e11218faa..bbd305b05 100644
--- a/app/notification.go
+++ b/app/notification.go
@@ -94,7 +94,7 @@ func (a *App) SendNotifications(post *model.Post, team *model.Team, channel *mod
outOfChannelMentions := result.Data.([]*model.User)
if channel.Type != model.CHANNEL_GROUP {
a.Go(func() {
- a.sendOutOfChannelMentions(sender, post, team.Id, outOfChannelMentions)
+ a.sendOutOfChannelMentions(sender, post, channel.Type, outOfChannelMentions)
})
}
}
@@ -723,7 +723,7 @@ func (a *App) getMobileAppSessions(userId string) ([]*model.Session, *model.AppE
}
}
-func (a *App) sendOutOfChannelMentions(sender *model.User, post *model.Post, teamId string, users []*model.User) *model.AppError {
+func (a *App) sendOutOfChannelMentions(sender *model.User, post *model.Post, channelType string, users []*model.User) *model.AppError {
if len(users) == 0 {
return nil
}
@@ -734,26 +734,51 @@ func (a *App) sendOutOfChannelMentions(sender *model.User, post *model.Post, tea
}
sort.Strings(usernames)
+ var userIds []string
+ for _, user := range users {
+ userIds = append(userIds, user.Id)
+ }
+
T := utils.GetUserTranslations(sender.Locale)
+ var localePhrase string
+ if channelType == model.CHANNEL_OPEN {
+ localePhrase = T("api.post.check_for_out_of_channel_mentions.link.public")
+ } else if channelType == model.CHANNEL_PRIVATE {
+ localePhrase = T("api.post.check_for_out_of_channel_mentions.link.private")
+ }
+
+ ephemeralPostId := model.NewId()
var message string
- if len(usernames) == 1 {
+ if len(users) == 1 {
message = T("api.post.check_for_out_of_channel_mentions.message.one", map[string]interface{}{
"Username": usernames[0],
+ "Phrase": localePhrase,
})
} else {
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],
+ "Phrase": localePhrase,
})
}
+ props := model.StringInterface{
+ model.PROPS_ADD_CHANNEL_MEMBER: model.StringInterface{
+ "post_id": ephemeralPostId,
+ "usernames": usernames,
+ "user_ids": userIds,
+ },
+ }
+
a.SendEphemeralPost(
post.UserId,
&model.Post{
+ Id: ephemeralPostId,
ChannelId: post.ChannelId,
Message: message,
CreateAt: post.CreateAt + 1,
+ Props: props,
},
)
diff --git a/app/post.go b/app/post.go
index f12866217..4d91e8122 100644
--- a/app/post.go
+++ b/app/post.go
@@ -104,6 +104,8 @@ func (a *App) CreatePostMissingChannel(post *model.Post, triggerWebhooks bool) (
}
func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhooks bool) (*model.Post, *model.AppError) {
+ post.SanitizeProps()
+
var pchan store.StoreChannel
if len(post.RootId) > 0 {
pchan = a.Srv.Store.Post().Get(post.RootId)
@@ -273,6 +275,8 @@ func (a *App) SendEphemeralPost(userId string, post *model.Post) *model.Post {
}
func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError) {
+ post.SanitizeProps()
+
var oldPost *model.Post
if result := <-a.Srv.Store.Post().Get(post.Id); result.Err != nil {
return nil, result.Err