diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-04-01 20:47:04 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-04-01 20:47:04 -0400 |
| commit | 6ac37b4d6cae064545b13fd7fdb414d0cffa178b (patch) | |
| tree | 8e938baa2b15ccd233e91429d7f5ed7566ae3606 /packages/backend/src/core | |
| parent | fix typo in check_connect.js (diff) | |
| download | sharkey-6ac37b4d6cae064545b13fd7fdb414d0cffa178b.tar.gz sharkey-6ac37b4d6cae064545b13fd7fdb414d0cffa178b.tar.bz2 sharkey-6ac37b4d6cae064545b13fd7fdb414d0cffa178b.zip | |
lint and type fixes
Diffstat (limited to 'packages/backend/src/core')
5 files changed, 38 insertions, 32 deletions
diff --git a/packages/backend/src/core/ApLogService.ts b/packages/backend/src/core/ApLogService.ts index 096ec21de7..f21c6da313 100644 --- a/packages/backend/src/core/ApLogService.ts +++ b/packages/backend/src/core/ApLogService.ts @@ -140,6 +140,24 @@ export class ApLogService { } /** + * Deletes all logged inbox activities from a user or users + * @param userIds IDs of the users to delete + */ + public async deleteInboxLogs(userIds: string | string[]): Promise<number> { + if (Array.isArray(userIds)) { + const logsDeleted = await this.apInboxLogsRepository.delete({ + authUserId: In(userIds), + }); + return logsDeleted.affected ?? 0; + } else { + const logsDeleted = await this.apInboxLogsRepository.delete({ + authUserId: userIds, + }); + return logsDeleted.affected ?? 0; + } + } + + /** * Deletes all expired AP logs and garbage-collects the AP context cache. * Returns the total number of deleted rows. */ diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index 72df948c8b..98d9571255 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -571,7 +571,7 @@ export class NoteCreateService implements OnApplicationShutdown { if (this.meta.enableStatsForFederatedInstances) { if (this.userEntityService.isRemoteUser(user)) { this.federatedInstanceService.fetchOrRegister(user.host).then(async i => { - if (note.renote && note.text || !note.renote) { + if (!this.isRenote(note) || this.isQuote(note)) { this.updateNotesCountQueue.enqueue(i.id, 1); } if (this.meta.enableChartsForFederatedInstances) { @@ -583,17 +583,12 @@ export class NoteCreateService implements OnApplicationShutdown { // ハッシュタグ更新 if (data.visibility === 'public' || data.visibility === 'home') { - if (user.isBot && this.meta.enableBotTrending) { - this.hashtagService.updateHashtags(user, tags); - } else if (!user.isBot) { + if (!user.isBot || this.meta.enableBotTrending) { this.hashtagService.updateHashtags(user, tags); } } - if (data.renote && data.text) { - // Increment notes count (user) - this.incNotesCountOfUser(user); - } else if (!data.renote) { + if (!this.isRenote(note) || this.isQuote(note)) { // Increment notes count (user) this.incNotesCountOfUser(user); } @@ -631,7 +626,7 @@ export class NoteCreateService implements OnApplicationShutdown { }); } - if (data.renote && data.text == null && data.renote.userId !== user.id && !user.isBot) { + if (this.isRenote(data) && !this.isQuote(data) && data.renote.userId !== user.id && !user.isBot) { this.incRenoteCount(data.renote); } @@ -706,13 +701,7 @@ export class NoteCreateService implements OnApplicationShutdown { }, }); - const [ - userIdsWhoMeMuting, - ] = data.renote.userId ? await Promise.all([ - this.cacheService.userMutingsCache.fetch(data.renote.userId), - ]) : [new Set<string>()]; - - const muted = isUserRelated(note, userIdsWhoMeMuting); + const muted = data.renote.userId && isUserRelated(note, await this.cacheService.userMutingsCache.fetch(data.renote.userId)); if (!isThreadMuted && !muted) { nm.push(data.renote.userId, type); @@ -848,13 +837,7 @@ export class NoteCreateService implements OnApplicationShutdown { }, }); - const [ - userIdsWhoMeMuting, - ] = u.id ? await Promise.all([ - this.cacheService.userMutingsCache.fetch(u.id), - ]) : [new Set<string>()]; - - const muted = isUserRelated(note, userIdsWhoMeMuting); + const muted = u.id && isUserRelated(note, await this.cacheService.userMutingsCache.fetch(u.id)); if (isThreadMuted || muted) { continue; diff --git a/packages/backend/src/core/activitypub/misc/validator.ts b/packages/backend/src/core/activitypub/misc/validator.ts index 4292b7e0f7..0ff83659c1 100644 --- a/packages/backend/src/core/activitypub/misc/validator.ts +++ b/packages/backend/src/core/activitypub/misc/validator.ts @@ -5,6 +5,8 @@ import type { Response } from 'node-fetch'; +// TODO throw identifiable or unrecoverable errors + export function validateContentTypeSetAsActivityPub(response: Response): void { const contentType = (response.headers.get('content-type') ?? '').toLowerCase(); diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index d7ee6c306b..c57c3f1704 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -322,6 +322,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown { const host = this.utilityService.punyHost(uri); if (host === this.utilityService.toPuny(this.config.host)) { + // TODO convert to unrecoverable error throw new StatusError(`cannot resolve local user: ${uri}`, 400, 'cannot resolve local user'); } @@ -570,7 +571,7 @@ export class ApPersonService implements OnModuleInit, OnApplicationShutdown { .catch(err => { if (!(err instanceof StatusError) || err.isRetryable) { this.logger.error('error occurred while fetching following/followers collection', { stack: err }); - // Do not update the visibiility on transient errors. + // Do not update the visibility on transient errors. return undefined; } return 'private'; diff --git a/packages/backend/src/core/entities/NoteEntityService.ts b/packages/backend/src/core/entities/NoteEntityService.ts index 537677ed34..c3d00ffa9d 100644 --- a/packages/backend/src/core/entities/NoteEntityService.ts +++ b/packages/backend/src/core/entities/NoteEntityService.ts @@ -479,14 +479,6 @@ export class NoteEntityService implements OnModuleInit { mentions: note.mentions && note.mentions.length > 0 ? note.mentions : undefined, uri: note.uri ?? undefined, url: note.url ?? undefined, - poll: note.hasPoll ? this.populatePoll(note, meId) : undefined, - ...(meId && Object.keys(reactions).length > 0 ? { - myReaction: this.populateMyReaction({ - id: note.id, - reactions: reactions, - reactionAndUserPairCache: reactionAndUserPairCache, - }, meId, options?._hint_), - } : {}), ...(opts.detail ? { clippedCount: note.clippedCount, @@ -505,6 +497,16 @@ export class NoteEntityService implements OnModuleInit { withReactionAndUserPairCache: opts.withReactionAndUserPairCache, _hint_: options?._hint_, }) : undefined, + + poll: note.hasPoll ? this.populatePoll(note, meId) : undefined, + + ...(meId && Object.keys(reactions).length > 0 ? { + myReaction: this.populateMyReaction({ + id: note.id, + reactions: reactions, + reactionAndUserPairCache: reactionAndUserPairCache, + }, meId, options?._hint_), + } : {}), } : {}), }); |