feat: チャンネル内→チャンネル外へのリノート制限機能追加 (#12230)

* チャンネル内→チャンネル外へのリノート制限機能追加

* fix CHANGELOG.md

* コメント対応(canRenoteSwitch→allowRenoteToExternal)

* コメント対応(別チャンネルへのリノート対策)

* コメント対応(canRenote->allowRenoteToExternal)

* fix comment

* Update misskey-js.api.md

* ✌️

---------

Co-authored-by: osamu <46447427+sam-osamu@users.noreply.github.com>
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
おさむのひと
2023-11-03 17:34:23 +09:00
committed by GitHub
parent 4631e6cd4a
commit 39a3f4ae98
17 changed files with 222 additions and 161 deletions

View File

@@ -85,6 +85,7 @@ export class ChannelEntityService {
usersCount: channel.usersCount,
notesCount: channel.notesCount,
isSensitive: channel.isSensitive,
allowRenoteToExternal: channel.allowRenoteToExternal,
...(me ? {
isFollowing,

View File

@@ -350,6 +350,7 @@ export class NoteEntityService implements OnModuleInit {
name: channel.name,
color: channel.color,
isSensitive: channel.isSensitive,
allowRenoteToExternal: channel.allowRenoteToExternal,
} : undefined,
mentions: note.mentions.length > 0 ? note.mentions : undefined,
uri: note.uri ?? undefined,

View File

@@ -93,4 +93,9 @@ export class MiChannel {
default: false,
})
public isSensitive: boolean;
@Column('boolean', {
default: true,
})
public allowRenoteToExternal: boolean;
}

View File

@@ -76,5 +76,9 @@ export const packedChannelSchema = {
type: 'boolean',
optional: false, nullable: false,
},
allowRenoteToExternal: {
type: 'boolean',
optional: false, nullable: false,
},
},
} as const;

View File

@@ -50,6 +50,7 @@ export const paramDef = {
bannerId: { type: 'string', format: 'misskey:id', nullable: true },
color: { type: 'string', minLength: 1, maxLength: 16 },
isSensitive: { type: 'boolean', nullable: true },
allowRenoteToExternal: { type: 'boolean', nullable: true },
},
required: ['name'],
} as const;
@@ -87,6 +88,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
bannerId: banner ? banner.id : null,
isSensitive: ps.isSensitive ?? false,
...(ps.color !== undefined ? { color: ps.color } : {}),
allowRenoteToExternal: ps.allowRenoteToExternal ?? true,
} as MiChannel).then(x => this.channelsRepository.findOneByOrFail(x.identifiers[0]));
return await this.channelEntityService.pack(channel, me);

View File

@@ -61,6 +61,7 @@ export const paramDef = {
},
color: { type: 'string', minLength: 1, maxLength: 16 },
isSensitive: { type: 'boolean', nullable: true },
allowRenoteToExternal: { type: 'boolean', nullable: true },
},
required: ['channelId'],
} as const;
@@ -115,6 +116,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
...(typeof ps.isArchived === 'boolean' ? { isArchived: ps.isArchived } : {}),
...(banner ? { bannerId: banner.id } : {}),
...(typeof ps.isSensitive === 'boolean' ? { isSensitive: ps.isSensitive } : {}),
...(typeof ps.allowRenoteToExternal === 'boolean' ? { allowRenoteToExternal: ps.allowRenoteToExternal } : {}),
});
return await this.channelEntityService.pack(channel.id, me);

View File

@@ -99,6 +99,12 @@ export const meta = {
code: 'NO_SUCH_FILE',
id: 'b6992544-63e7-67f0-fa7f-32444b1b5306',
},
cannotRenoteOutsideOfChannel: {
message: 'Cannot renote outside of channel.',
code: 'CANNOT_RENOTE_OUTSIDE_OF_CHANNEL',
id: '33510210-8452-094c-6227-4a6c05d99f00',
},
},
} as const;
@@ -246,6 +252,19 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// specified / direct noteはreject
throw new ApiError(meta.errors.cannotRenoteDueToVisibility);
}
if (renote.channelId && renote.channelId !== ps.channelId) {
// チャンネルのノートに対しリノート要求がきたとき、チャンネル外へのリノート可否をチェック
// リートのユースケースのうち、チャンネル内→チャンネル外は少数だと考えられるため、JOINはせず必要な時に都度取得する
const renoteChannel = await this.channelsRepository.findOneById(renote.channelId);
if (renoteChannel == null) {
// リノートしたいノートが書き込まれているチャンネルが無い
throw new ApiError(meta.errors.noSuchChannel);
} else if (!renoteChannel.allowRenoteToExternal) {
// リノート作成のリクエストだが、対象チャンネルがリノート禁止だった場合
throw new ApiError(meta.errors.cannotRenoteOutsideOfChannel);
}
}
}
let reply: MiNote | null = null;