Refactoring direct channel creation to use transaction to avaoid state where channel is created without both users

Этот коммит содержится в:
Christopher Speller
2015-10-22 09:31:27 -04:00
родитель e0cda76eb8
Коммит 6cc3bfe7a9
4 изменённых файлов: 261 добавлений и 69 удалений

Просмотреть файл

@@ -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
cm1 := &model.ChannelMember{
UserId: c.Session.UserId,
Roles: model.CHANNEL_ROLE_ADMIN,
NotifyProps: model.GetDefaultChannelNotifyProps(),
}
cm2 := &model.ChannelMember{
UserId: otherUserId,
Roles: "",
NotifyProps: model.GetDefaultChannelNotifyProps(),
}
if result := <-Srv.Store.Channel().SaveDirectChannel(channel, cm1, cm2); result.Err != nil {
return nil, result.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
}
return sc, nil
return result.Data.(*model.Channel), nil
}
}