summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-10-22 09:31:27 -0400
committerChristopher Speller <crspeller@gmail.com>2015-10-22 09:31:27 -0400
commit6cc3bfe7a96e66d27a5b7f08bc1dc15a742b36ab (patch)
tree4254a3b2b102815212ceb9c9e43717eb967d290c /api
parente0cda76eb816da8fda9c42d67197be71201c242e (diff)
downloadchat-6cc3bfe7a96e66d27a5b7f08bc1dc15a742b36ab.tar.gz
chat-6cc3bfe7a96e66d27a5b7f08bc1dc15a742b36ab.tar.bz2
chat-6cc3bfe7a96e66d27a5b7f08bc1dc15a742b36ab.zip
Refactoring direct channel creation to use transaction to avaoid state where channel is created without both users
Diffstat (limited to 'api')
-rw-r--r--api/channel.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/api/channel.go b/api/channel.go
index 70f7eba4b..9c7ac053b 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -131,16 +131,21 @@ func CreateDirectChannel(c *Context, otherUserId string) (*model.Channel, *model
return nil, model.NewAppError("CreateDirectChannel", "Invalid other user id ", otherUserId)
}
- if sc, err := CreateChannel(c, channel, true); err != nil {
- return nil, err
- } else {
- cm := &model.ChannelMember{ChannelId: sc.Id, UserId: otherUserId, Roles: "", NotifyProps: model.GetDefaultChannelNotifyProps()}
-
- if cmresult := <-Srv.Store.Channel().SaveMember(cm); cmresult.Err != nil {
- return nil, cmresult.Err
- }
+ cm1 := &model.ChannelMember{
+ UserId: c.Session.UserId,
+ Roles: model.CHANNEL_ROLE_ADMIN,
+ NotifyProps: model.GetDefaultChannelNotifyProps(),
+ }
+ cm2 := &model.ChannelMember{
+ UserId: otherUserId,
+ Roles: "",
+ NotifyProps: model.GetDefaultChannelNotifyProps(),
+ }
- return sc, nil
+ if result := <-Srv.Store.Channel().SaveDirectChannel(channel, cm1, cm2); result.Err != nil {
+ return nil, result.Err
+ } else {
+ return result.Data.(*model.Channel), nil
}
}