Exemplo n.º 1
0
func (cs BoltChannelStore) SaveMember(member *model.ChannelMember) StoreChannel {
	storeChannel := make(StoreChannel)
	go func() {
		var result StoreResult
		items, err := cs.channelMembersBucket.Items()
		if err != nil {
			result.Err = model.NewAppError("BoltChannelStore.SaveMember", "Error while save members", "")
		} else {
			id := len(items) + 1
			if len(items) <= 0 {
				member.Role = model.CHANNEL_ROLE_ADMIN
			}
			err := cs.channelMembersBucket.Put([]byte(strconv.Itoa(id)), []byte(member.ToJson()))
			if err != nil {
				result.Err = model.NewAppError("BoltChannelStore.SaveMember", "Error while save members", "")
			} else {
				result.Data = member
			}
		}

		storeChannel <- result
		close(storeChannel)
		return
	}()
	return storeChannel
}
Exemplo 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
}