1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-11-28 06:48:36 +09:00

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.
This commit is contained in:
mlatus 2023-06-29 11:57:56 +08:00 committed by NoriDev
parent 9781089c13
commit 1de49672e8
2 changed files with 20 additions and 4 deletions

View File

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

View File

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