Skip to content

Commit

Permalink
feat: add isindexable
Browse files Browse the repository at this point in the history
  • Loading branch information
Esurio committed Jul 18, 2024
1 parent 663ff6a commit d3e116b
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 1 deletion.
4 changes: 4 additions & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2951,3 +2951,7 @@ _dice:
rollDice: "Roll!"
diceCount: "Number of dice"
diceFaces: "Number of dice's faces"

_isIndexable:
title: "Indexable"
description: "This is kmyblue compatible feature. If you want to prevent your account from being indexed by search engines, please disable this option."
10 changes: 10 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11628,6 +11628,16 @@ export interface Locale extends ILocale {
*/
"diceFaces": string;
};
"_isIndexable": {
/**
* 公開ノートをインデックス化
*/
"title": string;
/**
* kmy互換機能。公開ノートをインデックス化するかどうかを設定します。
*/
"description": string;
};
}
declare const locales: {
[lang: string]: Locale;
Expand Down
4 changes: 4 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3104,3 +3104,7 @@ _dice:
rollDice: "サイコロを振る"
diceCount: "サイコロの数"
diceFaces: "サイコロの面数"

_isIndexable:
title: "公開ノートをインデックス化"
description: "kmy互換機能。公開ノートをインデックス化するかどうかを設定します。"
13 changes: 13 additions & 0 deletions packages/backend/migration/1721299883211-AddIsIndexable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class AddIsIndexable1721299883211 {
name = 'AddIsIndexable1721299883211'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "user" ADD "isIndexable" boolean NOT NULL DEFAULT true`);
await queryRunner.query(`ALTER TABLE "user_profile" ADD "isIndexable" boolean NOT NULL DEFAULT true`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "isIndexable"`);
await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "isIndexable"`);
}
}
4 changes: 3 additions & 1 deletion packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export class NoteCreateService implements OnApplicationShutdown {
host: MiUser['host'];
isBot: MiUser['isBot'];
isCat: MiUser['isCat'];
isIndexable: MiUser['isIndexable'];
}, data: Option, silent = false): Promise<MiNote> {
// チャンネル外にリプライしたら対象のスコープに合わせる
// (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで)
Expand Down Expand Up @@ -535,6 +536,7 @@ export class NoteCreateService implements OnApplicationShutdown {
username: MiUser['username'];
host: MiUser['host'];
isBot: MiUser['isBot'];
isIndexable: MiUser['isIndexable'];
}, data: Option, silent: boolean, tags: string[], mentionedUsers: MinimumUser[]) {
const meta = await this.metaService.fetch();

Expand Down Expand Up @@ -764,7 +766,7 @@ export class NoteCreateService implements OnApplicationShutdown {
}

// Register to search database
this.index(note);
if (user.isIndexable) this.index(note);
}

@bindThis
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/core/NoteUpdateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class NoteUpdateService implements OnApplicationShutdown {
username: MiUser['username'];
host: MiUser['host'];
isBot: MiUser['isBot'];
isIndexable: MiUser['isIndexable'];
}, data: Option, note: MiNote, silent = false): Promise<MiNote | null> {
if (data.updatedAt == null) data.updatedAt = new Date();

Expand Down Expand Up @@ -213,6 +214,7 @@ export class NoteUpdateService implements OnApplicationShutdown {
username: MiUser['username'];
host: MiUser['host'];
isBot: MiUser['isBot'];
isIndexable: MiUser['isIndexable'];
}, silent: boolean) {
if (!silent) {
if (this.userEntityService.isLocalUser(user)) this.activeUsersChart.write(user);
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/activitypub/ApRendererService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ export class ApRendererService {
discoverable: user.isExplorable,
publicKey: this.renderKey(user, keypair, '#main-key'),
isCat: user.isCat,
isIndexable: user.isIndexable,
attachment: attachment.length ? attachment : undefined,
};

Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/activitypub/misc/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ const extension_context_definition = {
Emoji: 'toot:Emoji',
featured: 'toot:featured',
discoverable: 'toot:discoverable',
indexable: 'toot:indexable',
// schema
schema: 'http://schema.org#',
PropertyValue: 'schema:PropertyValue',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ export class ApPersonService implements OnModuleInit {
tags,
isBot,
isCat: (person as any).isCat === true,
isIndexable: person.isIndexable ?? true,
emojis,
})) as MiRemoteUser;

Expand Down Expand Up @@ -634,6 +635,7 @@ export class ApPersonService implements OnModuleInit {
tags,
isBot: getApType(object) === 'Service' || getApType(object) === 'Application',
isCat: (person as any).isCat === true,
isIndexable: person.isIndexable ?? true,
isLocked: person.manuallyApprovesFollowers,
movedToUri: person.movedTo ?? null,
alsoKnownAs: person.alsoKnownAs ?? null,
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/activitypub/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export interface IActor extends IObject {
};
'vcard:bday'?: string;
'vcard:Address'?: string;
isIndexable?: boolean;
}

export const isCollection = (object: IObject): object is ICollection =>
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/core/entities/UserEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ export class UserEntityService implements OnModuleInit {
}))) : [],
isBot: user.isBot,
isCat: user.isCat,
isIndexable: user.isIndexable,
instance: user.host ? this.federatedInstanceService.federatedInstanceCache.fetch(user.host).then(instance => instance ? {
name: instance.name,
softwareName: instance.softwareName,
Expand Down
7 changes: 7 additions & 0 deletions packages/backend/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ export class MiUser {
})
public token: string | null;

@Index()
@Column('boolean', {
default: true,
comment: 'Whether the User is indexable',
})
public isIndexable: boolean;

constructor(data: Partial<MiUser>) {
if (data == null) return;

Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/models/UserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ export class MiUserProfile {
})
public noCrawle: boolean;

@Column('boolean', {
default: true,
comment: 'Whether User is indexable.',
})
public isIndexable: boolean;

@Column('boolean', {
default: true,
})
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/models/json-schema/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ export const packedMeDetailedOnlySchema = {
type: 'boolean',
nullable: false, optional: false,
},
isIndexable: {
type: 'boolean',
nullable: false, optional: false,
},
isDeleted: {
type: 'boolean',
nullable: false, optional: false,
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/server/api/endpoints/i/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export const paramDef = {
autoAcceptFollowed: { type: 'boolean' },
noCrawle: { type: 'boolean' },
preventAiLearning: { type: 'boolean' },
isIndexable: { type: 'boolean' },
isBot: { type: 'boolean' },
isCat: { type: 'boolean' },
injectFeaturedNote: { type: 'boolean' },
Expand Down Expand Up @@ -314,6 +315,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (typeof ps.autoAcceptFollowed === 'boolean') profileUpdates.autoAcceptFollowed = ps.autoAcceptFollowed;
if (typeof ps.noCrawle === 'boolean') profileUpdates.noCrawle = ps.noCrawle;
if (typeof ps.preventAiLearning === 'boolean') profileUpdates.preventAiLearning = ps.preventAiLearning;
if (typeof ps.isIndexable === 'boolean') profileUpdates.isIndexable = ps.isIndexable;
if (typeof ps.isCat === 'boolean') updates.isCat = ps.isCat;
if (typeof ps.injectFeaturedNote === 'boolean') profileUpdates.injectFeaturedNote = ps.injectFeaturedNote;
if (typeof ps.receiveAnnouncementEmail === 'boolean') profileUpdates.receiveAnnouncementEmail = ps.receiveAnnouncementEmail;
Expand Down
2 changes: 2 additions & 0 deletions packages/cherrypick-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4103,6 +4103,7 @@ export type components = {
noCrawle: boolean;
preventAiLearning: boolean;
isExplorable: boolean;
isIndexable: boolean;
isDeleted: boolean;
/** @enum {string} */
twoFactorBackupCodesStock: 'full' | 'partial' | 'none';
Expand Down Expand Up @@ -20457,6 +20458,7 @@ export type operations = {
autoAcceptFollowed?: boolean;
noCrawle?: boolean;
preventAiLearning?: boolean;
isIndexable?: boolean;
isBot?: boolean;
isCat?: boolean;
injectFeaturedNote?: boolean;
Expand Down
6 changes: 6 additions & 0 deletions packages/frontend/src/pages/settings/privacy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ SPDX-License-Identifier: AGPL-3.0-only
{{ i18n.ts.makeExplorable }}
<template #caption>{{ i18n.ts.makeExplorableDescription }}</template>
</MkSwitch>
<MkSwitch v-model="isIndexable" @update:modalValue="save()">
{{ i18n.ts._isIndexable.title }}
<template #caption>{{ i18n.ts._isIndexable.description }}</template>
</MkSwitch>

<FormSection>
<div class="_gaps_m">
Expand Down Expand Up @@ -89,6 +93,7 @@ const isLocked = ref($i.isLocked);
const autoAcceptFollowed = ref($i.autoAcceptFollowed);
const noCrawle = ref($i.noCrawle);
const preventAiLearning = ref($i.preventAiLearning);
const isIndexable = ref($i.isIndexable);
const isExplorable = ref($i.isExplorable);
const hideOnlineStatus = ref($i.hideOnlineStatus);
const publicReactions = ref($i.publicReactions);
Expand All @@ -106,6 +111,7 @@ function save() {
autoAcceptFollowed: !!autoAcceptFollowed.value,
noCrawle: !!noCrawle.value,
preventAiLearning: !!preventAiLearning.value,
isIndexable: !!isIndexable.value,
isExplorable: !!isExplorable.value,
hideOnlineStatus: !!hideOnlineStatus.value,
publicReactions: !!publicReactions.value,
Expand Down

0 comments on commit d3e116b

Please sign in to comment.