Add store.AddReply
This commit is contained in:
parent
db116660a5
commit
ec1f326c2a
@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.mlow.ca/mlow/lmcli/pkg/lmcli/model"
|
"git.mlow.ca/mlow/lmcli/pkg/lmcli/model"
|
||||||
sqids "github.com/sqids/sqids-go"
|
sqids "github.com/sqids/sqids-go"
|
||||||
@ -26,6 +27,7 @@ type ConversationStore interface {
|
|||||||
SaveMessage(message *model.Message) error
|
SaveMessage(message *model.Message) error
|
||||||
DeleteMessage(message *model.Message) error
|
DeleteMessage(message *model.Message) error
|
||||||
UpdateMessage(message *model.Message) error
|
UpdateMessage(message *model.Message) error
|
||||||
|
AddReply(conversation *model.Conversation, message model.Message) (*model.Message, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type SQLStore struct {
|
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
|
err := s.db.Where("conversation_id = ?", conversation.ID).Last(&message).Error
|
||||||
return &message, err
|
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)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user