diff options
author | George Goldberg <george@gberg.me> | 2017-06-28 15:26:38 +0100 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-06-28 07:26:38 -0700 |
commit | 37642a4f1e99b2cb89fa6969ad34a892fabab5be (patch) | |
tree | 5f11d2b29a19ef4a309395d3cbc3f0451696f3fa /app/channel.go | |
parent | fb2ef7708bfcf0f05adfe35b4bd3fe73fc73a54f (diff) | |
download | chat-37642a4f1e99b2cb89fa6969ad34a892fabab5be.tar.gz chat-37642a4f1e99b2cb89fa6969ad34a892fabab5be.tar.bz2 chat-37642a4f1e99b2cb89fa6969ad34a892fabab5be.zip |
PLT-6937: Bulk Importing of Direct/Group channels and posts. (#6761)
* PLT-6937: Bulk Importing of Direct/Group channels and posts.
* Show group/direct channels in sidebar.
Diffstat (limited to 'app/channel.go')
-rw-r--r-- | app/channel.go | 71 |
1 files changed, 48 insertions, 23 deletions
diff --git a/app/channel.go b/app/channel.go index 794379369..c9f89eb1a 100644 --- a/app/channel.go +++ b/app/channel.go @@ -160,6 +160,27 @@ func CreateChannel(channel *model.Channel, addMember bool) (*model.Channel, *mod } func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) { + if channel, err := createDirectChannel(userId, otherUserId); err != nil { + if err.Id == store.CHANNEL_EXISTS_ERROR { + return channel, nil + } else { + return nil, err + } + } else { + WaitForChannelMembership(channel.Id, userId) + + InvalidateCacheForUser(userId) + InvalidateCacheForUser(otherUserId) + + message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_DIRECT_ADDED, "", channel.Id, "", nil) + message.Add("teammate_id", otherUserId) + Publish(message) + + return channel, nil + } +} + +func createDirectChannel(userId string, otherUserId string) (*model.Channel, *model.AppError) { uc1 := Srv.Store.User().Get(userId) uc2 := Srv.Store.User().Get(otherUserId) @@ -173,22 +194,12 @@ func CreateDirectChannel(userId string, otherUserId string) (*model.Channel, *mo 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 + return result.Data.(*model.Channel), result.Err } else { return nil, result.Err } } else { channel := result.Data.(*model.Channel) - - WaitForChannelMembership(channel.Id, userId) - - InvalidateCacheForUser(userId) - InvalidateCacheForUser(otherUserId) - - message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_DIRECT_ADDED, "", channel.Id, "", nil) - message.Add("teammate_id", otherUserId) - Publish(message) - return channel, nil } } @@ -219,6 +230,30 @@ func WaitForChannelMembership(channelId string, userId string) { } func CreateGroupChannel(userIds []string, creatorId string) (*model.Channel, *model.AppError) { + if channel, err := createGroupChannel(userIds, creatorId); err != nil { + if err.Id == store.CHANNEL_EXISTS_ERROR { + return channel, nil + } else { + return nil, err + } + } else { + for _, userId := range userIds { + if userId == creatorId { + WaitForChannelMembership(channel.Id, creatorId) + } + + InvalidateCacheForUser(userId) + } + + message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_GROUP_ADDED, "", channel.Id, "", nil) + message.Add("teammate_ids", model.ArrayToJson(userIds)) + Publish(message) + + return channel, nil + } +} + +func createGroupChannel(userIds []string, creatorId string) (*model.Channel, *model.AppError) { if len(userIds) > model.CHANNEL_GROUP_MAX_USERS || len(userIds) < model.CHANNEL_GROUP_MIN_USERS { return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_size.app_error", nil, "", http.StatusBadRequest) } @@ -231,7 +266,7 @@ func CreateGroupChannel(userIds []string, creatorId string) (*model.Channel, *mo } if len(users) != len(userIds) { - return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids="+model.ArrayToJson(userIds), http.StatusBadRequest) + return nil, model.NewAppError("CreateGroupChannel", "api.channel.create_group.bad_user.app_error", nil, "user_ids=" + model.ArrayToJson(userIds), http.StatusBadRequest) } group := &model.Channel{ @@ -242,7 +277,7 @@ func CreateGroupChannel(userIds []string, creatorId string) (*model.Channel, *mo if result := <-Srv.Store.Channel().Save(group); result.Err != nil { if result.Err.Id == store.CHANNEL_EXISTS_ERROR { - return result.Data.(*model.Channel), nil + return result.Data.(*model.Channel), result.Err } else { return nil, result.Err } @@ -260,18 +295,8 @@ func CreateGroupChannel(userIds []string, creatorId string) (*model.Channel, *mo if result := <-Srv.Store.Channel().SaveMember(cm); result.Err != nil { return nil, result.Err } - - if user.Id == creatorId { - WaitForChannelMembership(group.Id, creatorId) - } - - InvalidateCacheForUser(user.Id) } - message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_GROUP_ADDED, "", group.Id, "", nil) - message.Add("teammate_ids", model.ArrayToJson(userIds)) - Publish(message) - return channel, nil } } |