Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance(sensitive-flag):センシティブフラグの機能の強化 #936

Open
wants to merge 7 commits into
base: io
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5362,6 +5362,15 @@ export interface Locale extends ILocale {
* {x}に投稿されます
*/
"willBePostedAt": ParameterizedString<"x">;
/**
* 管理者によって、ドライブのファイルがセンシティブとして設定されました。
* 詳細については[NSFWガイドライン](https://go.misskey.io/media-guideline)を確認してください
*/
"sensitiveByModerator": string;
/**
* この情報は他のユーザーには公開されません。
*/
"thisInfoIsNotVisibleOtherUser": string;
"_bubbleGame": {
/**
* 遊び方
Expand Down Expand Up @@ -9739,6 +9748,10 @@ export interface Locale extends ILocale {
* 通知の履歴をリセットする
*/
"flushNotification": string;
/**
* ドライブのファイルがセンシティブとして設定されました
*/
"sensitiveFlagAssigned": string;
"_types": {
/**
* すべて
Expand Down
3 changes: 3 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,8 @@ scheduled: "予約済み"
unschedule: "予約を解除"
setScheduledTime: "予約日時を設定"
willBePostedAt: "{x}に投稿されます"
sensitiveByModerator: "管理者によって、ドライブのファイルがセンシティブとして設定されました。\n詳細については[NSFWガイドライン](https://go.misskey.io/media-guideline)を確認してください"
thisInfoIsNotVisibleOtherUser: "この情報は他のユーザーには公開されません。"

_bubbleGame:
howToPlay: "遊び方"
Expand Down Expand Up @@ -2560,6 +2562,7 @@ _notification:
renotedBySomeUsers: "{n}人がリノートしました"
followedBySomeUsers: "{n}人にフォローされました"
flushNotification: "通知の履歴をリセットする"
sensitiveFlagAssigned: "ドライブのファイルがセンシティブとして設定されました"

_types:
all: "すべて"
Expand Down
13 changes: 13 additions & 0 deletions packages/backend/migration/1739335129758-sensitiveFlag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class SensitiveFlag1739335129758 {
name = 'SensitiveFlag1739335129758'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "drive_file" ADD "isSensitiveByModerator" boolean NOT NULL DEFAULT false`);
await queryRunner.query(`CREATE INDEX "IDX_e779d1afdfa44dc3d64213cd2e" ON "drive_file" ("isSensitiveByModerator") `);
}

async down(queryRunner) {
await queryRunner.query(`DROP INDEX "public"."IDX_e779d1afdfa44dc3d64213cd2e"`);
await queryRunner.query(`ALTER TABLE "drive_file" DROP COLUMN "isSensitiveByModerator"`);
}
}
15 changes: 14 additions & 1 deletion packages/backend/src/core/DriveService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { correctFilename } from '@/misc/correct-filename.js';
import { isMimeImage } from '@/misc/is-mime-image.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
import { LoggerService } from '@/core/LoggerService.js';
import { NotificationService } from '@/core/NotificationService.js';

type AddFileArgs = {
/** User who wish to add file */
Expand Down Expand Up @@ -129,6 +130,7 @@ export class DriveService {
private driveChart: DriveChart,
private perUserDriveChart: PerUserDriveChart,
private instanceChart: InstanceChart,
private notificationService: NotificationService,
) {
const logger = this.loggerService.getLogger('drive', 'blue');
this.registerLogger = logger.createSubLogger('register', 'yellow');
Expand Down Expand Up @@ -590,6 +592,7 @@ export class DriveService {
if (info.sensitive && profile!.autoSensitive) file.isSensitive = true;
if (info.sensitive && instance.setSensitiveFlagAutomatically) file.isSensitive = true;
if (userRoleNSFW) file.isSensitive = true;
if (file.isSensitiveByModerator) file.isSensitive = true;

if (url !== null) {
file.src = url;
Expand Down Expand Up @@ -660,6 +663,7 @@ export class DriveService {
@bindThis
public async updateFile(file: MiDriveFile, values: Partial<MiDriveFile>, updater: MiUser) {
const alwaysMarkNsfw = (await this.roleService.getUserPolicies(file.userId)).alwaysMarkNsfw;
const isModerator = await this.roleService.isModerator(updater);

if (values.name != null && !this.driveFileEntityService.validateFileName(values.name)) {
throw new DriveService.InvalidFileNameError();
Expand All @@ -680,6 +684,10 @@ export class DriveService {
}
}

if (isModerator && file.userId !== updater.id) {
values.isSensitiveByModerator = values.isSensitive;
}

await this.driveFilesRepository.update(file.id, values);

const fileObj = await this.driveFileEntityService.pack(file.id, updater, { self: true });
Expand All @@ -689,7 +697,7 @@ export class DriveService {
this.globalEventService.publishDriveStream(file.userId, 'fileUpdated', fileObj);
}

if (await this.roleService.isModerator(updater) && (file.userId !== updater.id)) {
if (isModerator && (file.userId !== updater.id)) {
if (values.isSensitive !== undefined && values.isSensitive !== file.isSensitive) {
const user = file.userId ? await this.usersRepository.findOneByOrFail({ id: file.userId }) : null;
if (values.isSensitive) {
Expand All @@ -699,6 +707,11 @@ export class DriveService {
fileUserUsername: user?.username ?? null,
fileUserHost: user?.host ?? null,
});
if (file.userId) {
this.notificationService.createNotification(file.userId, 'sensitiveFlagAssigned', {
fileId: file.id,
});
}
} else {
this.moderationLogService.log(updater, 'unmarkSensitiveDriveFile', {
fileId: file.id,
Expand Down
6 changes: 6 additions & 0 deletions packages/backend/src/core/entities/DriveFileEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ export class DriveFileEntityService {
md5: file.md5,
size: file.size,
isSensitive: file.isSensitive,
...(opts.detail ? {
isSensitiveByModerator: file.isSensitiveByModerator,
} : {}),
blurhash: file.blurhash,
properties: opts.self ? file.properties : this.getPublicProperties(file),
url: opts.self ? file.url : this.getPublicUrl(file),
Expand Down Expand Up @@ -247,6 +250,9 @@ export class DriveFileEntityService {
md5: file.md5,
size: file.size,
isSensitive: file.isSensitive,
...(opts.detail ? {
isSensitiveByModerator: file.isSensitiveByModerator,
} : {}),
blurhash: file.blurhash,
properties: opts.self ? file.properties : this.getPublicProperties(file),
url: opts.self ? file.url : this.getPublicUrl(file),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ export class NotificationEntityService implements OnModuleInit {
header: notification.customHeader,
icon: notification.customIcon,
} : {}),
...(notification.type === 'sensitiveFlagAssigned' ? {
fileId: notification.fileId,
} : {}),
});
}

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

@Index()
@Column('boolean', {
default: false,
})
public isSensitiveByModerator: boolean;

@Index()
@Column('boolean', {
default: false,
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/models/Notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export type MiNotification = {
id: string;
createdAt: string;
draftId: MiScheduledNote['id'];
} | {
type: 'sensitiveFlagAssigned'
id: string;
fileId: string;
createdAt: string;
} | {
type: 'app';
id: string;
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/models/json-schema/drive-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export const packedDriveFileSchema = {
type: 'boolean',
optional: false, nullable: false,
},
isSensitiveByModerator: {
type: 'boolean',
optional: true, nullable: true,
},
blurhash: {
type: 'string',
optional: false, nullable: true,
Expand Down
25 changes: 19 additions & 6 deletions packages/backend/src/models/json-schema/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ export const packedNotificationSchema = {
type: 'object',
ref: 'NoteDraft',
optional: false, nullable: false,
}
}
},
},
}, {
type: 'object',
properties: {
Expand All @@ -324,8 +324,8 @@ export const packedNotificationSchema = {
type: 'object',
ref: 'Note',
optional: false, nullable: false,
}
}
},
},
}, {
type: 'object',
properties: {
Expand All @@ -339,8 +339,21 @@ export const packedNotificationSchema = {
type: 'object',
ref: 'NoteDraft',
optional: false, nullable: false,
}
}
},
},
}, {
type: 'object',
properties: {
...baseSchema.properties,
type: {
type: 'string',
optional: false, nullable: false,
enum: ['sensitiveFlagAssigned'],
},
fileId: {
optional: false, nullable: false,
},
},
}, {
type: 'object',
properties: {
Expand Down
10 changes: 10 additions & 0 deletions packages/backend/src/server/api/endpoints/drive/files/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export const meta = {
code: 'RESTRICTED_BY_ROLE',
id: '7f59dccb-f465-75ab-5cf4-3ce44e3282f7',
},

restrictedByModerator: {
message: 'The isSensitive specified by the administrator cannot be changed.',
code: 'RESTRICTED_BY_ADMINISTRATOR',
id: '20e6c501-e579-400d-97e4-1c7efc286f35',
},
},
res: {
type: 'object',
Expand Down Expand Up @@ -90,6 +96,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.accessDenied);
}

if (!await this.roleService.isModerator(me) && file.isSensitiveByModerator) {
throw new ApiError(meta.errors.restrictedByModerator);
}

let packedFile;

try {
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type { MiNote } from '@/models/Note.js';
* noteScheduled - 予約投稿が予約された
* scheduledNotePosted - 予約投稿が投稿された
* scheduledNoteError - 予約投稿がエラーになった
* sensitiveFlagAssigned - センシティブフラグが付与された
* app - アプリ通知
* test - テスト通知(サーバー側)
*/
Expand All @@ -45,6 +46,7 @@ export const notificationTypes = [
'noteScheduled',
'scheduledNotePosted',
'scheduledNoteError',
'sensitiveFlagAssigned',
'app',
'test',
] as const;
Expand Down
1 change: 1 addition & 0 deletions packages/backend/test/unit/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ describe('NoteCreateService', () => {
folderId: null,
folder: null,
isSensitive: false,
isSensitiveByModerator: false,
maybeSensitive: false,
maybePorn: false,
isLink: false,
Expand Down
55 changes: 55 additions & 0 deletions packages/frontend/src/components/MkNotification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ SPDX-License-Identifier: AGPL-3.0-only
<div :class="$style.head">
<MkAvatar v-if="['pollEnded', 'note'].includes(notification.type) && notification.note" :class="$style.icon" :user="notification.note.user" link preview/>
<MkAvatar v-else-if="['roleAssigned', 'achievementEarned', 'noteScheduled', 'scheduledNotePosted', 'scheduledNoteError'].includes(notification.type)" :class="$style.icon" :user="$i" link preview/>
<div
v-else-if="notification.type === 'sensitiveFlagAssigned'"
:class="$style.iconFrame"
>
<div :class="[$style.iconInner]">
<img :class="$style.iconImg" src="/fluent-emoji/1f6a9.png">
</div>
</div>
<div v-else-if="notification.type === 'reaction:grouped' && notification.note.reactionAcceptance === 'likeOnly'" :class="[$style.icon, $style.icon_reactionGroupHeart]"><i class="ti ti-heart" style="line-height: 1;"></i></div>
<div v-else-if="notification.type === 'reaction:grouped'" :class="[$style.icon, $style.icon_reactionGroup]"><i class="ti ti-plus" style="line-height: 1;"></i></div>
<div v-else-if="notification.type === 'renote:grouped'" :class="[$style.icon, $style.icon_renoteGroup]"><i class="ti ti-repeat" style="line-height: 1;"></i></div>
Expand Down Expand Up @@ -71,6 +79,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<span v-else-if="notification.type === 'reaction:grouped'" :class="$style.headerName">{{ i18n.tsx._notification.reactedBySomeUsers({ n: getActualReactedUsersCount(notification) }) }}</span>
<span v-else-if="notification.type === 'renote:grouped'" :class="$style.headerName">{{ i18n.tsx._notification.renotedBySomeUsers({ n: notification.users.length }) }}</span>
<span v-else-if="notification.type === 'app'" :class="$style.headerName">{{ notification.header }}</span>
<MkA v-else-if="notification.type === 'sensitiveFlagAssigned'" :to="'/my/drive/file/'+notification.fileId" :class="$style.headerName">{{ i18n.ts._notification.sensitiveFlagAssigned }}</MkA>
<MkTime v-if="withTime" :time="notification.createdAt" :class="$style.headerTime"/>
</header>
<div>
Expand Down Expand Up @@ -159,6 +168,10 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkAvatar :class="$style.reactionsItemAvatar" :user="user" link preview/>
</div>
</div>
<Mfm v-else-if="notification.type === 'sensitiveFlagAssigned'" :text="i18n.ts.sensitiveByModerator"/>
<span v-if="['sensitiveFlagAssigned'].includes(notification.type)" :class="$style.text" style="opacity: 0.6;">
{{ i18n.ts.thisInfoIsNotVisibleOtherUser }}
</span>
</div>
</div>
</div>
Expand Down Expand Up @@ -341,6 +354,12 @@ function getActualReactedUsersCount(notification: Misskey.entities.Notification)
pointer-events: none;
}

.t_sensitiveFlagAssigned {
padding: 3px;
background: var(--eventOther);
pointer-events: none;
}

.tail {
flex: 1;
min-width: 0;
Expand Down Expand Up @@ -430,6 +449,42 @@ function getActualReactedUsersCount(notification: Misskey.entities.Notification)
color: #fff;
}

.iconFrame {
position: relative;
width: 100%;
height: 100%;
padding: 4px;
border-radius: 100%;
box-sizing: border-box;
pointer-events: none;
user-select: none;
filter: drop-shadow(0px 2px 2px #00000044);
box-shadow: 0 1px 0px #ffffff88 inset;
overflow: clip;
background: linear-gradient(0deg, #703827, #d37566);
}

.iconImg {
width: calc(100% - 12px);
height: calc(100% - 12px);
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
margin: auto;
filter: drop-shadow(0px 1px 2px #000000aa);
}

.iconInner {
position: relative;
width: 100%;
height: 100%;
border-radius: 100%;
box-shadow: 0 1px 0px #ffffff88 inset;
background: linear-gradient(0deg, #d37566, #703827);
}

@container (max-width: 600px) {
.root {
padding: 16px;
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/src/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const notificationTypes = [
'noteScheduled',
'scheduledNotePosted',
'scheduledNoteError',
'sensitiveFlagAssigned',
'app',
] as const;
export const obsoleteNotificationTypes = ['pollVote', 'groupInvited'] as const;
Expand Down
Loading
Loading