diff options
Diffstat (limited to 'app/webhook.go')
-rw-r--r-- | app/webhook.go | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/app/webhook.go b/app/webhook.go index e92805608..29f642ea8 100644 --- a/app/webhook.go +++ b/app/webhook.go @@ -490,48 +490,43 @@ func HandleIncomingWebhook(hookId string, req *model.IncomingWebhookRequest) *mo var channel *model.Channel var cchan store.StoreChannel - var directUserId string if len(channelName) != 0 { if channelName[0] == '@' { if result := <-Srv.Store.User().GetByUsername(channelName[1:]); result.Err != nil { return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.user.app_error", nil, "err="+result.Err.Message, http.StatusBadRequest) } else { - directUserId = result.Data.(*model.User).Id - channelName = model.GetDMNameFromIds(directUserId, hook.UserId) + if ch, err := GetDirectChannel(hook.UserId, result.Data.(*model.User).Id); err != nil { + return err + } else { + channel = ch + } } } else if channelName[0] == '#' { - channelName = channelName[1:] + cchan = Srv.Store.Channel().GetByName(hook.TeamId, channelName[1:], true) + } else { + cchan = Srv.Store.Channel().GetByName(hook.TeamId, channelName, true) } - - cchan = Srv.Store.Channel().GetByName(hook.TeamId, channelName, true) } else { cchan = Srv.Store.Channel().Get(hook.ChannelId, true) } - overrideUsername := req.Username - overrideIconUrl := req.IconURL - - 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 { - return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+newChanResult.Err.Message, http.StatusBadRequest) + if channel == nil { + result := <-cchan + if result.Err != nil { + return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+result.Err.Message, result.Err.StatusCode) } else { - channel = newChanResult.Data.(*model.Channel) - InvalidateCacheForUser(directUserId) - InvalidateCacheForUser(hook.UserId) + channel = result.Data.(*model.Channel) } - } else if result.Err != nil { - return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.channel.app_error", nil, "err="+result.Err.Message, result.Err.StatusCode) - } else { - channel = result.Data.(*model.Channel) } if channel.Type != model.CHANNEL_OPEN && !HasPermissionToChannel(hook.UserId, channel.Id, model.PERMISSION_READ_CHANNEL) { return model.NewAppError("HandleIncomingWebhook", "web.incoming_webhook.permissions.app_error", nil, "", http.StatusForbidden) } + overrideUsername := req.Username + overrideIconUrl := req.IconURL + if _, err := CreateWebhookPost(hook.UserId, hook.TeamId, channel.Id, text, overrideUsername, overrideIconUrl, req.Props, webhookType); err != nil { return err } |