summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/ReactionService.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-10-06 14:24:25 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-10-06 14:24:25 +0900
commitdab205edb87ea9cdaee5b6564aa11dfcea245d7b (patch)
treee29a7874da5395a67a516c2164a82c050071dd2d /packages/backend/src/core/ReactionService.ts
parentchore(backend): response isHibernated in admin/show-user (diff)
downloadsharkey-dab205edb87ea9cdaee5b6564aa11dfcea245d7b.tar.gz
sharkey-dab205edb87ea9cdaee5b6564aa11dfcea245d7b.tar.bz2
sharkey-dab205edb87ea9cdaee5b6564aa11dfcea245d7b.zip
enhance(backend): improve featured system
Diffstat (limited to 'packages/backend/src/core/ReactionService.ts')
-rw-r--r--packages/backend/src/core/ReactionService.ts18
1 files changed, 15 insertions, 3 deletions
diff --git a/packages/backend/src/core/ReactionService.ts b/packages/backend/src/core/ReactionService.ts
index 25464b19a8..298a62ffd9 100644
--- a/packages/backend/src/core/ReactionService.ts
+++ b/packages/backend/src/core/ReactionService.ts
@@ -4,6 +4,7 @@
*/
import { Inject, Injectable } from '@nestjs/common';
+import * as Redis from 'ioredis';
import { DI } from '@/di-symbols.js';
import type { EmojisRepository, NoteReactionsRepository, UsersRepository, NotesRepository } from '@/models/_.js';
import { IdentifiableError } from '@/misc/identifiable-error.js';
@@ -26,6 +27,7 @@ import { UtilityService } from '@/core/UtilityService.js';
import { UserBlockingService } from '@/core/UserBlockingService.js';
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
import { RoleService } from '@/core/RoleService.js';
+import { FeaturedService } from '@/core/FeaturedService.js';
const FALLBACK = '❤';
@@ -66,6 +68,9 @@ const decodeCustomEmojiRegexp = /^:([\w+-]+)(?:@([\w.-]+))?:$/;
@Injectable()
export class ReactionService {
constructor(
+ @Inject(DI.redis)
+ private redisClient: Redis.Redis,
+
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
@@ -86,6 +91,7 @@ export class ReactionService {
private noteEntityService: NoteEntityService,
private userBlockingService: UserBlockingService,
private idService: IdService,
+ private featuredService: FeaturedService,
private globalEventService: GlobalEventService,
private apRendererService: ApRendererService,
private apDeliverManagerService: ApDeliverManagerService,
@@ -182,11 +188,19 @@ export class ReactionService {
await this.notesRepository.createQueryBuilder().update()
.set({
reactions: () => sql,
- ... (!user.isBot ? { score: () => '"score" + 1' } : {}),
})
.where('id = :id', { id: note.id })
.execute();
+ // 30%の確率でハイライト用ランキング更新
+ if (Math.random() < 0.3) {
+ if (note.channelId != null) {
+ this.featuredService.updateInChannelNotesRanking(note.id, note.channelId, 1);
+ } else if (note.visibility === 'public' && note.userHost == null) {
+ this.featuredService.updateGlobalNotesRanking(note.id, 1);
+ }
+ }
+
const meta = await this.metaService.fetch();
if (meta.enableChartsForRemoteUser || (user.host == null)) {
@@ -275,8 +289,6 @@ export class ReactionService {
.where('id = :id', { id: note.id })
.execute();
- if (!user.isBot) this.notesRepository.decrement({ id: note.id }, 'score', 1);
-
this.globalEventService.publishNoteStream(note.id, 'unreacted', {
reaction: this.decodeReaction(exist.reaction).reaction,
userId: user.id,