// newMessageManager creates a new message manager.
// Calls into tsv have to be made asynchronously. Otherwise,
// it can lead to deadlocks.
778313
func newMessageManager(tsv TabletService, table *schema.Table, conns *connpool.Pool, postponeSema *sync2.Semaphore) *messageManager {
	mm := &messageManager{
		tsv:  tsv,
		name: table.Name,
		fieldResult: &sqltypes.Result{
			Fields: table.MessageInfo.Fields,
		},
		ackWaitTime:  table.MessageInfo.AckWaitDuration,
		purgeAfter:   table.MessageInfo.PurgeAfterDuration,
		batchSize:    table.MessageInfo.BatchSize,
		cache:        newCache(table.MessageInfo.CacheSize),
		pollerTicks:  timer.NewTimer(table.MessageInfo.PollInterval),
		purgeTicks:   timer.NewTimer(table.MessageInfo.PollInterval),
		conns:        conns,
		postponeSema: postponeSema,
	}
	mm.cond.L = &mm.mu

	columnList := buildSelectColumnList(table)
	mm.readByTimeNext = sqlparser.BuildParsedQuery(
		"select time_next, epoch, time_created, %s from %v where time_next < %a order by time_next desc limit %a",
		columnList, mm.name, ":time_next", ":max")
	mm.loadMessagesQuery = sqlparser.BuildParsedQuery(
		"select time_next, epoch, time_created, %s from %v where %a",
		columnList, mm.name, ":#pk")
	mm.ackQuery = sqlparser.BuildParsedQuery(
		"update %v set time_acked = %a, time_next = null where id in %a and time_acked is null",
		mm.name, ":time_acked", "::ids")
	mm.postponeQuery = sqlparser.BuildParsedQuery(
		"update %v set time_next = %a+(%a<<epoch), epoch = epoch+1 where id in %a and time_acked is null",
		mm.name, ":time_now", ":wait_time", "::ids")
	mm.purgeQuery = sqlparser.BuildParsedQuery(
		"delete from %v where time_scheduled < %a and time_acked is not null limit 500",
		mm.name, ":time_scheduled")
	return mm
}
929215
func NewEncrypterManager(key []byte, iv []byte) (manager *EncrypterManager, err error) {
	var encrypter Encrypter
	manager = new(EncrypterManager)
	switch len(iv) {
	case 12:
		// ChaCha20
		encrypter, err = crypto.NewChaChaEncrypter(key, iv)
	case 16:
		// AES
		encrypter, err = crypto.NewAESEncrypter(key, iv)
	default:
		return nil, ErrUnsupportedEncrypterType
	}
	manager.Encrypter = encrypter
	return
}
291598
func createMessage(message newMessage, sender, reference uint64, text, language string) error {
	message.ClearDefaults()
	message.SetSender(sender)
	message.SetReference(reference)
	message.SetText(html.EscapeString(text))
	return message.SetLanguage(language)
}
1200325
func newMessageView(g *libkb.GlobalContext, conversationID chat1.ConversationID, m chat1.MessageUnboxed) (mv messageView, err error) {
	state, err := m.State()
	if err != nil {
		return mv, fmt.Errorf("unexpected empty message")
	}
	switch state {
	case chat1.MessageUnboxedState_ERROR:
		return newMessageViewError(g, conversationID, m.Error())
	case chat1.MessageUnboxedState_OUTBOX:
		return newMessageViewOutbox(g, conversationID, m.Outbox())
	case chat1.MessageUnboxedState_VALID:
		return newMessageViewValid(g, conversationID, m.Valid())
	default:
		return mv, fmt.Errorf("unexpected message state: %v", state)
	}

}
678808
func NewMessage(seqNum uint32, items []FetchItem) *Message {
	msg := &Message{
		SeqNum:     seqNum,
		Items:      make(map[FetchItem]interface{}),
		Body:       make(map[*BodySectionName]Literal),
		itemsOrder: items,
	}

	for _, k := range items {
		msg.Items[k] = nil
	}

	return msg
}
563446
func NewMessageStore(db *channeldb.DB) (*MessageStore, error) {
	err := db.Update(func(tx *bbolt.Tx) error {
		_, err := tx.CreateBucketIfNotExists(messageStoreBucket)
		return err
	})
	if err != nil {
		return nil, fmt.Errorf("unable to create required buckets: %v",
			err)
	}

	return &MessageStore{db}, nil
}
1362902
func NewMessage(severity int, path string, err error) Message {
	return Message{Severity: severity, Path: path, Err: err}
}
817235
func NewMessageEdit(channelID string, messageID string) *MessageEdit {
	return &MessageEdit{
		Channel: channelID,
		ID:      messageID,
	}
}
37505
func NewMessagesSentTotalStatsHandler(sub Subsystem, vec *prometheus.CounterVec) *MessagesSentTotalStatsHandler {
	return &MessagesSentTotalStatsHandler{
		baseStatsHandler: baseStatsHandler{
			subsystem: sub,
			collector: vec,
		},
		vec: vec,
	}
}
528535
func New(msg string, a ...interface{}) Error {
	msg = fmt.Sprintf(msg, a...)
	return Error{
		error: errors.New(msg),
	}
}
1108848
func NewMessage(id uint64, phstr string) *Message {
	return &Message{id, Parts(phstr)}
}
715530
func (api *Client) CreateMessage(data *CreateMessageData) (string, error) {
	_, headers, err := api.makeRequest(http.MethodPost, api.concatUserPath(messagesPath), nil, data)
	if err != nil {
		return "", err
	}
	return getIDFromLocationHeader(headers), nil
}
898906
func (sc *Client) NewMessageFilter(ctx context.Context, criteria whisper.Criteria) (string, error) {
	var id string
	return id, sc.c.CallContext(ctx, &id, "shh_newMessageFilter", criteria)
}
368060
func NewDefaultMessage(p level.Priority, message string) Composer {
	m := &stringMessage{
		Message: message,
	}

	_ = m.SetPriority(p)

	return m
}
349735
func (c *Context) NewMessage() *OutgoingMessage {
	bot := c.Bot()
	msg := &OutgoingMessage{}
	msg.BotID = bot.ID
	msg.FromID = bot.ID
	msg.WebPreview = true
	if c.Chat.ID != 0 {
		msg.ChatID = c.Chat.ID
	} else {
		msg.ChatID = c.User.ID
	}
	msg.ctx = c
	return msg
}
214271
func NewMessage(sz int) *Message {
	var m *Message
	for i := range messageCache {
		if sz < messageCache[i].maxbody {
			m = messageCache[i].pool.Get().(*Message)
			break
		}
	}
	if m == nil {
		m = newMsg(sz)
	}

	m.refcnt = 1
	m.Body = m.bbuf
	m.Header = m.hbuf
	return m
}
244570
func New(c *choria.Framework, conn choria.PublishableConnector, logger *logrus.Entry) *Manager {
	r := &Manager{
		log:       logger.WithFields(logrus.Fields{"subsystem": "registration"}),
		choria:    c,
		cfg:       c.Config,
		connector: conn,
		datac:     make(chan *data.RegistrationItem, 1),
	}

	return r
}