Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into eric/getSuggestedFollowsBy…
Browse files Browse the repository at this point in the history
…Actor

* origin:
  Get rate limit ip correctly (#1577)
  Remove temp.upgradeRepoVersion (#1588)
  Fix getRepo `since` (#1579)
  Prevent user pref races (#1576)
  Feature: block lists (#1531)
  Enable appview proxy in dev-env full network (#1580)
  Increase timeline threshold (#1573)
  @atproto/[email protected]
  Fixes and updates to the preferences API (#1575)
  Remove legacy repo sync impl (#1570)
  Move fuzzy matcher to appview (#1566)
  @atproto/[email protected]
  Add personal-details user preference with birth date (#1565)
  enable granular perms for publish action (#1563)
  maintain feed order (#1559)
  • Loading branch information
estrattonbailey committed Sep 12, 2023
2 parents a32995e + 0533fab commit 6af359c
Show file tree
Hide file tree
Showing 127 changed files with 5,136 additions and 2,617 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ jobs:
build:
name: Build & Publish
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/repo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Test
on:
pull_request:
branches:
- main
- '*'

concurrency:
group: '${{ github.workflow }}-${{ github.head_ref || github.ref }}'
Expand Down
17 changes: 16 additions & 1 deletion lexicons/app/bsky/actor/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@
"type": "array",
"items": {
"type": "union",
"refs": ["#adultContentPref", "#contentLabelPref", "#savedFeedsPref"]
"refs": [
"#adultContentPref",
"#contentLabelPref",
"#savedFeedsPref",
"#personalDetailsPref"
]
}
},
"adultContentPref": {
Expand Down Expand Up @@ -134,6 +139,16 @@
}
}
}
},
"personalDetailsPref": {
"type": "object",
"properties": {
"birthDate": {
"type": "string",
"format": "datetime",
"description": "The birth date of the owner of the account."
}
}
}
}
}
3 changes: 2 additions & 1 deletion lexicons/app/bsky/graph/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"listViewerState": {
"type": "object",
"properties": {
"muted": { "type": "boolean" }
"muted": { "type": "boolean" },
"blocked": { "type": "string", "format": "at-uri" }
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions lexicons/app/bsky/graph/getListBlocks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"lexicon": 1,
"id": "app.bsky.graph.getListBlocks",
"defs": {
"main": {
"type": "query",
"description": "Which lists is the requester's account blocking?",
"parameters": {
"type": "params",
"properties": {
"limit": {
"type": "integer",
"minimum": 1,
"maximum": 100,
"default": 50
},
"cursor": { "type": "string" }
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["lists"],
"properties": {
"cursor": { "type": "string" },
"lists": {
"type": "array",
"items": { "type": "ref", "ref": "app.bsky.graph.defs#listView" }
}
}
}
}
}
}
}
19 changes: 19 additions & 0 deletions lexicons/app/bsky/graph/listblock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"lexicon": 1,
"id": "app.bsky.graph.listblock",
"defs": {
"main": {
"type": "record",
"description": "A block of an entire list of actors.",
"key": "tid",
"record": {
"type": "object",
"required": ["subject", "createdAt"],
"properties": {
"subject": { "type": "string", "format": "at-uri" },
"createdAt": { "type": "string", "format": "datetime" }
}
}
}
}
}
1 change: 0 additions & 1 deletion lexicons/com/atproto/sync/getRepo.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
},
"since": {
"type": "string",
"format": "cid",
"description": "The revision of the repo to catch up from."
}
}
Expand Down
1 change: 0 additions & 1 deletion lexicons/com/atproto/sync/listBlobs.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
},
"since": {
"type": "string",
"format": "cid",
"description": "Optional revision of the repo to list blobs since"
},
"limit": {
Expand Down
21 changes: 0 additions & 21 deletions lexicons/com/atproto/temp/upgradeRepoVersion.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@atproto/api",
"version": "0.6.10",
"version": "0.6.12",
"main": "src/index.ts",
"publishConfig": {
"main": "dist/index.js",
Expand Down
72 changes: 61 additions & 11 deletions packages/api/src/bsky-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ import {
} from './client'
import { BskyPreferences, BskyLabelPreference } from './types'

declare global {
interface Array<T> {
findLast(
predicate: (value: T, index: number, obj: T[]) => unknown,
thisArg?: any,
): T
}
}

export class BskyAgent extends AtpAgent {
get app() {
return this.api.app
Expand Down Expand Up @@ -247,6 +256,7 @@ export class BskyAgent extends AtpAgent {
},
adultContentEnabled: false,
contentLabels: {},
birthDate: undefined,
}
const res = await this.app.bsky.actor.getPreferences({})
for (const pref of res.data.preferences) {
Expand All @@ -272,6 +282,13 @@ export class BskyAgent extends AtpAgent {
) {
prefs.feeds.saved = pref.saved
prefs.feeds.pinned = pref.pinned
} else if (
AppBskyActorDefs.isPersonalDetailsPref(pref) &&
AppBskyActorDefs.validatePersonalDetailsPref(pref).success
) {
if (pref.birthDate) {
prefs.birthDate = new Date(pref.birthDate)
}
}
}
return prefs
Expand Down Expand Up @@ -314,20 +331,22 @@ export class BskyAgent extends AtpAgent {

async setAdultContentEnabled(v: boolean) {
await updatePreferences(this, (prefs: AppBskyActorDefs.Preferences) => {
const existing = prefs.find(
let adultContentPref = prefs.findLast(
(pref) =>
AppBskyActorDefs.isAdultContentPref(pref) &&
AppBskyActorDefs.validateAdultContentPref(pref).success,
)
if (existing) {
existing.enabled = v
if (adultContentPref) {
adultContentPref.enabled = v
} else {
prefs.push({
adultContentPref = {
$type: 'app.bsky.actor.defs#adultContentPref',
enabled: v,
})
}
}
return prefs
.filter((pref) => !AppBskyActorDefs.isAdultContentPref(pref))
.concat([adultContentPref])
})
}

Expand All @@ -338,22 +357,53 @@ export class BskyAgent extends AtpAgent {
}

await updatePreferences(this, (prefs: AppBskyActorDefs.Preferences) => {
const existing = prefs.find(
let labelPref = prefs.findLast(
(pref) =>
AppBskyActorDefs.isContentLabelPref(pref) &&
AppBskyActorDefs.validateAdultContentPref(pref).success &&
pref.label === key,
)
if (existing) {
existing.visibility = value
if (labelPref) {
labelPref.visibility = value
} else {
prefs.push({
labelPref = {
$type: 'app.bsky.actor.defs#contentLabelPref',
label: key,
visibility: value,
})
}
}
return prefs
.filter(
(pref) =>
!AppBskyActorDefs.isContentLabelPref(pref) || pref.label !== key,
)
.concat([labelPref])
})
}

async setPersonalDetails({
birthDate,
}: {
birthDate: string | Date | undefined
}) {
birthDate = birthDate instanceof Date ? birthDate.toISOString() : birthDate
await updatePreferences(this, (prefs: AppBskyActorDefs.Preferences) => {
let personalDetailsPref = prefs.findLast(
(pref) =>
AppBskyActorDefs.isPersonalDetailsPref(pref) &&
AppBskyActorDefs.validatePersonalDetailsPref(pref).success,
)
if (personalDetailsPref) {
personalDetailsPref.birthDate = birthDate
} else {
personalDetailsPref = {
$type: 'app.bsky.actor.defs#personalDetailsPref',
birthDate,
}
}
return prefs
.filter((pref) => !AppBskyActorDefs.isPersonalDetailsPref(pref))
.concat([personalDetailsPref])
})
}
}
Expand Down Expand Up @@ -394,7 +444,7 @@ async function updateFeedPreferences(
): Promise<{ saved: string[]; pinned: string[] }> {
let res
await updatePreferences(agent, (prefs: AppBskyActorDefs.Preferences) => {
let feedsPref = prefs.find(
let feedsPref = prefs.findLast(
(pref) =>
AppBskyActorDefs.isSavedFeedsPref(pref) &&
AppBskyActorDefs.validateSavedFeedsPref(pref).success,
Expand Down
Loading

0 comments on commit 6af359c

Please sign in to comment.