@atproto/bsky 0.0.15 → 0.0.17
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 +18 -0
- package/dist/api/com/atproto/moderation/util.d.ts +4 -3
- package/dist/cache/read-through.d.ts +30 -0
- package/dist/config.d.ts +18 -0
- package/dist/context.d.ts +21 -6
- package/dist/daemon/config.d.ts +15 -0
- package/dist/daemon/context.d.ts +15 -0
- package/dist/daemon/index.d.ts +23 -0
- package/dist/daemon/logger.d.ts +3 -0
- package/dist/daemon/notifications.d.ts +18 -0
- package/dist/daemon/services.d.ts +11 -0
- package/dist/db/database-schema.d.ts +1 -2
- package/dist/db/index.js +41 -1
- package/dist/db/index.js.map +3 -3
- package/dist/db/migrations/20231003T202833377Z-create-moderation-subject-status.d.ts +3 -0
- package/dist/db/migrations/20231205T000257238Z-remove-did-cache.d.ts +3 -0
- package/dist/db/migrations/index.d.ts +2 -0
- package/dist/db/pagination.d.ts +2 -1
- package/dist/db/{periodic-moderation-action-reversal.d.ts → periodic-moderation-event-reversal.d.ts} +3 -5
- package/dist/db/tables/moderation.d.ts +24 -34
- package/dist/did-cache.d.ts +10 -7
- package/dist/feed-gen/types.d.ts +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +4370 -2758
- package/dist/index.js.map +3 -3
- package/dist/indexer/context.d.ts +2 -0
- package/dist/indexer/index.d.ts +1 -0
- package/dist/lexicon/index.d.ts +23 -18
- package/dist/lexicon/lexicons.d.ts +561 -412
- package/dist/lexicon/types/app/bsky/feed/defs.d.ts +1 -7
- package/dist/lexicon/types/app/bsky/graph/defs.d.ts +1 -0
- package/dist/lexicon/types/com/atproto/admin/defs.d.ts +114 -48
- package/dist/lexicon/types/com/atproto/admin/{resolveModerationReports.d.ts → deleteAccount.d.ts} +2 -13
- package/dist/lexicon/types/com/atproto/admin/{takeModerationAction.d.ts → emitModerationEvent.d.ts} +5 -6
- package/dist/lexicon/types/com/atproto/admin/{getModerationAction.d.ts → getModerationEvent.d.ts} +1 -1
- package/dist/lexicon/types/com/atproto/admin/{getModerationActions.d.ts → queryModerationEvents.d.ts} +5 -1
- package/dist/lexicon/types/com/atproto/admin/{getModerationReports.d.ts → queryModerationStatuses.d.ts} +12 -6
- package/dist/lexicon/types/com/atproto/admin/sendEmail.d.ts +1 -0
- package/dist/lexicon/types/com/atproto/{admin/getModerationReport.d.ts → temp/importRepo.d.ts} +10 -7
- package/dist/lexicon/types/com/atproto/temp/pushBlob.d.ts +25 -0
- package/dist/lexicon/types/com/atproto/{admin/reverseModerationAction.d.ts → temp/transferAccount.d.ts} +11 -5
- package/dist/logger.d.ts +1 -0
- package/dist/migrate-moderation-data.d.ts +1 -0
- package/dist/redis.d.ts +10 -1
- package/dist/services/actor/index.d.ts +18 -4
- package/dist/services/actor/views.d.ts +6 -8
- package/dist/services/feed/index.d.ts +7 -4
- package/dist/services/feed/util.d.ts +9 -1
- package/dist/services/feed/views.d.ts +11 -21
- package/dist/services/graph/index.d.ts +5 -29
- package/dist/services/graph/types.d.ts +1 -0
- package/dist/services/index.d.ts +3 -7
- package/dist/services/label/index.d.ts +10 -4
- package/dist/services/moderation/index.d.ts +134 -72
- package/dist/services/moderation/pagination.d.ts +36 -0
- package/dist/services/moderation/status.d.ts +13 -0
- package/dist/services/moderation/types.d.ts +35 -0
- package/dist/services/moderation/views.d.ts +18 -14
- package/dist/services/types.d.ts +3 -0
- package/dist/services/util/notification.d.ts +5 -0
- package/dist/services/util/post.d.ts +6 -6
- package/dist/util/debug.d.ts +1 -1
- package/dist/util/retry.d.ts +1 -6
- package/package.json +11 -11
- package/src/api/app/bsky/feed/getActorFeeds.ts +2 -1
- package/src/api/app/bsky/feed/getActorLikes.ts +1 -3
- package/src/api/app/bsky/feed/getAuthorFeed.ts +1 -3
- package/src/api/app/bsky/feed/getFeed.ts +9 -9
- package/src/api/app/bsky/feed/getFeedGenerator.ts +3 -0
- package/src/api/app/bsky/feed/getFeedGenerators.ts +2 -1
- package/src/api/app/bsky/feed/getListFeed.ts +1 -3
- package/src/api/app/bsky/feed/getPostThread.ts +15 -54
- package/src/api/app/bsky/feed/getPosts.ts +21 -18
- package/src/api/app/bsky/feed/getSuggestedFeeds.ts +2 -1
- package/src/api/app/bsky/feed/getTimeline.ts +1 -3
- package/src/api/app/bsky/feed/searchPosts.ts +20 -17
- package/src/api/app/bsky/graph/getList.ts +6 -3
- package/src/api/app/bsky/graph/getListBlocks.ts +3 -2
- package/src/api/app/bsky/graph/getListMutes.ts +2 -1
- package/src/api/app/bsky/graph/getLists.ts +2 -1
- package/src/api/app/bsky/unspecced/getPopularFeedGenerators.ts +3 -1
- package/src/api/blob-resolver.ts +6 -11
- package/src/api/com/atproto/admin/emitModerationEvent.ts +220 -0
- package/src/api/com/atproto/admin/{getModerationActions.ts → getModerationEvent.ts} +5 -11
- package/src/api/com/atproto/admin/getRecord.ts +1 -0
- package/src/api/com/atproto/admin/{getModerationReports.ts → queryModerationEvents.ts} +13 -16
- package/src/api/com/atproto/admin/queryModerationStatuses.ts +55 -0
- package/src/api/com/atproto/moderation/createReport.ts +9 -7
- package/src/api/com/atproto/moderation/util.ts +38 -20
- package/src/api/index.ts +8 -14
- package/src/auth.ts +29 -21
- package/src/auto-moderator/index.ts +26 -19
- package/src/cache/read-through.ts +151 -0
- package/src/config.ts +90 -1
- package/src/context.ts +11 -7
- package/src/daemon/config.ts +60 -0
- package/src/daemon/context.ts +27 -0
- package/src/daemon/index.ts +78 -0
- package/src/daemon/logger.ts +6 -0
- package/src/daemon/notifications.ts +54 -0
- package/src/daemon/services.ts +22 -0
- package/src/db/database-schema.ts +0 -2
- package/src/db/migrations/20231003T202833377Z-create-moderation-subject-status.ts +123 -0
- package/src/db/migrations/20231205T000257238Z-remove-did-cache.ts +14 -0
- package/src/db/migrations/index.ts +2 -0
- package/src/db/pagination.ts +26 -3
- package/src/db/{periodic-moderation-action-reversal.ts → periodic-moderation-event-reversal.ts} +50 -46
- package/src/db/tables/moderation.ts +35 -52
- package/src/did-cache.ts +33 -56
- package/src/feed-gen/bsky-team.ts +1 -1
- package/src/feed-gen/hot-classic.ts +1 -1
- package/src/feed-gen/index.ts +0 -4
- package/src/feed-gen/mutuals.ts +6 -2
- package/src/feed-gen/types.ts +1 -1
- package/src/index.ts +57 -17
- package/src/indexer/context.ts +5 -0
- package/src/indexer/index.ts +10 -7
- package/src/lexicon/index.ts +80 -67
- package/src/lexicon/lexicons.ts +698 -507
- package/src/lexicon/types/app/bsky/feed/defs.ts +1 -18
- package/src/lexicon/types/app/bsky/graph/defs.ts +1 -0
- package/src/lexicon/types/com/atproto/admin/defs.ts +276 -84
- package/src/lexicon/types/com/atproto/admin/{resolveModerationReports.ts → deleteAccount.ts} +2 -13
- package/src/lexicon/types/com/atproto/admin/{takeModerationAction.ts → emitModerationEvent.ts} +13 -11
- package/src/lexicon/types/com/atproto/admin/{getModerationReport.ts → getModerationEvent.ts} +1 -1
- package/src/lexicon/types/com/atproto/admin/{getModerationActions.ts → queryModerationEvents.ts} +8 -1
- package/src/lexicon/types/com/atproto/admin/{getModerationReports.ts → queryModerationStatuses.ts} +21 -14
- package/src/lexicon/types/com/atproto/admin/sendEmail.ts +1 -0
- package/src/lexicon/types/com/atproto/{admin/getModerationAction.ts → temp/importRepo.ts} +11 -7
- package/src/lexicon/types/com/atproto/temp/pushBlob.ts +39 -0
- package/src/lexicon/types/com/atproto/{admin/reverseModerationAction.ts → temp/transferAccount.ts} +18 -5
- package/src/logger.ts +2 -0
- package/src/migrate-moderation-data.ts +414 -0
- package/src/redis.ts +43 -3
- package/src/services/actor/index.ts +55 -7
- package/src/services/actor/views.ts +18 -21
- package/src/services/feed/index.ts +52 -19
- package/src/services/feed/util.ts +47 -19
- package/src/services/feed/views.ts +87 -13
- package/src/services/graph/index.ts +21 -3
- package/src/services/graph/types.ts +1 -0
- package/src/services/index.ts +14 -14
- package/src/services/indexing/index.ts +7 -10
- package/src/services/indexing/plugins/block.ts +2 -3
- package/src/services/indexing/plugins/feed-generator.ts +2 -3
- package/src/services/indexing/plugins/follow.ts +2 -3
- package/src/services/indexing/plugins/like.ts +2 -3
- package/src/services/indexing/plugins/list-block.ts +2 -3
- package/src/services/indexing/plugins/list-item.ts +2 -3
- package/src/services/indexing/plugins/list.ts +2 -3
- package/src/services/indexing/plugins/post.ts +16 -4
- package/src/services/indexing/plugins/repost.ts +2 -3
- package/src/services/indexing/plugins/thread-gate.ts +2 -3
- package/src/services/label/index.ts +68 -25
- package/src/services/moderation/index.ts +380 -395
- package/src/services/moderation/pagination.ts +96 -0
- package/src/services/moderation/status.ts +241 -0
- package/src/services/moderation/types.ts +49 -0
- package/src/services/moderation/views.ts +278 -329
- package/src/services/types.ts +4 -0
- package/src/services/util/notification.ts +70 -0
- package/src/util/debug.ts +2 -2
- package/src/util/retry.ts +1 -44
- package/tests/__snapshots__/feed-generation.test.ts.snap +322 -6
- package/tests/__snapshots__/indexing.test.ts.snap +0 -6
- package/tests/admin/__snapshots__/get-record.test.ts.snap +30 -132
- package/tests/admin/__snapshots__/get-repo.test.ts.snap +14 -60
- package/tests/admin/__snapshots__/moderation-events.test.ts.snap +146 -0
- package/tests/admin/__snapshots__/moderation-statuses.test.ts.snap +64 -0
- package/tests/admin/__snapshots__/moderation.test.ts.snap +0 -125
- package/tests/admin/get-record.test.ts +5 -9
- package/tests/admin/get-repo.test.ts +10 -12
- package/tests/admin/moderation-events.test.ts +221 -0
- package/tests/admin/moderation-statuses.test.ts +145 -0
- package/tests/admin/moderation.test.ts +512 -860
- package/tests/admin/repo-search.test.ts +3 -3
- package/tests/algos/hot-classic.test.ts +1 -2
- package/tests/auth.test.ts +1 -1
- package/tests/auto-moderator/fuzzy-matcher.test.ts +2 -1
- package/tests/auto-moderator/labeler.test.ts +19 -20
- package/tests/auto-moderator/takedowns.test.ts +61 -28
- package/tests/blob-resolver.test.ts +4 -2
- package/tests/daemon.test.ts +191 -0
- package/tests/did-cache.test.ts +20 -5
- package/tests/feed-generation.test.ts +57 -9
- package/tests/handle-invalidation.test.ts +1 -5
- package/tests/indexing.test.ts +20 -13
- package/tests/redis-cache.test.ts +231 -0
- package/tests/seeds/basic.ts +3 -0
- package/tests/subscription/repo.test.ts +4 -7
- package/tests/views/__snapshots__/block-lists.test.ts.snap +3 -9
- package/tests/views/__snapshots__/blocks.test.ts.snap +0 -9
- package/tests/views/__snapshots__/mute-lists.test.ts.snap +5 -5
- package/tests/views/__snapshots__/mutes.test.ts.snap +0 -3
- package/tests/views/__snapshots__/thread.test.ts.snap +0 -30
- package/tests/views/actor-search.test.ts +2 -3
- package/tests/views/author-feed.test.ts +42 -36
- package/tests/views/follows.test.ts +40 -35
- package/tests/views/list-feed.test.ts +17 -9
- package/tests/views/notifications.test.ts +13 -9
- package/tests/views/profile.test.ts +20 -19
- package/tests/views/thread.test.ts +117 -94
- package/tests/views/threadgating.test.ts +89 -19
- package/tests/views/timeline.test.ts +21 -13
- package/dist/api/com/atproto/admin/resolveModerationReports.d.ts +0 -3
- package/dist/api/com/atproto/admin/reverseModerationAction.d.ts +0 -3
- package/dist/api/com/atproto/admin/takeModerationAction.d.ts +0 -3
- package/dist/db/tables/did-cache.d.ts +0 -10
- package/dist/feed-gen/best-of-follows.d.ts +0 -29
- package/dist/feed-gen/whats-hot.d.ts +0 -29
- package/dist/feed-gen/with-friends.d.ts +0 -3
- package/dist/label-cache.d.ts +0 -19
- package/src/api/com/atproto/admin/getModerationAction.ts +0 -44
- package/src/api/com/atproto/admin/getModerationReport.ts +0 -43
- package/src/api/com/atproto/admin/resolveModerationReports.ts +0 -24
- package/src/api/com/atproto/admin/reverseModerationAction.ts +0 -115
- package/src/api/com/atproto/admin/takeModerationAction.ts +0 -156
- package/src/db/tables/did-cache.ts +0 -13
- package/src/feed-gen/best-of-follows.ts +0 -74
- package/src/feed-gen/whats-hot.ts +0 -101
- package/src/feed-gen/with-friends.ts +0 -39
- package/src/label-cache.ts +0 -90
- package/tests/admin/__snapshots__/get-moderation-action.test.ts.snap +0 -172
- package/tests/admin/__snapshots__/get-moderation-actions.test.ts.snap +0 -178
- package/tests/admin/__snapshots__/get-moderation-report.test.ts.snap +0 -177
- package/tests/admin/__snapshots__/get-moderation-reports.test.ts.snap +0 -307
- package/tests/admin/get-moderation-action.test.ts +0 -100
- package/tests/admin/get-moderation-actions.test.ts +0 -164
- package/tests/admin/get-moderation-report.test.ts +0 -100
- package/tests/admin/get-moderation-reports.test.ts +0 -332
- package/tests/algos/whats-hot.test.ts +0 -118
- package/tests/algos/with-friends.test.ts +0 -145
- /package/dist/api/com/atproto/admin/{getModerationAction.d.ts → emitModerationEvent.d.ts} +0 -0
- /package/dist/api/com/atproto/admin/{getModerationActions.d.ts → getModerationEvent.d.ts} +0 -0
- /package/dist/api/com/atproto/admin/{getModerationReport.d.ts → queryModerationEvents.d.ts} +0 -0
- /package/dist/api/com/atproto/admin/{getModerationReports.d.ts → queryModerationStatuses.d.ts} +0 -0
package/src/services/index.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { Database, PrimaryDatabase } from '../db'
|
|
2
1
|
import { ImageUriBuilder } from '../image/uri'
|
|
3
2
|
import { ActorService } from './actor'
|
|
4
3
|
import { FeedService } from './feed'
|
|
5
4
|
import { GraphService } from './graph'
|
|
6
5
|
import { ModerationService } from './moderation'
|
|
7
|
-
import { LabelService } from './label'
|
|
6
|
+
import { LabelCacheOpts, LabelService } from './label'
|
|
8
7
|
import { ImageInvalidator } from '../image/invalidator'
|
|
9
|
-
import {
|
|
8
|
+
import { FromDb, FromDbPrimary } from './types'
|
|
10
9
|
|
|
11
10
|
export function createServices(resources: {
|
|
12
11
|
imgUriBuilder: ImageUriBuilder
|
|
13
12
|
imgInvalidator: ImageInvalidator
|
|
14
|
-
|
|
13
|
+
labelCacheOpts: LabelCacheOpts
|
|
15
14
|
}): Services {
|
|
16
|
-
const { imgUriBuilder, imgInvalidator,
|
|
15
|
+
const { imgUriBuilder, imgInvalidator, labelCacheOpts } = resources
|
|
16
|
+
const label = LabelService.creator(labelCacheOpts)
|
|
17
|
+
const graph = GraphService.creator(imgUriBuilder)
|
|
18
|
+
const actor = ActorService.creator(imgUriBuilder, graph, label)
|
|
19
|
+
const moderation = ModerationService.creator(imgUriBuilder, imgInvalidator)
|
|
20
|
+
const feed = FeedService.creator(imgUriBuilder, actor, label, graph)
|
|
17
21
|
return {
|
|
18
|
-
actor
|
|
19
|
-
feed
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
label
|
|
22
|
+
actor,
|
|
23
|
+
feed,
|
|
24
|
+
moderation,
|
|
25
|
+
graph,
|
|
26
|
+
label,
|
|
23
27
|
}
|
|
24
28
|
}
|
|
25
29
|
|
|
@@ -30,7 +34,3 @@ export type Services = {
|
|
|
30
34
|
moderation: FromDbPrimary<ModerationService>
|
|
31
35
|
label: FromDb<LabelService>
|
|
32
36
|
}
|
|
33
|
-
|
|
34
|
-
type FromDb<T> = (db: Database) => T
|
|
35
|
-
|
|
36
|
-
type FromDbPrimary<T> = (db: PrimaryDatabase) => T
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
verifyRepo,
|
|
8
8
|
Commit,
|
|
9
9
|
VerifiedRepo,
|
|
10
|
+
getAndParseRecord,
|
|
10
11
|
} from '@atproto/repo'
|
|
11
12
|
import { AtUri } from '@atproto/syntax'
|
|
12
13
|
import { IdResolver, getPds } from '@atproto/identity'
|
|
@@ -201,10 +202,11 @@ export class IndexingService {
|
|
|
201
202
|
if (op.op === 'delete') {
|
|
202
203
|
await this.deleteRecord(uri)
|
|
203
204
|
} else {
|
|
205
|
+
const parsed = await getAndParseRecord(blocks, cid)
|
|
204
206
|
await this.indexRecord(
|
|
205
207
|
uri,
|
|
206
208
|
cid,
|
|
207
|
-
|
|
209
|
+
parsed.record,
|
|
208
210
|
op.op === 'create' ? WriteOpAction.Create : WriteOpAction.Update,
|
|
209
211
|
now,
|
|
210
212
|
)
|
|
@@ -389,19 +391,15 @@ type UriAndCid = {
|
|
|
389
391
|
cid: CID
|
|
390
392
|
}
|
|
391
393
|
|
|
392
|
-
type RecordDescript = UriAndCid & {
|
|
393
|
-
value: unknown
|
|
394
|
-
}
|
|
395
|
-
|
|
396
394
|
type IndexOp =
|
|
397
395
|
| ({
|
|
398
396
|
op: 'create' | 'update'
|
|
399
|
-
} &
|
|
397
|
+
} & UriAndCid)
|
|
400
398
|
| ({ op: 'delete' } & UriAndCid)
|
|
401
399
|
|
|
402
400
|
const findDiffFromCheckout = (
|
|
403
401
|
curr: Record<string, UriAndCid>,
|
|
404
|
-
checkout: Record<string,
|
|
402
|
+
checkout: Record<string, UriAndCid>,
|
|
405
403
|
): IndexOp[] => {
|
|
406
404
|
const ops: IndexOp[] = []
|
|
407
405
|
for (const uri of Object.keys(checkout)) {
|
|
@@ -428,14 +426,13 @@ const findDiffFromCheckout = (
|
|
|
428
426
|
const formatCheckout = (
|
|
429
427
|
did: string,
|
|
430
428
|
verifiedRepo: VerifiedRepo,
|
|
431
|
-
): Record<string,
|
|
432
|
-
const records: Record<string,
|
|
429
|
+
): Record<string, UriAndCid> => {
|
|
430
|
+
const records: Record<string, UriAndCid> = {}
|
|
433
431
|
for (const create of verifiedRepo.creates) {
|
|
434
432
|
const uri = AtUri.make(did, create.collection, create.rkey)
|
|
435
433
|
records[uri.toString()] = {
|
|
436
434
|
uri,
|
|
437
435
|
cid: create.cid,
|
|
438
|
-
value: create.record,
|
|
439
436
|
}
|
|
440
437
|
}
|
|
441
438
|
return records
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Selectable } from 'kysely'
|
|
2
|
-
import { AtUri } from '@atproto/syntax'
|
|
3
|
-
import { toSimplifiedISOSafe } from '@atproto/common'
|
|
2
|
+
import { AtUri, normalizeDatetimeAlways } from '@atproto/syntax'
|
|
4
3
|
import { CID } from 'multiformats/cid'
|
|
5
4
|
import * as Block from '../../../lexicon/types/app/bsky/graph/block'
|
|
6
5
|
import * as lex from '../../../lexicon/lexicons'
|
|
@@ -27,7 +26,7 @@ const insertFn = async (
|
|
|
27
26
|
cid: cid.toString(),
|
|
28
27
|
creator: uri.host,
|
|
29
28
|
subjectDid: obj.subject,
|
|
30
|
-
createdAt:
|
|
29
|
+
createdAt: normalizeDatetimeAlways(obj.createdAt),
|
|
31
30
|
indexedAt: timestamp,
|
|
32
31
|
})
|
|
33
32
|
.onConflict((oc) => oc.doNothing())
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Selectable } from 'kysely'
|
|
2
|
-
import { AtUri } from '@atproto/syntax'
|
|
3
|
-
import { toSimplifiedISOSafe } from '@atproto/common'
|
|
2
|
+
import { AtUri, normalizeDatetimeAlways } from '@atproto/syntax'
|
|
4
3
|
import { CID } from 'multiformats/cid'
|
|
5
4
|
import * as FeedGenerator from '../../../lexicon/types/app/bsky/feed/generator'
|
|
6
5
|
import * as lex from '../../../lexicon/lexicons'
|
|
@@ -33,7 +32,7 @@ const insertFn = async (
|
|
|
33
32
|
? JSON.stringify(obj.descriptionFacets)
|
|
34
33
|
: undefined,
|
|
35
34
|
avatarCid: obj.avatar?.ref.toString(),
|
|
36
|
-
createdAt:
|
|
35
|
+
createdAt: normalizeDatetimeAlways(obj.createdAt),
|
|
37
36
|
indexedAt: timestamp,
|
|
38
37
|
})
|
|
39
38
|
.onConflict((oc) => oc.doNothing())
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Selectable } from 'kysely'
|
|
2
|
-
import { AtUri } from '@atproto/syntax'
|
|
3
|
-
import { toSimplifiedISOSafe } from '@atproto/common'
|
|
2
|
+
import { AtUri, normalizeDatetimeAlways } from '@atproto/syntax'
|
|
4
3
|
import { CID } from 'multiformats/cid'
|
|
5
4
|
import * as Follow from '../../../lexicon/types/app/bsky/graph/follow'
|
|
6
5
|
import * as lex from '../../../lexicon/lexicons'
|
|
@@ -28,7 +27,7 @@ const insertFn = async (
|
|
|
28
27
|
cid: cid.toString(),
|
|
29
28
|
creator: uri.host,
|
|
30
29
|
subjectDid: obj.subject,
|
|
31
|
-
createdAt:
|
|
30
|
+
createdAt: normalizeDatetimeAlways(obj.createdAt),
|
|
32
31
|
indexedAt: timestamp,
|
|
33
32
|
})
|
|
34
33
|
.onConflict((oc) => oc.doNothing())
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Selectable } from 'kysely'
|
|
2
|
-
import { AtUri } from '@atproto/syntax'
|
|
3
|
-
import { toSimplifiedISOSafe } from '@atproto/common'
|
|
2
|
+
import { AtUri, normalizeDatetimeAlways } from '@atproto/syntax'
|
|
4
3
|
import { CID } from 'multiformats/cid'
|
|
5
4
|
import * as Like from '../../../lexicon/types/app/bsky/feed/like'
|
|
6
5
|
import * as lex from '../../../lexicon/lexicons'
|
|
@@ -29,7 +28,7 @@ const insertFn = async (
|
|
|
29
28
|
creator: uri.host,
|
|
30
29
|
subject: obj.subject.uri,
|
|
31
30
|
subjectCid: obj.subject.cid,
|
|
32
|
-
createdAt:
|
|
31
|
+
createdAt: normalizeDatetimeAlways(obj.createdAt),
|
|
33
32
|
indexedAt: timestamp,
|
|
34
33
|
})
|
|
35
34
|
.onConflict((oc) => oc.doNothing())
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Selectable } from 'kysely'
|
|
2
|
-
import { AtUri } from '@atproto/syntax'
|
|
3
|
-
import { toSimplifiedISOSafe } from '@atproto/common'
|
|
2
|
+
import { AtUri, normalizeDatetimeAlways } from '@atproto/syntax'
|
|
4
3
|
import { CID } from 'multiformats/cid'
|
|
5
4
|
import * as ListBlock from '../../../lexicon/types/app/bsky/graph/listblock'
|
|
6
5
|
import * as lex from '../../../lexicon/lexicons'
|
|
@@ -27,7 +26,7 @@ const insertFn = async (
|
|
|
27
26
|
cid: cid.toString(),
|
|
28
27
|
creator: uri.host,
|
|
29
28
|
subjectUri: obj.subject,
|
|
30
|
-
createdAt:
|
|
29
|
+
createdAt: normalizeDatetimeAlways(obj.createdAt),
|
|
31
30
|
indexedAt: timestamp,
|
|
32
31
|
})
|
|
33
32
|
.onConflict((oc) => oc.doNothing())
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Selectable } from 'kysely'
|
|
2
|
-
import { AtUri } from '@atproto/syntax'
|
|
3
|
-
import { toSimplifiedISOSafe } from '@atproto/common'
|
|
2
|
+
import { AtUri, normalizeDatetimeAlways } from '@atproto/syntax'
|
|
4
3
|
import { CID } from 'multiformats/cid'
|
|
5
4
|
import * as ListItem from '../../../lexicon/types/app/bsky/graph/listitem'
|
|
6
5
|
import * as lex from '../../../lexicon/lexicons'
|
|
@@ -35,7 +34,7 @@ const insertFn = async (
|
|
|
35
34
|
creator: uri.host,
|
|
36
35
|
subjectDid: obj.subject,
|
|
37
36
|
listUri: obj.list,
|
|
38
|
-
createdAt:
|
|
37
|
+
createdAt: normalizeDatetimeAlways(obj.createdAt),
|
|
39
38
|
indexedAt: timestamp,
|
|
40
39
|
})
|
|
41
40
|
.onConflict((oc) => oc.doNothing())
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Selectable } from 'kysely'
|
|
2
|
-
import { AtUri } from '@atproto/syntax'
|
|
3
|
-
import { toSimplifiedISOSafe } from '@atproto/common'
|
|
2
|
+
import { AtUri, normalizeDatetimeAlways } from '@atproto/syntax'
|
|
4
3
|
import { CID } from 'multiformats/cid'
|
|
5
4
|
import * as List from '../../../lexicon/types/app/bsky/graph/list'
|
|
6
5
|
import * as lex from '../../../lexicon/lexicons'
|
|
@@ -33,7 +32,7 @@ const insertFn = async (
|
|
|
33
32
|
? JSON.stringify(obj.descriptionFacets)
|
|
34
33
|
: undefined,
|
|
35
34
|
avatarCid: obj.avatar?.ref.toString(),
|
|
36
|
-
createdAt:
|
|
35
|
+
createdAt: normalizeDatetimeAlways(obj.createdAt),
|
|
37
36
|
indexedAt: timestamp,
|
|
38
37
|
})
|
|
39
38
|
.onConflict((oc) => oc.doNothing())
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Insertable, Selectable, sql } from 'kysely'
|
|
2
2
|
import { CID } from 'multiformats/cid'
|
|
3
|
-
import { AtUri } from '@atproto/syntax'
|
|
4
|
-
import { toSimplifiedISOSafe } from '@atproto/common'
|
|
3
|
+
import { AtUri, normalizeDatetimeAlways } from '@atproto/syntax'
|
|
5
4
|
import { jsonStringToLex } from '@atproto/lexicon'
|
|
6
5
|
import {
|
|
7
6
|
Record as PostRecord,
|
|
@@ -68,7 +67,7 @@ const insertFn = async (
|
|
|
68
67
|
cid: cid.toString(),
|
|
69
68
|
creator: uri.host,
|
|
70
69
|
text: obj.text,
|
|
71
|
-
createdAt:
|
|
70
|
+
createdAt: normalizeDatetimeAlways(obj.createdAt),
|
|
72
71
|
replyRoot: obj.reply?.root?.uri || null,
|
|
73
72
|
replyRootCid: obj.reply?.root?.cid || null,
|
|
74
73
|
replyParent: obj.reply?.parent?.uri || null,
|
|
@@ -113,6 +112,7 @@ const insertFn = async (
|
|
|
113
112
|
obj.reply,
|
|
114
113
|
)
|
|
115
114
|
if (invalidReplyRoot || violatesThreadGate) {
|
|
115
|
+
Object.assign(insertedPost, { invalidReplyRoot, violatesThreadGate })
|
|
116
116
|
await db
|
|
117
117
|
.updateTable('post')
|
|
118
118
|
.where('uri', '=', post.uri)
|
|
@@ -242,6 +242,13 @@ const notifsForInsert = (obj: IndexedPost) => {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
+
if (obj.post.violatesThreadGate) {
|
|
246
|
+
// don't generate reply notifications when post violates threadgate
|
|
247
|
+
return notifs
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// reply notifications
|
|
251
|
+
|
|
245
252
|
for (const ancestor of obj.ancestors ?? []) {
|
|
246
253
|
if (ancestor.uri === obj.post.uri) continue // no need to notify for own post
|
|
247
254
|
if (ancestor.height < REPLY_NOTIF_DEPTH) {
|
|
@@ -354,6 +361,11 @@ const updateAggregates = async (db: DatabaseSchema, postIdx: IndexedPost) => {
|
|
|
354
361
|
replyCount: db
|
|
355
362
|
.selectFrom('post')
|
|
356
363
|
.where('post.replyParent', '=', postIdx.post.replyParent)
|
|
364
|
+
.where((qb) =>
|
|
365
|
+
qb
|
|
366
|
+
.where('post.violatesThreadGate', 'is', null)
|
|
367
|
+
.orWhere('post.violatesThreadGate', '=', false),
|
|
368
|
+
)
|
|
357
369
|
.select(countAll.as('count')),
|
|
358
370
|
})
|
|
359
371
|
.onConflict((oc) =>
|
|
@@ -420,7 +432,7 @@ async function validateReply(
|
|
|
420
432
|
const violatesThreadGate = await feedutil.violatesThreadGate(
|
|
421
433
|
db,
|
|
422
434
|
creator,
|
|
423
|
-
new AtUri(reply.root.uri).
|
|
435
|
+
new AtUri(reply.root.uri).hostname,
|
|
424
436
|
replyRefs.root?.record ?? null,
|
|
425
437
|
replyRefs.gate?.record ?? null,
|
|
426
438
|
)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Selectable } from 'kysely'
|
|
2
2
|
import { CID } from 'multiformats/cid'
|
|
3
|
-
import { AtUri } from '@atproto/syntax'
|
|
4
|
-
import { toSimplifiedISOSafe } from '@atproto/common'
|
|
3
|
+
import { AtUri, normalizeDatetimeAlways } from '@atproto/syntax'
|
|
5
4
|
import * as Repost from '../../../lexicon/types/app/bsky/feed/repost'
|
|
6
5
|
import * as lex from '../../../lexicon/lexicons'
|
|
7
6
|
import { DatabaseSchema, DatabaseSchemaType } from '../../../db/database-schema'
|
|
@@ -27,7 +26,7 @@ const insertFn = async (
|
|
|
27
26
|
creator: uri.host,
|
|
28
27
|
subject: obj.subject.uri,
|
|
29
28
|
subjectCid: obj.subject.cid,
|
|
30
|
-
createdAt:
|
|
29
|
+
createdAt: normalizeDatetimeAlways(obj.createdAt),
|
|
31
30
|
indexedAt: timestamp,
|
|
32
31
|
}
|
|
33
32
|
const [inserted] = await Promise.all([
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { AtUri } from '@atproto/syntax'
|
|
1
|
+
import { AtUri, normalizeDatetimeAlways } from '@atproto/syntax'
|
|
2
2
|
import { InvalidRequestError } from '@atproto/xrpc-server'
|
|
3
|
-
import { toSimplifiedISOSafe } from '@atproto/common'
|
|
4
3
|
import { CID } from 'multiformats/cid'
|
|
5
4
|
import * as Threadgate from '../../../lexicon/types/app/bsky/feed/threadgate'
|
|
6
5
|
import * as lex from '../../../lexicon/lexicons'
|
|
@@ -33,7 +32,7 @@ const insertFn = async (
|
|
|
33
32
|
cid: cid.toString(),
|
|
34
33
|
creator: uri.host,
|
|
35
34
|
postUri: obj.post,
|
|
36
|
-
createdAt:
|
|
35
|
+
createdAt: normalizeDatetimeAlways(obj.createdAt),
|
|
37
36
|
indexedAt: timestamp,
|
|
38
37
|
})
|
|
39
38
|
.onConflict((oc) => oc.doNothing())
|
|
@@ -1,18 +1,38 @@
|
|
|
1
1
|
import { sql } from 'kysely'
|
|
2
|
-
import { AtUri } from '@atproto/syntax'
|
|
3
|
-
import { toSimplifiedISOSafe } from '@atproto/common'
|
|
2
|
+
import { AtUri, normalizeDatetimeAlways } from '@atproto/syntax'
|
|
4
3
|
import { Database } from '../../db'
|
|
5
4
|
import { Label, isSelfLabels } from '../../lexicon/types/com/atproto/label/defs'
|
|
6
5
|
import { ids } from '../../lexicon/lexicons'
|
|
7
|
-
import {
|
|
6
|
+
import { ReadThroughCache } from '../../cache/read-through'
|
|
7
|
+
import { Redis } from '../../redis'
|
|
8
8
|
|
|
9
9
|
export type Labels = Record<string, Label[]>
|
|
10
10
|
|
|
11
|
+
export type LabelCacheOpts = {
|
|
12
|
+
redis: Redis
|
|
13
|
+
staleTTL: number
|
|
14
|
+
maxTTL: number
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
export class LabelService {
|
|
12
|
-
|
|
18
|
+
public cache: ReadThroughCache<Label[]> | null
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
constructor(public db: Database, cacheOpts: LabelCacheOpts | null) {
|
|
21
|
+
if (cacheOpts) {
|
|
22
|
+
this.cache = new ReadThroughCache(cacheOpts.redis, {
|
|
23
|
+
...cacheOpts,
|
|
24
|
+
fetchMethod: async (subject: string) => {
|
|
25
|
+
const res = await fetchLabelsForSubjects(db, [subject])
|
|
26
|
+
return res[subject] ?? []
|
|
27
|
+
},
|
|
28
|
+
fetchManyMethod: (subjects: string[]) =>
|
|
29
|
+
fetchLabelsForSubjects(db, subjects),
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static creator(cacheOpts: LabelCacheOpts | null) {
|
|
35
|
+
return (db: Database) => new LabelService(db, cacheOpts)
|
|
16
36
|
}
|
|
17
37
|
|
|
18
38
|
async formatAndCreate(
|
|
@@ -73,24 +93,19 @@ export class LabelService {
|
|
|
73
93
|
},
|
|
74
94
|
): Promise<Labels> {
|
|
75
95
|
if (subjects.length < 1) return {}
|
|
76
|
-
const res =
|
|
77
|
-
this.cache
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
cid: cur.cid === '' ? undefined : cur.cid,
|
|
90
|
-
neg: cur.neg,
|
|
91
|
-
})
|
|
92
|
-
return acc
|
|
93
|
-
}, {} as Labels)
|
|
96
|
+
const res = this.cache
|
|
97
|
+
? await this.cache.getMany(subjects, { revalidate: opts?.skipCache })
|
|
98
|
+
: await fetchLabelsForSubjects(this.db, subjects)
|
|
99
|
+
|
|
100
|
+
if (opts?.includeNeg) {
|
|
101
|
+
return res
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const noNegs: Labels = {}
|
|
105
|
+
for (const [key, val] of Object.entries(res)) {
|
|
106
|
+
noNegs[key] = val.filter((label) => !label.neg)
|
|
107
|
+
}
|
|
108
|
+
return noNegs
|
|
94
109
|
}
|
|
95
110
|
|
|
96
111
|
// gets labels for any record. when did is present, combine labels for both did & profile record.
|
|
@@ -166,9 +181,37 @@ export function getSelfLabels(details: {
|
|
|
166
181
|
const src = new AtUri(uri).host // record creator
|
|
167
182
|
const cts =
|
|
168
183
|
typeof record.createdAt === 'string'
|
|
169
|
-
?
|
|
184
|
+
? normalizeDatetimeAlways(record.createdAt)
|
|
170
185
|
: new Date(0).toISOString()
|
|
171
186
|
return record.labels.values.map(({ val }) => {
|
|
172
187
|
return { src, uri, cid, val, cts, neg: false }
|
|
173
188
|
})
|
|
174
189
|
}
|
|
190
|
+
|
|
191
|
+
const fetchLabelsForSubjects = async (
|
|
192
|
+
db: Database,
|
|
193
|
+
subjects: string[],
|
|
194
|
+
): Promise<Record<string, Label[]>> => {
|
|
195
|
+
if (subjects.length === 0) {
|
|
196
|
+
return {}
|
|
197
|
+
}
|
|
198
|
+
const res = await db.db
|
|
199
|
+
.selectFrom('label')
|
|
200
|
+
.where('label.uri', 'in', subjects)
|
|
201
|
+
.selectAll()
|
|
202
|
+
.execute()
|
|
203
|
+
const labelMap = res.reduce((acc, cur) => {
|
|
204
|
+
acc[cur.uri] ??= []
|
|
205
|
+
acc[cur.uri].push({
|
|
206
|
+
...cur,
|
|
207
|
+
cid: cur.cid === '' ? undefined : cur.cid,
|
|
208
|
+
neg: cur.neg,
|
|
209
|
+
})
|
|
210
|
+
return acc
|
|
211
|
+
}, {} as Record<string, Label[]>)
|
|
212
|
+
// ensure we cache negatives
|
|
213
|
+
for (const subject of subjects) {
|
|
214
|
+
labelMap[subject] ??= []
|
|
215
|
+
}
|
|
216
|
+
return labelMap
|
|
217
|
+
}
|