From 55ef4c4d93d02e5c02f776e8dbfeb0a66e7d5bbd Mon Sep 17 00:00:00 2001 From: Mar0xy Date: Fri, 17 Nov 2023 15:05:58 +0100 Subject: upd: completely change handling of `indexable` --- .../backend/migration/1700228972000-update-indexable.js | 15 +++++++++++++++ packages/backend/src/core/NoteCreateService.ts | 12 ++++++------ packages/backend/src/core/NoteEditService.ts | 6 +++--- .../backend/src/core/activitypub/ApRendererService.ts | 2 +- .../src/core/activitypub/models/ApPersonService.ts | 4 ++-- packages/backend/src/core/activitypub/type.ts | 2 +- packages/backend/src/core/entities/UserEntityService.ts | 2 +- packages/backend/src/models/User.ts | 6 +++--- packages/backend/src/models/json-schema/user.ts | 2 +- packages/backend/src/server/api/endpoints/i/update.ts | 4 ++-- 10 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 packages/backend/migration/1700228972000-update-indexable.js (limited to 'packages/backend') diff --git a/packages/backend/migration/1700228972000-update-indexable.js b/packages/backend/migration/1700228972000-update-indexable.js new file mode 100644 index 0000000000..30db7529b2 --- /dev/null +++ b/packages/backend/migration/1700228972000-update-indexable.js @@ -0,0 +1,15 @@ +export class UpdateIndexable1700228972000 { + name = 'UpdateIndexable1700228972000' + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "user" RENAME COLUMN "isIndexable" TO "noindex"`); + await queryRunner.query(`ALTER TABLE "user" ALTER COLUMN "noindex" SET DEFAULT false`); + await queryRunner.query(`UPDATE "user" SET "noindex" = false WHERE "noindex" = true`); + } + + async down(queryRunner) { + await queryRunner.query(`UPDATE "user" SET "noindex" = true WHERE "noindex" = false`); + await queryRunner.query(`ALTER TABLE "user" ALTER COLUMN "noindex" SET DEFAULT true`); + await queryRunner.query(`ALTER TABLE "user" RENAME COLUMN "noindex" TO "isIndexable"`); + } +} diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index fb20a22691..3a75c37bb1 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -223,7 +223,7 @@ export class NoteCreateService implements OnApplicationShutdown { username: MiUser['username']; host: MiUser['host']; isBot: MiUser['isBot']; - isIndexable: MiUser['isIndexable']; + noindex: MiUser['noindex']; }, data: Option, silent = false): Promise { // チャンネル外にリプライしたら対象のスコープに合わせる // (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで) @@ -384,7 +384,7 @@ export class NoteCreateService implements OnApplicationShutdown { username: MiUser['username']; host: MiUser['host']; isBot: MiUser['isBot']; - isIndexable: MiUser['isIndexable']; + noindex: MiUser['noindex']; }, data: Option, silent = false): Promise { // チャンネル外にリプライしたら対象のスコープに合わせる // (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで) @@ -642,7 +642,7 @@ export class NoteCreateService implements OnApplicationShutdown { username: MiUser['username']; host: MiUser['host']; isBot: MiUser['isBot']; - isIndexable: MiUser['isIndexable']; + noindex: MiUser['noindex']; }, data: Option, silent: boolean, tags: string[], mentionedUsers: MinimumUser[]) { const meta = await this.metaService.fetch(); @@ -873,7 +873,7 @@ export class NoteCreateService implements OnApplicationShutdown { } // Register to search database - if (user.isIndexable) this.index(note); + if (!user.noindex) this.index(note); } @bindThis @@ -882,7 +882,7 @@ export class NoteCreateService implements OnApplicationShutdown { username: MiUser['username']; host: MiUser['host']; isBot: MiUser['isBot']; - isIndexable: MiUser['isIndexable']; + noindex: MiUser['noindex']; }, data: Option, silent: boolean, tags: string[], mentionedUsers: MinimumUser[]) { const meta = await this.metaService.fetch(); @@ -972,7 +972,7 @@ export class NoteCreateService implements OnApplicationShutdown { } // Register to search database - if (user.isIndexable) this.index(note); + if (!user.noindex) this.index(note); } @bindThis diff --git a/packages/backend/src/core/NoteEditService.ts b/packages/backend/src/core/NoteEditService.ts index 23ce2ab7a9..dfcff0e5b1 100644 --- a/packages/backend/src/core/NoteEditService.ts +++ b/packages/backend/src/core/NoteEditService.ts @@ -224,7 +224,7 @@ export class NoteEditService implements OnApplicationShutdown { username: MiUser['username']; host: MiUser['host']; isBot: MiUser['isBot']; - isIndexable: MiUser['isIndexable']; + noindex: MiUser['noindex']; }, editid: MiNote['id'], data: Option, silent = false): Promise { if (!editid) { throw new Error('fail'); @@ -499,7 +499,7 @@ export class NoteEditService implements OnApplicationShutdown { username: MiUser['username']; host: MiUser['host']; isBot: MiUser['isBot']; - isIndexable: MiUser['isIndexable']; + noindex: MiUser['noindex']; }, data: Option, silent: boolean, tags: string[], mentionedUsers: MinimumUser[]) { // Register host if (this.userEntityService.isRemoteUser(user)) { @@ -688,7 +688,7 @@ export class NoteEditService implements OnApplicationShutdown { } // Register to search database - if (user.isIndexable) this.index(note); + if (!user.noindex) this.index(note); } @bindThis diff --git a/packages/backend/src/core/activitypub/ApRendererService.ts b/packages/backend/src/core/activitypub/ApRendererService.ts index 76287d74b9..fa2fa88304 100644 --- a/packages/backend/src/core/activitypub/ApRendererService.ts +++ b/packages/backend/src/core/activitypub/ApRendererService.ts @@ -525,7 +525,7 @@ export class ApRendererService { discoverable: user.isExplorable, publicKey: this.renderKey(user, keypair, '#main-key'), isCat: user.isCat, - noindex: user.isIndexable, + noindex: user.noindex, speakAsCat: user.speakAsCat, attachment: attachment.length ? attachment : undefined, }; diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 01a90897e9..8507c6f949 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -310,7 +310,7 @@ export class ApPersonService implements OnModuleInit { backgroundId: null, lastFetchedAt: new Date(), name: truncate(person.name, nameLength), - isIndexable: (person as any).noindex ?? true, + noindex: (person as any).noindex ?? false, isLocked: person.manuallyApprovesFollowers, movedToUri: person.movedTo, movedAt: person.movedTo ? new Date() : null, @@ -477,7 +477,7 @@ export class ApPersonService implements OnModuleInit { isBot: getApType(object) === 'Service' || getApType(object) === 'Application', isCat: (person as any).isCat === true, speakAsCat: (person as any).speakAsCat != null ? (person as any).speakAsCat === true : (person as any).isCat === true, - isIndexable: (person as any).noindex ?? true, + noindex: (person as any).noindex ?? false, isLocked: person.manuallyApprovesFollowers, movedToUri: person.movedTo ?? null, alsoKnownAs: person.alsoKnownAs ?? null, diff --git a/packages/backend/src/core/activitypub/type.ts b/packages/backend/src/core/activitypub/type.ts index 02667214d3..b5ba8cd5ab 100644 --- a/packages/backend/src/core/activitypub/type.ts +++ b/packages/backend/src/core/activitypub/type.ts @@ -184,7 +184,7 @@ export interface IActor extends IObject { }; 'vcard:bday'?: string; 'vcard:Address'?: string; - isIndexable?: boolean; + noindex?: boolean; listenbrainz?: string; backgroundUrl?: string; } diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts index 06ce60c7c2..b9d5f27d54 100644 --- a/packages/backend/src/core/entities/UserEntityService.ts +++ b/packages/backend/src/core/entities/UserEntityService.ts @@ -399,7 +399,7 @@ export class UserEntityService implements OnModuleInit { }))) : [], isBot: user.isBot, isCat: user.isCat, - isIndexable: user.isIndexable, + noindex: user.noindex, isSilenced: user.isSilenced || this.roleService.getUserPolicies(user.id).then(r => !r.canPublicNote), speakAsCat: user.speakAsCat ?? false, approved: user.approved, diff --git a/packages/backend/src/models/User.ts b/packages/backend/src/models/User.ts index bff2b142e2..1e1c07bfc4 100644 --- a/packages/backend/src/models/User.ts +++ b/packages/backend/src/models/User.ts @@ -189,10 +189,10 @@ export class MiUser { public isSilenced: boolean; @Column('boolean', { - default: true, - comment: 'Whether the User\'s notes get indexed.', + default: false, + comment: 'Whether the User\'s notes dont get indexed.', }) - public isIndexable: boolean; + public noindex: boolean; @Column('boolean', { default: false, diff --git a/packages/backend/src/models/json-schema/user.ts b/packages/backend/src/models/json-schema/user.ts index aa293d583b..5b12050541 100644 --- a/packages/backend/src/models/json-schema/user.ts +++ b/packages/backend/src/models/json-schema/user.ts @@ -79,7 +79,7 @@ export const packedUserLiteSchema = { type: 'boolean', nullable: false, optional: false, }, - isIndexable: { + noindex: { type: 'boolean', nullable: false, optional: false, }, diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts index 78c32c5352..394a122169 100644 --- a/packages/backend/src/server/api/endpoints/i/update.ts +++ b/packages/backend/src/server/api/endpoints/i/update.ts @@ -177,7 +177,7 @@ export const paramDef = { autoAcceptFollowed: { type: 'boolean' }, noCrawle: { type: 'boolean' }, preventAiLearning: { type: 'boolean' }, - isIndexable: { type: 'boolean' }, + noindex: { type: 'boolean' }, isBot: { type: 'boolean' }, isCat: { type: 'boolean' }, speakAsCat: { type: 'boolean' }, @@ -279,7 +279,7 @@ export default class extends Endpoint { // eslint- if (typeof ps.isExplorable === 'boolean') updates.isExplorable = ps.isExplorable; if (typeof ps.hideOnlineStatus === 'boolean') updates.hideOnlineStatus = ps.hideOnlineStatus; if (typeof ps.publicReactions === 'boolean') profileUpdates.publicReactions = ps.publicReactions; - if (typeof ps.isIndexable === 'boolean') updates.isIndexable = ps.isIndexable; + if (typeof ps.noindex === 'boolean') updates.noindex = ps.noindex; if (typeof ps.isBot === 'boolean') updates.isBot = ps.isBot; if (typeof ps.carefulBot === 'boolean') profileUpdates.carefulBot = ps.carefulBot; if (typeof ps.autoAcceptFollowed === 'boolean') profileUpdates.autoAcceptFollowed = ps.autoAcceptFollowed; -- cgit v1.2.3-freya