Update ReactionService.ts
This commit is contained in:
		| @@ -5,7 +5,7 @@ | |||||||
|  |  | ||||||
| import { Inject, Injectable } from '@nestjs/common'; | import { Inject, Injectable } from '@nestjs/common'; | ||||||
| import { DI } from '@/di-symbols.js'; | import { DI } from '@/di-symbols.js'; | ||||||
| import type { EmojisRepository, NoteReactionsRepository, UsersRepository, NotesRepository } from '@/models/_.js'; | import type { EmojisRepository, NoteReactionsRepository, UsersRepository, NotesRepository, MiMeta } from '@/models/_.js'; | ||||||
| import { IdentifiableError } from '@/misc/identifiable-error.js'; | import { IdentifiableError } from '@/misc/identifiable-error.js'; | ||||||
| import type { MiRemoteUser, MiUser } from '@/models/User.js'; | import type { MiRemoteUser, MiUser } from '@/models/User.js'; | ||||||
| import type { MiNote } from '@/models/Note.js'; | import type { MiNote } from '@/models/Note.js'; | ||||||
| @@ -20,7 +20,6 @@ import { ApDeliverManagerService } from '@/core/activitypub/ApDeliverManagerServ | |||||||
| import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; | import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; | ||||||
| import { UserEntityService } from '@/core/entities/UserEntityService.js'; | import { UserEntityService } from '@/core/entities/UserEntityService.js'; | ||||||
| import { ApRendererService } from '@/core/activitypub/ApRendererService.js'; | import { ApRendererService } from '@/core/activitypub/ApRendererService.js'; | ||||||
| import { MetaService } from '@/core/MetaService.js'; |  | ||||||
| import { bindThis } from '@/decorators.js'; | import { bindThis } from '@/decorators.js'; | ||||||
| import { UtilityService } from '@/core/UtilityService.js'; | import { UtilityService } from '@/core/UtilityService.js'; | ||||||
| import { UserBlockingService } from '@/core/UserBlockingService.js'; | import { UserBlockingService } from '@/core/UserBlockingService.js'; | ||||||
| @@ -71,6 +70,9 @@ const decodeCustomEmojiRegexp = /^:([\w+-]+)(?:@([\w.-]+))?:$/; | |||||||
| @Injectable() | @Injectable() | ||||||
| export class ReactionService { | export class ReactionService { | ||||||
| 	constructor( | 	constructor( | ||||||
|  | 		@Inject(DI.meta) | ||||||
|  | 		private meta: MiMeta, | ||||||
|  |  | ||||||
| 		@Inject(DI.usersRepository) | 		@Inject(DI.usersRepository) | ||||||
| 		private usersRepository: UsersRepository, | 		private usersRepository: UsersRepository, | ||||||
|  |  | ||||||
| @@ -84,7 +86,6 @@ export class ReactionService { | |||||||
| 		private emojisRepository: EmojisRepository, | 		private emojisRepository: EmojisRepository, | ||||||
|  |  | ||||||
| 		private utilityService: UtilityService, | 		private utilityService: UtilityService, | ||||||
| 		private metaService: MetaService, |  | ||||||
| 		private customEmojiService: CustomEmojiService, | 		private customEmojiService: CustomEmojiService, | ||||||
| 		private roleService: RoleService, | 		private roleService: RoleService, | ||||||
| 		private userEntityService: UserEntityService, | 		private userEntityService: UserEntityService, | ||||||
| @@ -103,8 +104,6 @@ export class ReactionService { | |||||||
|  |  | ||||||
| 	@bindThis | 	@bindThis | ||||||
| 	public async create(user: { id: MiUser['id']; host: MiUser['host']; isBot: MiUser['isBot'] }, note: MiNote, _reaction?: string | null) { | 	public async create(user: { id: MiUser['id']; host: MiUser['host']; isBot: MiUser['isBot'] }, note: MiNote, _reaction?: string | null) { | ||||||
| 		const meta = await this.metaService.fetch(); |  | ||||||
|  |  | ||||||
| 		// Check blocking | 		// Check blocking | ||||||
| 		if (note.userId !== user.id) { | 		if (note.userId !== user.id) { | ||||||
| 			const blocked = await this.userBlockingService.checkBlocked(note.userId, user.id); | 			const blocked = await this.userBlockingService.checkBlocked(note.userId, user.id); | ||||||
| @@ -150,7 +149,7 @@ export class ReactionService { | |||||||
| 						} | 						} | ||||||
|  |  | ||||||
| 						// for media silenced host, custom emoji reactions are not allowed | 						// for media silenced host, custom emoji reactions are not allowed | ||||||
| 						if (reacterHost != null && this.utilityService.isMediaSilencedHost(meta.mediaSilencedHosts, reacterHost)) { | 						if (reacterHost != null && this.utilityService.isMediaSilencedHost(this.meta.mediaSilencedHosts, reacterHost)) { | ||||||
| 							reaction = FALLBACK; | 							reaction = FALLBACK; | ||||||
| 						} | 						} | ||||||
| 					} else { | 					} else { | ||||||
| @@ -195,7 +194,7 @@ export class ReactionService { | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		// Increment reactions count | 		// Increment reactions count | ||||||
| 		if (meta.enableReactionsBuffering) { | 		if (this.meta.enableReactionsBuffering) { | ||||||
| 			await this.reactionsBufferingService.create(note.id, user.id, reaction, note.reactionAndUserPairCache); | 			await this.reactionsBufferingService.create(note.id, user.id, reaction, note.reactionAndUserPairCache); | ||||||
| 		} else { | 		} else { | ||||||
| 			const sql = `jsonb_set("reactions", '{${reaction}}', (COALESCE("reactions"->>'${reaction}', '0')::int + 1)::text::jsonb)`; | 			const sql = `jsonb_set("reactions", '{${reaction}}', (COALESCE("reactions"->>'${reaction}', '0')::int + 1)::text::jsonb)`; | ||||||
| @@ -228,7 +227,7 @@ export class ReactionService { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (meta.enableChartsForRemoteUser || (user.host == null)) { | 		if (this.meta.enableChartsForRemoteUser || (user.host == null)) { | ||||||
| 			this.perUserReactionsChart.update(user, note); | 			this.perUserReactionsChart.update(user, note); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -305,10 +304,8 @@ export class ReactionService { | |||||||
| 			throw new IdentifiableError('60527ec9-b4cb-4a88-a6bd-32d3ad26817d', 'not reacted'); | 			throw new IdentifiableError('60527ec9-b4cb-4a88-a6bd-32d3ad26817d', 'not reacted'); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		const meta = await this.metaService.fetch(); |  | ||||||
|  |  | ||||||
| 		// Decrement reactions count | 		// Decrement reactions count | ||||||
| 		if (meta.enableReactionsBuffering) { | 		if (this.meta.enableReactionsBuffering) { | ||||||
| 			await this.reactionsBufferingService.delete(note.id, user.id, exist.reaction); | 			await this.reactionsBufferingService.delete(note.id, user.id, exist.reaction); | ||||||
| 		} else { | 		} else { | ||||||
| 			const sql = `jsonb_set("reactions", '{${exist.reaction}}', (COALESCE("reactions"->>'${exist.reaction}', '0')::int - 1)::text::jsonb)`; | 			const sql = `jsonb_set("reactions", '{${exist.reaction}}', (COALESCE("reactions"->>'${exist.reaction}', '0')::int - 1)::text::jsonb)`; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 syuilo
					syuilo