// Create a new group mode message
188478
func NewGroupMod() *GroupMod {
	g := new(GroupMod)
	g.Header = NewOfp13Header()
	g.Header.Type = Type_GroupMod

	g.Command = OFPGC_ADD
	g.Type = OFPGT_ALL
	g.GroupId = 0
	g.Buckets = make([]Bucket, 0)
	return g
}
580520
func (api *API) HostGroupsCreate(hostGroups HostGroups) (err error) {
	response, err := api.CallWithError("hostgroup.create", hostGroups)
	if err != nil {
		return
	}

	result := response.Result.(map[string]interface{})
	groupids := result["groupids"].([]interface{})
	for i, id := range groupids {
		hostGroups[i].GroupId = id.(string)
	}
	return
}
445903
func NewGroup(name string, members []string) (*Group, error) {
	g, err := newGroup(name, members)
	if err != nil {
		return nil, err
	}
	return g, sendUpdate(g)
}
603812
func NewMessage(chatID int64, text string) MessageConfig {
	return MessageConfig{
		BaseChat: BaseChat{
			ChatID:           chatID,
			ReplyToMessageID: 0,
		},
		Text:                  text,
		DisableWebPagePreview: false,
	}
}
842048
func (api *Client) CreateGroupContext(ctx context.Context, group string) (*Group, error) {
	values := url.Values{
		"token": {api.token},
		"name":  {group},
	}

	response, err := api.groupRequest(ctx, "groups.create", values)
	if err != nil {
		return nil, err
	}
	return &response.Group, nil
}
640975
func (store *defaultGroupStore) newInBulkSetMsg(r io.Reader, l uint64) (uint64, error) {
	var bsm *groupBulkSetMsg
	select {
	case bsm = <-store.bulkSetState.inFreeMsgChan:
	default:
		// If there isn't a free groupBulkSetMsg, just read and discard the
		// incoming bulk-set message.
		left := l
		var sn int
		var err error
		for left > 0 {
			t := toss
			if left < uint64(len(t)) {
				t = t[:left]
			}
			sn, err = r.Read(t)
			left -= uint64(sn)
			if err != nil {
				atomic.AddInt32(&store.inBulkSetInvalids, 1)
				return l - left, err
			}
		}
		atomic.AddInt32(&store.inBulkSetDrops, 1)
		return l, nil
	}
	// If the message is obviously too short, just throw it away.
	if l < _GROUP_BULK_SET_MSG_HEADER_LENGTH+_GROUP_BULK_SET_MSG_MIN_ENTRY_LENGTH {
		store.bulkSetState.inFreeMsgChan <- bsm
		left := l
		var sn int
		var err error
		for left > 0 {
			t := toss
			if left < uint64(len(t)) {
				t = t[:left]
			}
			sn, err = r.Read(t)
			left -= uint64(sn)
			if err != nil {
				atomic.AddInt32(&store.inBulkSetInvalids, 1)
				return l - left, err
			}
		}
		atomic.AddInt32(&store.inBulkSetInvalids, 1)
		return l, nil
	}
	var n int
	var sn int
	var err error
	for n != len(bsm.header) {
		sn, err = r.Read(bsm.header[n:])
		n += sn
		if err != nil {
			store.bulkSetState.inFreeMsgChan <- bsm
			atomic.AddInt32(&store.inBulkSetInvalids, 1)
			return uint64(n), err
		}
	}
	l -= uint64(len(bsm.header))
	// TODO: I think we should cap the body size to store.bulkSetState.msgCap
	// but that also means that the inBulkSet worker will need to handle the
	// likely trailing truncated entry. Once all this is done, the overall
	// cluster should work even if the caps are set differently from node to
	// node (definitely not recommended though), as the bulk-set messages would
	// eventually start falling under the minimum cap as the front-end data is
	// tranferred and acknowledged. Anyway, I think this is needed in case
	// someone accidentally screws up the cap on one node, making it way too
	// big. Rather just have that one node abuse/run-out-of memory instead of
	// it causing every other node it sends bulk-set messages to also have
	// memory issues.
	if l > uint64(cap(bsm.body)) {
		bsm.body = make([]byte, l)
	}
	bsm.body = bsm.body[:l]
	n = 0
	for n != len(bsm.body) {
		sn, err = r.Read(bsm.body[n:])
		n += sn
		if err != nil {
			store.bulkSetState.inFreeMsgChan <- bsm
			atomic.AddInt32(&store.inBulkSetInvalids, 1)
			return uint64(len(bsm.header)) + uint64(n), err
		}
	}
	store.bulkSetState.inMsgChan <- bsm
	atomic.AddInt32(&store.inBulkSets, 1)
	return uint64(len(bsm.header)) + l, nil
}
767753
func (c *Command) addHelpGroup(showHelp func() error) *Group {
	var help struct {
		ShowHelp func() error `short:"h" long:"help" description:"Show this help message"`
	}

	help.ShowHelp = showHelp
	ret, _ := c.AddGroup("Help Options", "", &help)
	ret.isBuiltinHelp = true

	return ret
}
1123898
func (groups *Groups) AddGroup(newGroup *Group) {
	if newGroup.GroupID != "" {
		for key, group := range groups.Groups.Items {
			if group.GroupID == newGroup.GroupID {
				groups.Groups.Items[key] = newGroup
				return
			}
		}
	}

	newGroup.parent = groups

	groups.Groups.Items = append(groups.Groups.Items, newGroup)
}
884572
func (this *FcmClient) NewFcmRegIdsMsg(list []string, body interface{}) *FcmClient {
	this.newDevicesList(list)
	this.Message.Data = body

	return this

}
1301176
func (s *SendMessageBatchRequestEntry) SetMessageGroupId(v string) *SendMessageBatchRequestEntry {
	s.MessageGroupId = &v
	return s
}
748771
func (m *Message) FromGroup() bool {
	return m.Chat.Type == ChatGroup || m.Chat.Type == ChatSuperGroup
}
922255
func (c *Command) AddGroup(shortDescription string, longDescription string, data interface{}) (*Group, error) {
	group := newGroup(shortDescription, longDescription, data)

	group.parent = c

	if err := group.scanType(c.scanSubcommandHandler(group)); err != nil {
		return nil, err
	}

	c.groups = append(c.groups, group)
	return group, nil
}
84722
func Create(c *messagebird.Client, originator string, recipients []string, msgParams *Params) (*Message, error) {
	params, err := paramsForMessage(msgParams)
	if err != nil {
		return nil, err
	}

	params.Set("originator", originator)
	params.Set("recipients", strings.Join(recipients, ","))

	mmsMessage := &Message{}
	if err := c.Request(mmsMessage, http.MethodPost, path, params); err != nil {
		return nil, err
	}

	return mmsMessage, nil
}
1339865
func NewMessage(from, subject, body string) *Message {
	return NewMessageType(from, subject, body, "text/plain")
}
69803
func CreateMessage(c *messagebird.Client, conversationID string, req *MessageCreateRequest) (*Message, error) {
	uri := fmt.Sprintf("%s/%s/%s", path, conversationID, messagesPath)

	message := &Message{}
	if err := request(c, message, http.MethodPost, uri, req); err != nil {
		return nil, err
	}

	return message, nil
}
512399
func (api *Client) CreateMessages(data ...*CreateMessageData) ([]*CreateMessageResult, error) {
	result, _, err := api.makeRequest(http.MethodPost, api.concatUserPath(messagesPath), &[]*CreateMessageResult{}, data)
	if err != nil {
		return nil, err
	}
	list := *(result.(*[]*CreateMessageResult))
	for _, r := range list {
		r.ID = getIDFromLocation(r.Location)
	}
	return list, nil
}
855553
func NewMessage(payload string, agent string, collective string, msgType string, request *Message, choria *Framework) (msg *Message, err error) {
	id, err := choria.NewRequestID()
	if err != nil {
		return
	}

	msg = &Message{
		Payload:         payload,
		RequestID:       id,
		TTL:             choria.Config.TTL,
		DiscoveredHosts: []string{},
		SenderID:        choria.Config.Identity,
		CallerID:        choria.CallerID(),
		Filter:          protocol.NewFilter(),
		choria:          choria,
	}

	err = msg.SetType(msgType)
	if err != nil {
		return
	}

	if request == nil {
		msg.Agent = agent
		err = msg.SetCollective(collective)
		if err != nil {
			return
		}
	} else {
		msg.Request = request
		msg.Agent = request.Agent
		msg.replyTo = request.ReplyTo()
		msg.SetType("reply")
		err = msg.SetCollective(request.collective)
		if err != nil {
			return
		}
	}

	_, err = msg.Validate()

	return
}