diff options
author | Alexander Smaga <smagaan@gmail.com> | 2016-10-17 15:12:56 +0300 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-10-17 08:12:56 -0400 |
commit | e7b25f4cd8b7d87b99153fd4a901d3f9f92d7b0d (patch) | |
tree | 9dfad731f8a4320e72e287732b50f46946ce76fe /api/webhook.go | |
parent | b1e2b23b882ec062cfd7209abeed417eb07e121e (diff) | |
download | chat-e7b25f4cd8b7d87b99153fd4a901d3f9f92d7b0d.tar.gz chat-e7b25f4cd8b7d87b99153fd4a901d3f9f92d7b0d.tar.bz2 chat-e7b25f4cd8b7d87b99153fd4a901d3f9f92d7b0d.zip |
GH-4187 Create direct channel during incoming webhook if not exists (#4206)
Diffstat (limited to 'api/webhook.go')
-rw-r--r-- | api/webhook.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/api/webhook.go b/api/webhook.go index 2995a4a9d..2daac03f2 100644 --- a/api/webhook.go +++ b/api/webhook.go @@ -412,6 +412,7 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) { var channel *model.Channel var cchan store.StoreChannel + var directUserId string if len(channelName) != 0 { if channelName[0] == '@' { @@ -419,7 +420,8 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) { c.Err = model.NewLocAppError("incomingWebhook", "web.incoming_webhook.user.app_error", nil, "err="+result.Err.Message) return } else { - channelName = model.GetDMNameFromIds(result.Data.(*model.User).Id, hook.UserId) + directUserId = result.Data.(*model.User).Id + channelName = model.GetDMNameFromIds(directUserId, hook.UserId) } } else if channelName[0] == '#' { channelName = channelName[1:] @@ -433,7 +435,16 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) { overrideUsername := parsedRequest.Username overrideIconUrl := parsedRequest.IconURL - if result := <-cchan; result.Err != nil { + result := <-cchan + if result.Err != nil && result.Err.Id == store.MISSING_CHANNEL_ERROR && directUserId != "" { + newChanResult := <-Srv.Store.Channel().CreateDirectChannel(directUserId, hook.UserId) + if newChanResult.Err != nil { + c.Err = model.NewLocAppError("incomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+newChanResult.Err.Message) + return + } else { + channel = newChanResult.Data.(*model.Channel) + } + } else if result.Err != nil { c.Err = model.NewLocAppError("incomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+result.Err.Message) return } else { |