From e6daafb0f8010f62dbce3f38e3b2c4a2e280621b Mon Sep 17 00:00:00 2001 From: Foysal Ahamed Date: Fri, 15 Nov 2024 21:43:02 +0100 Subject: [PATCH] :sparkles: Fix breaking changes due to lexicon changes --- api/chat/convodefs.go | 1 + api/ozone/moderationdefs.go | 72 +++++++++++++++++++++++++--- api/ozone/moderationqueryStatuses.go | 12 ++++- api/ozone/settingdefs.go | 23 +++++++++ api/ozone/settinglistOptions.go | 38 +++++++++++++++ api/ozone/settingremoveOptions.go | 31 ++++++++++++ api/ozone/settingupsertOption.go | 36 ++++++++++++++ automod/engine/reroute.go | 6 ++- automod/rules/mod_event.go | 2 + 9 files changed, 212 insertions(+), 9 deletions(-) create mode 100644 api/ozone/settingdefs.go create mode 100644 api/ozone/settinglistOptions.go create mode 100644 api/ozone/settingremoveOptions.go create mode 100644 api/ozone/settingupsertOption.go diff --git a/api/chat/convodefs.go b/api/chat/convodefs.go index 9e215d0fe..59193ce08 100644 --- a/api/chat/convodefs.go +++ b/api/chat/convodefs.go @@ -18,6 +18,7 @@ type ConvoDefs_ConvoView struct { LastMessage *ConvoDefs_ConvoView_LastMessage `json:"lastMessage,omitempty" cborgen:"lastMessage,omitempty"` Members []*ActorDefs_ProfileViewBasic `json:"members" cborgen:"members"` Muted bool `json:"muted" cborgen:"muted"` + Opened *bool `json:"opened,omitempty" cborgen:"opened,omitempty"` Rev string `json:"rev" cborgen:"rev"` UnreadCount int64 `json:"unreadCount" cborgen:"unreadCount"` } diff --git a/api/ozone/moderationdefs.go b/api/ozone/moderationdefs.go index 7c8e939c2..0033c9358 100644 --- a/api/ozone/moderationdefs.go +++ b/api/ozone/moderationdefs.go @@ -21,12 +21,25 @@ import ( type ModerationDefs_AccountEvent struct { LexiconTypeID string `json:"$type,const=tools.ozone.moderation.defs#accountEvent" cborgen:"$type,const=tools.ozone.moderation.defs#accountEvent"` // active: Indicates that the account has a repository which can be fetched from the host that emitted this event. - Active *bool `json:"active,omitempty" cborgen:"active,omitempty"` + Active bool `json:"active" cborgen:"active"` Comment *string `json:"comment,omitempty" cborgen:"comment,omitempty"` - Status string `json:"status" cborgen:"status"` + Status *string `json:"status,omitempty" cborgen:"status,omitempty"` Timestamp string `json:"timestamp" cborgen:"timestamp"` } +// ModerationDefs_AccountHosting is a "accountHosting" in the tools.ozone.moderation.defs schema. +// +// RECORDTYPE: ModerationDefs_AccountHosting +type ModerationDefs_AccountHosting struct { + LexiconTypeID string `json:"$type,const=tools.ozone.moderation.defs#accountHosting" cborgen:"$type,const=tools.ozone.moderation.defs#accountHosting"` + CreatedAt *string `json:"createdAt,omitempty" cborgen:"createdAt,omitempty"` + DeactivatedAt *string `json:"deactivatedAt,omitempty" cborgen:"deactivatedAt,omitempty"` + DeletedAt *string `json:"deletedAt,omitempty" cborgen:"deletedAt,omitempty"` + ReactivatedAt *string `json:"reactivatedAt,omitempty" cborgen:"reactivatedAt,omitempty"` + Status string `json:"status" cborgen:"status"` + UpdatedAt *string `json:"updatedAt,omitempty" cborgen:"updatedAt,omitempty"` +} + // ModerationDefs_BlobView is a "blobView" in the tools.ozone.moderation.defs schema. type ModerationDefs_BlobView struct { Cid string `json:"cid" cborgen:"cid"` @@ -180,8 +193,8 @@ type ModerationDefs_ModEventMute struct { type ModerationDefs_ModEventMuteReporter struct { LexiconTypeID string `json:"$type,const=tools.ozone.moderation.defs#modEventMuteReporter" cborgen:"$type,const=tools.ozone.moderation.defs#modEventMuteReporter"` Comment *string `json:"comment,omitempty" cborgen:"comment,omitempty"` - // durationInHours: Indicates how long the account should remain muted. - DurationInHours int64 `json:"durationInHours" cborgen:"durationInHours"` + // durationInHours: Indicates how long the account should remain muted. Falsy value here means a permanent mute. + DurationInHours *int64 `json:"durationInHours,omitempty" cborgen:"durationInHours,omitempty"` } // ModerationDefs_ModEventReport is a "modEventReport" in the tools.ozone.moderation.defs schema. @@ -735,6 +748,17 @@ type ModerationDefs_RecordEvent struct { Timestamp string `json:"timestamp" cborgen:"timestamp"` } +// ModerationDefs_RecordHosting is a "recordHosting" in the tools.ozone.moderation.defs schema. +// +// RECORDTYPE: ModerationDefs_RecordHosting +type ModerationDefs_RecordHosting struct { + LexiconTypeID string `json:"$type,const=tools.ozone.moderation.defs#recordHosting" cborgen:"$type,const=tools.ozone.moderation.defs#recordHosting"` + CreatedAt *string `json:"createdAt,omitempty" cborgen:"createdAt,omitempty"` + DeletedAt *string `json:"deletedAt,omitempty" cborgen:"deletedAt,omitempty"` + Status string `json:"status" cborgen:"status"` + UpdatedAt *string `json:"updatedAt,omitempty" cborgen:"updatedAt,omitempty"` +} + // ModerationDefs_RecordView is a "recordView" in the tools.ozone.moderation.defs schema. // // RECORDTYPE: ModerationDefs_RecordView @@ -826,8 +850,9 @@ type ModerationDefs_SubjectStatusView struct { // comment: Sticky comment on the subject. Comment *string `json:"comment,omitempty" cborgen:"comment,omitempty"` // createdAt: Timestamp referencing the first moderation status impacting event was emitted on the subject - CreatedAt string `json:"createdAt" cborgen:"createdAt"` - Id int64 `json:"id" cborgen:"id"` + CreatedAt string `json:"createdAt" cborgen:"createdAt"` + Hosting *ModerationDefs_SubjectStatusView_Hosting `json:"hosting,omitempty" cborgen:"hosting,omitempty"` + Id int64 `json:"id" cborgen:"id"` // lastAppealedAt: Timestamp referencing when the author of the subject appealed a moderation action LastAppealedAt *string `json:"lastAppealedAt,omitempty" cborgen:"lastAppealedAt,omitempty"` LastReportedAt *string `json:"lastReportedAt,omitempty" cborgen:"lastReportedAt,omitempty"` @@ -846,6 +871,41 @@ type ModerationDefs_SubjectStatusView struct { UpdatedAt string `json:"updatedAt" cborgen:"updatedAt"` } +type ModerationDefs_SubjectStatusView_Hosting struct { + ModerationDefs_AccountHosting *ModerationDefs_AccountHosting + ModerationDefs_RecordHosting *ModerationDefs_RecordHosting +} + +func (t *ModerationDefs_SubjectStatusView_Hosting) MarshalJSON() ([]byte, error) { + if t.ModerationDefs_AccountHosting != nil { + t.ModerationDefs_AccountHosting.LexiconTypeID = "tools.ozone.moderation.defs#accountHosting" + return json.Marshal(t.ModerationDefs_AccountHosting) + } + if t.ModerationDefs_RecordHosting != nil { + t.ModerationDefs_RecordHosting.LexiconTypeID = "tools.ozone.moderation.defs#recordHosting" + return json.Marshal(t.ModerationDefs_RecordHosting) + } + return nil, fmt.Errorf("cannot marshal empty enum") +} +func (t *ModerationDefs_SubjectStatusView_Hosting) UnmarshalJSON(b []byte) error { + typ, err := util.TypeExtract(b) + if err != nil { + return err + } + + switch typ { + case "tools.ozone.moderation.defs#accountHosting": + t.ModerationDefs_AccountHosting = new(ModerationDefs_AccountHosting) + return json.Unmarshal(b, t.ModerationDefs_AccountHosting) + case "tools.ozone.moderation.defs#recordHosting": + t.ModerationDefs_RecordHosting = new(ModerationDefs_RecordHosting) + return json.Unmarshal(b, t.ModerationDefs_RecordHosting) + + default: + return nil + } +} + type ModerationDefs_SubjectStatusView_Subject struct { AdminDefs_RepoRef *comatprototypes.AdminDefs_RepoRef RepoStrongRef *comatprototypes.RepoStrongRef diff --git a/api/ozone/moderationqueryStatuses.go b/api/ozone/moderationqueryStatuses.go index 969d77e9d..bbe0351f5 100644 --- a/api/ozone/moderationqueryStatuses.go +++ b/api/ozone/moderationqueryStatuses.go @@ -21,6 +21,11 @@ type ModerationQueryStatuses_Output struct { // appealed: Get subjects in unresolved appealed status // collections: If specified, subjects belonging to the given collections will be returned. When subjectType is set to 'account', this will be ignored. // comment: Search subjects by keyword from comments +// hostingDeletedAfter: Search subjects where the associated record/account was deleted after a given timestamp +// hostingDeletedBefore: Search subjects where the associated record/account was deleted before a given timestamp +// hostingStatuses: Search subjects by the status of the associated record/account +// hostingUpdatedAfter: Search subjects where the associated record/account was updated after a given timestamp +// hostingUpdatedBefore: Search subjects where the associated record/account was updated before a given timestamp // includeAllUserRecords: All subjects, or subjects from given 'collections' param, belonging to the account specified in the 'subject' param will be returned. // includeMuted: By default, we don't include muted subjects in the results. Set this to true to include them. // lastReviewedBy: Get all subject statuses that were reviewed by a specific moderator @@ -33,7 +38,7 @@ type ModerationQueryStatuses_Output struct { // subject: The subject to get the status for. // subjectType: If specified, subjects of the given type (account or record) will be returned. When this is set to 'account' the 'collections' parameter will be ignored. When includeAllUserRecords or subject is set, this will be ignored. // takendown: Get subjects that were taken down -func ModerationQueryStatuses(ctx context.Context, c *xrpc.Client, appealed bool, collections []string, comment string, cursor string, excludeTags []string, ignoreSubjects []string, includeAllUserRecords bool, includeMuted bool, lastReviewedBy string, limit int64, onlyMuted bool, reportedAfter string, reportedBefore string, reviewState string, reviewedAfter string, reviewedBefore string, sortDirection string, sortField string, subject string, subjectType string, tags []string, takendown bool) (*ModerationQueryStatuses_Output, error) { +func ModerationQueryStatuses(ctx context.Context, c *xrpc.Client, appealed bool, collections []string, comment string, cursor string, excludeTags []string, hostingDeletedAfter string, hostingDeletedBefore string, hostingStatuses []string, hostingUpdatedAfter string, hostingUpdatedBefore string, ignoreSubjects []string, includeAllUserRecords bool, includeMuted bool, lastReviewedBy string, limit int64, onlyMuted bool, reportedAfter string, reportedBefore string, reviewState string, reviewedAfter string, reviewedBefore string, sortDirection string, sortField string, subject string, subjectType string, tags []string, takendown bool) (*ModerationQueryStatuses_Output, error) { var out ModerationQueryStatuses_Output params := map[string]interface{}{ @@ -42,6 +47,11 @@ func ModerationQueryStatuses(ctx context.Context, c *xrpc.Client, appealed bool, "comment": comment, "cursor": cursor, "excludeTags": excludeTags, + "hostingDeletedAfter": hostingDeletedAfter, + "hostingDeletedBefore": hostingDeletedBefore, + "hostingStatuses": hostingStatuses, + "hostingUpdatedAfter": hostingUpdatedAfter, + "hostingUpdatedBefore": hostingUpdatedBefore, "ignoreSubjects": ignoreSubjects, "includeAllUserRecords": includeAllUserRecords, "includeMuted": includeMuted, diff --git a/api/ozone/settingdefs.go b/api/ozone/settingdefs.go new file mode 100644 index 000000000..ccf334413 --- /dev/null +++ b/api/ozone/settingdefs.go @@ -0,0 +1,23 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +package ozone + +// schema: tools.ozone.setting.defs + +import ( + "github.com/bluesky-social/indigo/lex/util" +) + +// SettingDefs_Option is a "option" in the tools.ozone.setting.defs schema. +type SettingDefs_Option struct { + CreatedAt *string `json:"createdAt,omitempty" cborgen:"createdAt,omitempty"` + CreatedBy string `json:"createdBy" cborgen:"createdBy"` + Description *string `json:"description,omitempty" cborgen:"description,omitempty"` + Did string `json:"did" cborgen:"did"` + Key string `json:"key" cborgen:"key"` + LastUpdatedBy string `json:"lastUpdatedBy" cborgen:"lastUpdatedBy"` + ManagerRole *string `json:"managerRole,omitempty" cborgen:"managerRole,omitempty"` + Scope string `json:"scope" cborgen:"scope"` + UpdatedAt *string `json:"updatedAt,omitempty" cborgen:"updatedAt,omitempty"` + Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` +} diff --git a/api/ozone/settinglistOptions.go b/api/ozone/settinglistOptions.go new file mode 100644 index 000000000..8fbdadeca --- /dev/null +++ b/api/ozone/settinglistOptions.go @@ -0,0 +1,38 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +package ozone + +// schema: tools.ozone.setting.listOptions + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// SettingListOptions_Output is the output of a tools.ozone.setting.listOptions call. +type SettingListOptions_Output struct { + Cursor *string `json:"cursor,omitempty" cborgen:"cursor,omitempty"` + Options []*SettingDefs_Option `json:"options" cborgen:"options"` +} + +// SettingListOptions calls the XRPC method "tools.ozone.setting.listOptions". +// +// keys: Filter for only the specified keys. Ignored if prefix is provided +// prefix: Filter keys by prefix +func SettingListOptions(ctx context.Context, c *xrpc.Client, cursor string, keys []string, limit int64, prefix string, scope string) (*SettingListOptions_Output, error) { + var out SettingListOptions_Output + + params := map[string]interface{}{ + "cursor": cursor, + "keys": keys, + "limit": limit, + "prefix": prefix, + "scope": scope, + } + if err := c.Do(ctx, xrpc.Query, "", "tools.ozone.setting.listOptions", params, nil, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/ozone/settingremoveOptions.go b/api/ozone/settingremoveOptions.go new file mode 100644 index 000000000..5171bb617 --- /dev/null +++ b/api/ozone/settingremoveOptions.go @@ -0,0 +1,31 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +package ozone + +// schema: tools.ozone.setting.removeOptions + +import ( + "context" + + "github.com/bluesky-social/indigo/xrpc" +) + +// SettingRemoveOptions_Input is the input argument to a tools.ozone.setting.removeOptions call. +type SettingRemoveOptions_Input struct { + Keys []string `json:"keys" cborgen:"keys"` + Scope string `json:"scope" cborgen:"scope"` +} + +// SettingRemoveOptions_Output is the output of a tools.ozone.setting.removeOptions call. +type SettingRemoveOptions_Output struct { +} + +// SettingRemoveOptions calls the XRPC method "tools.ozone.setting.removeOptions". +func SettingRemoveOptions(ctx context.Context, c *xrpc.Client, input *SettingRemoveOptions_Input) (*SettingRemoveOptions_Output, error) { + var out SettingRemoveOptions_Output + if err := c.Do(ctx, xrpc.Procedure, "application/json", "tools.ozone.setting.removeOptions", nil, input, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/api/ozone/settingupsertOption.go b/api/ozone/settingupsertOption.go new file mode 100644 index 000000000..c7d12cffb --- /dev/null +++ b/api/ozone/settingupsertOption.go @@ -0,0 +1,36 @@ +// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT. + +package ozone + +// schema: tools.ozone.setting.upsertOption + +import ( + "context" + + "github.com/bluesky-social/indigo/lex/util" + "github.com/bluesky-social/indigo/xrpc" +) + +// SettingUpsertOption_Input is the input argument to a tools.ozone.setting.upsertOption call. +type SettingUpsertOption_Input struct { + Description *string `json:"description,omitempty" cborgen:"description,omitempty"` + Key string `json:"key" cborgen:"key"` + ManagerRole *string `json:"managerRole,omitempty" cborgen:"managerRole,omitempty"` + Scope string `json:"scope" cborgen:"scope"` + Value *util.LexiconTypeDecoder `json:"value" cborgen:"value"` +} + +// SettingUpsertOption_Output is the output of a tools.ozone.setting.upsertOption call. +type SettingUpsertOption_Output struct { + Option *SettingDefs_Option `json:"option" cborgen:"option"` +} + +// SettingUpsertOption calls the XRPC method "tools.ozone.setting.upsertOption". +func SettingUpsertOption(ctx context.Context, c *xrpc.Client, input *SettingUpsertOption_Input) (*SettingUpsertOption_Output, error) { + var out SettingUpsertOption_Output + if err := c.Do(ctx, xrpc.Procedure, "application/json", "tools.ozone.setting.upsertOption", nil, input, &out); err != nil { + return nil, err + } + + return &out, nil +} diff --git a/automod/engine/reroute.go b/automod/engine/reroute.go index 21d2a0298..5eeec2fe0 100644 --- a/automod/engine/reroute.go +++ b/automod/engine/reroute.go @@ -14,8 +14,8 @@ func (eng *Engine) RerouteAccountEventToOzone(c context.Context, e *comatproto.S ModerationDefs_AccountEvent: &toolsozone.ModerationDefs_AccountEvent{ Comment: &comment, Timestamp: e.Time, - Status: *e.Status, - Active: &e.Active, + Status: e.Status, + Active: e.Active, }, }, toolsozone.ModerationEmitEvent_Input_Subject{ AdminDefs_RepoRef: &comatproto.AdminDefs_RepoRef{ @@ -118,6 +118,7 @@ func (eng *Engine) IsDuplicatingEvent(ctx context.Context, event toolsozone.Mode xrpcc, nil, nil, + []string{}, "", time.Now().Add(-time.Minute*5).Format(time.RFC3339), "", @@ -131,6 +132,7 @@ func (eng *Engine) IsDuplicatingEvent(ctx context.Context, event toolsozone.Mode nil, "", eventSubject, + "", []string{eventType}, ) diff --git a/automod/rules/mod_event.go b/automod/rules/mod_event.go index f21ab2995..88708e57d 100644 --- a/automod/rules/mod_event.go +++ b/automod/rules/mod_event.go @@ -2,6 +2,7 @@ package rules import ( "github.com/bluesky-social/indigo/automod" + "github.com/labstack/gommon/log" ) var _ automod.OzoneEventRuleFunc = CountModEventRule @@ -14,6 +15,7 @@ func CountModEventRule(c *automod.OzoneEventContext) error { } c.Increment("mod-event", counterKey) + log.Print("mod-event", counterKey, c.GetCount("mod-event", counterKey, automod.PeriodTotal)) return nil }