forward chat msg fix

This commit is contained in:
Krispire Admin
2026-09-02 23:00:55 +05:30
parent 0fee56d272
commit 6633d0cca3
3 changed files with 134 additions and 0 deletions
+34
View File
@@ -1325,6 +1325,40 @@ func (r *ChatRepo) SaveSticker(ctx context.Context, userID, key, fromMessageID s
return nil
}
// CopyAttachments duplicates one message's attachments onto another.
//
// Forwarding needs this: a quote, a sticker, a photo or a shared post lives in
// an attachment row, not in the body, so copying only body+entities forwards
// an empty bubble.
//
// conversation_id is rewritten to the destination, which is what keeps access
// correct: reads authorize against the attachment's OWN conversation, so the
// copy is readable by the new thread's participants and the original stays
// scoped to the old one. Media rows point at the same stored object rather
// than duplicating it.
//
// Entity rows carry only their reference forward; visibility is re-resolved
// per viewer on every read, so forwarding a post cannot leak one.
func (r *ChatRepo) CopyAttachments(ctx context.Context, fromMessageID, toMessageID, toConversationID string) error {
_, err := r.pg.Pool.Exec(ctx, `
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,
entity_type, entity_id, snapshot)
SELECT $2, $3, ord, kind, r2_key, mime, size_bytes,
width, height, duration_ms, blurhash, file_name,
url, title, description, site_name, image_url,
entity_type, entity_id, snapshot
FROM message_attachments
WHERE message_id = $1
ORDER BY ord`, fromMessageID, toMessageID, toConversationID)
if err != nil {
return fmt.Errorf("copy attachments: %w", err)
}
return nil
}
// ReactionDetails lists everyone who reacted to one message, newest first.
//
// Separate from ReactionsFor: the grouped counts are what a thread renders,