Skip to content

Commit ecb0923

Browse files
committed
feat: post event to posthog on map report
1 parent 1627d40 commit ecb0923

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

services/map-service/api/v3/intnl/server_map.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ func (s *server) ReportMap(ctx context.Context, request ReportMapRequestObject)
715715
return nil, fmt.Errorf("failed to fetch map: %w", err)
716716
}
717717

718+
var shouldDislike = false
718719
reportParams := db.InsertMapReportParams{
719720
MapID: request.MapId,
720721
PlayerID: request.Body.Reporter,
@@ -723,6 +724,10 @@ func (s *server) ReportMap(ctx context.Context, request ReportMapRequestObject)
723724
}
724725
for i, category := range request.Body.Categories {
725726
reportParams.Categories[i] = mapReportCategoryFromAPI(category)
727+
728+
if model.ReportCategoriesToDislike[reportParams.Categories[i]] == true {
729+
shouldDislike = true
730+
}
726731
}
727732

728733
// Save the report to the database immediately for future lookup
@@ -732,12 +737,25 @@ func (s *server) ReportMap(ctx context.Context, request ReportMapRequestObject)
732737
}
733738
s.log.Infow("created map report #"+strconv.Itoa(report.ID), "report", report)
734739

735-
// Submitting a report always results in disliking the map
736-
err = s.store.UpsertMapRating(ctx, report.MapID, report.PlayerID, int(model.RatingStateDisliked))
737-
if err != nil {
738-
// This is non fatal, just log it
739-
s.log.Errorw("failed to dislike map during report", "error", err)
740+
if shouldDislike {
741+
// Submitting a report that is dislikable should always results in disliking the map
742+
err = s.store.UpsertMapRating(ctx, report.MapID, report.PlayerID, int(model.RatingStateDisliked))
743+
if err != nil {
744+
// This is non fatal, just log it
745+
s.log.Errorw("failed to dislike map during report", "error", err)
746+
}
747+
}
748+
749+
reportEvent := model.MapReportedEvent{
750+
PlayerId: request.Body.Reporter,
751+
MapId: request.MapId,
752+
Categories: make([]string, len(request.Body.Categories)),
753+
Comment: request.Body.Comment,
754+
}
755+
for i, category := range request.Body.Categories {
756+
reportEvent.Categories[i] = string(category)
740757
}
758+
go s.metrics.Write(reportEvent)
741759

742760
return ReportMap200Response{}, nil
743761
}

services/map-service/internal/pkg/model/map.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@ var ReportCategoryNameMap = []string{
268268
"Spam", "Troll Map", "Crashes/Unloadable",
269269
}
270270

271+
var ReportCategoriesToDislike = map[int]bool{
272+
MapReportDiscrimination: true,
273+
MapReportExplicitContent: true,
274+
MapReportSpam: true,
275+
MapReportTroll: true,
276+
MapReportDCMA: true,
277+
}
278+
271279
type MapSortOrder = string
272280

273281
const (

services/map-service/internal/pkg/model/metrics.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ type MapCompletedEvent struct {
3232
Playtime int `mapstructure:"playtime"`
3333
Difficulty string `mapstructure:"difficulty"`
3434
}
35+
36+
type MapReportedEvent struct {
37+
PlayerId string `mapstructure:"player_id"`
38+
MapId string `mapstructure:"map_id"`
39+
Categories []string `mapstructure:"reason"`
40+
Comment *string `mapstructure:"comment"`
41+
}

0 commit comments

Comments
 (0)