summaryrefslogtreecommitdiffstats
path: root/api/channel.go
diff options
context:
space:
mode:
authorAlexander Smaga <smagaan@gmail.com>2016-10-17 15:12:56 +0300
committerChristopher Speller <crspeller@gmail.com>2016-10-17 08:12:56 -0400
commite7b25f4cd8b7d87b99153fd4a901d3f9f92d7b0d (patch)
tree9dfad731f8a4320e72e287732b50f46946ce76fe /api/channel.go
parentb1e2b23b882ec062cfd7209abeed417eb07e121e (diff)
downloadchat-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/channel.go')
-rw-r--r--api/channel.go23
1 files changed, 3 insertions, 20 deletions
diff --git a/api/channel.go b/api/channel.go
index 538c2d497..f40c979ca 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -137,36 +137,19 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) {
uc := Srv.Store.User().Get(otherUserId)
- channel := new(model.Channel)
-
- channel.DisplayName = ""
- channel.Name = model.GetDMNameFromIds(otherUserId, userId)
-
- channel.Header = ""
- channel.Type = model.CHANNEL_DIRECT
-
if uresult := <-uc; uresult.Err != nil {
return nil, model.NewLocAppError("CreateDirectChannel", "api.channel.create_direct_channel.invalid_user.app_error", nil, otherUserId)
}
- cm1 := &model.ChannelMember{
- UserId: userId,
- NotifyProps: model.GetDefaultChannelNotifyProps(),
- Roles: model.ROLE_CHANNEL_USER.Id,
- }
- cm2 := &model.ChannelMember{
- UserId: otherUserId,
- NotifyProps: model.GetDefaultChannelNotifyProps(),
- Roles: model.ROLE_CHANNEL_USER.Id,
- }
-
- if result := <-Srv.Store.Channel().SaveDirectChannel(channel, cm1, cm2); result.Err != nil {
+ if result := <-Srv.Store.Channel().CreateDirectChannel(userId, otherUserId); result.Err != nil {
if result.Err.Id == store.CHANNEL_EXISTS_ERROR {
return result.Data.(*model.Channel), nil
} else {
return nil, result.Err
}
} else {
+ channel := result.Data.(*model.Channel)
+
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_DIRECT_ADDED, "", channel.Id, "", nil)
message.Add("teammate_id", otherUserId)
go Publish(message)