@atproto/ozone 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +4 -0
- package/dist/api/moderation/queryEvents.d.ts.map +1 -1
- package/dist/api/moderation/queryEvents.js +2 -1
- package/dist/api/moderation/queryEvents.js.map +1 -1
- package/dist/api/moderation/queryStatuses.js +2 -2
- package/dist/api/moderation/queryStatuses.js.map +1 -1
- package/dist/db/migrations/20261012T000000000Z-inbox-notification-categories.d.ts +4 -0
- package/dist/db/migrations/20261012T000000000Z-inbox-notification-categories.d.ts.map +1 -0
- package/dist/db/migrations/20261012T000000000Z-inbox-notification-categories.js +25 -0
- package/dist/db/migrations/20261012T000000000Z-inbox-notification-categories.js.map +1 -0
- package/dist/db/migrations/index.d.ts +1 -0
- package/dist/db/migrations/index.d.ts.map +1 -1
- package/dist/db/migrations/index.js +1 -0
- package/dist/db/migrations/index.js.map +1 -1
- package/dist/db/schema/inbox_notification_preference.d.ts +5 -1
- package/dist/db/schema/inbox_notification_preference.d.ts.map +1 -1
- package/dist/db/schema/inbox_notification_preference.js.map +1 -1
- package/dist/inbox/appeal-outcome.d.ts +8 -0
- package/dist/inbox/appeal-outcome.d.ts.map +1 -0
- package/dist/inbox/appeal-outcome.js +53 -0
- package/dist/inbox/appeal-outcome.js.map +1 -0
- package/dist/inbox/appeal.d.ts +2 -0
- package/dist/inbox/appeal.d.ts.map +1 -1
- package/dist/inbox/appeal.js +25 -1
- package/dist/inbox/appeal.js.map +1 -1
- package/dist/inbox/notification-visibility.d.ts +2 -2
- package/dist/inbox/notification-visibility.d.ts.map +1 -1
- package/dist/inbox/notification-visibility.js +5 -3
- package/dist/inbox/notification-visibility.js.map +1 -1
- package/dist/inbox/notifications.d.ts +1 -0
- package/dist/inbox/notifications.d.ts.map +1 -1
- package/dist/inbox/notifications.js +2 -2
- package/dist/inbox/notifications.js.map +1 -1
- package/dist/inbox/preferences.d.ts +1 -1
- package/dist/inbox/preferences.d.ts.map +1 -1
- package/dist/inbox/preferences.js +24 -7
- package/dist/inbox/preferences.js.map +1 -1
- package/dist/inbox/reports.d.ts.map +1 -1
- package/dist/inbox/reports.js +5 -1
- package/dist/inbox/reports.js.map +1 -1
- package/dist/inbox/subject-batch.d.ts.map +1 -1
- package/dist/inbox/subject-batch.js +31 -10
- package/dist/inbox/subject-batch.js.map +1 -1
- package/dist/inbox/subjects.d.ts.map +1 -1
- package/dist/inbox/subjects.js +6 -3
- package/dist/inbox/subjects.js.map +1 -1
- package/dist/lexicons/app/bsky/actor/defs.defs.d.ts +1 -0
- package/dist/lexicons/app/bsky/actor/defs.defs.d.ts.map +1 -1
- package/dist/lexicons/app/bsky/actor/defs.defs.js +3 -0
- package/dist/lexicons/app/bsky/actor/defs.defs.js.map +1 -1
- package/dist/lexicons/app/bsky/actor/link.defs.d.ts +15 -0
- package/dist/lexicons/app/bsky/actor/link.defs.d.ts.map +1 -1
- package/dist/lexicons/app/bsky/actor/link.defs.js +5 -0
- package/dist/lexicons/app/bsky/actor/link.defs.js.map +1 -1
- package/dist/lexicons/tools/ozone/inbox/defs.defs.d.ts +22 -1
- package/dist/lexicons/tools/ozone/inbox/defs.defs.d.ts.map +1 -1
- package/dist/lexicons/tools/ozone/inbox/defs.defs.js +10 -1
- package/dist/lexicons/tools/ozone/inbox/defs.defs.js.map +1 -1
- package/dist/lexicons/tools/ozone/inbox/getNotificationPreferences.defs.d.ts +1 -0
- package/dist/lexicons/tools/ozone/inbox/getNotificationPreferences.defs.d.ts.map +1 -1
- package/dist/lexicons/tools/ozone/inbox/getNotificationPreferences.defs.js +1 -0
- package/dist/lexicons/tools/ozone/inbox/getNotificationPreferences.defs.js.map +1 -1
- package/dist/lexicons/tools/ozone/inbox/putNotificationPreferences.defs.d.ts +7 -2
- package/dist/lexicons/tools/ozone/inbox/putNotificationPreferences.defs.d.ts.map +1 -1
- package/dist/lexicons/tools/ozone/inbox/putNotificationPreferences.defs.js +4 -1
- package/dist/lexicons/tools/ozone/inbox/putNotificationPreferences.defs.js.map +1 -1
- package/dist/mod-service/index.d.ts +4 -1
- package/dist/mod-service/index.d.ts.map +1 -1
- package/dist/mod-service/index.js +10 -4
- package/dist/mod-service/index.js.map +1 -1
- package/dist/mod-service/report.d.ts +4 -0
- package/dist/mod-service/report.d.ts.map +1 -1
- package/dist/mod-service/report.js +43 -1
- package/dist/mod-service/report.js.map +1 -1
- package/dist/report/activity.d.ts.map +1 -1
- package/dist/report/activity.js +5 -2
- package/dist/report/activity.js.map +1 -1
- package/dist/report/handle-report-update.d.ts.map +1 -1
- package/dist/report/handle-report-update.js +7 -0
- package/dist/report/handle-report-update.js.map +1 -1
- package/dist/report/notifications.d.ts.map +1 -1
- package/dist/report/notifications.js +15 -4
- package/dist/report/notifications.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @atproto/ozone
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#5642](https://github.com/bluesky-social/atproto/pull/5642) [`2db2f9d`](https://github.com/bluesky-social/atproto/commit/2db2f9d9cc619906d4cde3284d512c87bf26b9e7) Thanks [@foysalit](https://github.com/foysalit)! - Expose approved or denied outcomes on resolved moderation inbox appeals and snapshot outcomes in appeal resolution notifications. Preserve unknown historical outcomes, record no-action denials, and close targeted appeal reports when reversing a takedown.
|
|
8
|
+
|
|
9
|
+
Resolve outcomes only after indexed lookups select each subject's latest appeal, keeping page hydration independent of appeal history.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#5640](https://github.com/bluesky-social/atproto/pull/5640) [`b05cf65`](https://github.com/bluesky-social/atproto/commit/b05cf65ad24cbe76d79ce40795be3e5f5e1af67b) Thanks [@foysalit](https://github.com/foysalit)! - Cancel queryEvents and queryStatuses listing SQL when the HTTP client disconnects.
|
|
14
|
+
|
|
15
|
+
## 0.8.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [#5641](https://github.com/bluesky-social/atproto/pull/5641) [`7184ed7`](https://github.com/bluesky-social/atproto/commit/7184ed74423e1d976ceb9e57310d2983c90c2f18) Thanks [@foysalit](https://github.com/foysalit)! - Replace the moderation inbox global push preference with independent reports, account, and labels preferences. Support atomic partial updates and preserve existing opt-outs through nullable category columns that inherit the stored global value. Clients must switch to the category fields.
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#5644](https://github.com/bluesky-social/atproto/pull/5644) [`dff8990`](https://github.com/bluesky-social/atproto/commit/dff8990f2fd409a0e78309f64e18e7ad36befcaf) Thanks [@foysalit](https://github.com/foysalit)! - Keep moderation inbox report pages, actioned subject lists and notification visibility checks bounded to the viewer's post-cutoff rows at scale
|
|
24
|
+
|
|
25
|
+
- [#5597](https://github.com/bluesky-social/atproto/pull/5597) [`8c05fa0`](https://github.com/bluesky-social/atproto/commit/8c05fa00d32e912bc75f4481274ca74ff4c8e6b0) Thanks [@foysalit](https://github.com/foysalit)! - Associate email events with reports targeted by ID without changing report status. Other email report targeting modes remain no-ops.
|
|
26
|
+
|
|
3
27
|
## 0.7.0
|
|
4
28
|
|
|
5
29
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -11,6 +11,10 @@ Wildcard patterns in `com.atproto.label.queryLabels` are disabled by default, in
|
|
|
11
11
|
|
|
12
12
|
Set `OZONE_LABEL_QUERY_WILDCARDS_ENABLED=true` and restart the API to restore wildcard support. Unset or `false` disables it.
|
|
13
13
|
|
|
14
|
+
## Moderation query cancellation
|
|
15
|
+
|
|
16
|
+
`queryEvents` and `queryStatuses` cancel their listing SQL when the HTTP client disconnects, using Kysely's `cancel query` abort strategy. Kysely uses a separate PostgreSQL connection for cancellation and holds the listing connection until SQL and cancellation finish. This adds no query deadline.
|
|
17
|
+
|
|
14
18
|
## Moderation inbox standing
|
|
15
19
|
|
|
16
20
|
Set `NEXT_PUBLIC_STRIKE_SUSPENSION_CONFIG` to the same value used by Ozone UI, for example `4:72,8:168,12:336,16:Infinity`. Each entry maps a strike count to suspension hours; `Infinity` represents a permanent suspension. The backend retains the full map and uses the second and third thresholds, sorted by strike count, for `warning` and `atRisk`. The first tier does not change standing. With no configuration, standing derives from the account's enforcement and restrictions; strike thresholds are disabled. Invalid entries fail configuration at startup.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryEvents.d.ts","sourceRoot":"","sources":["../../../src/api/moderation/queryEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAIlD,MAAM,CAAC,OAAO,WAAW,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"queryEvents.d.ts","sourceRoot":"","sources":["../../../src/api/moderation/queryEvents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAIlD,MAAM,CAAC,OAAO,WAAW,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,QAoEvD"}
|
|
@@ -3,11 +3,12 @@ import { getEventType } from '../util.js';
|
|
|
3
3
|
export default function (server, ctx) {
|
|
4
4
|
server.add(tools.ozone.moderation.queryEvents, {
|
|
5
5
|
auth: ctx.authVerifier.modOrAdminToken,
|
|
6
|
-
handler: async ({ params }) => {
|
|
6
|
+
handler: async ({ params, signal }) => {
|
|
7
7
|
const { subject, limit = 50, cursor, sortDirection = 'desc', types, includeAllUserRecords = false, hasComment, comment, createdBy, createdAfter, createdBefore, addedLabels = [], removedLabels = [], addedTags = [], removedTags = [], reportTypes, collections = [], subjectType, policies, modTool, ageAssuranceState, batchId, withStrike, } = params;
|
|
8
8
|
const db = ctx.db;
|
|
9
9
|
const modService = ctx.modService(db);
|
|
10
10
|
const results = await modService.getEvents({
|
|
11
|
+
signal,
|
|
11
12
|
types: types?.length ? types.map(getEventType) : [],
|
|
12
13
|
subject,
|
|
13
14
|
createdBy,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryEvents.js","sourceRoot":"","sources":["../../../src/api/moderation/queryEvents.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,MAAM,CAAC,OAAO,WAAW,MAAc,EAAE,GAAe;IACtD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE;QAC7C,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,eAAe;QACtC,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"queryEvents.js","sourceRoot":"","sources":["../../../src/api/moderation/queryEvents.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,MAAM,CAAC,OAAO,WAAW,MAAc,EAAE,GAAe;IACtD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE;QAC7C,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,eAAe;QACtC,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE;YACpC,MAAM,EACJ,OAAO,EACP,KAAK,GAAG,EAAE,EACV,MAAM,EACN,aAAa,GAAG,MAAM,EACtB,KAAK,EACL,qBAAqB,GAAG,KAAK,EAC7B,UAAU,EACV,OAAO,EACP,SAAS,EACT,YAAY,EACZ,aAAa,EACb,WAAW,GAAG,EAAE,EAChB,aAAa,GAAG,EAAE,EAClB,SAAS,GAAG,EAAE,EACd,WAAW,GAAG,EAAE,EAChB,WAAW,EACX,WAAW,GAAG,EAAE,EAChB,WAAW,EACX,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,OAAO,EACP,UAAU,GACX,GAAG,MAAM,CAAA;YACV,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,CAAA;YACjB,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;YACrC,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC;gBACzC,MAAM;gBACN,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE;gBACnD,OAAO;gBACP,SAAS;gBACT,KAAK;gBACL,MAAM;gBACN,aAAa;gBACb,qBAAqB;gBACrB,UAAU;gBACV,OAAO;gBACP,YAAY;gBACZ,aAAa;gBACb,WAAW;gBACX,SAAS;gBACT,aAAa;gBACb,WAAW;gBACX,WAAW;gBACX,WAAW;gBACX,WAAW;gBACX,QAAQ;gBACR,OAAO;gBACP,iBAAiB;gBACjB,OAAO;gBACP,UAAU;aACX,CAAC,CAAA;YACF,OAAO;gBACL,QAAQ,EAAE,kBAAkB;gBAC5B,IAAI,EAAE;oBACJ,MAAM,EAAE,OAAO,CAAC,MAAM;oBACtB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACjC,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAClC;iBACF;aACF,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import type { Server } from '@atproto/xrpc-server'\nimport type { AppContext } from '../../context.js'\nimport { tools } from '../../lexicons/index.js'\nimport { getEventType } from '../util.js'\n\nexport default function (server: Server, ctx: AppContext) {\n server.add(tools.ozone.moderation.queryEvents, {\n auth: ctx.authVerifier.modOrAdminToken,\n handler: async ({ params, signal }) => {\n const {\n subject,\n limit = 50,\n cursor,\n sortDirection = 'desc',\n types,\n includeAllUserRecords = false,\n hasComment,\n comment,\n createdBy,\n createdAfter,\n createdBefore,\n addedLabels = [],\n removedLabels = [],\n addedTags = [],\n removedTags = [],\n reportTypes,\n collections = [],\n subjectType,\n policies,\n modTool,\n ageAssuranceState,\n batchId,\n withStrike,\n } = params\n const db = ctx.db\n const modService = ctx.modService(db)\n const results = await modService.getEvents({\n signal,\n types: types?.length ? types.map(getEventType) : [],\n subject,\n createdBy,\n limit,\n cursor,\n sortDirection,\n includeAllUserRecords,\n hasComment,\n comment,\n createdAfter,\n createdBefore,\n addedLabels,\n addedTags,\n removedLabels,\n removedTags,\n reportTypes,\n collections,\n subjectType,\n policies,\n modTool,\n ageAssuranceState,\n batchId,\n withStrike,\n })\n return {\n encoding: 'application/json',\n body: {\n cursor: results.cursor,\n events: results.events.map((evt) =>\n modService.views.formatEvent(evt),\n ),\n },\n }\n },\n })\n}\n"]}
|
|
@@ -2,10 +2,10 @@ import { tools } from '../../lexicons/index.js';
|
|
|
2
2
|
export default function (server, ctx) {
|
|
3
3
|
server.add(tools.ozone.moderation.queryStatuses, {
|
|
4
4
|
auth: ctx.authVerifier.modOrAdminToken,
|
|
5
|
-
handler: async ({ params }) => {
|
|
5
|
+
handler: async ({ params, signal }) => {
|
|
6
6
|
const db = ctx.db;
|
|
7
7
|
const modService = ctx.modService(db);
|
|
8
|
-
const results = await modService.getSubjectStatuses(params);
|
|
8
|
+
const results = await modService.getSubjectStatuses({ ...params, signal });
|
|
9
9
|
const subjectStatuses = results.statuses.map((status) => modService.views.formatSubjectStatus(status));
|
|
10
10
|
return {
|
|
11
11
|
encoding: 'application/json',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryStatuses.js","sourceRoot":"","sources":["../../../src/api/moderation/queryStatuses.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAE/C,MAAM,CAAC,OAAO,WAAW,MAAc,EAAE,GAAe;IACtD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,EAAE;QAC/C,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,eAAe;QACtC,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"queryStatuses.js","sourceRoot":"","sources":["../../../src/api/moderation/queryStatuses.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAE/C,MAAM,CAAC,OAAO,WAAW,MAAc,EAAE,GAAe;IACtD,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,aAAa,EAAE;QAC/C,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,eAAe;QACtC,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE;YACpC,MAAM,EAAE,GAAG,GAAG,CAAC,EAAE,CAAA;YACjB,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;YACrC,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,kBAAkB,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;YAC1E,MAAM,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACtD,UAAU,CAAC,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAC7C,CAAA;YACD,OAAO;gBACL,QAAQ,EAAE,kBAAkB;gBAC5B,IAAI,EAAE;oBACJ,MAAM,EAAE,OAAO,CAAC,MAAM;oBACtB,eAAe;iBAChB;aACF,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import type { Server } from '@atproto/xrpc-server'\nimport type { AppContext } from '../../context.js'\nimport { tools } from '../../lexicons/index.js'\n\nexport default function (server: Server, ctx: AppContext) {\n server.add(tools.ozone.moderation.queryStatuses, {\n auth: ctx.authVerifier.modOrAdminToken,\n handler: async ({ params, signal }) => {\n const db = ctx.db\n const modService = ctx.modService(db)\n const results = await modService.getSubjectStatuses({ ...params, signal })\n const subjectStatuses = results.statuses.map((status) =>\n modService.views.formatSubjectStatus(status),\n )\n return {\n encoding: 'application/json',\n body: {\n cursor: results.cursor,\n subjectStatuses,\n },\n }\n },\n })\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20261012T000000000Z-inbox-notification-categories.d.ts","sourceRoot":"","sources":["../../../src/db/migrations/20261012T000000000Z-inbox-notification-categories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAO,MAAM,QAAQ,CAAA;AAEzC,wBAAsB,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ3D;AAED,wBAAsB,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAe7D"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { sql } from 'kysely';
|
|
2
|
+
export async function up(db) {
|
|
3
|
+
// @NOTE Unset categories inherit push, preserving opt-outs without a backfill.
|
|
4
|
+
await db.schema
|
|
5
|
+
.alterTable('inbox_notification_preference')
|
|
6
|
+
.addColumn('reports', 'boolean')
|
|
7
|
+
.addColumn('account', 'boolean')
|
|
8
|
+
.addColumn('labels', 'boolean')
|
|
9
|
+
.execute();
|
|
10
|
+
}
|
|
11
|
+
export async function down(db) {
|
|
12
|
+
// @NOTE The global preference cannot express mixed categories; preserve opt-outs.
|
|
13
|
+
await sql `update inbox_notification_preference
|
|
14
|
+
set push = coalesce(reports, push)
|
|
15
|
+
and coalesce(account, push)
|
|
16
|
+
and coalesce(labels, push)
|
|
17
|
+
where reports is not null or account is not null or labels is not null`.execute(db);
|
|
18
|
+
await db.schema
|
|
19
|
+
.alterTable('inbox_notification_preference')
|
|
20
|
+
.dropColumn('reports')
|
|
21
|
+
.dropColumn('account')
|
|
22
|
+
.dropColumn('labels')
|
|
23
|
+
.execute();
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=20261012T000000000Z-inbox-notification-categories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"20261012T000000000Z-inbox-notification-categories.js","sourceRoot":"","sources":["../../../src/db/migrations/20261012T000000000Z-inbox-notification-categories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,GAAG,EAAE,MAAM,QAAQ,CAAA;AAEzC,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC,EAAmB;IAC1C,+EAA+E;IAC/E,MAAM,EAAE,CAAC,MAAM;SACZ,UAAU,CAAC,+BAA+B,CAAC;SAC3C,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC;SAC/B,SAAS,CAAC,SAAS,EAAE,SAAS,CAAC;SAC/B,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC;SAC9B,OAAO,EAAE,CAAA;AACd,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,EAAmB;IAC5C,kFAAkF;IAClF,MAAM,GAAG,CAAA;;;;2EAIgE,CAAC,OAAO,CAC/E,EAAE,CACH,CAAA;IACD,MAAM,EAAE,CAAC,MAAM;SACZ,UAAU,CAAC,+BAA+B,CAAC;SAC3C,UAAU,CAAC,SAAS,CAAC;SACrB,UAAU,CAAC,SAAS,CAAC;SACrB,UAAU,CAAC,QAAQ,CAAC;SACpB,OAAO,EAAE,CAAA;AACd,CAAC","sourcesContent":["import { type Kysely, sql } from 'kysely'\n\nexport async function up(db: Kysely<unknown>): Promise<void> {\n // @NOTE Unset categories inherit push, preserving opt-outs without a backfill.\n await db.schema\n .alterTable('inbox_notification_preference')\n .addColumn('reports', 'boolean')\n .addColumn('account', 'boolean')\n .addColumn('labels', 'boolean')\n .execute()\n}\n\nexport async function down(db: Kysely<unknown>): Promise<void> {\n // @NOTE The global preference cannot express mixed categories; preserve opt-outs.\n await sql`update inbox_notification_preference\n set push = coalesce(reports, push)\n and coalesce(account, push)\n and coalesce(labels, push)\n where reports is not null or account is not null or labels is not null`.execute(\n db,\n )\n await db.schema\n .alterTable('inbox_notification_preference')\n .dropColumn('reports')\n .dropColumn('account')\n .dropColumn('labels')\n .execute()\n}\n"]}
|
|
@@ -49,4 +49,5 @@ export * as _20261005T000000000Z from './20261005T000000000Z-inbox-seen.js';
|
|
|
49
49
|
export * as _20261005T000000001Z from './20261005T000000001Z-inbox-notifications.js';
|
|
50
50
|
export * as _20261008T000000000Z from './20261008T000000000Z-add-report-priority.js';
|
|
51
51
|
export * as _20261008T000000001Z from './20261008T000000001Z-add-report-closure-target-stats.js';
|
|
52
|
+
export * as _20261012T000000000Z from './20261012T000000000Z-inbox-notification-categories.js';
|
|
52
53
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/db/migrations/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,oBAAoB,MAAM,+BAA+B,CAAA;AACrE,OAAO,KAAK,oBAAoB,MAAM,iDAAiD,CAAA;AACvF,OAAO,KAAK,oBAAoB,MAAM,0CAA0C,CAAA;AAChF,OAAO,KAAK,oBAAoB,MAAM,gEAAgE,CAAA;AACtG,OAAO,KAAK,oBAAoB,MAAM,yCAAyC,CAAA;AAC/E,OAAO,KAAK,oBAAoB,MAAM,yCAAyC,CAAA;AAC/E,OAAO,KAAK,oBAAoB,MAAM,0CAA0C,CAAA;AAChF,OAAO,KAAK,oBAAoB,MAAM,iCAAiC,CAAA;AACvE,OAAO,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AA+C,CAAA;AACrF,OAAO,KAAK,oBAAoB,MAAM,iDAAiD,CAAA;AACvF,OAAO,KAAK,oBAAoB,MAAM,oDAAoD,CAAA;AAC1F,OAAO,KAAK,oBAAoB,MAAM,0CAA0C,CAAA;AAChF,OAAO,KAAK,oBAAoB,MAAM,iDAAiD,CAAA;AACvF,OAAO,KAAK,oBAAoB,MAAM,+CAA+C,CAAA;AACrF,OAAO,KAAK,oBAAoB,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,oBAAoB,MAAM,iDAAiD,CAAA;AACvF,OAAO,KAAK,oBAAoB,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,oBAAoB,MAAM,mEAAmE,CAAA;AACzG,OAAO,KAAK,oBAAoB,MAAM,sDAAsD,CAAA;AAC5F,OAAO,KAAK,oBAAoB,MAAM,qDAAqD,CAAA;AAC3F,OAAO,KAAK,oBAAoB,MAAM,uCAAuC,CAAA;AAC7E,OAAO,KAAK,oBAAoB,MAAM,kDAAkD,CAAA;AACxF,OAAO,KAAK,oBAAoB,MAAM,qCAAqC,CAAA;AAC3E,OAAO,KAAK,oBAAoB,MAAM,8CAA8C,CAAA;AACpF,OAAO,KAAK,oBAAoB,MAAM,8CAA8C,CAAA;AACpF,OAAO,KAAK,oBAAoB,MAAM,0DAA0D,CAAA;AAChG,OAAO,KAAK,oBAAoB,MAAM,wDAAwD,CAAA"}
|
|
@@ -52,4 +52,5 @@ export * as _20261005T000000000Z from './20261005T000000000Z-inbox-seen.js';
|
|
|
52
52
|
export * as _20261005T000000001Z from './20261005T000000001Z-inbox-notifications.js';
|
|
53
53
|
export * as _20261008T000000000Z from './20261008T000000000Z-add-report-priority.js';
|
|
54
54
|
export * as _20261008T000000001Z from './20261008T000000001Z-add-report-closure-target-stats.js';
|
|
55
|
+
export * as _20261012T000000000Z from './20261012T000000000Z-inbox-notification-categories.js';
|
|
55
56
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":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AA;AACpF,OAAO,KAAK,oBAAoB,MAAM,0DAA0D,CAAA","sourcesContent":["// NOTE this file can be edited by hand, but it is also appended to by the migration:create command.\n// It's important that every migration is exported from here with the proper name. We'd simplify\n// this with kysely's FileMigrationProvider, but it doesn't play nicely with the build process.\n\nexport * as _20231219T205730722Z from './20231219T205730722Z-init.js'\nexport * as _20240116T085607200Z from './20240116T085607200Z-communication-template.js'\nexport * as _20240201T051104136Z from './20240201T051104136Z-mod-event-blobs.js'\nexport * as _20240208T213404429Z from './20240208T213404429Z-add-tags-column-to-moderation-subject.js'\nexport * as _20240228T003647759Z from './20240228T003647759Z-add-label-sigs.js'\nexport * as _20240408T192432676Z from './20240408T192432676Z-mute-reporting.js'\nexport * as _20240506T225055595Z from './20240506T225055595Z-message-subject.js'\nexport * as _20240430T211332580Z from './20240521T211332580Z-member.js'\nexport * as _20240814T003647759Z from './20240814T003647759Z-event-created-at-index.js'\nexport * as _20240903T205730722Z from './20240903T205730722Z-add-template-lang.js'\nexport * as _20240904T205730722Z from './20240904T205730722Z-add-subject-did-index.js'\nexport * as _20241001T205730722Z from './20241001T205730722Z-subject-status-review-state-index.js'\nexport * as _20241008T205730722Z from './20241008T205730722Z-sets.js'\nexport * as _20241018T205730722Z from './20241018T205730722Z-setting.js'\nexport * as _20241026T205730722Z from './20241026T205730722Z-add-hosting-status-to-subject-status.js'\nexport * as _20241220T144630860Z from './20241220T144630860Z-stats-materialized-views.js'\nexport * as _20250204T003647759Z from './20250204T003647759Z-add-subject-priority-score.js'\nexport * as _20250211T003647759Z from './20250211T003647759Z-add-reporter-stats-index.js'\nexport * as _20250211T132135150Z from './20250211T132135150Z-moderation-event-message-partial-idx.js'\nexport * as _20250221T132135150Z from './20250221T132135150Z-member-details.js'\nexport * as _20250404T201720309Z from './20250404T201720309Z-subject-status-sort-idxs.js'\nexport * as _20250415T201720309Z from './20250415T201720309Z-verification.js'\nexport * as _20250417T201720309Z from './20250417T201720309Z-firehose-cursor.js'\nexport * as _20250609T110704000Z from './20250609T110704000Z-safelink.js'\nexport * as _20250618T180246000Z from './20250618T180246000Z-add-mod-tool-to-moderation-event.js'\nexport * as _20250701T000000000Z from './20250701T000000000Z-add-age-assurance-state.js'\nexport * as _20250715T000000000Z from './20250715T000000000Z-add-mod-event-external-id.js'\nexport * as _20250718T150931000Z from './20250718T150931000Z-update-appeal-reason-stats.js'\nexport * as _20250813T000000000Z from './20250813T000000000Z-mod-tool-batch-id-index.js'\nexport * as _20250923T000000000Z from './20250923T000000000Z-scheduled-actions.js'\nexport * as _20251008T120000000Z from './20251008T120000000Z-add-strike-system.js'\nexport * as _20260210T154806448Z from './20260210T154806448Z-mod-event-created-by-indexes.js'\nexport * as _20260219T164523000Z from './20260219T164523000Z-create-report-table.js'\nexport * as _20260219T165302248Z from './20260219T165302248Z-moderator-assignment.js'\nexport * as _20260225T000000000Z from './20260225T000000000Z-add-report-queue-table.js'\nexport * as _20260313T000000000Z from './20260313T000000000Z-add-report-activity-table.js'\nexport * as _20260318T152058935Z from './20260318T152058935Z-add-report-stat.js'\nexport * as _20260428T000000000Z from './20260428T000000000Z-add-expiring-tag-table.js'\nexport * as _20260513T202941104Z from './20260513T202941104Z-add-subject-convo-id.js'\nexport * as _20260602T120000000Z from './20260602T120000000Z-add-report-activity-created-index.js'\nexport * as _20260617T210022765Z from './20260617T210022765Z-add-report-isautomated.js'\nexport * as _20260720T000000000Z from './20260720T000000000Z-add-convo-subjects-to-stats-views.js'\nexport * as _20260731T000000000Z from './20260731T000000000Z-add-recommended-policies-to-report-queue.js'\nexport * as _20260810T000000000Z from './20260810T000000000Z-add-report-stats-components.js'\nexport * as _20260922T153505234Z from './20260922T153505234Z-add-report-closed-at-index.js'\nexport * as _20260928T000000000Z from './20260928T000000000Z-inbox-appeal.js'\nexport * as _20261002T000000000Z from './20261002T000000000Z-add-report-reporter-did.js'\nexport * as _20261005T000000000Z from './20261005T000000000Z-inbox-seen.js'\nexport * as _20261005T000000001Z from './20261005T000000001Z-inbox-notifications.js'\nexport * as _20261008T000000000Z from './20261008T000000000Z-add-report-priority.js'\nexport * as _20261008T000000001Z from './20261008T000000001Z-add-report-closure-target-stats.js'\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/db/migrations/index.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,gGAAgG;AAChG,+FAA+F;AAE/F,OAAO,KAAK,oBAAoB,MAAM,+BAA+B,CAAA;AACrE,OAAO,KAAK,oBAAoB,MAAM,iDAAiD,CAAA;AACvF,OAAO,KAAK,oBAAoB,MAAM,0CAA0C,CAAA;AAChF,OAAO,KAAK,oBAAoB,MAAM,gEAAgE,CAAA;AACtG,OAAO,KAAK,oBAAoB,MAAM,yCAAyC,CAAA;AAC/E,OAAO,KAAK,oBAAoB,MAAM,yCAAyC,CAAA;AAC/E,OAAO,KAAK,oBAAoB,MAAM,0CAA0C,CAAA;AAChF,OAAO,KAAK,oBAAoB,MAAM,iCAAiC,CAAA;AACvE,OAAO,KAAK,oBAAoB,MAAM,iDAAiD,CAAA;AACvF,OAAO,KAAK,oBAAoB,MAAM,4CAA4C,CAAA;AAClF,OAAO,KAAK,oBAAoB,MAAM,gDAAgD,CAAA;AACtF,OAAO,KAAK,oBAAoB,MAAM,4DAA4D,CAAA;AAClG,OAAO,KAAK,oBAAoB,MAAM,+BAA+B,CAAA;AACrE,OAAO,KAAK,oBAAoB,MAAM,kCAAkC,CAAA;AACxE,OAAO,KAAK,oBAAoB,MAAM,+DAA+D,CAAA;AACrG,OAAO,KAAK,oBAAoB,MAAM,mDAAmD,CAAA;AACzF,OAAO,KAAK,oBAAoB,MAAM,qDAAqD,CAAA;AAC3F,OAAO,KAAK,oBAAoB,MAAM,mDAAmD,CAAA;AACzF,OAAO,KAAK,oBAAoB,MAAM,+DAA+D,CAAA;AACrG,OAAO,KAAK,oBAAoB,MAAM,yCAAyC,CAAA;AAC/E,OAAO,KAAK,oBAAoB,MAAM,mDAAmD,CAAA;AACzF,OAAO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AAK,oBAAoB,MAAM,qCAAqC,CAAA;AAC3E,OAAO,KAAK,oBAAoB,MAAM,8CAA8C,CAAA;AACpF,OAAO,KAAK,oBAAoB,MAAM,8CAA8C,CAAA;AACpF,OAAO,KAAK,oBAAoB,MAAM,0DAA0D,CAAA;AAChG,OAAO,KAAK,oBAAoB,MAAM,wDAAwD,CAAA","sourcesContent":["// NOTE this file can be edited by hand, but it is also appended to by the migration:create command.\n// It's important that every migration is exported from here with the proper name. We'd simplify\n// this with kysely's FileMigrationProvider, but it doesn't play nicely with the build process.\n\nexport * as _20231219T205730722Z from './20231219T205730722Z-init.js'\nexport * as _20240116T085607200Z from './20240116T085607200Z-communication-template.js'\nexport * as _20240201T051104136Z from './20240201T051104136Z-mod-event-blobs.js'\nexport * as _20240208T213404429Z from './20240208T213404429Z-add-tags-column-to-moderation-subject.js'\nexport * as _20240228T003647759Z from './20240228T003647759Z-add-label-sigs.js'\nexport * as _20240408T192432676Z from './20240408T192432676Z-mute-reporting.js'\nexport * as _20240506T225055595Z from './20240506T225055595Z-message-subject.js'\nexport * as _20240430T211332580Z from './20240521T211332580Z-member.js'\nexport * as _20240814T003647759Z from './20240814T003647759Z-event-created-at-index.js'\nexport * as _20240903T205730722Z from './20240903T205730722Z-add-template-lang.js'\nexport * as _20240904T205730722Z from './20240904T205730722Z-add-subject-did-index.js'\nexport * as _20241001T205730722Z from './20241001T205730722Z-subject-status-review-state-index.js'\nexport * as _20241008T205730722Z from './20241008T205730722Z-sets.js'\nexport * as _20241018T205730722Z from './20241018T205730722Z-setting.js'\nexport * as _20241026T205730722Z from './20241026T205730722Z-add-hosting-status-to-subject-status.js'\nexport * as _20241220T144630860Z from './20241220T144630860Z-stats-materialized-views.js'\nexport * as _20250204T003647759Z from './20250204T003647759Z-add-subject-priority-score.js'\nexport * as _20250211T003647759Z from './20250211T003647759Z-add-reporter-stats-index.js'\nexport * as _20250211T132135150Z from './20250211T132135150Z-moderation-event-message-partial-idx.js'\nexport * as _20250221T132135150Z from './20250221T132135150Z-member-details.js'\nexport * as _20250404T201720309Z from './20250404T201720309Z-subject-status-sort-idxs.js'\nexport * as _20250415T201720309Z from './20250415T201720309Z-verification.js'\nexport * as _20250417T201720309Z from './20250417T201720309Z-firehose-cursor.js'\nexport * as _20250609T110704000Z from './20250609T110704000Z-safelink.js'\nexport * as _20250618T180246000Z from './20250618T180246000Z-add-mod-tool-to-moderation-event.js'\nexport * as _20250701T000000000Z from './20250701T000000000Z-add-age-assurance-state.js'\nexport * as _20250715T000000000Z from './20250715T000000000Z-add-mod-event-external-id.js'\nexport * as _20250718T150931000Z from './20250718T150931000Z-update-appeal-reason-stats.js'\nexport * as _20250813T000000000Z from './20250813T000000000Z-mod-tool-batch-id-index.js'\nexport * as _20250923T000000000Z from './20250923T000000000Z-scheduled-actions.js'\nexport * as _20251008T120000000Z from './20251008T120000000Z-add-strike-system.js'\nexport * as _20260210T154806448Z from './20260210T154806448Z-mod-event-created-by-indexes.js'\nexport * as _20260219T164523000Z from './20260219T164523000Z-create-report-table.js'\nexport * as _20260219T165302248Z from './20260219T165302248Z-moderator-assignment.js'\nexport * as _20260225T000000000Z from './20260225T000000000Z-add-report-queue-table.js'\nexport * as _20260313T000000000Z from './20260313T000000000Z-add-report-activity-table.js'\nexport * as _20260318T152058935Z from './20260318T152058935Z-add-report-stat.js'\nexport * as _20260428T000000000Z from './20260428T000000000Z-add-expiring-tag-table.js'\nexport * as _20260513T202941104Z from './20260513T202941104Z-add-subject-convo-id.js'\nexport * as _20260602T120000000Z from './20260602T120000000Z-add-report-activity-created-index.js'\nexport * as _20260617T210022765Z from './20260617T210022765Z-add-report-isautomated.js'\nexport * as _20260720T000000000Z from './20260720T000000000Z-add-convo-subjects-to-stats-views.js'\nexport * as _20260731T000000000Z from './20260731T000000000Z-add-recommended-policies-to-report-queue.js'\nexport * as _20260810T000000000Z from './20260810T000000000Z-add-report-stats-components.js'\nexport * as _20260922T153505234Z from './20260922T153505234Z-add-report-closed-at-index.js'\nexport * as _20260928T000000000Z from './20260928T000000000Z-inbox-appeal.js'\nexport * as _20261002T000000000Z from './20261002T000000000Z-add-report-reporter-did.js'\nexport * as _20261005T000000000Z from './20261005T000000000Z-inbox-seen.js'\nexport * as _20261005T000000001Z from './20261005T000000001Z-inbox-notifications.js'\nexport * as _20261008T000000000Z from './20261008T000000000Z-add-report-priority.js'\nexport * as _20261008T000000001Z from './20261008T000000001Z-add-report-closure-target-stats.js'\nexport * as _20261012T000000000Z from './20261012T000000000Z-inbox-notification-categories.js'\n"]}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import type { Generated } from 'kysely';
|
|
1
2
|
import type { DidString } from '@atproto/lex';
|
|
2
3
|
export declare const inboxNotificationPreferenceTableName = "inbox_notification_preference";
|
|
3
4
|
export interface InboxNotificationPreference {
|
|
4
5
|
did: DidString;
|
|
5
|
-
push: boolean
|
|
6
|
+
push: Generated<boolean>;
|
|
7
|
+
reports: Generated<boolean | null>;
|
|
8
|
+
account: Generated<boolean | null>;
|
|
9
|
+
labels: Generated<boolean | null>;
|
|
6
10
|
}
|
|
7
11
|
export type PartialDB = {
|
|
8
12
|
[inboxNotificationPreferenceTableName]: InboxNotificationPreference;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inbox_notification_preference.d.ts","sourceRoot":"","sources":["../../../src/db/schema/inbox_notification_preference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,eAAO,MAAM,oCAAoC,kCAChB,CAAA;AAEjC,MAAM,WAAW,2BAA2B;IAC1C,GAAG,EAAE,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"inbox_notification_preference.d.ts","sourceRoot":"","sources":["../../../src/db/schema/inbox_notification_preference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAE7C,eAAO,MAAM,oCAAoC,kCAChB,CAAA;AAEjC,MAAM,WAAW,2BAA2B;IAC1C,GAAG,EAAE,SAAS,CAAA;IAEd,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;IACxB,OAAO,EAAE,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAClC,OAAO,EAAE,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAClC,MAAM,EAAE,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;CAClC;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,CAAC,oCAAoC,CAAC,EAAE,2BAA2B,CAAA;CACpE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inbox_notification_preference.js","sourceRoot":"","sources":["../../../src/db/schema/inbox_notification_preference.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"inbox_notification_preference.js","sourceRoot":"","sources":["../../../src/db/schema/inbox_notification_preference.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,oCAAoC,GAC/C,+BAA+B,CAAA","sourcesContent":["import type { Generated } from 'kysely'\nimport type { DidString } from '@atproto/lex'\n\nexport const inboxNotificationPreferenceTableName =\n 'inbox_notification_preference'\n\nexport interface InboxNotificationPreference {\n did: DidString\n // @NOTE Retained as the fallback for category preferences not yet set.\n push: Generated<boolean>\n reports: Generated<boolean | null>\n account: Generated<boolean | null>\n labels: Generated<boolean | null>\n}\n\nexport type PartialDB = {\n [inboxNotificationPreferenceTableName]: InboxNotificationPreference\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type RawBuilder, type SqlBool } from 'kysely';
|
|
2
|
+
export type AppealOutcome = 'approved' | 'denied';
|
|
3
|
+
export declare const appealReportSelection: readonly ['id', 'did', 'recordPath', 'reportType', 'status', 'createdAt', 'updatedAt', 'closedAt', 'eventId', 'actionEventIds'];
|
|
4
|
+
/** Match only the closing activity's linked resolution on the same subject. */
|
|
5
|
+
export declare function appealResolutionFilter(reportAlias: 'report' | 'r', activityAlias: 'closure' | 'activity'): RawBuilder<SqlBool>;
|
|
6
|
+
/** Derive the decision from a closure and its already joined resolution. */
|
|
7
|
+
export declare function appealActivityOutcome(reportAlias: 'report' | 'r', activityAlias: 'closure' | 'activity'): RawBuilder<AppealOutcome | null>;
|
|
8
|
+
//# sourceMappingURL=appeal-outcome.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appeal-outcome.d.ts","sourceRoot":"","sources":["../../src/inbox/appeal-outcome.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,OAAO,EAAO,MAAM,QAAQ,CAAA;AAG3D,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,QAAQ,CAAA;AAEjD,eAAO,MAAM,qBAAqB,YAChC,IAAI,EACJ,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,WAAW,EACX,UAAU,EACV,SAAS,EACT,gBAAgB,CACR,CAAA;AAEV,+EAA+E;AAC/E,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,QAAQ,GAAG,GAAG,EAC3B,aAAa,EAAE,SAAS,GAAG,UAAU,GACpC,UAAU,CAAC,OAAO,CAAC,CAqBrB;AAED,4EAA4E;AAC5E,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,QAAQ,GAAG,GAAG,EAC3B,aAAa,EAAE,SAAS,GAAG,UAAU,GACpC,UAAU,CAAC,aAAa,GAAG,IAAI,CAAC,CAalC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { sql } from 'kysely';
|
|
2
|
+
import { com, tools } from '../lexicons/index.js';
|
|
3
|
+
export const appealReportSelection = [
|
|
4
|
+
'id',
|
|
5
|
+
'did',
|
|
6
|
+
'recordPath',
|
|
7
|
+
'reportType',
|
|
8
|
+
'status',
|
|
9
|
+
'createdAt',
|
|
10
|
+
'updatedAt',
|
|
11
|
+
'closedAt',
|
|
12
|
+
'eventId',
|
|
13
|
+
'actionEventIds',
|
|
14
|
+
];
|
|
15
|
+
/** Match only the closing activity's linked resolution on the same subject. */
|
|
16
|
+
export function appealResolutionFilter(reportAlias, activityAlias) {
|
|
17
|
+
const report = (column) => sql.ref(`${reportAlias}.${column}`);
|
|
18
|
+
const activity = (column) => sql.ref(`${activityAlias}.${column}`);
|
|
19
|
+
return sql `
|
|
20
|
+
${report('reportType')} = ${tools.ozone.report.defs.ReasonAppeal}
|
|
21
|
+
AND ${activity('activityType')} = 'closeActivity'
|
|
22
|
+
AND ${activity('meta')} ->> 'appealOutcome' IS DISTINCT FROM 'denied'
|
|
23
|
+
AND resolution.id = CASE
|
|
24
|
+
WHEN (${activity('meta')} ->> 'actionEventId') ~ '^[1-9][0-9]{0,9}$'
|
|
25
|
+
THEN (${activity('meta')} ->> 'actionEventId')::bigint END
|
|
26
|
+
AND resolution.id > ${report('eventId')}
|
|
27
|
+
AND ${report('actionEventIds')} @> jsonb_build_array(resolution.id)
|
|
28
|
+
AND resolution."subjectDid" = ${report('did')}
|
|
29
|
+
AND (
|
|
30
|
+
(${report('recordPath')} = ''
|
|
31
|
+
AND resolution."subjectType" = ${com.atproto.admin.defs.repoRef.$type})
|
|
32
|
+
OR (${report('recordPath')} <> ''
|
|
33
|
+
AND resolution."subjectType" = ${com.atproto.repo.strongRef.$type}
|
|
34
|
+
AND resolution."subjectUri" = 'at://' || ${report('did')} || '/' || ${report('recordPath')})
|
|
35
|
+
)
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
38
|
+
/** Derive the decision from a closure and its already joined resolution. */
|
|
39
|
+
export function appealActivityOutcome(reportAlias, activityAlias) {
|
|
40
|
+
const report = (column) => sql.ref(`${reportAlias}.${column}`);
|
|
41
|
+
const activity = (column) => sql.ref(`${activityAlias}.${column}`);
|
|
42
|
+
return sql `CASE
|
|
43
|
+
WHEN ${report('reportType')} <> ${tools.ozone.report.defs.ReasonAppeal}
|
|
44
|
+
OR ${activity('activityType')} <> 'closeActivity'
|
|
45
|
+
OR ${activity('id')} IS NULL THEN NULL
|
|
46
|
+
WHEN ${activity('meta')} ->> 'appealOutcome' = 'denied' THEN 'denied'
|
|
47
|
+
WHEN resolution.id IS NULL THEN NULL
|
|
48
|
+
WHEN resolution.action = ${tools.ozone.moderation.defs.modEventReverseTakedown.$type}
|
|
49
|
+
OR (resolution.action = ${tools.ozone.moderation.defs.modEventLabel.$type}
|
|
50
|
+
AND nullif(btrim(resolution."negateLabelVals"), '') IS NOT NULL)
|
|
51
|
+
THEN 'approved' ELSE 'denied' END`;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=appeal-outcome.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appeal-outcome.js","sourceRoot":"","sources":["../../src/inbox/appeal-outcome.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC3D,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAIjD,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI;IACJ,KAAK;IACL,YAAY;IACZ,YAAY;IACZ,QAAQ;IACR,WAAW;IACX,WAAW;IACX,UAAU;IACV,SAAS;IACT,gBAAgB;CACR,CAAA;AAEV,+EAA+E;AAC/E,MAAM,UAAU,sBAAsB,CACpC,WAA2B,EAC3B,aAAqC;IAErC,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,WAAW,IAAI,MAAM,EAAE,CAAC,CAAA;IACtE,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,aAAa,IAAI,MAAM,EAAE,CAAC,CAAA;IAC1E,OAAO,GAAG,CAAS;MACf,MAAM,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,KAAK,CAAC,MAAM,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ent":["import { type RawBuilder, type SqlBool, sql } from 'kysely'\nimport { com, tools } from '../lexicons/index.js'\n\nexport type AppealOutcome = 'approved' | 'denied'\n\nexport const appealReportSelection = [\n 'id',\n 'did',\n 'recordPath',\n 'reportType',\n 'status',\n 'createdAt',\n 'updatedAt',\n 'closedAt',\n 'eventId',\n 'actionEventIds',\n] as const\n\n/** Match only the closing activity's linked resolution on the same subject. */\nexport function appealResolutionFilter(\n reportAlias: 'report' | 'r',\n activityAlias: 'closure' | 'activity',\n): RawBuilder<SqlBool> {\n const report = (column: string) => sql.ref(`${reportAlias}.${column}`)\n const activity = (column: string) => sql.ref(`${activityAlias}.${column}`)\n return sql<SqlBool>`\n ${report('reportType')} = ${tools.ozone.report.defs.ReasonAppeal}\n AND ${activity('activityType')} = 'closeActivity'\n AND ${activity('meta')} ->> 'appealOutcome' IS DISTINCT FROM 'denied'\n AND resolution.id = CASE\n WHEN (${activity('meta')} ->> 'actionEventId') ~ '^[1-9][0-9]{0,9}$'\n THEN (${activity('meta')} ->> 'actionEventId')::bigint END\n AND resolution.id > ${report('eventId')}\n AND ${report('actionEventIds')} @> jsonb_build_array(resolution.id)\n AND resolution.\"subjectDid\" = ${report('did')}\n AND (\n (${report('recordPath')} = ''\n AND resolution.\"subjectType\" = ${com.atproto.admin.defs.repoRef.$type})\n OR (${report('recordPath')} <> ''\n AND resolution.\"subjectType\" = ${com.atproto.repo.strongRef.$type}\n AND resolution.\"subjectUri\" = 'at://' || ${report('did')} || '/' || ${report('recordPath')})\n )\n `\n}\n\n/** Derive the decision from a closure and its already joined resolution. */\nexport function appealActivityOutcome(\n reportAlias: 'report' | 'r',\n activityAlias: 'closure' | 'activity',\n): RawBuilder<AppealOutcome | null> {\n const report = (column: string) => sql.ref(`${reportAlias}.${column}`)\n const activity = (column: string) => sql.ref(`${activityAlias}.${column}`)\n return sql<AppealOutcome | null>`CASE\n WHEN ${report('reportType')} <> ${tools.ozone.report.defs.ReasonAppeal}\n OR ${activity('activityType')} <> 'closeActivity'\n OR ${activity('id')} IS NULL THEN NULL\n WHEN ${activity('meta')} ->> 'appealOutcome' = 'denied' THEN 'denied'\n WHEN resolution.id IS NULL THEN NULL\n WHEN resolution.action = ${tools.ozone.moderation.defs.modEventReverseTakedown.$type}\n OR (resolution.action = ${tools.ozone.moderation.defs.modEventLabel.$type}\n AND nullif(btrim(resolution.\"negateLabelVals\"), '') IS NOT NULL)\n THEN 'approved' ELSE 'denied' END`\n}\n"]}
|
package/dist/inbox/appeal.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { tools } from '../lexicons/index.js';
|
|
|
7
7
|
import type { AppealView } from '../lexicons/tools/ozone/inbox/defs.js';
|
|
8
8
|
import type { ModSubject } from '../mod-service/subject.js';
|
|
9
9
|
import type { ModerationSubjectStatusRow } from '../mod-service/types.js';
|
|
10
|
+
import { type AppealOutcome } from './appeal-outcome.js';
|
|
10
11
|
export declare const APPEAL_REASON_TYPE = "tools.ozone.report.defs#reasonAppeal";
|
|
11
12
|
export declare const TAKEDOWN = "tools.ozone.moderation.defs#modEventTakedown";
|
|
12
13
|
export declare const REVERSE_TAKEDOWN = "tools.ozone.moderation.defs#modEventReverseTakedown";
|
|
@@ -25,6 +26,7 @@ export type AppealReport = {
|
|
|
25
26
|
createdAt: DatetimeString;
|
|
26
27
|
updatedAt: DatetimeString;
|
|
27
28
|
closedAt: DatetimeString | null;
|
|
29
|
+
outcome?: AppealOutcome | null;
|
|
28
30
|
};
|
|
29
31
|
export type AppealInput = {
|
|
30
32
|
subject: ModSubject;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appeal.d.ts","sourceRoot":"","sources":["../../src/inbox/appeal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAEpE,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,SAAS,EAGf,MAAM,cAAc,CAAA;AAGr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AAO,EAAE,UAAU,CAAA;IACnB,6DAA6D;IAC7D,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,mDAAmD;IACnD,MAAM,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,qBAAqB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAA;IACrE,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE;aAAG,CAAC,IAAI,MAAM,GAAG,OAAO;SAAE,CAAA;KAAE,CAAA;CAC9D,CAAA;AA4GD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,QAChB,UAAU,mFASZ,eAAe,KACjB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAmC9B,CAAA"}
|
package/dist/inbox/appeal.js
CHANGED
|
@@ -5,6 +5,7 @@ import { ForbiddenError, InvalidRequestError } from '@atproto/xrpc-server';
|
|
|
5
5
|
import { jsonb } from '../db/types.js';
|
|
6
6
|
import { tools } from '../lexicons/index.js';
|
|
7
7
|
import { findMatchingQueue } from '../queue/service.js';
|
|
8
|
+
import { appealActivityOutcome, appealReportSelection, appealResolutionFilter, } from './appeal-outcome.js';
|
|
8
9
|
export const APPEAL_REASON_TYPE = 'tools.ozone.report.defs#reasonAppeal';
|
|
9
10
|
export const TAKEDOWN = 'tools.ozone.moderation.defs#modEventTakedown';
|
|
10
11
|
export const REVERSE_TAKEDOWN = 'tools.ozone.moderation.defs#modEventReverseTakedown';
|
|
@@ -54,6 +55,8 @@ export const toAppealState = ({ subject, status, report, eligibilityReport = rep
|
|
|
54
55
|
view.appealedAt = status?.lastAppealedAt ?? report.createdAt;
|
|
55
56
|
if (state === 'resolved' && report.closedAt)
|
|
56
57
|
view.resolvedAt = report.closedAt;
|
|
58
|
+
if (state === 'resolved' && report.outcome)
|
|
59
|
+
view.outcome = report.outcome;
|
|
57
60
|
}
|
|
58
61
|
if (appealableUntil)
|
|
59
62
|
view.appealableUntil = appealableUntil;
|
|
@@ -192,12 +195,33 @@ export const appealsExhausted = (subject, report) => {
|
|
|
192
195
|
};
|
|
193
196
|
export const findLatestAppealReport = async (db, subject) => {
|
|
194
197
|
const report = await db.db
|
|
198
|
+
.selectFrom(db.db
|
|
195
199
|
.selectFrom('report')
|
|
196
200
|
.where('reportType', '=', APPEAL_REASON_TYPE)
|
|
197
201
|
.where((eb) => reportSubjectFilter(eb, subject))
|
|
198
202
|
.orderBy('id', 'desc')
|
|
199
203
|
.limit(1)
|
|
200
|
-
.select(
|
|
204
|
+
.select(appealReportSelection)
|
|
205
|
+
.as('report'))
|
|
206
|
+
.leftJoinLateral((eb) => eb
|
|
207
|
+
.selectFrom('report_activity')
|
|
208
|
+
.where('report.status', '=', 'closed')
|
|
209
|
+
.whereRef('reportId', '=', 'report.id')
|
|
210
|
+
.where('activityType', '=', 'closeActivity')
|
|
211
|
+
.whereRef('createdAt', '=', 'report.closedAt')
|
|
212
|
+
.orderBy('id', 'desc')
|
|
213
|
+
.limit(1)
|
|
214
|
+
.select(['id', 'activityType', 'meta'])
|
|
215
|
+
.as('closure'), (join) => join.onTrue())
|
|
216
|
+
.leftJoin('moderation_event as resolution', (join) => join.on(appealResolutionFilter('report', 'closure')))
|
|
217
|
+
.select([
|
|
218
|
+
'report.id',
|
|
219
|
+
'report.status',
|
|
220
|
+
'report.createdAt',
|
|
221
|
+
'report.updatedAt',
|
|
222
|
+
'report.closedAt',
|
|
223
|
+
])
|
|
224
|
+
.select(appealActivityOutcome('report', 'closure').as('outcome'))
|
|
201
225
|
.executeTakeFirst();
|
|
202
226
|
return report ?? null;
|
|
203
227
|
};
|
package/dist/inbox/appeal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"appeal.js","sourceRoot":"","sources":["../../src/inbox/appeal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM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,YAAY,CAAC,KAAK,CAAC,CAAC,qBAAqB,CAAC;YACnD,KAAK,EAAE,WAAW;YAClB,UAAU,EAAE,kBAAkB;YAC9B,OAAO;YACP,QAAQ;YACR,cAAc,EACZ,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC;SAC7D,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,QAAQ,EAAE,CAAA;AACrB,CAAC,CAAA","sourcesContent":["import type { Expression, ExpressionBuilder, SqlBool } from 'kysely'\nimport { sql } from 'kysely'\nimport {\n type DatetimeString,\n type DidString,\n type UriString,\n currentDatetimeString,\n toDatetimeString,\n} from '@atproto/lex'\nimport { AtUri } from '@atproto/syntax'\nimport { ForbiddenError, InvalidRequestError } from '@atproto/xrpc-server'\nimport type { AppContext } from '../context.js'\nimport type { Database } from '../db/index.js'\nimport type { DatabaseSchemaType } from '../db/schema/index.js'\nimport { jsonb } from '../db/types.js'\nimport { tools } from '../lexicons/index.js'\nimport type { AppealView } from '../lexicons/tools/ozone/inbox/defs.js'\nimport type { ModSubject } from '../mod-service/subject.js'\nimport type { ModerationSubjectStatusRow } from '../mod-service/types.js'\nimport { findMatchingQueue } from '../queue/service.js'\n\nexport const APPEAL_REASON_TYPE = 'tools.ozone.report.defs#reasonAppeal'\nexport const TAKEDOWN = 'tools.ozone.moderation.defs#modEventTakedown'\nexport const REVERSE_TAKEDOWN =\n 'tools.ozone.moderation.defs#modEventReverseTakedown'\nexport const LABEL = 'tools.ozone.moderation.defs#modEventLabel'\nexport const EMAIL = 'tools.ozone.moderation.defs#modEventEmail'\nexport const MUTE_REPORTER = 'tools.ozone.moderation.defs#modEventMuteReporter'\nexport const REVOKE_CREDENTIALS =\n 'tools.ozone.moderation.defs#revokeAccountCredentialsEvent'\n\n/**\n * The subject's most recent `reasonAppeal` report, reduced to the columns the\n * appeal state derives from. Deliberately excludes `actionNote` and everything\n * else a moderator wrote for other moderators.\n */\nexport type AppealReport = {\n id: number\n status: string\n createdAt: DatetimeString\n updatedAt: DatetimeString\n closedAt: DatetimeString | null\n}\n\nexport type AppealInput = {\n subject: ModSubject\n status: Pick<ModerationSubjectStatusRow, 'appealed' | 'lastAppealedAt'> | null\n report: AppealReport | null\n /** Eligibility retains older appeals even when their history is hidden. */\n eligibilityReport?: AppealReport | null\n\n /** Calendar months an action stays appealable, from `InboxConfig`. */\n windowMonths: number\n latestAppealableAt: DatetimeString | null\n}\n\nexport type AppealState = {\n view: AppealView\n availableActions: string[]\n}\n\nexport const PUBLIC_EVENT_ACTIONS = [\n TAKEDOWN,\n LABEL,\n EMAIL,\n MUTE_REPORTER,\n REVOKE_CREDENTIALS,\n REVERSE_TAKEDOWN,\n] as const\n\nexport const APPEALABLE_EVENT_ACTIONS = [TAKEDOWN, LABEL] as const\n\nexport const isAppealableEvent = (action: string): boolean =>\n (APPEALABLE_EVENT_ACTIONS as readonly string[]).includes(action)\n\nexport const appealWindowEnd = (\n actionCreatedAt: DatetimeString,\n windowMonths: number,\n): DatetimeString => {\n const end = new Date(actionCreatedAt)\n const day = end.getUTCDate()\n end.setUTCMonth(end.getUTCMonth() + windowMonths)\n // Clamp a rollover: 31 Aug + 6 months is 28/29 Feb, not 2/3 Mar.\n if (end.getUTCDate() !== day) end.setUTCDate(0)\n return toDatetimeString(end)\n}\n\nexport const isAppealWindowOpen = (\n actionCreatedAt: DatetimeString,\n windowMonths: number,\n now = new Date(),\n): boolean => new Date(appealWindowEnd(actionCreatedAt, windowMonths)) > now\n\n/**\n * Appeal state, derived entirely from data Ozone already records.\n */\nexport const toAppealState = ({\n subject,\n status,\n report,\n eligibilityReport = report,\n latestAppealableAt,\n windowMonths,\n}: AppealInput): AppealState => {\n const appealableUntil = latestAppealableAt\n ? appealWindowEnd(latestAppealableAt, windowMonths)\n : null\n const windowOpen = !!appealableUntil && new Date(appealableUntil) > new Date()\n\n let state: AppealView['state']\n if (report) {\n // @NOTE Report activities do not maintain the subject's appealed flag.\n // Use the same source of truth as the appeal submission guard.\n state = report.status === 'closed' ? 'resolved' : 'pending'\n } else {\n state = appealableUntil && !windowOpen ? 'expired' : 'none'\n }\n\n const view: AppealView = { state }\n if (report) {\n view.appealedAt = status?.lastAppealedAt ?? report.createdAt\n if (state === 'resolved' && report.closedAt)\n view.resolvedAt = report.closedAt\n }\n if (appealableUntil) view.appealableUntil = appealableUntil\n\n const availableActions =\n windowOpen && !appealsExhausted(subject, eligibilityReport)\n ? ['appeal']\n : []\n\n return { view, availableActions }\n}\n\n/**\n * Stable identity of a moderated subject, independent of which action touched\n * it. Two appeals against the same record - or the same message, or the same\n * conversation - share a key even when they name different action IDs.\n */\nexport const subjectKey = (subject: ModSubject): string => {\n const { subjectDid, subjectMessageId, subjectConvoId } = subject.info()\n if (subject.isMessage())\n return `message:${subjectDid}:${subjectConvoId}:${subjectMessageId}`\n if (subject.isConvo()) return `convo:${subjectDid}:${subjectConvoId}`\n if (subject.isRecord()) return `record:${subjectDid}:${subject.recordPath}`\n return `account:${subjectDid}`\n}\n\n/**\n * Match report rows by that identity. Mirrors the subject normalization in\n * `mod-service/report.ts`: `recordPath` is '' for accounts, messages, and\n * conversations alike, so an account match has to exclude the chat columns.\n */\nexport const reportSubjectFilter = (\n eb: ExpressionBuilder<DatabaseSchemaType, 'report'>,\n subject: ModSubject,\n): Expression<SqlBool> => {\n const { subjectDid, subjectMessageId, subjectConvoId } = subject.info()\n if (subject.isMessage()) {\n return eb.and([\n eb('did', '=', subjectDid),\n eb('subjectMessageId', '=', subjectMessageId),\n eb('subjectConvoId', '=', subjectConvoId),\n ])\n }\n if (subject.isConvo()) {\n return eb.and([\n eb('did', '=', subjectDid),\n eb('subjectConvoId', '=', subjectConvoId),\n eb('subjectMessageId', 'is', null),\n ])\n }\n if (subject.isRecord()) {\n return eb.and([\n eb('did', '=', subjectDid),\n eb('recordPath', '=', subject.recordPath),\n ])\n }\n return eb.and([\n eb('did', '=', subjectDid),\n eb('recordPath', '=', ''),\n eb('subjectMessageId', 'is', null),\n eb('subjectConvoId', 'is', null),\n ])\n}\n\nexport const eventSubjectFilter = (\n eb: ExpressionBuilder<DatabaseSchemaType, 'moderation_event'>,\n subject: ModSubject,\n): Expression<SqlBool> => {\n const {\n subjectType,\n subjectDid,\n subjectUri,\n subjectMessageId,\n subjectConvoId,\n } = subject.info()\n if (subject.isMessage()) {\n return eb.and([\n eb('subjectDid', '=', subjectDid),\n eb('subjectMessageId', '=', subjectMessageId),\n eb('subjectConvoId', '=', subjectConvoId),\n ])\n }\n if (subject.isConvo()) {\n return eb.and([\n eb('subjectDid', '=', subjectDid),\n eb('subjectConvoId', '=', subjectConvoId),\n eb('subjectMessageId', 'is', null),\n ])\n }\n if (subject.isRecord()) {\n return eb.and([\n eb('subjectDid', '=', subjectDid),\n eb('subjectUri', '=', subjectUri),\n eb('subjectType', '=', subjectType),\n ])\n }\n return eb.and([\n eb('subjectDid', '=', subjectDid),\n eb('subjectType', '=', subjectType),\n ])\n}\n\nexport const findAppealedEvent = async (\n ctx: AppContext,\n subject: ModSubject,\n action: { type: 'label'; val: string } | { type: 'takedown' },\n) => {\n let query = ctx.db.db\n .selectFrom('moderation_event')\n .where((eb) => eventSubjectFilter(eb, subject))\n .where('action', '=', action.type === 'label' ? LABEL : TAKEDOWN)\n .$if(ctx.cfg.inbox.startAt !== undefined, (qb) =>\n qb.where('createdAt', '>=', ctx.cfg.inbox.startAt!),\n )\n\n if (action.type === 'label') {\n query = query.where(\n sql<boolean>`${action.val} = ANY(string_to_array(\"createLabelVals\", ' '))`,\n )\n }\n\n const matches = await query\n .orderBy('id', 'desc')\n .limit(2)\n .selectAll()\n .execute()\n return matches.length === 1 ? matches[0] : undefined\n}\n\nexport const resolveAppealAction = async (\n ctx: AppContext,\n subject: ModSubject,\n action: tools.ozone.inbox.appealActionedSubject.$InputBody['action'],\n) => {\n if (!action) return undefined\n const reference = tools.ozone.inbox.appealActionedSubject\n if (reference.actionRef.$isTypeOf(action)) {\n return ctx.modService(ctx.db).getEvent(action.id)\n }\n if (reference.labelRef.$isTypeOf(action)) {\n return findAppealedEvent(ctx, subject, { type: 'label', val: action.val })\n }\n if (reference.takedownRef.$isTypeOf(action)) {\n return findAppealedEvent(ctx, subject, { type: 'takedown' })\n }\n throw new InvalidRequestError(\n 'Unknown appeal action reference',\n 'InvalidAppealSubject',\n )\n}\n\n/**\n * Label rows are keyed by a single string: the record URI, or the DID for an\n * account.\n */\nexport const subjectLabelUri = (subject: ModSubject): UriString =>\n (subject.info().subjectUri ?? subject.did) as UriString\n\n/**\n * Whether the subject has used up its appeals.\n *\n * Non-account subjects get one ever, closed or not. An account gets one at a\n * time, based on whether the latest appeal report is closed.\n *\n * The read path calls this to decide whether to offer `appeal`, and the write\n * path calls it to decide whether to accept one. They have to be the same\n * question: anything else advertises an appeal that submission will refuse.\n */\nexport const appealsExhausted = (\n subject: ModSubject,\n report: AppealReport | null,\n): boolean => {\n if (!report) return false\n return subject.isRepo() ? report.status !== 'closed' : true\n}\n\nexport const findLatestAppealReport = async (\n db: Database,\n subject: ModSubject,\n): Promise<AppealReport | null> => {\n const report = await db.db\n .selectFrom('report')\n .where('reportType', '=', APPEAL_REASON_TYPE)\n .where((eb) => reportSubjectFilter(eb, subject))\n .orderBy('id', 'desc')\n .limit(1)\n .select(['id', 'status', 'createdAt', 'updatedAt', 'closedAt'])\n .executeTakeFirst()\n return report ?? null\n}\n\n/**\n * Reject an appeal the subject is no longer entitled to.\n *\n * Answers the same question as the `availableActions` the read path\n * advertises, through {@link appealsExhausted}, so the two cannot drift.\n */\nexport const assertAppealAllowed = async (\n dbTxn: Database,\n subject: ModSubject,\n) => {\n dbTxn.assertTransaction()\n await sql`select pg_advisory_xact_lock(\n hashtextextended(${subjectKey(subject)}, 0)\n )`.execute(dbTxn.db)\n\n const existing = await findLatestAppealReport(dbTxn, subject)\n\n if (appealsExhausted(subject, existing)) {\n throw new ForbiddenError(\n subject.isRepo()\n ? 'Awaiting decision on previous appeal'\n : 'This has already been appealed',\n 'AlreadyAppealed',\n )\n }\n}\n\nexport type FileAppealInput = {\n /** DID of the affected account, shown as the appeal reporter. */\n requester: DidString\n /** Moderator filing on the affected account's behalf, when applicable. */\n submittedBy?: DidString\n /** The subject being appealed, already resolved and authorized. */\n subject: ModSubject\n /** Resolved moderation event ID, when one could be found. */\n resolvedActionId?: number\n /** The action reference supplied by the caller. */\n action?: tools.ozone.inbox.appealActionedSubject.$InputBody['action']\n /** Optional: an appeal is a request for review, not an argued case. */\n reason?: string\n modTool?: { name: string; meta?: { [_ in string]: unknown } }\n}\n\nconst buildAppealEventMeta = (\n action: FileAppealInput['action'],\n): Record<string, string | number | boolean> | undefined => {\n if (!action) return undefined\n const meta: Record<string, string | number | boolean> = {\n appealActionType: action.$type,\n }\n const reference = tools.ozone.inbox.appealActionedSubject\n if (reference.actionRef.$isTypeOf(action)) {\n meta.appealActionId = action.id\n } else if (reference.labelRef.$isTypeOf(action)) {\n meta.appealLabel = action.val\n }\n return meta\n}\n\nconst findSourceQueueIds = async (\n db: Database,\n subject: ModSubject,\n actionId: number,\n): Promise<(number | null)[]> => {\n // @NOTE Closed reports retain the source action link. Query each status\n // separately so the existing active-subject and closed-DID indexes apply.\n const query = db.db\n .selectFrom('report')\n .where((eb) => reportSubjectFilter(eb, subject))\n .where('reportType', '!=', APPEAL_REASON_TYPE)\n .where('actionEventIds', '@>', jsonb([actionId]))\n\n const [active, closed] = await Promise.all([\n query\n .where(sql<boolean>`status != 'closed'`)\n .select('queueId')\n .execute(),\n query\n .where(sql<boolean>`status = 'closed'`)\n .select('queueId')\n .execute(),\n ])\n return [...active, ...closed].map((report) => report.queueId)\n}\n\n/**\n * Pick the queue an appeal should land in.\n *\n * A linked appeal inherits the queue of the report the appealed action\n * resolved, but only when every candidate agrees - bulk and collateral actions\n * can link one event to reports sitting in different queues, and guessing\n * between them is worse than using normal appeal routing. An unlinked or\n * ambiguously linked appeal falls back to whatever queue accepts appeals.\n *\n * This is a read of best-effort routing data, so it deliberately runs outside\n * the appeal transaction: holding the subject lock across a queue listing and\n * a report scan would serialize unrelated appeals for no consistency gain, and\n * if the routing data moves underneath us the router reassigns anyway.\n */\nconst selectQueue = async (\n ctx: AppContext,\n subject: ModSubject,\n resolvedActionId: number | undefined,\n action: FileAppealInput['action'],\n) => {\n const sourceQueueIds =\n resolvedActionId === undefined\n ? []\n : await findSourceQueueIds(ctx.db, subject, resolvedActionId)\n const allSourcesAssigned =\n sourceQueueIds.length > 0 &&\n sourceQueueIds.every(\n (queueId): queueId is number => queueId !== null && queueId > 0,\n )\n const sourceQueues = new Set(sourceQueueIds)\n let queueId: number | null =\n allSourcesAssigned && sourceQueues.size === 1\n ? (sourceQueueIds[0] as number)\n : null\n const queueService = ctx.queueService(ctx.db)\n if (\n queueId === null &&\n action &&\n tools.ozone.inbox.appealActionedSubject.labelRef.$isTypeOf(action)\n ) {\n queueId = (await queueService.getByRecommendedLabel(action.val))?.id ?? null\n }\n if (queueId === null) {\n const { queues } = await queueService.list({ limit: 1000, enabled: true })\n const subjectUri = subject.info().subjectUri\n const collection = subjectUri ? new AtUri(subjectUri).collection : null\n queueId =\n findMatchingQueue(\n queues,\n subject.isRecord() ? 'record' : 'account',\n collection,\n APPEAL_REASON_TYPE,\n )?.id ?? -1\n }\n\n // An unrouted report carries no queue timestamp: `queuedAt` records when a\n // report entered a queue, and matches the `queueId: -1` / `status: 'open'`\n // shape the queue service uses for everything it cannot route.\n return {\n queueId,\n queuedAt: queueId > 0 ? currentDatetimeString() : null,\n }\n}\n\n/**\n * File an appeal: validate the subject, route it, and record it.\n *\n * An appeal is an ordinary `reasonAppeal` report, so it inherits the report\n * lifecycle, queue routing, and activity machinery rather than introducing a\n * parallel one. What makes it a *linked* appeal is `actionEventIds`, whose\n * first entry is the action being challenged.\n *\n * Everything that must be atomic - the eligibility guard, the report event,\n * and the report row - shares one transaction. Everything that needs\n * not be, is already done by the time it opens.\n */\nexport const fileAppeal = async (\n ctx: AppContext,\n {\n requester,\n submittedBy,\n subject,\n resolvedActionId,\n action,\n reason,\n modTool,\n }: FileAppealInput,\n): Promise<{ reportId: number }> => {\n const { queueId, queuedAt } = await selectQueue(\n ctx,\n subject,\n resolvedActionId,\n action,\n )\n\n const reportId = await ctx.db.transaction(async (dbTxn) => {\n await assertAppealAllowed(dbTxn, subject)\n\n // create event and report row\n const moderationTxn = ctx.modService(dbTxn)\n const { event: reportEvent } = await moderationTxn.report({\n reason,\n subject,\n reasonType: APPEAL_REASON_TYPE,\n reportedBy: requester,\n modTool,\n eventMeta: {\n ...buildAppealEventMeta(action),\n ...(submittedBy ? { appealSubmittedBy: submittedBy } : {}),\n },\n })\n return ctx.queueService(dbTxn).insertReportFromEvent({\n event: reportEvent,\n reportType: APPEAL_REASON_TYPE,\n queueId,\n queuedAt,\n actionEventIds:\n resolvedActionId === undefined ? null : [resolvedActionId],\n })\n })\n\n return { reportId }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"appeal.js","sourceRoot":"","sources":["../../src/inbox/appeal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AAC5B,OAAO,EAIL,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAI1E,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAI5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAEL,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,qBAAqB,CAAA;AAE5B,MAAM,CAAC,MAAM,kBAAkB,GAAG,sCAAsC,CAAA;AACxE,MAAM,CAAC,MAAM,QAAQ,GAAG,8CAA8C,CAAA;AAC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,EAAE,EAAE;QACxD,MAAM,mBAAmB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAEzC,8BAA8B;QAC9B,MAAM,aAAa,GAAG,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QAC3C,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,aAAa,CAAC,MAAM,CAAC;YACxD,MAAM;YACN,OAAO;YACP,UAAU,EAAE,kBAAkB;YAC9B,UAAU,EAAE,SAAS;YACrB,OAAO;YACP,SAAS,EAAE;gBACT,GAAG,oBAAoB,CAAC,MAAM,CAAC;gBAC/B,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC3D;SACF,CAAC,CAAA;QACF,OAAO,GAAG,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,qBAAqB,CAAC;YACnD,KAAK,EAAE,WAAW;YAClB,UAAU,EAAE,kBAAkB;YAC9B,OAAO;YACP,QAAQ;YACR,cAAc,EACZ,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC;SAC7D,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,QAAQ,EAAE,CAAA;AACrB,CAAC,CAAA","sourcesContent":["import type { Expression, ExpressionBuilder, SqlBool } from 'kysely'\nimport { sql } from 'kysely'\nimport {\n type DatetimeString,\n type DidString,\n type UriString,\n currentDatetimeString,\n toDatetimeString,\n} from '@atproto/lex'\nimport { AtUri } from '@atproto/syntax'\nimport { ForbiddenError, InvalidRequestError } from '@atproto/xrpc-server'\nimport type { AppContext } from '../context.js'\nimport type { Database } from '../db/index.js'\nimport type { DatabaseSchemaType } from '../db/schema/index.js'\nimport { jsonb } from '../db/types.js'\nimport { tools } from '../lexicons/index.js'\nimport type { AppealView } from '../lexicons/tools/ozone/inbox/defs.js'\nimport type { ModSubject } from '../mod-service/subject.js'\nimport type { ModerationSubjectStatusRow } from '../mod-service/types.js'\nimport { findMatchingQueue } from '../queue/service.js'\nimport {\n type AppealOutcome,\n appealActivityOutcome,\n appealReportSelection,\n appealResolutionFilter,\n} from './appeal-outcome.js'\n\nexport const APPEAL_REASON_TYPE = 'tools.ozone.report.defs#reasonAppeal'\nexport const TAKEDOWN = 'tools.ozone.moderation.defs#modEventTakedown'\nexport const REVERSE_TAKEDOWN =\n 'tools.ozone.moderation.defs#modEventReverseTakedown'\nexport const LABEL = 'tools.ozone.moderation.defs#modEventLabel'\nexport const EMAIL = 'tools.ozone.moderation.defs#modEventEmail'\nexport const MUTE_REPORTER = 'tools.ozone.moderation.defs#modEventMuteReporter'\nexport const REVOKE_CREDENTIALS =\n 'tools.ozone.moderation.defs#revokeAccountCredentialsEvent'\n\n/**\n * The subject's most recent `reasonAppeal` report, reduced to the columns the\n * appeal state derives from. Deliberately excludes `actionNote` and everything\n * else a moderator wrote for other moderators.\n */\nexport type AppealReport = {\n id: number\n status: string\n createdAt: DatetimeString\n updatedAt: DatetimeString\n closedAt: DatetimeString | null\n outcome?: AppealOutcome | null\n}\n\nexport type AppealInput = {\n subject: ModSubject\n status: Pick<ModerationSubjectStatusRow, 'appealed' | 'lastAppealedAt'> | null\n report: AppealReport | null\n /** Eligibility retains older appeals even when their history is hidden. */\n eligibilityReport?: AppealReport | null\n\n /** Calendar months an action stays appealable, from `InboxConfig`. */\n windowMonths: number\n latestAppealableAt: DatetimeString | null\n}\n\nexport type AppealState = {\n view: AppealView\n availableActions: string[]\n}\n\nexport const PUBLIC_EVENT_ACTIONS = [\n TAKEDOWN,\n LABEL,\n EMAIL,\n MUTE_REPORTER,\n REVOKE_CREDENTIALS,\n REVERSE_TAKEDOWN,\n] as const\n\nexport const APPEALABLE_EVENT_ACTIONS = [TAKEDOWN, LABEL] as const\n\nexport const isAppealableEvent = (action: string): boolean =>\n (APPEALABLE_EVENT_ACTIONS as readonly string[]).includes(action)\n\nexport const appealWindowEnd = (\n actionCreatedAt: DatetimeString,\n windowMonths: number,\n): DatetimeString => {\n const end = new Date(actionCreatedAt)\n const day = end.getUTCDate()\n end.setUTCMonth(end.getUTCMonth() + windowMonths)\n // Clamp a rollover: 31 Aug + 6 months is 28/29 Feb, not 2/3 Mar.\n if (end.getUTCDate() !== day) end.setUTCDate(0)\n return toDatetimeString(end)\n}\n\nexport const isAppealWindowOpen = (\n actionCreatedAt: DatetimeString,\n windowMonths: number,\n now = new Date(),\n): boolean => new Date(appealWindowEnd(actionCreatedAt, windowMonths)) > now\n\n/**\n * Appeal state, derived entirely from data Ozone already records.\n */\nexport const toAppealState = ({\n subject,\n status,\n report,\n eligibilityReport = report,\n latestAppealableAt,\n windowMonths,\n}: AppealInput): AppealState => {\n const appealableUntil = latestAppealableAt\n ? appealWindowEnd(latestAppealableAt, windowMonths)\n : null\n const windowOpen = !!appealableUntil && new Date(appealableUntil) > new Date()\n\n let state: AppealView['state']\n if (report) {\n // @NOTE Report activities do not maintain the subject's appealed flag.\n // Use the same source of truth as the appeal submission guard.\n state = report.status === 'closed' ? 'resolved' : 'pending'\n } else {\n state = appealableUntil && !windowOpen ? 'expired' : 'none'\n }\n\n const view: AppealView = { state }\n if (report) {\n view.appealedAt = status?.lastAppealedAt ?? report.createdAt\n if (state === 'resolved' && report.closedAt)\n view.resolvedAt = report.closedAt\n if (state === 'resolved' && report.outcome) view.outcome = report.outcome\n }\n if (appealableUntil) view.appealableUntil = appealableUntil\n\n const availableActions =\n windowOpen && !appealsExhausted(subject, eligibilityReport)\n ? ['appeal']\n : []\n\n return { view, availableActions }\n}\n\n/**\n * Stable identity of a moderated subject, independent of which action touched\n * it. Two appeals against the same record - or the same message, or the same\n * conversation - share a key even when they name different action IDs.\n */\nexport const subjectKey = (subject: ModSubject): string => {\n const { subjectDid, subjectMessageId, subjectConvoId } = subject.info()\n if (subject.isMessage())\n return `message:${subjectDid}:${subjectConvoId}:${subjectMessageId}`\n if (subject.isConvo()) return `convo:${subjectDid}:${subjectConvoId}`\n if (subject.isRecord()) return `record:${subjectDid}:${subject.recordPath}`\n return `account:${subjectDid}`\n}\n\n/**\n * Match report rows by that identity. Mirrors the subject normalization in\n * `mod-service/report.ts`: `recordPath` is '' for accounts, messages, and\n * conversations alike, so an account match has to exclude the chat columns.\n */\nexport const reportSubjectFilter = (\n eb: ExpressionBuilder<DatabaseSchemaType, 'report'>,\n subject: ModSubject,\n): Expression<SqlBool> => {\n const { subjectDid, subjectMessageId, subjectConvoId } = subject.info()\n if (subject.isMessage()) {\n return eb.and([\n eb('did', '=', subjectDid),\n eb('subjectMessageId', '=', subjectMessageId),\n eb('subjectConvoId', '=', subjectConvoId),\n ])\n }\n if (subject.isConvo()) {\n return eb.and([\n eb('did', '=', subjectDid),\n eb('subjectConvoId', '=', subjectConvoId),\n eb('subjectMessageId', 'is', null),\n ])\n }\n if (subject.isRecord()) {\n return eb.and([\n eb('did', '=', subjectDid),\n eb('recordPath', '=', subject.recordPath),\n ])\n }\n return eb.and([\n eb('did', '=', subjectDid),\n eb('recordPath', '=', ''),\n eb('subjectMessageId', 'is', null),\n eb('subjectConvoId', 'is', null),\n ])\n}\n\nexport const eventSubjectFilter = (\n eb: ExpressionBuilder<DatabaseSchemaType, 'moderation_event'>,\n subject: ModSubject,\n): Expression<SqlBool> => {\n const {\n subjectType,\n subjectDid,\n subjectUri,\n subjectMessageId,\n subjectConvoId,\n } = subject.info()\n if (subject.isMessage()) {\n return eb.and([\n eb('subjectDid', '=', subjectDid),\n eb('subjectMessageId', '=', subjectMessageId),\n eb('subjectConvoId', '=', subjectConvoId),\n ])\n }\n if (subject.isConvo()) {\n return eb.and([\n eb('subjectDid', '=', subjectDid),\n eb('subjectConvoId', '=', subjectConvoId),\n eb('subjectMessageId', 'is', null),\n ])\n }\n if (subject.isRecord()) {\n return eb.and([\n eb('subjectDid', '=', subjectDid),\n eb('subjectUri', '=', subjectUri),\n eb('subjectType', '=', subjectType),\n ])\n }\n return eb.and([\n eb('subjectDid', '=', subjectDid),\n eb('subjectType', '=', subjectType),\n ])\n}\n\nexport const findAppealedEvent = async (\n ctx: AppContext,\n subject: ModSubject,\n action: { type: 'label'; val: string } | { type: 'takedown' },\n) => {\n let query = ctx.db.db\n .selectFrom('moderation_event')\n .where((eb) => eventSubjectFilter(eb, subject))\n .where('action', '=', action.type === 'label' ? LABEL : TAKEDOWN)\n .$if(ctx.cfg.inbox.startAt !== undefined, (qb) =>\n qb.where('createdAt', '>=', ctx.cfg.inbox.startAt!),\n )\n\n if (action.type === 'label') {\n query = query.where(\n sql<boolean>`${action.val} = ANY(string_to_array(\"createLabelVals\", ' '))`,\n )\n }\n\n const matches = await query\n .orderBy('id', 'desc')\n .limit(2)\n .selectAll()\n .execute()\n return matches.length === 1 ? matches[0] : undefined\n}\n\nexport const resolveAppealAction = async (\n ctx: AppContext,\n subject: ModSubject,\n action: tools.ozone.inbox.appealActionedSubject.$InputBody['action'],\n) => {\n if (!action) return undefined\n const reference = tools.ozone.inbox.appealActionedSubject\n if (reference.actionRef.$isTypeOf(action)) {\n return ctx.modService(ctx.db).getEvent(action.id)\n }\n if (reference.labelRef.$isTypeOf(action)) {\n return findAppealedEvent(ctx, subject, { type: 'label', val: action.val })\n }\n if (reference.takedownRef.$isTypeOf(action)) {\n return findAppealedEvent(ctx, subject, { type: 'takedown' })\n }\n throw new InvalidRequestError(\n 'Unknown appeal action reference',\n 'InvalidAppealSubject',\n )\n}\n\n/**\n * Label rows are keyed by a single string: the record URI, or the DID for an\n * account.\n */\nexport const subjectLabelUri = (subject: ModSubject): UriString =>\n (subject.info().subjectUri ?? subject.did) as UriString\n\n/**\n * Whether the subject has used up its appeals.\n *\n * Non-account subjects get one ever, closed or not. An account gets one at a\n * time, based on whether the latest appeal report is closed.\n *\n * The read path calls this to decide whether to offer `appeal`, and the write\n * path calls it to decide whether to accept one. They have to be the same\n * question: anything else advertises an appeal that submission will refuse.\n */\nexport const appealsExhausted = (\n subject: ModSubject,\n report: AppealReport | null,\n): boolean => {\n if (!report) return false\n return subject.isRepo() ? report.status !== 'closed' : true\n}\n\nexport const findLatestAppealReport = async (\n db: Database,\n subject: ModSubject,\n): Promise<AppealReport | null> => {\n const report = await db.db\n .selectFrom(\n db.db\n .selectFrom('report')\n .where('reportType', '=', APPEAL_REASON_TYPE)\n .where((eb) => reportSubjectFilter(eb, subject))\n .orderBy('id', 'desc')\n .limit(1)\n .select(appealReportSelection)\n .as('report'),\n )\n .leftJoinLateral(\n (eb) =>\n eb\n .selectFrom('report_activity')\n .where('report.status', '=', 'closed')\n .whereRef('reportId', '=', 'report.id')\n .where('activityType', '=', 'closeActivity')\n .whereRef('createdAt', '=', 'report.closedAt')\n .orderBy('id', 'desc')\n .limit(1)\n .select(['id', 'activityType', 'meta'])\n .as('closure'),\n (join) => join.onTrue(),\n )\n .leftJoin('moderation_event as resolution', (join) =>\n join.on(appealResolutionFilter('report', 'closure')),\n )\n .select([\n 'report.id',\n 'report.status',\n 'report.createdAt',\n 'report.updatedAt',\n 'report.closedAt',\n ])\n .select(appealActivityOutcome('report', 'closure').as('outcome'))\n .executeTakeFirst()\n return report ?? null\n}\n\n/**\n * Reject an appeal the subject is no longer entitled to.\n *\n * Answers the same question as the `availableActions` the read path\n * advertises, through {@link appealsExhausted}, so the two cannot drift.\n */\nexport const assertAppealAllowed = async (\n dbTxn: Database,\n subject: ModSubject,\n) => {\n dbTxn.assertTransaction()\n await sql`select pg_advisory_xact_lock(\n hashtextextended(${subjectKey(subject)}, 0)\n )`.execute(dbTxn.db)\n\n const existing = await findLatestAppealReport(dbTxn, subject)\n\n if (appealsExhausted(subject, existing)) {\n throw new ForbiddenError(\n subject.isRepo()\n ? 'Awaiting decision on previous appeal'\n : 'This has already been appealed',\n 'AlreadyAppealed',\n )\n }\n}\n\nexport type FileAppealInput = {\n /** DID of the affected account, shown as the appeal reporter. */\n requester: DidString\n /** Moderator filing on the affected account's behalf, when applicable. */\n submittedBy?: DidString\n /** The subject being appealed, already resolved and authorized. */\n subject: ModSubject\n /** Resolved moderation event ID, when one could be found. */\n resolvedActionId?: number\n /** The action reference supplied by the caller. */\n action?: tools.ozone.inbox.appealActionedSubject.$InputBody['action']\n /** Optional: an appeal is a request for review, not an argued case. */\n reason?: string\n modTool?: { name: string; meta?: { [_ in string]: unknown } }\n}\n\nconst buildAppealEventMeta = (\n action: FileAppealInput['action'],\n): Record<string, string | number | boolean> | undefined => {\n if (!action) return undefined\n const meta: Record<string, string | number | boolean> = {\n appealActionType: action.$type,\n }\n const reference = tools.ozone.inbox.appealActionedSubject\n if (reference.actionRef.$isTypeOf(action)) {\n meta.appealActionId = action.id\n } else if (reference.labelRef.$isTypeOf(action)) {\n meta.appealLabel = action.val\n }\n return meta\n}\n\nconst findSourceQueueIds = async (\n db: Database,\n subject: ModSubject,\n actionId: number,\n): Promise<(number | null)[]> => {\n // @NOTE Closed reports retain the source action link. Query each status\n // separately so the existing active-subject and closed-DID indexes apply.\n const query = db.db\n .selectFrom('report')\n .where((eb) => reportSubjectFilter(eb, subject))\n .where('reportType', '!=', APPEAL_REASON_TYPE)\n .where('actionEventIds', '@>', jsonb([actionId]))\n\n const [active, closed] = await Promise.all([\n query\n .where(sql<boolean>`status != 'closed'`)\n .select('queueId')\n .execute(),\n query\n .where(sql<boolean>`status = 'closed'`)\n .select('queueId')\n .execute(),\n ])\n return [...active, ...closed].map((report) => report.queueId)\n}\n\n/**\n * Pick the queue an appeal should land in.\n *\n * A linked appeal inherits the queue of the report the appealed action\n * resolved, but only when every candidate agrees - bulk and collateral actions\n * can link one event to reports sitting in different queues, and guessing\n * between them is worse than using normal appeal routing. An unlinked or\n * ambiguously linked appeal falls back to whatever queue accepts appeals.\n *\n * This is a read of best-effort routing data, so it deliberately runs outside\n * the appeal transaction: holding the subject lock across a queue listing and\n * a report scan would serialize unrelated appeals for no consistency gain, and\n * if the routing data moves underneath us the router reassigns anyway.\n */\nconst selectQueue = async (\n ctx: AppContext,\n subject: ModSubject,\n resolvedActionId: number | undefined,\n action: FileAppealInput['action'],\n) => {\n const sourceQueueIds =\n resolvedActionId === undefined\n ? []\n : await findSourceQueueIds(ctx.db, subject, resolvedActionId)\n const allSourcesAssigned =\n sourceQueueIds.length > 0 &&\n sourceQueueIds.every(\n (queueId): queueId is number => queueId !== null && queueId > 0,\n )\n const sourceQueues = new Set(sourceQueueIds)\n let queueId: number | null =\n allSourcesAssigned && sourceQueues.size === 1\n ? (sourceQueueIds[0] as number)\n : null\n const queueService = ctx.queueService(ctx.db)\n if (\n queueId === null &&\n action &&\n tools.ozone.inbox.appealActionedSubject.labelRef.$isTypeOf(action)\n ) {\n queueId = (await queueService.getByRecommendedLabel(action.val))?.id ?? null\n }\n if (queueId === null) {\n const { queues } = await queueService.list({ limit: 1000, enabled: true })\n const subjectUri = subject.info().subjectUri\n const collection = subjectUri ? new AtUri(subjectUri).collection : null\n queueId =\n findMatchingQueue(\n queues,\n subject.isRecord() ? 'record' : 'account',\n collection,\n APPEAL_REASON_TYPE,\n )?.id ?? -1\n }\n\n // An unrouted report carries no queue timestamp: `queuedAt` records when a\n // report entered a queue, and matches the `queueId: -1` / `status: 'open'`\n // shape the queue service uses for everything it cannot route.\n return {\n queueId,\n queuedAt: queueId > 0 ? currentDatetimeString() : null,\n }\n}\n\n/**\n * File an appeal: validate the subject, route it, and record it.\n *\n * An appeal is an ordinary `reasonAppeal` report, so it inherits the report\n * lifecycle, queue routing, and activity machinery rather than introducing a\n * parallel one. What makes it a *linked* appeal is `actionEventIds`, whose\n * first entry is the action being challenged.\n *\n * Everything that must be atomic - the eligibility guard, the report event,\n * and the report row - shares one transaction. Everything that needs\n * not be, is already done by the time it opens.\n */\nexport const fileAppeal = async (\n ctx: AppContext,\n {\n requester,\n submittedBy,\n subject,\n resolvedActionId,\n action,\n reason,\n modTool,\n }: FileAppealInput,\n): Promise<{ reportId: number }> => {\n const { queueId, queuedAt } = await selectQueue(\n ctx,\n subject,\n resolvedActionId,\n action,\n )\n\n const reportId = await ctx.db.transaction(async (dbTxn) => {\n await assertAppealAllowed(dbTxn, subject)\n\n // create event and report row\n const moderationTxn = ctx.modService(dbTxn)\n const { event: reportEvent } = await moderationTxn.report({\n reason,\n subject,\n reasonType: APPEAL_REASON_TYPE,\n reportedBy: requester,\n modTool,\n eventMeta: {\n ...buildAppealEventMeta(action),\n ...(submittedBy ? { appealSubmittedBy: submittedBy } : {}),\n },\n })\n return ctx.queueService(dbTxn).insertReportFromEvent({\n event: reportEvent,\n reportType: APPEAL_REASON_TYPE,\n queueId,\n queuedAt,\n actionEventIds:\n resolvedActionId === undefined ? null : [resolvedActionId],\n })\n })\n\n return { reportId }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DatetimeString } from '@atproto/lex';
|
|
1
|
+
import type { DatetimeString, DidString } from '@atproto/lex';
|
|
2
2
|
/** Match notification targets to the same post-cutoff history their detail exposes. */
|
|
3
|
-
export declare function notificationVisibility(startAt: DatetimeString): import("kysely").RawBuilder<boolean>;
|
|
3
|
+
export declare function notificationVisibility(recipientDid: DidString, startAt: DatetimeString): import("kysely").RawBuilder<boolean>;
|
|
4
4
|
//# sourceMappingURL=notification-visibility.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notification-visibility.d.ts","sourceRoot":"","sources":["../../src/inbox/notification-visibility.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"notification-visibility.d.ts","sourceRoot":"","sources":["../../src/inbox/notification-visibility.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAQ7D,uFAAuF;AACvF,wBAAgB,sBAAsB,CACpC,YAAY,EAAE,SAAS,EACvB,OAAO,EAAE,cAAc,wCA+BxB"}
|