summaryrefslogtreecommitdiffstats
path: root/api/post.go
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2016-02-03 15:21:03 -0500
committerhmhealey <harrisonmhealey@gmail.com>2016-02-04 11:38:58 -0500
commitf935be121c0b6764e1e30f1b5d4eb6e78137fa36 (patch)
treed0d2907d9fd394d786a59b774261adae4afca44c /api/post.go
parent70c3715b963cd8f2a710f8909f23696f9de7fcc7 (diff)
downloadchat-f935be121c0b6764e1e30f1b5d4eb6e78137fa36.tar.gz
chat-f935be121c0b6764e1e30f1b5d4eb6e78137fa36.tar.bz2
chat-f935be121c0b6764e1e30f1b5d4eb6e78137fa36.zip
Added helper methods to send ephemeral messages to specific users
Diffstat (limited to 'api/post.go')
-rw-r--r--api/post.go54
1 files changed, 35 insertions, 19 deletions
diff --git a/api/post.go b/api/post.go
index e7c3f6913..a2018bdbd 100644
--- a/api/post.go
+++ b/api/post.go
@@ -747,34 +747,27 @@ func checkForOutOfChannelMentions(c *Context, post *model.Post, channel *model.C
}
sort.Strings(usernames)
- var messageText string
+ var message string
if len(usernames) == 1 {
- messageText = c.T("api.post.check_for_out_of_channel_mentions.message.one", map[string]interface{}{
+ message = c.T("api.post.check_for_out_of_channel_mentions.message.one", map[string]interface{}{
"Username": usernames[0],
})
} else {
- messageText = c.T("api.post.check_for_out_of_channel_mentions.message.multiple", map[string]interface{}{
+ message = c.T("api.post.check_for_out_of_channel_mentions.message.multiple", map[string]interface{}{
"Usernames": strings.Join(usernames[:len(usernames)-1], ", "),
"LastUsername": usernames[len(usernames)-1],
})
}
- // create an ephemeral post that will be sent only to the sender of this original post and not stored in the DB
- warningPost := model.Post{
- Id: model.NewId(),
- ChannelId: post.ChannelId,
- Message: messageText,
- Type: model.POST_EPHEMERAL,
- CreateAt: post.CreateAt + 1,
- Props: model.StringInterface{},
- Filenames: []string{},
- }
-
- message := model.NewMessage(c.Session.TeamId, channel.Id, post.UserId, model.ACTION_EPHEMERAL_MESSAGE)
- message.Add("post", warningPost.ToJson())
- message.Add("channel_type", channel.Type)
-
- PublishAndForget(message)
+ SendEphemeralPost(
+ c.Session.TeamId,
+ post.UserId,
+ &model.Post{
+ ChannelId: post.ChannelId,
+ Message: message,
+ CreateAt: post.CreateAt + 1,
+ },
+ )
}
// Gets a list of users that were mentioned in a given post that aren't in the channel that the post was made in
@@ -803,6 +796,29 @@ func getOutOfChannelMentions(post *model.Post, allProfiles map[string]*model.Use
return mentioned
}
+func SendEphemeralPost(teamId, userId string, post *model.Post) {
+ post.Type = model.POST_EPHEMERAL
+
+ // fill in fields which haven't been specified which have sensible defaults
+ if post.Id == "" {
+ post.Id = model.NewId()
+ }
+ if post.CreateAt == 0 {
+ post.CreateAt = model.GetMillis()
+ }
+ if post.Props == nil {
+ post.Props = model.StringInterface{}
+ }
+ if post.Filenames == nil {
+ post.Filenames = []string{}
+ }
+
+ message := model.NewMessage(teamId, post.ChannelId, userId, model.ACTION_EPHEMERAL_MESSAGE)
+ message.Add("post", post.ToJson())
+
+ PublishAndForget(message)
+}
+
func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
post := model.PostFromJson(r.Body)