feat: sync ephemeral transient messages
Sync telesrv 570ccf8 (feat(ephemeral): implement Layer 228 transient messages). Skipped telesrv docs changes per public sync rules; normalized the public appearance seed label.
This commit is contained in:
parent
3f78eaa2c6
commit
f49c817def
53 changed files with 5793 additions and 112 deletions
49
internal/store/postgres/ephemeral_report.go
Normal file
49
internal/store/postgres/ephemeral_report.go
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"telesrv/internal/domain"
|
||||
"telesrv/internal/store/postgres/sqlcgen"
|
||||
)
|
||||
|
||||
// EphemeralReportStore persists the low-volume abuse-review evidence path.
|
||||
// The hot ephemeral send/edit/delete path remains entirely in Redis.
|
||||
type EphemeralReportStore struct {
|
||||
db sqlcgen.DBTX
|
||||
}
|
||||
|
||||
func NewEphemeralReportStore(db sqlcgen.DBTX) *EphemeralReportStore {
|
||||
return &EphemeralReportStore{db: db}
|
||||
}
|
||||
|
||||
func (s *EphemeralReportStore) CreateEphemeralReport(ctx context.Context, report domain.EphemeralAbuseReport) (bool, error) {
|
||||
if s == nil || s.db == nil {
|
||||
return false, fmt.Errorf("ephemeral report store is not configured")
|
||||
}
|
||||
if err := report.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
evidence, err := json.Marshal(report.Evidence)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("marshal ephemeral report evidence: %w", err)
|
||||
}
|
||||
tag, err := s.db.Exec(ctx, `
|
||||
INSERT INTO ephemeral_abuse_reports (
|
||||
reporter_user_id, channel_id, ephemeral_message_id, sender_user_id,
|
||||
receiver_user_id, report_option, report_comment, comment_hash,
|
||||
payload_hash, evidence, created_at
|
||||
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10::jsonb, $11)
|
||||
ON CONFLICT (
|
||||
reporter_user_id, channel_id, ephemeral_message_id, report_option, comment_hash
|
||||
) DO NOTHING
|
||||
`, report.ReporterUserID, report.Evidence.Peer.ID, report.Evidence.MessageID,
|
||||
report.Evidence.SenderUserID, report.Evidence.ReceiverUserID,
|
||||
report.Option, report.Comment, report.CommentHash[:], report.Evidence.PayloadHash[:], evidence, report.CreatedAt)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("insert ephemeral abuse report: %w", err)
|
||||
}
|
||||
return tag.RowsAffected() == 1, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue