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
53
internal/store/memory/ephemeral_report.go
Normal file
53
internal/store/memory/ephemeral_report.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package memory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"telesrv/internal/domain"
|
||||
)
|
||||
|
||||
type ephemeralReportKey struct {
|
||||
reporterUserID int64
|
||||
channelID int64
|
||||
messageID int
|
||||
option string
|
||||
commentHash [32]byte
|
||||
}
|
||||
|
||||
// EphemeralReportStore is the deterministic in-memory test implementation.
|
||||
type EphemeralReportStore struct {
|
||||
mu sync.Mutex
|
||||
reports map[ephemeralReportKey]domain.EphemeralAbuseReport
|
||||
}
|
||||
|
||||
func NewEphemeralReportStore() *EphemeralReportStore {
|
||||
return &EphemeralReportStore{reports: make(map[ephemeralReportKey]domain.EphemeralAbuseReport)}
|
||||
}
|
||||
|
||||
func (s *EphemeralReportStore) CreateEphemeralReport(_ context.Context, report domain.EphemeralAbuseReport) (bool, error) {
|
||||
if err := report.Validate(); err != nil {
|
||||
return false, err
|
||||
}
|
||||
key := ephemeralReportKey{
|
||||
reporterUserID: report.ReporterUserID, channelID: report.Evidence.Peer.ID,
|
||||
messageID: report.Evidence.MessageID, option: report.Option, commentHash: report.CommentHash,
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if _, exists := s.reports[key]; exists {
|
||||
return false, nil
|
||||
}
|
||||
s.reports[key] = report
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (s *EphemeralReportStore) Reports() []domain.EphemeralAbuseReport {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
out := make([]domain.EphemeralAbuseReport, 0, len(s.reports))
|
||||
for _, report := range s.reports {
|
||||
out = append(out, report)
|
||||
}
|
||||
return out
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue