Ejemplo n.º 1
0
func (cs BoltChannelStore) Update(channel *model.Channel) StoreChannel {
	storeChannel := make(StoreChannel)

	go func() {
		var result StoreResult
		channelJson := channel.ToJson()
		err := cs.channelsBucket.Put([]byte(channel.Id), []byte(channelJson))
		if err != nil {
			result.Err = model.NewAppError("BoltChannelStore.Update", "Error while update", "")
		} else {
			result.Data = channelJson
		}
		storeChannel <- result
		close(storeChannel)
		return
	}()

	return storeChannel
}
Ejemplo n.º 2
0
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
}
Ejemplo n.º 3
0
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
}