diff --git a/src/services/count-same-renotes.ts b/src/services/count-same-renotes.ts new file mode 100644 index 000000000..a20b4fbf8 --- /dev/null +++ b/src/services/count-same-renotes.ts @@ -0,0 +1,15 @@ +import { Notes } from '../models'; + +export default async function(userId: string, renoteId: string, excludeNoteId: string | undefined): Promise { + // 指定したユーザーの指定したノートのリノートがいくつあるか数える + const query = Notes.createQueryBuilder('note') + .where('note.userId = :userId', { userId }) + .andWhere('note.renoteId = :renoteId', { renoteId }) + + // 指定した投稿を除く + if (excludeNoteId) { + query.andWhere('note.id != :excludeNoteId', { excludeNoteId }) + } + + return await query.getCount(); +} diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 3426083e3..98b173180 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -30,6 +30,7 @@ import { isDuplicateKeyValueError } from '../../misc/is-duplicate-key-value-erro import { ensure } from '../../prelude/ensure'; import { checkHitAntenna } from '../../misc/check-hit-antenna'; import { addNoteToAntenna } from '../add-note-to-antenna'; +import countSameRenotes from '../count-same-renotes'; type NotificationType = 'reply' | 'renote' | 'quote' | 'mention'; @@ -236,7 +237,8 @@ export default async (user: User, data: Option, silent = false) => new Promise