Include limited info on blocked embeds ()

* add block info to embeds

* fix codegen

* Correctly handle blocked embeds and add block-other cause

* update snaps

* Correctly identify blocking behavior in embeds

---------

Co-authored-by: Paul Frazee <pfrazee@gmail.com>
This commit is contained in:
Daniel Holmgren 2023-08-10 15:54:24 -05:00 committed by GitHub
parent 29a1ee791a
commit 244bf46e74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 162 additions and 25 deletions
lexicons/app/bsky/embed
packages
api/src
client
lexicons.ts
types/app/bsky/embed
moderation
bsky
src
lexicon
lexicons.ts
types/app/bsky/embed
services/feed
tests
pds
src
app-view/services/feed
lexicon
lexicons.ts
types/app/bsky/embed
tests

@ -55,16 +55,19 @@
},
"viewNotFound": {
"type": "object",
"required": ["uri"],
"required": ["uri", "notFound"],
"properties": {
"uri": {"type": "string", "format": "at-uri"}
"uri": {"type": "string", "format": "at-uri"},
"notFound": {"type": "boolean", "const": true}
}
},
"viewBlocked": {
"type": "object",
"required": ["uri"],
"required": ["uri", "blocked", "author"],
"properties": {
"uri": {"type": "string", "format": "at-uri"}
"uri": {"type": "string", "format": "at-uri"},
"blocked": {"type": "boolean", "const": true},
"author": {"type": "ref", "ref": "app.bsky.feed.defs#blockedAuthor"}
}
}
}

@ -4283,22 +4283,34 @@ export const schemaDict = {
},
viewNotFound: {
type: 'object',
required: ['uri'],
required: ['uri', 'notFound'],
properties: {
uri: {
type: 'string',
format: 'at-uri',
},
notFound: {
type: 'boolean',
const: true,
},
},
},
viewBlocked: {
type: 'object',
required: ['uri'],
required: ['uri', 'blocked', 'author'],
properties: {
uri: {
type: 'string',
format: 'at-uri',
},
blocked: {
type: 'boolean',
const: true,
},
author: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#blockedAuthor',
},
},
},
},

