From ec1f326c2a61ffac30805d0e39353077549c9bc2 Mon Sep 17 00:00:00 2001 From: Matt Low Date: Wed, 13 Mar 2024 21:19:12 +0000 Subject: [PATCH] Add store.AddReply --- pkg/lmcli/store.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/lmcli/store.go b/pkg/lmcli/store.go index f0b3b98..3cecb86 100644 --- a/pkg/lmcli/store.go +++ b/pkg/lmcli/store.go @@ -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) +}