From 1de49672e896831f672d55b9ec34777f4bd9b1ff Mon Sep 17 00:00:00 2001 From: mlatus Date: Thu, 29 Jun 2023 11:57:56 +0800 Subject: [PATCH 1/3] fix(backend): publish notes announced by relay Publish notes announced by relays instead of creating renotes. Some relays (e.g. aode-relay, buzzrelay) deliver notes using Announce activity, which will result in a lot of renotes in the timeline, usually this is not desired. --- packages/backend/src/core/RelayService.ts | 11 ++++++++--- .../backend/src/core/activitypub/ApInboxService.ts | 13 ++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/core/RelayService.ts b/packages/backend/src/core/RelayService.ts index 3a903a79bc..69d817c3fd 100644 --- a/packages/backend/src/core/RelayService.ts +++ b/packages/backend/src/core/RelayService.ts @@ -110,13 +110,18 @@ export class RelayService { return JSON.stringify(result); } + @bindThis + public async getAcceptedRelays(): Promise { + return await this.relaysCache.fetch(() => this.relaysRepository.findBy({ + status: 'accepted', + })); + } + @bindThis public async deliverToRelays(user: { id: MiUser['id']; host: null; }, activity: any): Promise { if (activity == null) return; - const relays = await this.relaysCache.fetch(() => this.relaysRepository.findBy({ - status: 'accepted', - })); + const relays = await this.getAcceptedRelays(); if (relays.length === 0) return; const copy = deepClone(activity); diff --git a/packages/backend/src/core/activitypub/ApInboxService.ts b/packages/backend/src/core/activitypub/ApInboxService.ts index f548db8760..b1fafe770a 100644 --- a/packages/backend/src/core/activitypub/ApInboxService.ts +++ b/packages/backend/src/core/activitypub/ApInboxService.ts @@ -29,6 +29,7 @@ import type { UsersRepository, NotesRepository, FollowingsRepository, MessagingM import { bindThis } from '@/decorators.js'; import type { MiRemoteUser } from '@/models/User.js'; import { getApHrefNullable, getApId, getApIds, getApType, isAccept, isActor, isAdd, isAnnounce, isBlock, isCollection, isCollectionOrOrderedCollection, isCreate, isDelete, isFlag, isFollow, isLike, isMove, isPost, isRead, isReject, isRemove, isTombstone, isUndo, isUpdate, validActor, validPost } from './type.js'; +import { GlobalEventService } from '@/core/GlobalEventService.js'; import { ApNoteService } from './models/ApNoteService.js'; import { ApLoggerService } from './ApLoggerService.js'; import { ApDbResolverService } from './ApDbResolverService.js'; @@ -87,6 +88,7 @@ export class ApInboxService { private apQuestionService: ApQuestionService, private queueService: QueueService, private messagingService: MessagingService, + private globalEventService: GlobalEventService, ) { this.logger = this.apLoggerService.logger; } @@ -301,11 +303,14 @@ export class ApInboxService { const meta = await this.metaService.fetch(); if (this.utilityService.isBlockedHost(meta.blockedHosts, this.utilityService.extractDbHost(uri))) return; + const relays = await this.relayService.getAcceptedRelays(); + const fromRelay = !!actor.inbox && relays.map(r => r.inbox).includes(actor.inbox); + const unlock = await this.appLockService.getApLock(uri); try { // 既に同じURIを持つものが登録されていないかチェック - const exist = await this.apNoteService.fetchNote(uri); + const exist = await this.apNoteService.fetchNote(fromRelay ? targetUri : uri); if (exist) { return; } @@ -333,6 +338,12 @@ export class ApInboxService { return; } + if (fromRelay) { + const noteObj = await this.noteEntityService.pack(renote); + this.globalEventService.publishNotesStream(noteObj); + return; + } + this.logger.info(`Creating the (Re)Note: ${uri}`); const activityAudience = await this.apAudienceService.parseAudience(actor, activity.to, activity.cc); From f827204a21f1a99cf03787478b0657c93b3cfbce Mon Sep 17 00:00:00 2001 From: NoriDev Date: Wed, 4 Oct 2023 18:52:31 +0900 Subject: [PATCH 2/3] tweak 1de49672 --- packages/backend/src/core/RelayService.ts | 14 +++++++------- .../backend/src/core/activitypub/ApInboxService.ts | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/core/RelayService.ts b/packages/backend/src/core/RelayService.ts index 69d817c3fd..e5aeb6787b 100644 --- a/packages/backend/src/core/RelayService.ts +++ b/packages/backend/src/core/RelayService.ts @@ -110,18 +110,18 @@ export class RelayService { return JSON.stringify(result); } - @bindThis - public async getAcceptedRelays(): Promise { - return await this.relaysCache.fetch(() => this.relaysRepository.findBy({ - status: 'accepted', - })); - } + @bindThis + public async getAcceptedRelays(): Promise { + return await this.relaysCache.fetch(() => this.relaysRepository.findBy({ + status: 'accepted', + })); + } @bindThis public async deliverToRelays(user: { id: MiUser['id']; host: null; }, activity: any): Promise { if (activity == null) return; - const relays = await this.getAcceptedRelays(); + const relays = await this.getAcceptedRelays(); if (relays.length === 0) return; const copy = deepClone(activity); diff --git a/packages/backend/src/core/activitypub/ApInboxService.ts b/packages/backend/src/core/activitypub/ApInboxService.ts index b1fafe770a..cc82e9000f 100644 --- a/packages/backend/src/core/activitypub/ApInboxService.ts +++ b/packages/backend/src/core/activitypub/ApInboxService.ts @@ -28,8 +28,8 @@ import { MessagingService } from '@/core/MessagingService.js'; import type { UsersRepository, NotesRepository, FollowingsRepository, MessagingMessagesRepository, AbuseUserReportsRepository, FollowRequestsRepository } from '@/models/_.js'; import { bindThis } from '@/decorators.js'; import type { MiRemoteUser } from '@/models/User.js'; -import { getApHrefNullable, getApId, getApIds, getApType, isAccept, isActor, isAdd, isAnnounce, isBlock, isCollection, isCollectionOrOrderedCollection, isCreate, isDelete, isFlag, isFollow, isLike, isMove, isPost, isRead, isReject, isRemove, isTombstone, isUndo, isUpdate, validActor, validPost } from './type.js'; import { GlobalEventService } from '@/core/GlobalEventService.js'; +import { getApHrefNullable, getApId, getApIds, getApType, isAccept, isActor, isAdd, isAnnounce, isBlock, isCollection, isCollectionOrOrderedCollection, isCreate, isDelete, isFlag, isFollow, isLike, isMove, isPost, isRead, isReject, isRemove, isTombstone, isUndo, isUpdate, validActor, validPost } from './type.js'; import { ApNoteService } from './models/ApNoteService.js'; import { ApLoggerService } from './ApLoggerService.js'; import { ApDbResolverService } from './ApDbResolverService.js'; From 4313a830e1f6c0d453ed9911fef7fb110286fc49 Mon Sep 17 00:00:00 2001 From: NoriDev Date: Wed, 4 Oct 2023 18:55:05 +0900 Subject: [PATCH 3/3] Update CHANGELOG_CHERRYPICK.md --- CHANGELOG_CHERRYPICK.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG_CHERRYPICK.md b/CHANGELOG_CHERRYPICK.md index a6b0d560ad..8797ef8b65 100644 --- a/CHANGELOG_CHERRYPICK.md +++ b/CHANGELOG_CHERRYPICK.md @@ -42,6 +42,7 @@ Misskey의 전체 변경 사항을 확인하려면, [CHANGELOG.md#2023xx](CHANGE ### Server - Revert: Feat: 이모티콘 중복 체크 (misskey-dev/misskey#11941) +- Fix: Publish notes announced by relay (misskey-dev/misskey#11056) ---