summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/NoteCreateService.ts
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-12-15 17:27:12 +0000
committerdakkar <dakkar@thenautilus.net>2024-12-15 17:27:12 +0000
commite2352839e4639b09e2e52b2ada1399097fad1d8d (patch)
tree9268cda477b8c1dcfb2c78eaabcb173a1566a469 /packages/backend/src/core/NoteCreateService.ts
parentmerge: Fix rate limits under multi-node environments (!809) (diff)
parentupstream merge checklist: remember to check federated profile fields (diff)
downloadsharkey-e2352839e4639b09e2e52b2ada1399097fad1d8d.tar.gz
sharkey-e2352839e4639b09e2e52b2ada1399097fad1d8d.tar.bz2
sharkey-e2352839e4639b09e2e52b2ada1399097fad1d8d.zip
merge: upstream changes for 2024.11 (!742)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/742 Closes #645 and #646 Approved-by: Hazelnoot <acomputerdog@gmail.com> Approved-by: Marie <github@yuugi.dev>
Diffstat (limited to 'packages/backend/src/core/NoteCreateService.ts')
-rw-r--r--packages/backend/src/core/NoteCreateService.ts44
1 files changed, 26 insertions, 18 deletions
diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts
index 35a2d8e290..96bb30a0d6 100644
--- a/packages/backend/src/core/NoteCreateService.ts
+++ b/packages/backend/src/core/NoteCreateService.ts
@@ -51,13 +51,13 @@ import { FeaturedService } from '@/core/FeaturedService.js';
import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
import { UtilityService } from '@/core/UtilityService.js';
import { UserBlockingService } from '@/core/UserBlockingService.js';
-import { CacheService } from '@/core/CacheService.js';
import { isReply } from '@/misc/is-reply.js';
import { trackPromise } from '@/misc/promise-tracker.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import { IdentifiableError } from '@/misc/identifiable-error.js';
import { LatestNoteService } from '@/core/LatestNoteService.js';
import { CollapsedQueue } from '@/misc/collapsed-queue.js';
+import { CacheService } from '@/core/CacheService.js';
type NotificationType = 'reply' | 'renote' | 'quote' | 'mention';
@@ -224,7 +224,7 @@ export class NoteCreateService implements OnApplicationShutdown {
private cacheService: CacheService,
private latestNoteService: LatestNoteService,
) {
- this.updateNotesCountQueue = new CollapsedQueue(60 * 1000 * 5, this.collapseNotesCount, this.performUpdateNotesCount);
+ this.updateNotesCountQueue = new CollapsedQueue(process.env.NODE_ENV !== 'test' ? 60 * 1000 * 5 : 0, this.collapseNotesCount, this.performUpdateNotesCount);
}
@bindThis
@@ -413,7 +413,7 @@ export class NoteCreateService implements OnApplicationShutdown {
}
if (user.host && !data.cw) {
- await this.federatedInstanceService.fetch(user.host).then(async i => {
+ await this.federatedInstanceService.fetchOrRegister(user.host).then(async i => {
if (i.isNSFW && !this.isPureRenote(data)) {
data.cw = 'Instance is marked as NSFW';
}
@@ -565,17 +565,17 @@ export class NoteCreateService implements OnApplicationShutdown {
}
// Register host
- if (this.userEntityService.isRemoteUser(user)) {
- this.federatedInstanceService.fetch(user.host).then(async i => {
- if (note.renote && note.text) {
- this.updateNotesCountQueue.enqueue(i.id, 1);
- } else if (!note.renote) {
- this.updateNotesCountQueue.enqueue(i.id, 1);
- }
- if (this.meta.enableChartsForFederatedInstances) {
- this.instanceChart.updateNote(i.host, note, true);
- }
- });
+ if (this.meta.enableStatsForFederatedInstances) {
+ if (this.userEntityService.isRemoteUser(user)) {
+ this.federatedInstanceService.fetchOrRegister(user.host).then(async i => {
+ if (note.renote && note.text || !note.renote) {
+ this.updateNotesCountQueue.enqueue(i.id, 1);
+ }
+ if (this.meta.enableChartsForFederatedInstances) {
+ this.instanceChart.updateNote(i.host, note, true);
+ }
+ });
+ }
}
// ハッシュタグ更新
@@ -608,13 +608,21 @@ export class NoteCreateService implements OnApplicationShutdown {
this.followingsRepository.findBy({
followeeId: user.id,
notify: 'normal',
- }).then(followings => {
+ }).then(async followings => {
if (note.visibility !== 'specified') {
+ const isPureRenote = this.isRenote(data) && !this.isQuote(data) ? true : false;
for (const following of followings) {
// TODO: ワードミュート考慮
- this.notificationService.createNotification(following.followerId, 'note', {
- noteId: note.id,
- }, user.id);
+ let isRenoteMuted = false;
+ if (isPureRenote) {
+ const userIdsWhoMeMutingRenotes = await this.cacheService.renoteMutingsCache.fetch(following.followerId);
+ isRenoteMuted = userIdsWhoMeMutingRenotes.has(user.id);
+ }
+ if (!isRenoteMuted) {
+ this.notificationService.createNotification(following.followerId, 'note', {
+ noteId: note.id,
+ }, user.id);
+ }
}
}
});