improve(backend): Skip note score incrementing when bots reacted (#9367)
fix Improved code quality fix small fix
This commit is contained in:
parent
bebcaad23b
commit
fe158339da
@ -198,6 +198,7 @@ export class NoteCreateService {
|
|||||||
host: User['host'];
|
host: User['host'];
|
||||||
isSilenced: User['isSilenced'];
|
isSilenced: User['isSilenced'];
|
||||||
createdAt: User['createdAt'];
|
createdAt: User['createdAt'];
|
||||||
|
isBot: User['isBot'];
|
||||||
}, data: Option, silent = false): Promise<Note> {
|
}, data: Option, silent = false): Promise<Note> {
|
||||||
// チャンネル外にリプライしたら対象のスコープに合わせる
|
// チャンネル外にリプライしたら対象のスコープに合わせる
|
||||||
// (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで)
|
// (クライアントサイドでやっても良い処理だと思うけどとりあえずサーバーサイドで)
|
||||||
@ -415,6 +416,7 @@ export class NoteCreateService {
|
|||||||
host: User['host'];
|
host: User['host'];
|
||||||
isSilenced: User['isSilenced'];
|
isSilenced: User['isSilenced'];
|
||||||
createdAt: User['createdAt'];
|
createdAt: User['createdAt'];
|
||||||
|
isBot: User['isBot'];
|
||||||
}, data: Option, silent: boolean, tags: string[], mentionedUsers: MinimumUser[]) {
|
}, data: Option, silent: boolean, tags: string[], mentionedUsers: MinimumUser[]) {
|
||||||
// 統計を更新
|
// 統計を更新
|
||||||
this.notesChart.update(note, true);
|
this.notesChart.update(note, true);
|
||||||
@ -484,7 +486,7 @@ export class NoteCreateService {
|
|||||||
|
|
||||||
// この投稿を除く指定したユーザーによる指定したノートのリノートが存在しないとき
|
// この投稿を除く指定したユーザーによる指定したノートのリノートが存在しないとき
|
||||||
if (data.renote && (await this.noteEntityService.countSameRenotes(user.id, data.renote.id, note.id) === 0)) {
|
if (data.renote && (await this.noteEntityService.countSameRenotes(user.id, data.renote.id, note.id) === 0)) {
|
||||||
this.incRenoteCount(data.renote);
|
if (!user.isBot) this.incRenoteCount(data.renote);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.poll && data.poll.expiresAt) {
|
if (data.poll && data.poll.expiresAt) {
|
||||||
|
@ -49,13 +49,13 @@ export class NoteDeleteService {
|
|||||||
* @param user 投稿者
|
* @param user 投稿者
|
||||||
* @param note 投稿
|
* @param note 投稿
|
||||||
*/
|
*/
|
||||||
async delete(user: { id: User['id']; uri: User['uri']; host: User['host']; }, note: Note, quiet = false) {
|
async delete(user: { id: User['id']; uri: User['uri']; host: User['host']; isBot: User['isBot']; }, note: Note, quiet = false) {
|
||||||
const deletedAt = new Date();
|
const deletedAt = new Date();
|
||||||
|
|
||||||
// この投稿を除く指定したユーザーによる指定したノートのリノートが存在しないとき
|
// この投稿を除く指定したユーザーによる指定したノートのリノートが存在しないとき
|
||||||
if (note.renoteId && (await this.noteEntityService.countSameRenotes(user.id, note.renoteId, note.id)) === 0) {
|
if (note.renoteId && (await this.noteEntityService.countSameRenotes(user.id, note.renoteId, note.id)) === 0) {
|
||||||
this.notesRepository.decrement({ id: note.renoteId }, 'renoteCount', 1);
|
this.notesRepository.decrement({ id: note.renoteId }, 'renoteCount', 1);
|
||||||
this.notesRepository.decrement({ id: note.renoteId }, 'score', 1);
|
if (!user.isBot) this.notesRepository.decrement({ id: note.renoteId }, 'score', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (note.replyId) {
|
if (note.replyId) {
|
||||||
|
@ -83,7 +83,7 @@ export class ReactionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async create(user: { id: User['id']; host: User['host']; }, note: Note, reaction?: string) {
|
public async create(user: { id: User['id']; host: User['host']; isBot: User['isBot'] }, note: Note, reaction?: string) {
|
||||||
// Check blocking
|
// Check blocking
|
||||||
if (note.userId !== user.id) {
|
if (note.userId !== user.id) {
|
||||||
const block = await this.blockingsRepository.findOneBy({
|
const block = await this.blockingsRepository.findOneBy({
|
||||||
@ -139,7 +139,7 @@ export class ReactionService {
|
|||||||
await this.notesRepository.createQueryBuilder().update()
|
await this.notesRepository.createQueryBuilder().update()
|
||||||
.set({
|
.set({
|
||||||
reactions: () => sql,
|
reactions: () => sql,
|
||||||
score: () => '"score" + 1',
|
... (!user.isBot ? { score: () => '"score" + 1' } : {}),
|
||||||
})
|
})
|
||||||
.where('id = :id', { id: note.id })
|
.where('id = :id', { id: note.id })
|
||||||
.execute();
|
.execute();
|
||||||
@ -199,7 +199,7 @@ export class ReactionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async delete(user: { id: User['id']; host: User['host']; }, note: Note) {
|
public async delete(user: { id: User['id']; host: User['host']; isBot: User['isBot']; }, note: Note) {
|
||||||
// if already unreacted
|
// if already unreacted
|
||||||
const exist = await this.noteReactionsRepository.findOneBy({
|
const exist = await this.noteReactionsRepository.findOneBy({
|
||||||
noteId: note.id,
|
noteId: note.id,
|
||||||
@ -226,7 +226,7 @@ export class ReactionService {
|
|||||||
.where('id = :id', { id: note.id })
|
.where('id = :id', { id: note.id })
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
this.notesRepository.decrement({ id: note.id }, 'score', 1);
|
if (!user.isBot) this.notesRepository.decrement({ id: note.id }, 'score', 1);
|
||||||
|
|
||||||
this.globalEventServie.publishNoteStream(note.id, 'unreacted', {
|
this.globalEventServie.publishNoteStream(note.id, 'unreacted', {
|
||||||
reaction: this.decodeReaction(exist.reaction).reaction,
|
reaction: this.decodeReaction(exist.reaction).reaction,
|
||||||
|
Loading…
Reference in New Issue
Block a user