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);