func (cs BoltChannelStore) SaveDirectChannel(channel *model.Channel, mb1 *model.ChannelMember, mb2 *model.ChannelMember) StoreChannel { storeChannel := make(StoreChannel) go func() { var result StoreResult channel.PreSave() mb1.ChannelId = channel.Id mb2.ChannelId = channel.Id err := cs.channelsBucket.Put([]byte(channel.Id), []byte(channel.ToJson())) if err != nil { result.Err = model.NewAppError("BoltChannelStore.SaveDirectChannel", "Error while save channel", "") } else { items, err := cs.channelMembersBucket.Items() if err != nil { result.Err = model.NewAppError("BoltChannelStore.SaveDirectChannel", "Error while save channel", "") } count := len(items) err = cs.channelMembersBucket.Put([]byte(strconv.Itoa(count+1)), []byte(mb1.ToJson())) if err != nil { result.Err = model.NewAppError("BoltChannelStore.SaveDirectChannel", "Error while save channel member", "") } err = cs.channelMembersBucket.Put([]byte(strconv.Itoa(count+2)), []byte(mb2.ToJson())) if err != nil { result.Err = model.NewAppError("BoltChannelStore.SaveDirectChannel", "Error while save channel member", "") } } result.Data = channel storeChannel <- result close(storeChannel) return }() return storeChannel }
func (cs BoltChannelStore) Save(channel *model.Channel) StoreChannel { storeChannel := make(StoreChannel) go func() { var result StoreResult if channel.Type == model.CHANNEL_DIRECT { result.Err = model.NewAppError("BoltChannelStore.Save", "Use Direct channel save to save direct channel", "") } else { channel.PreSave() err := cs.channelsBucket.Put([]byte(channel.Id), []byte(channel.ToJson())) if err != nil { result.Err = model.NewAppError("BoltChannelStore.Save", "Error while save", "") } else { result.Data = channel } } storeChannel <- result close(storeChannel) return }() return storeChannel }