@ -84,6 +84,7 @@ export function validateViewRecord(v: unknown): ValidationResult {
export interface ViewNotFound {
uri: string
notFound: true
[k: string]: unknown
}
@ -101,6 +102,8 @@ export function validateViewNotFound(v: unknown): ValidationResult {
export interface ViewBlocked {
uri: string
blocked: true
author: AppBskyFeedDefs.BlockedAuthor
[k: string]: unknown
}

@ -38,6 +38,16 @@ export class ModerationCauseAccumulator {
}
}
addBlockOther(blockOther: boolean | undefined) {
if (blockOther) {
this.causes.push({
type: 'block-other',
source: { type: 'user' },
priority: 4,
})
}
}
addLabel(label: Label, opts: ModerationOpts) {
// look up the label definition
const labelDef = LABELS[label.val]
@ -134,7 +144,11 @@ export class ModerationCauseAccumulator {
mod.additionalCauses = this.causes.slice(1)
// blocked user
if (mod.cause.type === 'blocking' || mod.cause.type === 'blocked-by') {
if (
mod.cause.type === 'blocking' ||
mod.cause.type === 'blocked-by' ||
mod.cause.type === 'block-other'
) {
// filter and blur, dont allow override
mod.filter = true
mod.blur = true

@ -17,6 +17,15 @@ export function decideQuotedPost(
acc.addLabel(label, opts)
}
}
} else if (AppBskyEmbedRecord.isViewBlocked(subject.record)) {
acc.setDid(subject.record.author.did)
if (subject.record.author.viewer?.blocking) {
acc.addBlocking(subject.record.author.viewer?.blocking)
} else if (subject.record.author.viewer?.blockedBy) {
acc.addBlockedBy(subject.record.author.viewer?.blockedBy)
} else {
acc.addBlockOther(true)
}
}
return acc.finalizeDecision(opts)
@ -46,6 +55,15 @@ export function decideQuotedPostWithMedia(
acc.addLabel(label, opts)
}
}
} else if (AppBskyEmbedRecord.isViewBlocked(subject.record.record)) {
acc.setDid(subject.record.record.author.did)
if (subject.record.record.author.viewer?.blocking) {
acc.addBlocking(subject.record.record.author.viewer?.blocking)
} else if (subject.record.record.author.viewer?.blockedBy) {
acc.addBlockedBy(subject.record.record.author.viewer?.blockedBy)
} else {
acc.addBlockOther(true)
}
}
return acc.finalizeDecision(opts)

@ -100,6 +100,7 @@ export type ModerationCauseSource =
export type ModerationCause =
| { type: 'blocking'; source: ModerationCauseSource; priority: 3 }
| { type: 'blocked-by'; source: ModerationCauseSource; priority: 4 }
| { type: 'block-other'; source: ModerationCauseSource; priority: 4 }
| {
type: 'label'
source: ModerationCauseSource

@ -70,25 +70,13 @@ export function isModerationDecisionNoop(
}
export function isQuotedPost(embed: unknown): embed is AppBskyEmbedRecord.View {
return Boolean(
embed &&
AppBskyEmbedRecord.isView(embed) &&
AppBskyEmbedRecord.isViewRecord(embed.record) &&
AppBskyFeedPost.isRecord(embed.record.value) &&
AppBskyFeedPost.validateRecord(embed.record.value).success,
)
return Boolean(embed && AppBskyEmbedRecord.isView(embed))
}
export function isQuotedPostWithMedia(
embed: unknown,
): embed is AppBskyEmbedRecordWithMedia.View {
return Boolean(
embed &&
AppBskyEmbedRecordWithMedia.isView(embed) &&
AppBskyEmbedRecord.isViewRecord(embed.record.record) &&
AppBskyFeedPost.isRecord(embed.record.record.value) &&
AppBskyFeedPost.validateRecord(embed.record.record.value).success,
)
return Boolean(embed && AppBskyEmbedRecordWithMedia.isView(embed))
}
export function toModerationUI(decision: ModerationDecision): ModerationUI {

@ -4283,22 +4283,34 @@ export const schemaDict = {
},
viewNotFound: {
type: 'object',
required: ['uri'],
required: ['uri', 'notFound'],
properties: {
uri: {
type: 'string',
format: 'at-uri',
},
notFound: {
type: 'boolean',
const: true,
},
},
},
viewBlocked: {
type: 'object',
required: ['uri'],
required: ['uri', 'blocked', 'author'],
properties: {
uri: {
type: 'string',
format: 'at-uri',
},
blocked: {
type: 'boolean',
const: true,
},
author: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#blockedAuthor',
},
},
},
},

@ -84,6 +84,7 @@ export function validateViewRecord(v: unknown): ValidationResult {
export interface ViewNotFound {
uri: string
notFound: true
[k: string]: unknown
}
@ -101,6 +102,8 @@ export function validateViewNotFound(v: unknown): ValidationResult {
export interface ViewBlocked {
uri: string
blocked: true
author: AppBskyFeedDefs.BlockedAuthor
[k: string]: unknown
}

@ -627,6 +627,7 @@ export class FeedService {
recordEmbedViews[uri] = {
$type: 'app.bsky.embed.record#viewNotFound',
uri,
notFound: true,
}
}
}
@ -701,6 +702,16 @@ function applyEmbedBlock(
return {
$type: 'app.bsky.embed.record#viewBlocked',
uri: view.uri,
blocked: true,
author: {
did: view.author.did,
viewer: view.author.viewer
? {
blockedBy: view.author.viewer?.blockedBy,
blocking: view.author.viewer?.blocking,
}
: undefined,
},
}
}
return view

@ -291,12 +291,23 @@ export class FeedViews {
return {
$type: 'app.bsky.embed.record#viewNotFound',
uri,
notFound: true,
}
}
if (post.author.viewer?.blocking || post.author.viewer?.blockedBy) {
return {
$type: 'app.bsky.embed.record#viewBlocked',
uri,
blocked: true,
author: {
did: post.author.did,
viewer: post.author.viewer
? {
blockedBy: post.author.viewer?.blockedBy,
blocking: post.author.viewer?.blocking,
}
: undefined,
},
}
}
return {

@ -18,6 +18,7 @@ Object {
"$type": "app.bsky.embed.record#view",
"record": Object {
"$type": "app.bsky.embed.record#viewNotFound",
"notFound": true,
"uri": "record(1)",
},
},

@ -54,6 +54,14 @@ Object {
"$type": "app.bsky.embed.record#view",
"record": Object {
"$type": "app.bsky.embed.record#viewBlocked",
"author": Object {
"did": "user(3)",
"viewer": Object {
"blockedBy": false,
"blocking": "record(5)",
},
},
"blocked": true,
"uri": "record(4)",
},
},

@ -167,6 +167,7 @@ Array [
"$type": "app.bsky.embed.record#view",
"record": Object {
"$type": "app.bsky.embed.record#viewNotFound",
"notFound": true,
"uri": "record(7)",
},
},
@ -294,6 +295,7 @@ Array [
"$type": "app.bsky.embed.record#view",
"record": Object {
"$type": "app.bsky.embed.record#viewNotFound",
"notFound": true,
"uri": "record(7)",
},
},
@ -703,6 +705,7 @@ Array [
"$type": "app.bsky.embed.record#view",
"record": Object {
"$type": "app.bsky.embed.record#viewNotFound",
"notFound": true,
"uri": "record(9)",
},
},

@ -582,6 +582,7 @@ export class FeedService {
recordEmbedViews[uri] = {
$type: 'app.bsky.embed.record#viewNotFound',
uri,
notFound: true,
}
}
}
@ -668,6 +669,16 @@ function applyEmbedBlock(
return {
$type: 'app.bsky.embed.record#viewBlocked',
uri: view.uri,
blocked: true,
author: {
did: view.author.did,
viewer: view.author.viewer
? {
blockedBy: view.author.viewer?.blockedBy,
blocking: view.author.viewer?.blocking,
}
: undefined,
},
}
}
return view

@ -289,12 +289,23 @@ export class FeedViews {
return {
$type: 'app.bsky.embed.record#viewNotFound',
uri,
notFound: true,
}
}
if (post.author.viewer?.blocking || post.author.viewer?.blockedBy) {
return {
$type: 'app.bsky.embed.record#viewBlocked',
uri,
blocked: true,
author: {
did: post.author.did,
viewer: post.author.viewer
? {
blockedBy: post.author.viewer?.blockedBy,
blocking: post.author.viewer?.blocking,
}
: undefined,
},
}
}
return {

@ -4283,22 +4283,34 @@ export const schemaDict = {
},
viewNotFound: {
type: 'object',
required: ['uri'],
required: ['uri', 'notFound'],
properties: {
uri: {
type: 'string',
format: 'at-uri',
},
notFound: {
type: 'boolean',
const: true,
},
},
},
viewBlocked: {
type: 'object',
required: ['uri'],
required: ['uri', 'blocked', 'author'],
properties: {
uri: {
type: 'string',
format: 'at-uri',
},
blocked: {
type: 'boolean',
const: true,
},
author: {
type: 'ref',
ref: 'lex:app.bsky.feed.defs#blockedAuthor',
},
},
},
},

@ -84,6 +84,7 @@ export function validateViewRecord(v: unknown): ValidationResult {
export interface ViewNotFound {
uri: string
notFound: true
[k: string]: unknown
}
@ -101,6 +102,8 @@ export function validateViewNotFound(v: unknown): ValidationResult {
export interface ViewBlocked {
uri: string
blocked: true
author: AppBskyFeedDefs.BlockedAuthor
[k: string]: unknown
}

@ -35,6 +35,7 @@ Object {
"$type": "app.bsky.embed.record#view",
"record": Object {
"$type": "app.bsky.embed.record#viewNotFound",
"notFound": true,
"uri": "record(2)",
},
},

@ -62,6 +62,14 @@ Object {
"$type": "app.bsky.embed.record#view",
"record": Object {
"$type": "app.bsky.embed.record#viewBlocked",
"author": Object {
"did": "user(2)",
"viewer": Object {
"blockedBy": false,
"blocking": "record(5)",
},
},
"blocked": true,
"uri": "record(4)",
},
},

@ -183,6 +183,7 @@ Array [
"$type": "app.bsky.embed.record#view",
"record": Object {
"$type": "app.bsky.embed.record#viewNotFound",
"notFound": true,
"uri": "record(7)",
},
},
@ -318,6 +319,7 @@ Array [
"$type": "app.bsky.embed.record#view",
"record": Object {
"$type": "app.bsky.embed.record#viewNotFound",
"notFound": true,
"uri": "record(7)",
},
},
@ -743,6 +745,7 @@ Array [
"$type": "app.bsky.embed.record#view",
"record": Object {
"$type": "app.bsky.embed.record#viewNotFound",
"notFound": true,
"uri": "record(9)",
},
},