fix: chat accepts posts
This commit is contained in:
@@ -547,6 +547,12 @@ type AddAttachmentParams struct {
|
||||
Description *string
|
||||
SiteName *string
|
||||
ImageURL *string
|
||||
|
||||
// Shared entity: the durable reference plus a snapshot used only as a
|
||||
// fallback. Live data is re-resolved per viewer at read time.
|
||||
EntityType *string
|
||||
EntityID *string
|
||||
Snapshot []byte
|
||||
}
|
||||
|
||||
// AddAttachment persists one attachment. conversation_id is denormalized here
|
||||
@@ -557,17 +563,20 @@ func (r *ChatRepo) AddAttachment(ctx context.Context, p AddAttachmentParams) (*m
|
||||
INSERT INTO message_attachments
|
||||
(message_id, conversation_id, ord, kind, r2_key, mime, size_bytes,
|
||||
width, height, duration_ms, blurhash, file_name,
|
||||
url, title, description, site_name, image_url)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17)
|
||||
url, title, description, site_name, image_url,
|
||||
entity_type, entity_id, snapshot)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20)
|
||||
RETURNING id, message_id, ord, kind, mime, size_bytes, width, height,
|
||||
duration_ms, blurhash, file_name, url, title, description,
|
||||
site_name, image_url, created_at`,
|
||||
site_name, image_url, entity_type, entity_id, snapshot, created_at`,
|
||||
p.MessageID, p.ConversationID, p.Ord, p.Kind, p.R2Key, p.Mime, p.SizeBytes,
|
||||
p.Width, p.Height, p.DurationMs, p.Blurhash, p.FileName,
|
||||
p.URL, p.Title, p.Description, p.SiteName, p.ImageURL,
|
||||
p.EntityType, p.EntityID, p.Snapshot,
|
||||
).Scan(&a.ID, &a.MessageID, &a.Ord, &a.Kind, &a.Mime, &a.SizeBytes, &a.Width,
|
||||
&a.Height, &a.DurationMs, &a.Blurhash, &a.FileName, &a.URL, &a.Title,
|
||||
&a.Description, &a.SiteName, &a.ImageURL, &a.CreatedAt)
|
||||
&a.Description, &a.SiteName, &a.ImageURL,
|
||||
&a.EntityType, &a.EntityID, &a.Entity, &a.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("add attachment: %w", err)
|
||||
}
|
||||
@@ -583,7 +592,7 @@ func (r *ChatRepo) AttachmentsFor(ctx context.Context, messageIDs []string) (map
|
||||
rows, err := r.pg.Pool.Query(ctx, `
|
||||
SELECT id, message_id, ord, kind, mime, size_bytes, width, height,
|
||||
duration_ms, blurhash, file_name, url, title, description,
|
||||
site_name, image_url, created_at
|
||||
site_name, image_url, entity_type, entity_id, snapshot, created_at
|
||||
FROM message_attachments
|
||||
WHERE message_id = ANY($1)
|
||||
ORDER BY message_id, ord`, messageIDs)
|
||||
@@ -595,7 +604,8 @@ func (r *ChatRepo) AttachmentsFor(ctx context.Context, messageIDs []string) (map
|
||||
var a model.Attachment
|
||||
if err := rows.Scan(&a.ID, &a.MessageID, &a.Ord, &a.Kind, &a.Mime, &a.SizeBytes,
|
||||
&a.Width, &a.Height, &a.DurationMs, &a.Blurhash, &a.FileName, &a.URL,
|
||||
&a.Title, &a.Description, &a.SiteName, &a.ImageURL, &a.CreatedAt); err != nil {
|
||||
&a.Title, &a.Description, &a.SiteName, &a.ImageURL,
|
||||
&a.EntityType, &a.EntityID, &a.Entity, &a.CreatedAt); err != nil {
|
||||
return nil, fmt.Errorf("scan attachment: %w", err)
|
||||
}
|
||||
out[a.MessageID] = append(out[a.MessageID], a)
|
||||
@@ -640,7 +650,8 @@ func (r *ChatRepo) Gallery(ctx context.Context, conversationID, userID string, k
|
||||
rows, err := r.pg.Pool.Query(ctx, `
|
||||
SELECT a.id, a.message_id, a.ord, a.kind, a.mime, a.size_bytes, a.width,
|
||||
a.height, a.duration_ms, a.blurhash, a.file_name, a.url, a.title,
|
||||
a.description, a.site_name, a.image_url, a.created_at
|
||||
a.description, a.site_name, a.image_url,
|
||||
a.entity_type, a.entity_id, a.snapshot, a.created_at
|
||||
FROM message_attachments a
|
||||
JOIN messages m ON m.id = a.message_id
|
||||
WHERE a.conversation_id = $1
|
||||
@@ -661,7 +672,8 @@ func (r *ChatRepo) Gallery(ctx context.Context, conversationID, userID string, k
|
||||
var a model.Attachment
|
||||
if err := rows.Scan(&a.ID, &a.MessageID, &a.Ord, &a.Kind, &a.Mime, &a.SizeBytes,
|
||||
&a.Width, &a.Height, &a.DurationMs, &a.Blurhash, &a.FileName, &a.URL,
|
||||
&a.Title, &a.Description, &a.SiteName, &a.ImageURL, &a.CreatedAt); err != nil {
|
||||
&a.Title, &a.Description, &a.SiteName, &a.ImageURL,
|
||||
&a.EntityType, &a.EntityID, &a.Entity, &a.CreatedAt); err != nil {
|
||||
return nil, fmt.Errorf("scan gallery row: %w", err)
|
||||
}
|
||||
out = append(out, a)
|
||||
|
||||
Reference in New Issue
Block a user