From 576251200f7d7910e5fc50e2964a5196b573038a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=BE=E3=81=A3=E3=81=A1=E3=82=83=E3=81=A8=E3=83=BC?= =?UTF-8?q?=E3=81=AB=E3=82=85?= <17376330+u1-liquid@users.noreply.github.com> Date: Tue, 15 Aug 2023 16:45:55 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"feat:=20=E5=80=8B=E4=BA=BA=E5=AE=9B?= =?UTF-8?q?=E3=81=A6=E3=81=8A=E7=9F=A5=E3=82=89=E3=81=9B=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=20(#107)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 7b1efd6b973d3117d41b2e730936c1d7b3cca757. --- locales/index.d.ts | 3 - locales/ja-JP.yml | 3 - .../1688647797135-userannouncement.js | 20 ---- .../src/core/entities/UserEntityService.ts | 10 +- .../src/models/entities/Announcement.ts | 13 --- .../endpoints/admin/announcements/create.ts | 12 --- .../api/endpoints/admin/announcements/list.ts | 41 +------- .../endpoints/admin/announcements/update.ts | 15 +-- .../src/server/api/endpoints/announcements.ts | 23 +---- .../api/endpoints/i/read-announcement.ts | 14 +-- packages/frontend/src/boot/main-boot.ts | 7 +- .../components/MkUserAnnouncementModal.vue | 95 ------------------- .../src/pages/admin/announcements.vue | 58 +---------- packages/frontend/src/pages/announcements.vue | 21 +--- packages/misskey-js/etc/misskey-js.api.md | 3 - packages/misskey-js/src/api.types.ts | 2 +- packages/misskey-js/src/entities.ts | 2 - 17 files changed, 18 insertions(+), 324 deletions(-) delete mode 100644 packages/backend/migration/1688647797135-userannouncement.js delete mode 100644 packages/frontend/src/components/MkUserAnnouncementModal.vue diff --git a/locales/index.d.ts b/locales/index.d.ts index e7f5a821b..b1a035a20 100644 --- a/locales/index.d.ts +++ b/locales/index.d.ts @@ -1075,9 +1075,6 @@ export interface Locale { "additionalEmojiDictionary": string; "installed": string; "branding": string; - "newUserAnnouncementAvailable": string; - "viewAnnouncement": string; - "dialogCloseDuration": string; "enableServerMachineStats": string; "enableIdenticonGeneration": string; "turnOffToImprovePerformance": string; diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index a5ec47546..1ca37e761 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1072,9 +1072,6 @@ goToMisskey: "Misskeyへ" additionalEmojiDictionary: "絵文字の追加辞書" installed: "インストール済み" branding: "ブランディング" -newUserAnnouncementAvailable: "新着のあなた宛てのお知らせがあります" -viewAnnouncement: "お知らせを見る" -dialogCloseDuration: "ダイアログを閉じるまでの待機時間" enableServerMachineStats: "サーバーのマシン情報を公開する" enableIdenticonGeneration: "ユーザーごとのIdenticon生成を有効にする" turnOffToImprovePerformance: "オフにするとパフォーマンスが向上します。" diff --git a/packages/backend/migration/1688647797135-userannouncement.js b/packages/backend/migration/1688647797135-userannouncement.js deleted file mode 100644 index 6b3ca6cd6..000000000 --- a/packages/backend/migration/1688647797135-userannouncement.js +++ /dev/null @@ -1,20 +0,0 @@ -/* - * SPDX-FileCopyrightText: syuilo and other misskey contributors - * SPDX-License-Identifier: AGPL-3.0-only - */ - -export class Userannouncement1688647797135 { - name = 'Userannouncement1688647797135' - - async up(queryRunner) { - await queryRunner.query(`ALTER TABLE "announcement" ADD COLUMN "userId" character varying(32)`); - await queryRunner.query(`ALTER TABLE "announcement" ADD COLUMN "closeDuration" integer NOT NULL DEFAULT 0`); - await queryRunner.query(`CREATE INDEX "IDX_fd25dfe3da37df1715f11ba6ec" ON "announcement" ("userId") `); - } - - async down(queryRunner) { - await queryRunner.query(`DROP INDEX "public"."IDX_fd25dfe3da37df1715f11ba6ec"`); - await queryRunner.query(`ALTER TABLE "announcement" DROP COLUMN "userId"`); - await queryRunner.query(`ALTER TABLE "announcement" DROP COLUMN "closeDuration"`); - } -} diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts index 41705d672..f612007f8 100644 --- a/packages/backend/src/core/entities/UserEntityService.ts +++ b/packages/backend/src/core/entities/UserEntityService.ts @@ -4,7 +4,7 @@ */ import { Inject, Injectable } from '@nestjs/common'; -import { In, IsNull, Not } from 'typeorm'; +import { In, Not } from 'typeorm'; import * as Redis from 'ioredis'; import _Ajv from 'ajv'; import { ModuleRef } from '@nestjs/core'; @@ -250,11 +250,9 @@ export class UserEntityService implements OnModuleInit { userId: userId, }); - const id = reads.length > 0 ? Not(In(reads.map(read => read.announcementId))) : undefined; - const count = await this.announcementsRepository.countBy([ - { id, userId: IsNull() }, - { id, userId: userId }, - ]); + const count = await this.announcementsRepository.countBy(reads.length > 0 ? { + id: Not(In(reads.map(read => read.announcementId))), + } : {}); return count > 0; } diff --git a/packages/backend/src/models/entities/Announcement.ts b/packages/backend/src/models/entities/Announcement.ts index 7a782b1e1..99cdf8933 100644 --- a/packages/backend/src/models/entities/Announcement.ts +++ b/packages/backend/src/models/entities/Announcement.ts @@ -38,19 +38,6 @@ export class Announcement { }) public imageUrl: string | null; - @Index() - @Column('varchar', { - ...id(), - nullable: true, - }) - public userId: string | null; - - @Column('integer', { - nullable: false, - default: 0, - }) - public closeDuration: number; - constructor(data: Partial) { if (data == null) return; diff --git a/packages/backend/src/server/api/endpoints/admin/announcements/create.ts b/packages/backend/src/server/api/endpoints/admin/announcements/create.ts index 246efcf14..8addffc6a 100644 --- a/packages/backend/src/server/api/endpoints/admin/announcements/create.ts +++ b/packages/backend/src/server/api/endpoints/admin/announcements/create.ts @@ -47,14 +47,6 @@ export const meta = { type: 'string', optional: false, nullable: true, }, - userId: { - type: 'string', - optional: false, nullable: true, - }, - closeDuration: { - type: 'number', - optional: false, nullable: false, - }, }, }, } as const; @@ -65,8 +57,6 @@ export const paramDef = { title: { type: 'string', minLength: 1 }, text: { type: 'string', minLength: 1 }, imageUrl: { type: 'string', nullable: true, minLength: 1 }, - userId: { type: 'string', nullable: true, format: 'misskey:id' }, - closeDuration: { type: 'number', nullable: false }, }, required: ['title', 'text', 'imageUrl'], } as const; @@ -88,8 +78,6 @@ export default class extends Endpoint { title: ps.title, text: ps.text, imageUrl: ps.imageUrl, - userId: ps.userId ?? null, - closeDuration: ps.closeDuration, }).then(x => this.announcementsRepository.findOneByOrFail(x.identifiers[0])); return Object.assign({}, announcement, { createdAt: announcement.createdAt.toISOString(), updatedAt: null }); diff --git a/packages/backend/src/server/api/endpoints/admin/announcements/list.ts b/packages/backend/src/server/api/endpoints/admin/announcements/list.ts index 288b4e665..ec0d4061a 100644 --- a/packages/backend/src/server/api/endpoints/admin/announcements/list.ts +++ b/packages/backend/src/server/api/endpoints/admin/announcements/list.ts @@ -4,12 +4,10 @@ */ import { Inject, Injectable } from '@nestjs/common'; -import { In } from 'typeorm'; -import type { AnnouncementsRepository, AnnouncementReadsRepository, UsersRepository } from '@/models/index.js'; +import type { AnnouncementsRepository, AnnouncementReadsRepository } from '@/models/index.js'; import type { Announcement } from '@/models/entities/Announcement.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { QueryService } from '@/core/QueryService.js'; -import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { DI } from '@/di-symbols.js'; export const meta = { @@ -53,23 +51,10 @@ export const meta = { type: 'string', optional: false, nullable: true, }, - userId: { - type: 'string', - optional: false, nullable: true, - }, - user: { - type: 'object', - optional: true, nullable: false, - ref: 'UserLite', - }, reads: { type: 'number', optional: false, nullable: false, }, - closeDuration: { - type: 'number', - optional: false, nullable: false, - }, }, }, }, @@ -81,7 +66,6 @@ export const paramDef = { limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, sinceId: { type: 'string', format: 'misskey:id' }, untilId: { type: 'string', format: 'misskey:id' }, - userId: { type: 'string', format: 'misskey:id' }, }, required: [], } as const; @@ -96,21 +80,10 @@ export default class extends Endpoint { @Inject(DI.announcementReadsRepository) private announcementReadsRepository: AnnouncementReadsRepository, - @Inject(DI.usersRepository) - private usersRepository: UsersRepository, - private queryService: QueryService, - private userEntityService: UserEntityService, ) { super(meta, paramDef, async (ps, me) => { - const builder = this.announcementsRepository.createQueryBuilder('announcement'); - if (ps.userId) { - builder.where('"userId" = :userId', { userId: ps.userId }); - } else { - builder.where('"userId" IS NULL'); - } - - const query = this.queryService.makePaginationQuery(builder, ps.sinceId, ps.untilId); + const query = this.queryService.makePaginationQuery(this.announcementsRepository.createQueryBuilder('announcement'), ps.sinceId, ps.untilId); const announcements = await query.limit(ps.limit).getMany(); @@ -122,13 +95,6 @@ export default class extends Endpoint { })); } - const users = await this.usersRepository.findBy({ - id: In(announcements.map(a => a.userId).filter(id => id != null)), - }); - const packedUsers = await this.userEntityService.packMany(users, me, { - detail: false, - }); - return announcements.map(announcement => ({ id: announcement.id, createdAt: announcement.createdAt.toISOString(), @@ -136,10 +102,7 @@ export default class extends Endpoint { title: announcement.title, text: announcement.text, imageUrl: announcement.imageUrl, - userId: announcement.userId, - user: packedUsers.find(user => user.id === announcement.userId), reads: reads.get(announcement)!, - closeDuration: announcement.closeDuration, })); }); } diff --git a/packages/backend/src/server/api/endpoints/admin/announcements/update.ts b/packages/backend/src/server/api/endpoints/admin/announcements/update.ts index 2e18f1966..b3df14320 100644 --- a/packages/backend/src/server/api/endpoints/admin/announcements/update.ts +++ b/packages/backend/src/server/api/endpoints/admin/announcements/update.ts @@ -5,7 +5,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; -import type { AnnouncementReadsRepository, AnnouncementsRepository } from '@/models/index.js'; +import type { AnnouncementsRepository } from '@/models/index.js'; import { DI } from '@/di-symbols.js'; import { ApiError } from '../../../error.js'; @@ -31,10 +31,8 @@ export const paramDef = { title: { type: 'string', minLength: 1 }, text: { type: 'string', minLength: 1 }, imageUrl: { type: 'string', nullable: true, minLength: 0 }, - userId: { type: 'string', nullable: true, format: 'misskey:id' }, - closeDuration: { type: 'number', nullable: false }, }, - required: ['id', 'title', 'text', 'imageUrl', 'closeDuration'], + required: ['id', 'title', 'text', 'imageUrl'], } as const; // eslint-disable-next-line import/no-default-export @@ -43,27 +41,18 @@ export default class extends Endpoint { constructor( @Inject(DI.announcementsRepository) private announcementsRepository: AnnouncementsRepository, - - @Inject(DI.announcementReadsRepository) - private announcementsReadsRepository: AnnouncementReadsRepository, ) { super(meta, paramDef, async (ps, me) => { const announcement = await this.announcementsRepository.findOneBy({ id: ps.id }); if (announcement == null) throw new ApiError(meta.errors.noSuchAnnouncement); - if (announcement.userId && announcement.userId !== ps.userId) { - await this.announcementsReadsRepository.delete({ id: announcement.id, userId: announcement.userId }); - } - await this.announcementsRepository.update(announcement.id, { updatedAt: new Date(), title: ps.title, text: ps.text, /* eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- 空の文字列の場合、nullを渡すようにするため */ imageUrl: ps.imageUrl || null, - userId: ps.userId ?? null, - closeDuration: ps.closeDuration, }); }); } diff --git a/packages/backend/src/server/api/endpoints/announcements.ts b/packages/backend/src/server/api/endpoints/announcements.ts index b951c2bce..df0a0afb0 100644 --- a/packages/backend/src/server/api/endpoints/announcements.ts +++ b/packages/backend/src/server/api/endpoints/announcements.ts @@ -53,14 +53,6 @@ export const meta = { type: 'boolean', optional: true, nullable: false, }, - isPrivate: { - type: 'boolean', - optional: false, nullable: true, - }, - closeDuration: { - type: 'number', - optional: false, nullable: false, - }, }, }, }, @@ -73,7 +65,6 @@ export const paramDef = { withUnreads: { type: 'boolean', default: false }, sinceId: { type: 'string', format: 'misskey:id' }, untilId: { type: 'string', format: 'misskey:id' }, - privateOnly: { type: 'boolean', default: false }, }, required: [], } as const; @@ -91,19 +82,8 @@ export default class extends Endpoint { private queryService: QueryService, ) { super(meta, paramDef, async (ps, me) => { - const builder = this.announcementsRepository.createQueryBuilder('announcement'); - if (me) { - if (ps.privateOnly) { - builder.where('"userId" = :userId', { userId: me.id }); - } else { - builder.where('"userId" IS NULL'); - builder.orWhere('"userId" = :userId', { userId: me.id }); - } - } else { - builder.where('"userId" IS NULL'); - } + const query = this.queryService.makePaginationQuery(this.announcementsRepository.createQueryBuilder('announcement'), ps.sinceId, ps.untilId); - const query = this.queryService.makePaginationQuery(builder, ps.sinceId, ps.untilId); const announcements = await query.limit(ps.limit).getMany(); if (me) { @@ -120,7 +100,6 @@ export default class extends Endpoint { ...a, createdAt: a.createdAt.toISOString(), updatedAt: a.updatedAt?.toISOString() ?? null, - isPrivate: !!a.userId, })); }); } diff --git a/packages/backend/src/server/api/endpoints/i/read-announcement.ts b/packages/backend/src/server/api/endpoints/i/read-announcement.ts index 61adb39a4..7bda6e262 100644 --- a/packages/backend/src/server/api/endpoints/i/read-announcement.ts +++ b/packages/backend/src/server/api/endpoints/i/read-announcement.ts @@ -4,7 +4,6 @@ */ import { Inject, Injectable } from '@nestjs/common'; -import { IsNull } from 'typeorm'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { IdService } from '@/core/IdService.js'; import type { AnnouncementReadsRepository, AnnouncementsRepository } from '@/models/index.js'; @@ -53,18 +52,7 @@ export default class extends Endpoint { ) { super(meta, paramDef, async (ps, me) => { // Check if announcement exists - const announcementExist = await this.announcementsRepository.exist({ - where: [ - { - id: ps.announcementId, - userId: IsNull(), - }, - { - id: ps.announcementId, - userId: me.id, - } - ] - }); + const announcementExist = await this.announcementsRepository.exist({ where: { id: ps.announcementId } }); if (!announcementExist) { throw new ApiError(meta.errors.noSuchAnnouncement); diff --git a/packages/frontend/src/boot/main-boot.ts b/packages/frontend/src/boot/main-boot.ts index d81c8033b..7459ea0fa 100644 --- a/packages/frontend/src/boot/main-boot.ts +++ b/packages/frontend/src/boot/main-boot.ts @@ -7,7 +7,7 @@ import { computed, createApp, watch, markRaw, version as vueVersion, defineAsync import { common } from './common'; import { version, ui, lang, updateLocale } from '@/config'; import { i18n, updateI18n } from '@/i18n'; -import { confirm, alert, post, popup, toast, api } from '@/os'; +import { confirm, alert, post, popup, toast } from '@/os'; import { useStream } from '@/stream'; import * as sound from '@/scripts/sound'; import { $i, refreshAccount, login, updateAccount, signout } from '@/account'; @@ -251,11 +251,6 @@ export async function mainBoot() { main.on('myTokenRegenerated', () => { signout(); }); - - const unreadUserAnnouncementsList = await api('announcements', { privateOnly: true, withUnreads: true }); - if (unreadUserAnnouncementsList.length > 0) { - unreadUserAnnouncementsList.forEach((v) => popup(defineAsyncComponent(() => import('@/components/MkUserAnnouncementModal.vue')), { title: v.title, text: v.text, closeDuration: v.closeDuration, announcementId: v.id }, {}, 'closed')); - } } // shortcut diff --git a/packages/frontend/src/components/MkUserAnnouncementModal.vue b/packages/frontend/src/components/MkUserAnnouncementModal.vue deleted file mode 100644 index 097028ea9..000000000 --- a/packages/frontend/src/components/MkUserAnnouncementModal.vue +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - diff --git a/packages/frontend/src/pages/admin/announcements.vue b/packages/frontend/src/pages/admin/announcements.vue index 7e493f5c6..2e80d028f 100644 --- a/packages/frontend/src/pages/admin/announcements.vue +++ b/packages/frontend/src/pages/admin/announcements.vue @@ -8,26 +8,10 @@ SPDX-License-Identifier: AGPL-3.0-only
- - - - - - - -
-
@{{ user.username }}
-
- {{ i18n.ts.selectUser }} - {{ i18n.ts.remove }} -
-
-
-
- - + + @@ -35,13 +19,7 @@ SPDX-License-Identifier: AGPL-3.0-only - - - -

{{ i18n.t('nUsersRead', { n: announcement.reads }) }}

- - {{ i18n.ts.specifyUser }}
{{ i18n.ts.save }} {{ i18n.ts.remove }} @@ -54,40 +32,17 @@ SPDX-License-Identifier: AGPL-3.0-only