Add store.AddReply

This commit is contained in:
Matt Low 2024-03-13 21:19:12 +00:00
parent db116660a5
commit ec1f326c2a

View File

@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"strings"
"time"
"git.mlow.ca/mlow/lmcli/pkg/lmcli/model"
sqids "github.com/sqids/sqids-go"
@ -26,6 +27,7 @@ type ConversationStore interface {
SaveMessage(message *model.Message) error
DeleteMessage(message *model.Message) error
UpdateMessage(message *model.Message) error
AddReply(conversation *model.Conversation, message model.Message) (*model.Message, error)
}
type SQLStore struct {
@ -119,3 +121,12 @@ func (s *SQLStore) LastMessage(conversation *model.Conversation) (*model.Message
err := s.db.Where("conversation_id = ?", conversation.ID).Last(&message).Error
return &message, err
}
// AddReply adds the given messages as a reply to the given conversation, can be
// used to easily copy a message associated with one conversation, to another
func (s *SQLStore) AddReply(c *model.Conversation, m model.Message) (*model.Message, error) {
m.ConversationID = c.ID
m.ID = 0
m.CreatedAt = time.Time{}
return &m, s.SaveMessage(&m)
}