Skip to content

Commit

Permalink
indexable
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Sep 23, 2023
1 parent 846df80 commit 5dabb34
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 7 deletions.
21 changes: 17 additions & 4 deletions src/remote/activitypub/models/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,25 @@ export async function fetchOutbox(user: IUser) {
}
}

function parseSearchableBy(actor: IActor) {
if (actor.searchableBy == null) return null;
/**
* リモートユーザーのsearchable検出
*/
function parseSearchableBy(actor: IActor): 'public' | 'none' | null {
// indexableで明示的に許可されていればpublic
if (actor.indexable === true) return 'public';

// searchableByでpublicならpublic
const searchableBy = toArray(actor.searchableBy);
if (searchableBy.includes('https://www.w3.org/ns/activitystreams#Public')) return 'public';
if (searchableBy.includes(getApId(actor.followers))) return 'none';
return 'none';

// indexableで明示的に拒否されていればnone
if (actor.indexable === false) return 'none';

// searchableByで明示的に拒否されていればnone (followersは未対応なので拒否扱い)
if (actor.searchableBy != null) return 'none';

// default
return null;
}

export const exportedForTesting = {
Expand Down
1 change: 1 addition & 0 deletions src/remote/activitypub/renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const renderActivity = (x: any): IActivity | null => {
Emoji: 'toot:Emoji',
featured: 'toot:featured',
discoverable: 'toot:discoverable',
indexable: 'toot:indexable',
// schema
schema: 'http://schema.org#',
PropertyValue: 'schema:PropertyValue',
Expand Down
1 change: 1 addition & 0 deletions src/remote/activitypub/renderer/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export default async (user: ILocalUser) => {
manuallyApprovesFollowers: user.isLocked || user.carefulRemote,
discoverable: !!user.isExplorable,
searchableBy: user.searchableBy === 'none' ? [] : ['https://www.w3.org/ns/activitystreams#Public'],
indexable: user.searchableBy !== 'none',
publicKey: renderKey(user, `#main-key`),
isCat: user.isCat,
attachment: attachment.length ? attachment : undefined,
Expand Down
1 change: 1 addition & 0 deletions src/remote/activitypub/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export interface IActor extends IObject {
manuallyApprovesFollowers?: boolean;
discoverable?: boolean;
searchableBy?: string[] | string;
indexable?: boolean;
inbox: string;
sharedInbox?: string;
publicKey?: {
Expand Down
76 changes: 73 additions & 3 deletions test/activitypub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,30 +310,100 @@ describe('ActivityPub', () => {
describe('parseSearchableBy', () => {
const parseSearchableBy = exportedForTesting.parseSearchableBy;

it('parseSearchableBy - public', () => {
it('parseSearchableBy - indexable: undef, public', () => {
assert.strictEqual(parseSearchableBy({
type: 'Person', preferredUsername: 'a', inbox: 'b', outbox: 'c', '@context': 'd',
followers: 'https://example.com/users/a/followers',
searchableBy: [ 'https://www.w3.org/ns/activitystreams#Public' ],
}), 'public');
});

it('parseSearchableBy - follower', () => {
it('parseSearchableBy - indexable: undef, followers', () => {
assert.strictEqual(parseSearchableBy({
type: 'Person', preferredUsername: 'a', inbox: 'b', outbox: 'c', '@context': 'd',
followers: 'https://example.com/users/a/followers',
searchableBy: [ 'https://example.com/users/a/followers' ],
}), 'none');
});

it('parseSearchableBy - reaction', () => {
it('parseSearchableBy - indexable: undef, reaction', () => {
assert.strictEqual(parseSearchableBy({
type: 'Person', preferredUsername: 'a', inbox: 'b', outbox: 'c', '@context': 'd',
followers: 'https://example.com/users/a/followers',
searchableBy: [],
}), 'none');
});

it('parseSearchableBy - indexable: true, public', () => {
assert.strictEqual(parseSearchableBy({
type: 'Person', preferredUsername: 'a', inbox: 'b', outbox: 'c', '@context': 'd',
followers: 'https://example.com/users/a/followers',
searchableBy: [ 'https://www.w3.org/ns/activitystreams#Public' ],
indexable: true,
}), 'public');
});

it('parseSearchableBy - indexable: true, followers', () => {
assert.strictEqual(parseSearchableBy({
type: 'Person', preferredUsername: 'a', inbox: 'b', outbox: 'c', '@context': 'd',
followers: 'https://example.com/users/a/followers',
searchableBy: [ 'https://example.com/users/a/followers' ],
indexable: true,
}), 'public');
});

it('parseSearchableBy - indexable: true, reaction', () => {
assert.strictEqual(parseSearchableBy({
type: 'Person', preferredUsername: 'a', inbox: 'b', outbox: 'c', '@context': 'd',
followers: 'https://example.com/users/a/followers',
searchableBy: [],
indexable: true,
}), 'public');
});

it('parseSearchableBy - indexable: false, public', () => {
assert.strictEqual(parseSearchableBy({
type: 'Person', preferredUsername: 'a', inbox: 'b', outbox: 'c', '@context': 'd',
followers: 'https://example.com/users/a/followers',
searchableBy: [ 'https://www.w3.org/ns/activitystreams#Public' ],
indexable: false,
}), 'public');
});

it('parseSearchableBy - indexable: false, followers', () => {
assert.strictEqual(parseSearchableBy({
type: 'Person', preferredUsername: 'a', inbox: 'b', outbox: 'c', '@context': 'd',
followers: 'https://example.com/users/a/followers',
searchableBy: [ 'https://example.com/users/a/followers' ],
indexable: false,
}), 'none');
});

it('parseSearchableBy - indexable: false, reaction', () => {
assert.strictEqual(parseSearchableBy({
type: 'Person', preferredUsername: 'a', inbox: 'b', outbox: 'c', '@context': 'd',
followers: 'https://example.com/users/a/followers',
searchableBy: [],
indexable: false,
}), 'none');
});

it('parseIndexable - true', () => {
assert.strictEqual(parseSearchableBy({
type: 'Person', preferredUsername: 'a', inbox: 'b', outbox: 'c', '@context': 'd',
followers: 'https://example.com/users/a/followers',
indexable: true,
}), 'public');
});

it('parseIndexable - false', () => {
assert.strictEqual(parseSearchableBy({
type: 'Person', preferredUsername: 'a', inbox: 'b', outbox: 'c', '@context': 'd',
followers: 'https://example.com/users/a/followers',
indexable: false,
}), 'none');
});

it('parseSearchableBy - undefined', () => {
assert.strictEqual(parseSearchableBy({
type: 'Person', preferredUsername: 'a', inbox: 'b', outbox: 'c', '@context': 'd',
Expand Down

0 comments on commit 5dabb34

Please sign in to comment.