working file sharing
This commit is contained in:
@@ -60,7 +60,8 @@ func Init(ctx context.Context) {
|
||||
sender_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
receiver_id UUID NOT NULL REFERENCES user_connections(id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
content TEXT NOT NULL
|
||||
content TEXT NOT NULL,
|
||||
attached_file TEXT NOT NULL DEFAULT ''
|
||||
)
|
||||
`)
|
||||
if err != nil {
|
||||
@@ -182,21 +183,21 @@ func ConnectionUpdateState(ctx context.Context, conn *types.Connection) error {
|
||||
func ConnectionMessageSave(ctx context.Context, message *types.Message) error {
|
||||
if message.Id != (uuid.UUID{}) {
|
||||
_, err := dbConn.Exec(ctx, `
|
||||
INSERT INTO direct_messages (id, sender_id, receiver_id, created_at, content) VALUES ($1, $2, $3, $4, $5)
|
||||
`, message.Id, message.Sender, message.Receiver, message.CreatedAt, message.Content)
|
||||
INSERT INTO direct_messages (id, sender_id, receiver_id, created_at, content, attached_file) VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`, message.Id, message.Sender, message.Receiver, message.CreatedAt, message.Content, message.AttachedFile)
|
||||
return err
|
||||
}
|
||||
return dbConn.QueryRow(ctx, `
|
||||
INSERT INTO direct_messages (sender_id, receiver_id, created_at, content) VALUES ($1, $2, $3, $4)
|
||||
INSERT INTO direct_messages (sender_id, receiver_id, created_at, content, attached_file) VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id
|
||||
`, message.Sender, message.Receiver, message.CreatedAt, message.Content).Scan(&message.Id)
|
||||
`, message.Sender, message.Receiver, message.CreatedAt, message.Content, message.AttachedFile).Scan(&message.Id)
|
||||
}
|
||||
|
||||
func ConnectionGetMessagesBefore(ctx context.Context, before time.Time, connection uuid.UUID, cap uint32) ([]*types.Message, error) {
|
||||
rows, err := dbConn.Query(ctx, `
|
||||
SELECT id, sender_id, receiver_id, created_at, content
|
||||
SELECT id, sender_id, receiver_id, created_at, content, attached_file
|
||||
FROM (
|
||||
SELECT id, sender_id, receiver_id, created_at, content
|
||||
SELECT id, sender_id, receiver_id, created_at, content, attached_file
|
||||
FROM direct_messages
|
||||
WHERE receiver_id = $1
|
||||
AND created_at < $2
|
||||
@@ -213,7 +214,7 @@ func ConnectionGetMessagesBefore(ctx context.Context, before time.Time, connecti
|
||||
messages := make([]*types.Message, 0, cap)
|
||||
for rows.Next() {
|
||||
msg := &types.Message{}
|
||||
if err = rows.Scan(&msg.Id, &msg.Sender, &msg.Receiver, &msg.CreatedAt, &msg.Content); err != nil {
|
||||
if err = rows.Scan(&msg.Id, &msg.Sender, &msg.Receiver, &msg.CreatedAt, &msg.Content, &msg.AttachedFile); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
messages = append(messages, msg)
|
||||
|
||||
Reference in New Issue
Block a user