diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2025-06-28 17:30:50 +0200 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2025-07-02 09:13:24 +0000 |
| commit | 8eca022fb899f81facfd753a892d33ad794e2846 (patch) | |
| tree | 38e3deed52689f467241e50c885c1c59582d75a0 /syz-cluster/pkg/service | |
| parent | d6d4e158298e946390e54d87a0a808a4238a24b4 (diff) | |
syz-cluster: make report reply tracking more flexible
Replace an UpdateReport() call with a RecordReply(). This will
eventually allow us to support the email sender implementations for
which we do not immediately know the MessageID of the reported message.
Diffstat (limited to 'syz-cluster/pkg/service')
| -rw-r--r-- | syz-cluster/pkg/service/discussion.go | 37 | ||||
| -rw-r--r-- | syz-cluster/pkg/service/report.go | 11 |
2 files changed, 22 insertions, 26 deletions
diff --git a/syz-cluster/pkg/service/discussion.go b/syz-cluster/pkg/service/discussion.go index f4be21fbd..8c17f1623 100644 --- a/syz-cluster/pkg/service/discussion.go +++ b/syz-cluster/pkg/service/discussion.go @@ -31,22 +31,10 @@ func NewDiscussionService(env *app.AppEnvironment) *DiscussionService { } func (d *DiscussionService) RecordReply(ctx context.Context, req *api.RecordReplyReq) (*api.RecordReplyResp, error) { - // First check if the message was a directl reply to the report. - report, err := d.reportRepo.FindByMessageID(ctx, req.Reporter, req.InReplyTo) + reportID, err := d.identifyReport(ctx, req) if err != nil { - return nil, fmt.Errorf("failed to search among the reports: %w", err) - } - var reportID string - if report != nil { - reportID = report.ID - } else { - // Now try to find a matching reply. - reportID, err = d.reportReplyRepo.FindParentReportID(ctx, req.Reporter, req.InReplyTo) - if err != nil { - return nil, fmt.Errorf("failed to search among the replies: %w", err) - } - } - if reportID == "" { + return nil, err + } else if reportID == "" { // We could not find the related report. return &api.RecordReplyResp{}, nil } @@ -78,3 +66,22 @@ func (d *DiscussionService) LastReply(ctx context.Context, reporter string) (*ap } return &api.LastReplyResp{}, nil } + +func (d *DiscussionService) identifyReport(ctx context.Context, req *api.RecordReplyReq) (string, error) { + // If the report ID was passed explicitly, just verify it. + if req.ReportID != "" { + report, err := d.reportRepo.GetByID(ctx, req.ReportID) + if err != nil { + return "", fmt.Errorf("failed to query the report: %w", err) + } else if report != nil { + return report.ID, nil + } + return "", nil + } + // Now try to find a matching reply. + reportID, err := d.reportReplyRepo.FindParentReportID(ctx, req.Reporter, req.InReplyTo) + if err != nil { + return "", fmt.Errorf("search among the replies failed: %w", err) + } + return reportID, nil +} diff --git a/syz-cluster/pkg/service/report.go b/syz-cluster/pkg/service/report.go index 5e6b6756a..4faef5b1e 100644 --- a/syz-cluster/pkg/service/report.go +++ b/syz-cluster/pkg/service/report.go @@ -30,17 +30,6 @@ func NewReportService(env *app.AppEnvironment) *ReportService { var ErrReportNotFound = errors.New("report is not found") -func (rs *ReportService) Update(ctx context.Context, id string, req *api.UpdateReportReq) error { - err := rs.reportRepo.Update(ctx, id, func(rep *db.SessionReport) error { - rep.MessageID = req.MessageID - return nil - }) - if errors.Is(err, db.ErrEntityNotFound) { - return ErrReportNotFound - } - return err -} - func (rs *ReportService) Confirm(ctx context.Context, id string) error { err := rs.reportRepo.Update(ctx, id, func(rep *db.SessionReport) error { if rep.ReportedAt.IsNull() { |
