Skip to content

Commit

Permalink
Merge branch 'fix-relay' of https://github.com/kokonect-link/cherrypick
Browse files Browse the repository at this point in the history
… into develop
  • Loading branch information
noridev committed Oct 4, 2023
2 parents ba23a14 + 4313a83 commit 4ab2c37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 8 additions & 3 deletions packages/backend/src/core/RelayService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,18 @@ export class RelayService {
return JSON.stringify(result);
}

@bindThis
public async getAcceptedRelays(): Promise<MiRelay[]> {
return await this.relaysCache.fetch(() => this.relaysRepository.findBy({
status: 'accepted',
}));
}

@bindThis
public async deliverToRelays(user: { id: MiUser['id']; host: null; }, activity: any): Promise<void> {
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);
Expand Down
13 changes: 12 additions & 1 deletion packages/backend/src/core/activitypub/ApInboxService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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 { 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';
Expand Down Expand Up @@ -87,6 +88,7 @@ export class ApInboxService {
private apQuestionService: ApQuestionService,
private queueService: QueueService,
private messagingService: MessagingService,
private globalEventService: GlobalEventService,
) {
this.logger = this.apLoggerService.logger;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4ab2c37

Please sign in to comment.