summaryrefslogtreecommitdiff
path: root/packages/backend/src/server
diff options
context:
space:
mode:
authorJulia <julia@insertdomain.name>2025-06-19 21:35:18 +0000
committerJulia <julia@insertdomain.name>2025-06-19 21:35:18 +0000
commita77c32b17da63d3932b219f74152cce023a30f4a (patch)
treed2a05796e942c8f250bbd01369eab0cbe5a14531 /packages/backend/src/server
parentmerge: release 2025.4.2 (!1051) (diff)
parentMerge branch 'develop' into release/2025.4.3 (diff)
downloadsharkey-a77c32b17da63d3932b219f74152cce023a30f4a.tar.gz
sharkey-a77c32b17da63d3932b219f74152cce023a30f4a.tar.bz2
sharkey-a77c32b17da63d3932b219f74152cce023a30f4a.zip
merge: prepare release 2025.4.3 (!1125)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1125 Approved-by: Marie <github@yuugi.dev> Approved-by: Julia <julia@insertdomain.name>
Diffstat (limited to 'packages/backend/src/server')
-rw-r--r--packages/backend/src/server/ActivityPubServerService.ts13
-rw-r--r--packages/backend/src/server/FileServerService.ts15
-rw-r--r--packages/backend/src/server/ServerService.ts3
-rw-r--r--packages/backend/src/server/SkRateLimiterService.ts2
-rw-r--r--packages/backend/src/server/api/ApiCallService.ts44
-rw-r--r--packages/backend/src/server/api/GetterService.ts8
-rw-r--r--packages/backend/src/server/api/SigninApiService.ts12
-rw-r--r--packages/backend/src/server/api/SigninWithPasskeyApiService.ts2
-rw-r--r--packages/backend/src/server/api/SignupApiService.ts16
-rw-r--r--packages/backend/src/server/api/endpoints.ts2
-rw-r--r--packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts17
-rw-r--r--packages/backend/src/server/api/endpoints/admin/nsfw-user.ts2
-rw-r--r--packages/backend/src/server/api/endpoints/admin/relays/add.ts7
-rw-r--r--packages/backend/src/server/api/endpoints/admin/show-user.ts10
-rw-r--r--packages/backend/src/server/api/endpoints/admin/update-meta.ts24
-rw-r--r--packages/backend/src/server/api/endpoints/antennas/notes.ts15
-rw-r--r--packages/backend/src/server/api/endpoints/ap/get.ts65
-rw-r--r--packages/backend/src/server/api/endpoints/ap/show.ts4
-rw-r--r--packages/backend/src/server/api/endpoints/channels/timeline.ts29
-rw-r--r--packages/backend/src/server/api/endpoints/charts/active-users.ts6
-rw-r--r--packages/backend/src/server/api/endpoints/charts/ap-request.ts6
-rw-r--r--packages/backend/src/server/api/endpoints/charts/drive.ts6
-rw-r--r--packages/backend/src/server/api/endpoints/charts/federation.ts6
-rw-r--r--packages/backend/src/server/api/endpoints/charts/instance.ts6
-rw-r--r--packages/backend/src/server/api/endpoints/charts/notes.ts6
-rw-r--r--packages/backend/src/server/api/endpoints/charts/user/drive.ts6
-rw-r--r--packages/backend/src/server/api/endpoints/charts/user/following.ts85
-rw-r--r--packages/backend/src/server/api/endpoints/charts/user/notes.ts6
-rw-r--r--packages/backend/src/server/api/endpoints/charts/user/pv.ts6
-rw-r--r--packages/backend/src/server/api/endpoints/charts/user/reactions.ts6
-rw-r--r--packages/backend/src/server/api/endpoints/charts/users.ts6
-rw-r--r--packages/backend/src/server/api/endpoints/clips/notes.ts3
-rw-r--r--packages/backend/src/server/api/endpoints/drive/files/attached-notes.ts18
-rw-r--r--packages/backend/src/server/api/endpoints/drive/files/create.ts7
-rw-r--r--packages/backend/src/server/api/endpoints/fetch-rss.ts213
-rw-r--r--packages/backend/src/server/api/endpoints/following/delete.ts9
-rw-r--r--packages/backend/src/server/api/endpoints/following/invalidate.ts9
-rw-r--r--packages/backend/src/server/api/endpoints/following/update-all.ts4
-rw-r--r--packages/backend/src/server/api/endpoints/following/update.ts9
-rw-r--r--packages/backend/src/server/api/endpoints/gallery/posts/create.ts2
-rw-r--r--packages/backend/src/server/api/endpoints/gallery/posts/update.ts2
-rw-r--r--packages/backend/src/server/api/endpoints/i/2fa/remove-key.ts2
-rw-r--r--packages/backend/src/server/api/endpoints/i/move.ts4
-rw-r--r--packages/backend/src/server/api/endpoints/i/notifications-grouped.ts87
-rw-r--r--packages/backend/src/server/api/endpoints/i/registry/get.ts4
-rw-r--r--packages/backend/src/server/api/endpoints/i/update.ts19
-rw-r--r--packages/backend/src/server/api/endpoints/notes.ts23
-rw-r--r--packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts69
-rw-r--r--packages/backend/src/server/api/endpoints/notes/children.ts28
-rw-r--r--packages/backend/src/server/api/endpoints/notes/create.ts2
-rw-r--r--packages/backend/src/server/api/endpoints/notes/edit.ts2
-rw-r--r--packages/backend/src/server/api/endpoints/notes/following.ts31
-rw-r--r--packages/backend/src/server/api/endpoints/notes/global-timeline.ts34
-rw-r--r--packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts114
-rw-r--r--packages/backend/src/server/api/endpoints/notes/local-timeline.ts63
-rw-r--r--packages/backend/src/server/api/endpoints/notes/mentions.ts72
-rw-r--r--packages/backend/src/server/api/endpoints/notes/polls/recommendation.ts94
-rw-r--r--packages/backend/src/server/api/endpoints/notes/renotes.ts14
-rw-r--r--packages/backend/src/server/api/endpoints/notes/replies.ts11
-rw-r--r--packages/backend/src/server/api/endpoints/notes/search-by-tag.ts34
-rw-r--r--packages/backend/src/server/api/endpoints/notes/timeline.ts124
-rw-r--r--packages/backend/src/server/api/endpoints/notes/translate.ts15
-rw-r--r--packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts103
-rw-r--r--packages/backend/src/server/api/endpoints/roles/notes.ts11
-rw-r--r--packages/backend/src/server/api/endpoints/sw/register.ts2
-rw-r--r--packages/backend/src/server/api/endpoints/sw/unregister.ts2
-rw-r--r--packages/backend/src/server/api/endpoints/sw/update-registration.ts2
-rw-r--r--packages/backend/src/server/api/endpoints/users/followers.ts9
-rw-r--r--packages/backend/src/server/api/endpoints/users/following.ts9
-rw-r--r--packages/backend/src/server/api/endpoints/users/notes.ts28
-rw-r--r--packages/backend/src/server/api/endpoints/users/reactions.ts7
-rw-r--r--packages/backend/src/server/api/endpoints/users/recommendation.ts1
-rw-r--r--packages/backend/src/server/api/endpoints/users/show.ts3
-rw-r--r--packages/backend/src/server/api/mastodon/MastodonApiServerService.ts7
-rw-r--r--packages/backend/src/server/api/mastodon/MastodonConverters.ts8
-rw-r--r--packages/backend/src/server/api/mastodon/MastodonDataService.ts81
-rw-r--r--packages/backend/src/server/api/mastodon/endpoints/status.ts24
-rw-r--r--packages/backend/src/server/api/stream/Connection.ts2
-rw-r--r--packages/backend/src/server/api/stream/channel.ts29
-rw-r--r--packages/backend/src/server/api/stream/channels/bubble-timeline.ts39
-rw-r--r--packages/backend/src/server/api/stream/channels/global-timeline.ts28
-rw-r--r--packages/backend/src/server/api/stream/channels/home-timeline.ts22
-rw-r--r--packages/backend/src/server/api/stream/channels/hybrid-timeline.ts20
-rw-r--r--packages/backend/src/server/api/stream/channels/local-timeline.ts31
-rw-r--r--packages/backend/src/server/api/stream/channels/main.ts8
-rw-r--r--packages/backend/src/server/api/stream/channels/role-timeline.ts22
-rw-r--r--packages/backend/src/server/api/stream/channels/user-list.ts33
-rw-r--r--packages/backend/src/server/web/FeedService.ts2
-rw-r--r--packages/backend/src/server/web/UrlPreviewService.ts96
89 files changed, 1258 insertions, 934 deletions
diff --git a/packages/backend/src/server/ActivityPubServerService.ts b/packages/backend/src/server/ActivityPubServerService.ts
index 41beadb56d..27d25d2152 100644
--- a/packages/backend/src/server/ActivityPubServerService.ts
+++ b/packages/backend/src/server/ActivityPubServerService.ts
@@ -33,7 +33,7 @@ import type Logger from '@/logger.js';
import { LoggerService } from '@/core/LoggerService.js';
import { bindThis } from '@/decorators.js';
import { IActivity, IAnnounce, ICreate } from '@/core/activitypub/type.js';
-import { isQuote, isRenote } from '@/misc/is-renote.js';
+import { isPureRenote, isQuote, isRenote } from '@/misc/is-renote.js';
import * as Acct from '@/misc/acct.js';
import { CacheService } from '@/core/CacheService.js';
import type { FastifyInstance, FastifyRequest, FastifyReply, FastifyPluginOptions, FastifyBodyParser } from 'fastify';
@@ -571,7 +571,7 @@ export class ActivityPubServerService {
const pinnedNotes = (await Promise.all(pinings.map(pining =>
this.notesRepository.findOneByOrFail({ id: pining.noteId }))))
- .filter(note => !note.localOnly && ['public', 'home'].includes(note.visibility));
+ .filter(note => !note.localOnly && ['public', 'home'].includes(note.visibility) && !isPureRenote(note));
const renderedNotes = await Promise.all(pinnedNotes.map(note => this.apRendererService.renderNote(note, user)));
@@ -791,6 +791,10 @@ export class ActivityPubServerService {
reply.header('Access-Control-Allow-Origin', '*');
reply.header('Access-Control-Expose-Headers', 'Vary');
+ // Tell crawlers not to index AP endpoints.
+ // https://developers.google.com/search/docs/crawling-indexing/block-indexing
+ reply.header('X-Robots-Tag', 'noindex');
+
/* tell any caching proxy that they should not cache these
responses: we wouldn't want the proxy to return a 403 to
someone presenting a valid signature, or return a cached
@@ -838,6 +842,11 @@ export class ActivityPubServerService {
return;
}
+ // Boosts don't federate directly - they should only be referenced as an activity
+ if (isPureRenote(note)) {
+ return 404;
+ }
+
this.setResponseType(request, reply);
const author = await this.usersRepository.findOneByOrFail({ id: note.userId });
diff --git a/packages/backend/src/server/FileServerService.ts b/packages/backend/src/server/FileServerService.ts
index 4ef5539cff..0910c0d36b 100644
--- a/packages/backend/src/server/FileServerService.ts
+++ b/packages/backend/src/server/FileServerService.ts
@@ -32,6 +32,7 @@ import { getIpHash } from '@/misc/get-ip-hash.js';
import { AuthenticateService } from '@/server/api/AuthenticateService.js';
import { SkRateLimiterService } from '@/server/SkRateLimiterService.js';
import { Keyed, RateLimit, sendRateLimitHeaders } from '@/misc/rate-limit-utils.js';
+import { renderInlineError } from '@/misc/render-inline-error.js';
import type { FastifyInstance, FastifyRequest, FastifyReply, FastifyPluginOptions } from 'fastify';
const _filename = fileURLToPath(import.meta.url);
@@ -69,6 +70,10 @@ export class FileServerService {
fastify.addHook('onRequest', (request, reply, done) => {
reply.header('Content-Security-Policy', 'default-src \'none\'; img-src \'self\'; media-src \'self\'; style-src \'unsafe-inline\'');
reply.header('Access-Control-Allow-Origin', '*');
+
+ // Tell crawlers not to index files endpoints.
+ // https://developers.google.com/search/docs/crawling-indexing/block-indexing
+ reply.header('X-Robots-Tag', 'noindex');
done();
});
@@ -120,7 +125,7 @@ export class FileServerService {
@bindThis
private async errorHandler(request: FastifyRequest<{ Params?: { [x: string]: any }; Querystring?: { [x: string]: any }; }>, reply: FastifyReply, err?: any) {
- this.logger.error(`${err}`);
+ this.logger.error(`Unhandled error in file server: ${renderInlineError(err)}`);
reply.header('Cache-Control', 'max-age=300');
@@ -353,7 +358,7 @@ export class FileServerService {
if (!request.headers['user-agent']) {
throw new StatusError('User-Agent is required', 400, 'User-Agent is required');
} else if (request.headers['user-agent'].toLowerCase().indexOf('misskey/') !== -1) {
- throw new StatusError('Refusing to proxy a request from another proxy', 403, 'Proxy is recursive');
+ throw new StatusError(`Refusing to proxy recursive request to ${url} (from user-agent ${request.headers['user-agent']})`, 403, 'Proxy is recursive');
}
// Create temp file
@@ -383,7 +388,7 @@ export class FileServerService {
) {
if (!isConvertibleImage) {
// 画像でないなら404でお茶を濁す
- throw new StatusError('Unexpected mime', 404);
+ throw new StatusError(`Unexpected non-convertible mime: ${file.mime}`, 404, 'Unexpected mime');
}
}
@@ -447,7 +452,7 @@ export class FileServerService {
} else if (file.mime === 'image/svg+xml') {
image = this.imageProcessingService.convertToWebpStream(file.path, 2048, 2048);
} else if (!file.mime.startsWith('image/') || !FILE_TYPE_BROWSERSAFE.includes(file.mime)) {
- throw new StatusError('Rejected type', 403, 'Rejected type');
+ throw new StatusError(`Blocked mime type: ${file.mime}`, 403, 'Blocked mime type');
}
if (!image) {
@@ -521,7 +526,7 @@ export class FileServerService {
> {
if (url.startsWith(`${this.config.url}/files/`)) {
const key = url.replace(`${this.config.url}/files/`, '').split('/').shift();
- if (!key) throw new StatusError('Invalid File Key', 400, 'Invalid File Key');
+ if (!key) throw new StatusError(`Invalid file URL ${url}`, 400, 'Invalid file url');
return await this.getFileFromKey(key);
}
diff --git a/packages/backend/src/server/ServerService.ts b/packages/backend/src/server/ServerService.ts
index 2d20aa1222..77b4519570 100644
--- a/packages/backend/src/server/ServerService.ts
+++ b/packages/backend/src/server/ServerService.ts
@@ -21,6 +21,7 @@ import { genIdenticon } from '@/misc/gen-identicon.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { LoggerService } from '@/core/LoggerService.js';
import { bindThis } from '@/decorators.js';
+import { renderInlineError } from '@/misc/render-inline-error.js';
import { ActivityPubServerService } from './ActivityPubServerService.js';
import { NodeinfoServerService } from './NodeinfoServerService.js';
import { ApiServerService } from './api/ApiServerService.js';
@@ -277,7 +278,7 @@ export class ServerService implements OnApplicationShutdown {
this.logger.error(`Port ${this.config.port} is already in use by another process.`);
break;
default:
- this.logger.error(err);
+ this.logger.error(`Unhandled error in server: ${renderInlineError(err)}`);
break;
}
diff --git a/packages/backend/src/server/SkRateLimiterService.ts b/packages/backend/src/server/SkRateLimiterService.ts
index 8978318045..35e87b0fe8 100644
--- a/packages/backend/src/server/SkRateLimiterService.ts
+++ b/packages/backend/src/server/SkRateLimiterService.ts
@@ -389,7 +389,7 @@ function createLimitKey(limit: ParsedLimit, actor: string, value: string): strin
return `rl_${actor}_${limit.key}_${value}`;
}
-class ConflictError extends Error {}
+export class ConflictError extends Error {}
interface LimitCounter {
timestamp: number;
diff --git a/packages/backend/src/server/api/ApiCallService.ts b/packages/backend/src/server/api/ApiCallService.ts
index 0d2dafd556..66d968224a 100644
--- a/packages/backend/src/server/api/ApiCallService.ts
+++ b/packages/backend/src/server/api/ApiCallService.ts
@@ -20,12 +20,14 @@ import { RoleService } from '@/core/RoleService.js';
import type { Config } from '@/config.js';
import { sendRateLimitHeaders } from '@/misc/rate-limit-utils.js';
import { SkRateLimiterService } from '@/server/SkRateLimiterService.js';
+import { renderInlineError } from '@/misc/render-inline-error.js';
import { ApiError } from './error.js';
import { ApiLoggerService } from './ApiLoggerService.js';
import { AuthenticateService, AuthenticationError } from './AuthenticateService.js';
import type { FastifyRequest, FastifyReply } from 'fastify';
import type { OnApplicationShutdown } from '@nestjs/common';
import type { IEndpointMeta, IEndpoint } from './endpoints.js';
+import { renderFullError } from '@/misc/render-full-error.js';
const accessDenied = {
message: 'Access denied.',
@@ -100,26 +102,26 @@ export class ApiCallService implements OnApplicationShutdown {
throw err;
} else {
const errId = randomUUID();
- this.logger.error(`Internal error occurred in ${ep.name}: ${err.message}`, {
- ep: ep.name,
- ps: data,
- e: {
- message: err.message,
- code: err.name,
- stack: err.stack,
- id: errId,
- },
+ const fullError = renderFullError(err);
+ const message = typeof(fullError) === 'string'
+ ? `Internal error id=${errId} occurred in ${ep.name}: ${fullError}`
+ : `Internal error id=${errId} occurred in ${ep.name}:`;
+ const data = typeof(fullError) === 'object'
+ ? { e: fullError }
+ : {};
+ this.logger.error(message, {
+ user: userId ?? '<unauthenticated>',
+ ...data,
});
if (this.config.sentryForBackend) {
- Sentry.captureMessage(`Internal error occurred in ${ep.name}: ${err.message}`, {
+ Sentry.captureMessage(`Internal error occurred in ${ep.name}: ${renderInlineError(err)}`, {
level: 'error',
user: {
id: userId,
},
extra: {
ep: ep.name,
- ps: data,
e: {
message: err.message,
code: err.name,
@@ -146,6 +148,10 @@ export class ApiCallService implements OnApplicationShutdown {
request: FastifyRequest<{ Body: Record<string, unknown> | undefined, Querystring: Record<string, unknown> }>,
reply: FastifyReply,
): void {
+ // Tell crawlers not to index API endpoints.
+ // https://developers.google.com/search/docs/crawling-indexing/block-indexing
+ reply.header('X-Robots-Tag', 'noindex');
+
const body = request.method === 'GET'
? request.query
: request.body;
@@ -344,14 +350,14 @@ export class ApiCallService implements OnApplicationShutdown {
}
if (ep.meta.requireCredential || ep.meta.requireModerator || ep.meta.requireAdmin) {
- if (user == null) {
+ if (user == null && ep.meta.requireCredential !== 'optional') {
throw new ApiError({
message: 'Credential required.',
code: 'CREDENTIAL_REQUIRED',
id: '1384574d-a912-4b81-8601-c7b1c4085df1',
httpStatusCode: 401,
});
- } else if (user!.isSuspended) {
+ } else if (user?.isSuspended) {
throw new ApiError({
message: 'Your account has been suspended.',
code: 'YOUR_ACCOUNT_SUSPENDED',
@@ -372,8 +378,8 @@ export class ApiCallService implements OnApplicationShutdown {
}
}
- if ((ep.meta.requireModerator || ep.meta.requireAdmin) && (this.meta.rootUserId !== user!.id)) {
- const myRoles = await this.roleService.getUserRoles(user!.id);
+ if ((ep.meta.requireModerator || ep.meta.requireAdmin) && (this.meta.rootUserId !== user?.id)) {
+ const myRoles = user ? await this.roleService.getUserRoles(user) : [];
if (ep.meta.requireModerator && !myRoles.some(r => r.isModerator || r.isAdministrator)) {
throw new ApiError({
message: 'You are not assigned to a moderator role.',
@@ -392,9 +398,9 @@ export class ApiCallService implements OnApplicationShutdown {
}
}
- if (ep.meta.requiredRolePolicy != null && (this.meta.rootUserId !== user!.id)) {
- const myRoles = await this.roleService.getUserRoles(user!.id);
- const policies = await this.roleService.getUserPolicies(user!.id);
+ if (ep.meta.requiredRolePolicy != null && (this.meta.rootUserId !== user?.id)) {
+ const myRoles = user ? await this.roleService.getUserRoles(user) : [];
+ const policies = await this.roleService.getUserPolicies(user ?? null);
if (!policies[ep.meta.requiredRolePolicy] && !myRoles.some(r => r.isAdministrator)) {
throw new ApiError({
message: 'You are not assigned to a required role.',
@@ -418,7 +424,7 @@ export class ApiCallService implements OnApplicationShutdown {
// Cast non JSON input
if ((ep.meta.requireFile || request.method === 'GET') && ep.params.properties) {
for (const k of Object.keys(ep.params.properties)) {
- const param = ep.params.properties![k];
+ const param = ep.params.properties[k];
if (['boolean', 'number', 'integer'].includes(param.type ?? '') && typeof data[k] === 'string') {
try {
data[k] = JSON.parse(data[k]);
diff --git a/packages/backend/src/server/api/GetterService.ts b/packages/backend/src/server/api/GetterService.ts
index 419017aaf4..f2850e6258 100644
--- a/packages/backend/src/server/api/GetterService.ts
+++ b/packages/backend/src/server/api/GetterService.ts
@@ -36,7 +36,7 @@ export class GetterService {
const note = await this.notesRepository.findOneBy({ id: noteId });
if (note == null) {
- throw new IdentifiableError('9725d0ce-ba28-4dde-95a7-2cbb2c15de24', 'No such note.');
+ throw new IdentifiableError('9725d0ce-ba28-4dde-95a7-2cbb2c15de24', `Note ${noteId} does not exist`);
}
return note;
@@ -47,7 +47,7 @@ export class GetterService {
const note = await this.notesRepository.findOne({ where: { id: noteId }, relations: ['user'] });
if (note == null) {
- throw new IdentifiableError('9725d0ce-ba28-4dde-95a7-2cbb2c15de24', 'No such note.');
+ throw new IdentifiableError('9725d0ce-ba28-4dde-95a7-2cbb2c15de24', `Note ${noteId} does not exist`);
}
return note;
@@ -59,7 +59,7 @@ export class GetterService {
@bindThis
public async getEdits(noteId: MiNote['id']) {
const edits = await this.noteEditRepository.findBy({ noteId: noteId }).catch(() => {
- throw new IdentifiableError('9725d0ce-ba28-4dde-95a7-2cbb2c15de24', 'No such note.');
+ throw new IdentifiableError('9725d0ce-ba28-4dde-95a7-2cbb2c15de24', `Note ${noteId} does not exist`);
});
return edits;
@@ -73,7 +73,7 @@ export class GetterService {
const user = await this.usersRepository.findOneBy({ id: userId });
if (user == null) {
- throw new IdentifiableError('15348ddd-432d-49c2-8a5a-8069753becff', 'No such user.');
+ throw new IdentifiableError('15348ddd-432d-49c2-8a5a-8069753becff', `User ${userId} does not exist`);
}
return user as MiLocalUser | MiRemoteUser;
diff --git a/packages/backend/src/server/api/SigninApiService.ts b/packages/backend/src/server/api/SigninApiService.ts
index 7f371ea309..a53fec88d0 100644
--- a/packages/backend/src/server/api/SigninApiService.ts
+++ b/packages/backend/src/server/api/SigninApiService.ts
@@ -205,37 +205,37 @@ export class SigninApiService {
if (process.env.NODE_ENV !== 'test') {
if (this.meta.enableHcaptcha && this.meta.hcaptchaSecretKey) {
await this.captchaService.verifyHcaptcha(this.meta.hcaptchaSecretKey, body['hcaptcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableMcaptcha && this.meta.mcaptchaSecretKey && this.meta.mcaptchaSitekey && this.meta.mcaptchaInstanceUrl) {
await this.captchaService.verifyMcaptcha(this.meta.mcaptchaSecretKey, this.meta.mcaptchaSitekey, this.meta.mcaptchaInstanceUrl, body['m-captcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableFC && this.meta.fcSecretKey) {
await this.captchaService.verifyFriendlyCaptcha(this.meta.fcSecretKey, body['frc-captcha-solution']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableRecaptcha && this.meta.recaptchaSecretKey) {
await this.captchaService.verifyRecaptcha(this.meta.recaptchaSecretKey, body['g-recaptcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableTurnstile && this.meta.turnstileSecretKey) {
await this.captchaService.verifyTurnstile(this.meta.turnstileSecretKey, body['turnstile-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableTestcaptcha) {
await this.captchaService.verifyTestcaptcha(body['testcaptcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
}
diff --git a/packages/backend/src/server/api/SigninWithPasskeyApiService.ts b/packages/backend/src/server/api/SigninWithPasskeyApiService.ts
index f84f50523b..38886f8876 100644
--- a/packages/backend/src/server/api/SigninWithPasskeyApiService.ts
+++ b/packages/backend/src/server/api/SigninWithPasskeyApiService.ts
@@ -128,7 +128,7 @@ export class SigninWithPasskeyApiService {
try {
authorizedUserId = await this.webAuthnService.verifySignInWithPasskeyAuthentication(context, credential);
} catch (err) {
- this.logger.warn(`Passkey challenge Verify error! : ${err}`);
+ this.logger.warn('Passkey challenge verify error:', err as Error);
const errorId = (err as IdentifiableError).id;
return error(403, {
id: errorId,
diff --git a/packages/backend/src/server/api/SignupApiService.ts b/packages/backend/src/server/api/SignupApiService.ts
index cb71047a24..81e3a5b706 100644
--- a/packages/backend/src/server/api/SignupApiService.ts
+++ b/packages/backend/src/server/api/SignupApiService.ts
@@ -83,37 +83,37 @@ export class SignupApiService {
if (process.env.NODE_ENV !== 'test') {
if (this.meta.enableHcaptcha && this.meta.hcaptchaSecretKey) {
await this.captchaService.verifyHcaptcha(this.meta.hcaptchaSecretKey, body['hcaptcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableMcaptcha && this.meta.mcaptchaSecretKey && this.meta.mcaptchaSitekey && this.meta.mcaptchaInstanceUrl) {
await this.captchaService.verifyMcaptcha(this.meta.mcaptchaSecretKey, this.meta.mcaptchaSitekey, this.meta.mcaptchaInstanceUrl, body['m-captcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableRecaptcha && this.meta.recaptchaSecretKey) {
await this.captchaService.verifyRecaptcha(this.meta.recaptchaSecretKey, body['g-recaptcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableTurnstile && this.meta.turnstileSecretKey) {
await this.captchaService.verifyTurnstile(this.meta.turnstileSecretKey, body['turnstile-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableFC && this.meta.fcSecretKey) {
await this.captchaService.verifyFriendlyCaptcha(this.meta.fcSecretKey, body['frc-captcha-solution']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
if (this.meta.enableTestcaptcha) {
await this.captchaService.verifyTestcaptcha(body['testcaptcha-response']).catch(err => {
- throw new FastifyReplyError(400, err);
+ throw new FastifyReplyError(400, String(err), err);
});
}
}
@@ -287,7 +287,7 @@ export class SignupApiService {
token: secret,
};
} catch (err) {
- throw new FastifyReplyError(400, typeof err === 'string' ? err : (err as Error).toString());
+ throw new FastifyReplyError(400, String(err), err);
}
}
}
@@ -356,7 +356,7 @@ export class SignupApiService {
return this.signinService.signin(request, reply, account as MiLocalUser);
} catch (err) {
- throw new FastifyReplyError(400, typeof err === 'string' ? err : (err as Error).toString());
+ throw new FastifyReplyError(400, String(err), err);
}
}
}
diff --git a/packages/backend/src/server/api/endpoints.ts b/packages/backend/src/server/api/endpoints.ts
index 0ba041c536..c7d884cce1 100644
--- a/packages/backend/src/server/api/endpoints.ts
+++ b/packages/backend/src/server/api/endpoints.ts
@@ -92,7 +92,7 @@ export type IEndpointMeta = (Omit<IEndpointMetaBase, 'requireCrential' | 'requir
}) | (Omit<IEndpointMetaBase, 'secure'> & {
secure: true,
}) | (Omit<IEndpointMetaBase, 'requireCredential' | 'kind'> & {
- requireCredential: true,
+ requireCredential: true | 'optional',
kind: (typeof permissions)[number],
}) | (Omit<IEndpointMetaBase, 'requireModerator' | 'kind'> & {
requireModerator: true,
diff --git a/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts b/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts
index 0dbfaae054..b8200c09aa 100644
--- a/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts
+++ b/packages/backend/src/server/api/endpoints/admin/abuse-user-reports.ts
@@ -69,6 +69,11 @@ export const meta = {
nullable: false, optional: false,
ref: 'UserDetailedNotMe',
},
+ targetInstance: {
+ type: 'object',
+ nullable: true, optional: false,
+ ref: 'FederationInstance',
+ },
assignee: {
type: 'object',
nullable: true, optional: false,
@@ -115,7 +120,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private queryService: QueryService,
) {
super(meta, paramDef, async (ps, me) => {
- const query = this.queryService.makePaginationQuery(this.abuseUserReportsRepository.createQueryBuilder('report'), ps.sinceId, ps.untilId);
+ const query = this.queryService.makePaginationQuery(this.abuseUserReportsRepository.createQueryBuilder('report'), ps.sinceId, ps.untilId)
+ .leftJoinAndSelect('report.targetUser', 'targetUser')
+ .leftJoinAndSelect('targetUser.userProfile', 'targetUserProfile')
+ .leftJoinAndSelect('report.targetUserInstance', 'targetUserInstance')
+ .leftJoinAndSelect('report.reporter', 'reporter')
+ .leftJoinAndSelect('reporter.userProfile', 'reporterProfile')
+ .leftJoinAndSelect('report.assignee', 'assignee')
+ .leftJoinAndSelect('assignee.userProfile', 'assigneeProfile')
+ ;
switch (ps.state) {
case 'resolved': query.andWhere('report.resolved = TRUE'); break;
@@ -134,7 +147,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const reports = await query.limit(ps.limit).getMany();
- return await this.abuseUserReportEntityService.packMany(reports);
+ return await this.abuseUserReportEntityService.packMany(reports, me);
});
}
}
diff --git a/packages/backend/src/server/api/endpoints/admin/nsfw-user.ts b/packages/backend/src/server/api/endpoints/admin/nsfw-user.ts
index 194e793eda..f6c4f0b635 100644
--- a/packages/backend/src/server/api/endpoints/admin/nsfw-user.ts
+++ b/packages/backend/src/server/api/endpoints/admin/nsfw-user.ts
@@ -47,7 +47,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
alwaysMarkNsfw: true,
});
- await this.cacheService.userProfileCache.refresh(ps.userId);
+ await this.cacheService.userProfileCache.delete(ps.userId);
});
}
}
diff --git a/packages/backend/src/server/api/endpoints/admin/relays/add.ts b/packages/backend/src/server/api/endpoints/admin/relays/add.ts
index 129f69aca9..4644a069ee 100644
--- a/packages/backend/src/server/api/endpoints/admin/relays/add.ts
+++ b/packages/backend/src/server/api/endpoints/admin/relays/add.ts
@@ -68,11 +68,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private readonly moderationLogService: ModerationLogService,
) {
super(meta, paramDef, async (ps, me) => {
- try {
- if (new URL(ps.inbox).protocol !== 'https:') throw new Error('https only');
- } catch {
- throw new ApiError(meta.errors.invalidUrl);
- }
+ if (!URL.canParse(ps.inbox)) throw new ApiError(meta.errors.invalidUrl);
+ if (new URL(ps.inbox).protocol !== 'https:') throw new ApiError(meta.errors.invalidUrl);
await this.moderationLogService.log(me, 'addRelay', {
inbox: ps.inbox,
diff --git a/packages/backend/src/server/api/endpoints/admin/show-user.ts b/packages/backend/src/server/api/endpoints/admin/show-user.ts
index 1579719246..6f0081f1f7 100644
--- a/packages/backend/src/server/api/endpoints/admin/show-user.ts
+++ b/packages/backend/src/server/api/endpoints/admin/show-user.ts
@@ -122,6 +122,10 @@ export const meta = {
type: 'boolean',
optional: false, nullable: false,
},
+ isAdministrator: {
+ type: 'boolean',
+ optional: false, nullable: false,
+ },
isSystem: {
type: 'boolean',
optional: false, nullable: false,
@@ -217,6 +221,10 @@ export const meta = {
},
},
},
+ signupReason: {
+ type: 'string',
+ optional: false, nullable: true,
+ },
},
},
} as const;
@@ -257,6 +265,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
const isModerator = await this.roleService.isModerator(user);
+ const isAdministrator = await this.roleService.isAdministrator(user);
const isSilenced = user.isSilenced || !(await this.roleService.getUserPolicies(user.id)).canPublicNote;
const _me = await this.usersRepository.findOneByOrFail({ id: me.id });
@@ -289,6 +298,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
mutedInstances: profile.mutedInstances,
notificationRecieveConfig: profile.notificationRecieveConfig,
isModerator: isModerator,
+ isAdministrator: isAdministrator,
isSystem: isSystemAccount(user),
isSilenced: isSilenced,
isSuspended: user.isSuspended,
diff --git a/packages/backend/src/server/api/endpoints/admin/update-meta.ts b/packages/backend/src/server/api/endpoints/admin/update-meta.ts
index 7c3d485a0f..4970d28cfa 100644
--- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts
+++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts
@@ -778,9 +778,29 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const after = await this.metaService.fetch(true);
this.moderationLogService.log(me, 'updateServerSettings', {
- before,
- after,
+ before: sanitize(before),
+ after: sanitize(after),
});
});
}
}
+
+function sanitize(meta: Partial<MiMeta>): Partial<MiMeta> {
+ return {
+ ...meta,
+ hcaptchaSecretKey: '<redacted>',
+ mcaptchaSecretKey: '<redacted>',
+ recaptchaSecretKey: '<redacted>',
+ turnstileSecretKey: '<redacted>',
+ fcSecretKey: '<redacted>',
+ smtpPass: '<redacted>',
+ swPrivateKey: '<redacted>',
+ objectStorageAccessKey: '<redacted>',
+ objectStorageSecretKey: '<redacted>',
+ deeplAuthKey: '<redacted>',
+ libreTranslateKey: '<redacted>',
+ verifymailAuthKey: '<redacted>',
+ truemailAuthKey: '<redacted>',
+ };
+}
+
diff --git a/packages/backend/src/server/api/endpoints/antennas/notes.ts b/packages/backend/src/server/api/endpoints/antennas/notes.ts
index b90ba6aa0d..e975b9ad0f 100644
--- a/packages/backend/src/server/api/endpoints/antennas/notes.ts
+++ b/packages/backend/src/server/api/endpoints/antennas/notes.ts
@@ -14,6 +14,7 @@ import { IdService } from '@/core/IdService.js';
import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
import { GlobalEventService } from '@/core/GlobalEventService.js';
import { trackPromise } from '@/misc/promise-tracker.js';
+import ActiveUsersChart from '@/core/chart/charts/active-users.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -75,6 +76,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private queryService: QueryService,
private fanoutTimelineService: FanoutTimelineService,
private globalEventService: GlobalEventService,
+ private readonly activeUsersChart: ActiveUsersChart,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
@@ -106,7 +108,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
return [];
}
- const query = this.notesRepository.createQueryBuilder('note')
+ const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
+ ps.sinceId, ps.untilId)
.where('note.id IN (:...noteIds)', { noteIds: noteIds })
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
@@ -121,13 +124,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
const notes = await query.getMany();
- if (sinceId != null && untilId == null) {
- notes.sort((a, b) => a.id < b.id ? -1 : 1);
- } else {
- notes.sort((a, b) => a.id > b.id ? -1 : 1);
- }
+
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
return await this.noteEntityService.packMany(notes, me);
});
diff --git a/packages/backend/src/server/api/endpoints/ap/get.ts b/packages/backend/src/server/api/endpoints/ap/get.ts
index 14286bc23e..e3e68b50af 100644
--- a/packages/backend/src/server/api/endpoints/ap/get.ts
+++ b/packages/backend/src/server/api/endpoints/ap/get.ts
@@ -3,10 +3,17 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import { Injectable } from '@nestjs/common';
+import { Inject, Injectable } from '@nestjs/common';
import ms from 'ms';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { ApResolverService } from '@/core/activitypub/ApResolverService.js';
+import { isCollectionOrOrderedCollection, isOrderedCollection, isOrderedCollectionPage } from '@/core/activitypub/type.js';
+import { ApiError } from '@/server/api/error.js';
+import { CacheService } from '@/core/CacheService.js';
+import { UserEntityService } from '@/core/entities/UserEntityService.js';
+import { DI } from '@/di-symbols.js';
+import type { NotesRepository } from '@/models/_.js';
+import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
export const meta = {
tags: ['federation'],
@@ -21,6 +28,16 @@ export const meta = {
},
errors: {
+ noInputSpecified: {
+ message: 'uri, userId, or noteId must be specified.',
+ code: 'NO_INPUT_SPECIFIED',
+ id: 'b43ff2a7-e7a2-4237-ad7f-7b079563c09e',
+ },
+ multipleInputsSpecified: {
+ message: 'Only one of uri, userId, or noteId can be specified',
+ code: 'MULTIPLE_INPUTS_SPECIFIED',
+ id: 'f1aa27ed-8f20-44f3-a92a-fe073c8ca52b',
+ },
},
res: {
@@ -32,19 +49,57 @@ export const meta = {
export const paramDef = {
type: 'object',
properties: {
- uri: { type: 'string' },
+ uri: { type: 'string', nullable: true },
+ userId: { type: 'string', format: 'misskey:id', nullable: true },
+ noteId: { type: 'string', format: 'misskey:id', nullable: true },
+ expandCollectionItems: { type: 'boolean' },
+ expandCollectionLimit: { type: 'integer', nullable: true },
+ allowAnonymous: { type: 'boolean' },
},
- required: ['uri'],
} as const;
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
+ @Inject(DI.notesRepository)
+ private readonly notesRepository: NotesRepository,
+
+ private readonly cacheService: CacheService,
+ private readonly userEntityService: UserEntityService,
+ private readonly noteEntityService: NoteEntityService,
private apResolverService: ApResolverService,
) {
- super(meta, paramDef, async (ps, me) => {
+ super(meta, paramDef, async (ps) => {
+ if (ps.uri && ps.userId && ps.noteId) {
+ throw new ApiError(meta.errors.multipleInputsSpecified);
+ }
+
+ let uri: string;
+ if (ps.uri) {
+ uri = ps.uri;
+ } else if (ps.userId) {
+ const user = await this.cacheService.findUserById(ps.userId);
+ uri = user.uri ?? this.userEntityService.genLocalUserUri(ps.userId);
+ } else if (ps.noteId) {
+ const note = await this.notesRepository.findOneByOrFail({ id: ps.noteId });
+ uri = note.uri ?? this.noteEntityService.genLocalNoteUri(ps.noteId);
+ } else {
+ throw new ApiError(meta.errors.noInputSpecified);
+ }
+
const resolver = this.apResolverService.createResolver();
- const object = await resolver.resolve(ps.uri);
+ const object = await resolver.resolve(uri, ps.allowAnonymous ?? false);
+
+ if (ps.expandCollectionItems && isCollectionOrOrderedCollection(object)) {
+ const items = await resolver.resolveCollectionItems(object, ps.expandCollectionLimit, ps.allowAnonymous ?? false);
+
+ if (isOrderedCollection(object) || isOrderedCollectionPage(object)) {
+ object.orderedItems = items;
+ } else {
+ object.items = items;
+ }
+ }
+
return object;
});
}
diff --git a/packages/backend/src/server/api/endpoints/ap/show.ts b/packages/backend/src/server/api/endpoints/ap/show.ts
index d69850515c..d631b002cc 100644
--- a/packages/backend/src/server/api/endpoints/ap/show.ts
+++ b/packages/backend/src/server/api/endpoints/ap/show.ts
@@ -173,6 +173,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
case '09d79f9e-64f1-4316-9cfa-e75c4d091574':
throw new ApiError(meta.errors.federationNotAllowed);
case '72180409-793c-4973-868e-5a118eb5519b':
+ case 'd09dc850-b76c-4f45-875a-7389339d78b8':
+ case 'dc110060-a5f2-461d-808b-39c62702ca64':
+ case '45793ab7-7648-4886-b503-429f8a0d0f73':
+ case '4bf8f36b-4d33-4ac9-ad76-63fa11f354e9':
throw new ApiError(meta.errors.responseInvalid);
// resolveLocal
diff --git a/packages/backend/src/server/api/endpoints/channels/timeline.ts b/packages/backend/src/server/api/endpoints/channels/timeline.ts
index 6336f43e9f..fa5b948eca 100644
--- a/packages/backend/src/server/api/endpoints/channels/timeline.ts
+++ b/packages/backend/src/server/api/endpoints/channels/timeline.ts
@@ -96,7 +96,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchChannel);
}
- if (me) this.activeUsersChart.read(me);
+ if (me) {
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
+ }
if (!this.serverSettings.enableFanoutTimeline) {
return await this.noteEntityService.packMany(await this.getFromDb({ untilId, sinceId, limit: ps.limit, channelId: channel.id, withFiles: ps.withFiles, withRenotes: ps.withRenotes }, me), me);
@@ -135,29 +139,28 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
.leftJoinAndSelect('renote.user', 'renoteUser')
- .leftJoinAndSelect('note.channel', 'channel');
+ .leftJoinAndSelect('note.channel', 'channel')
+ .limit(ps.limit);
+ this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
if (me) {
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
}
- if (ps.withRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere(new Brackets(qb => {
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- }));
- }));
- }
-
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
}
+
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else if (me) {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ }
//#endregion
- return await query.limit(ps.limit).getMany();
+ return await query.getMany();
}
}
diff --git a/packages/backend/src/server/api/endpoints/charts/active-users.ts b/packages/backend/src/server/api/endpoints/charts/active-users.ts
index dcdcf46d0b..9f5064fe83 100644
--- a/packages/backend/src/server/api/endpoints/charts/active-users.ts
+++ b/packages/backend/src/server/api/endpoints/charts/active-users.ts
@@ -17,11 +17,11 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
- // Burst up to 100, then 2/sec average
+ // Burst up to 200, then 5/sec average
limit: {
type: 'bucket',
- size: 100,
- dripRate: 500,
+ size: 200,
+ dripRate: 200,
},
} as const;
diff --git a/packages/backend/src/server/api/endpoints/charts/ap-request.ts b/packages/backend/src/server/api/endpoints/charts/ap-request.ts
index 28c64229e7..68dc87546e 100644
--- a/packages/backend/src/server/api/endpoints/charts/ap-request.ts
+++ b/packages/backend/src/server/api/endpoints/charts/ap-request.ts
@@ -17,11 +17,11 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
- // Burst up to 100, then 2/sec average
+ // Burst up to 200, then 5/sec average
limit: {
type: 'bucket',
- size: 100,
- dripRate: 500,
+ size: 200,
+ dripRate: 200,
},
} as const;
diff --git a/packages/backend/src/server/api/endpoints/charts/drive.ts b/packages/backend/src/server/api/endpoints/charts/drive.ts
index 69ff3c5d7a..c0bfb00608 100644
--- a/packages/backend/src/server/api/endpoints/charts/drive.ts
+++ b/packages/backend/src/server/api/endpoints/charts/drive.ts
@@ -17,11 +17,11 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
- // Burst up to 100, then 2/sec average
+ // Burst up to 200, then 5/sec average
limit: {
type: 'bucket',
- size: 100,
- dripRate: 500,
+ size: 200,
+ dripRate: 200,
},
} as const;
diff --git a/packages/backend/src/server/api/endpoints/charts/federation.ts b/packages/backend/src/server/api/endpoints/charts/federation.ts
index bd870cc3d9..bd15700670 100644
--- a/packages/backend/src/server/api/endpoints/charts/federation.ts
+++ b/packages/backend/src/server/api/endpoints/charts/federation.ts
@@ -17,11 +17,11 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
- // Burst up to 100, then 2/sec average
+ // Burst up to 200, then 5/sec average
limit: {
type: 'bucket',
- size: 100,
- dripRate: 500,
+ size: 200,
+ dripRate: 200,
},
} as const;
diff --git a/packages/backend/src/server/api/endpoints/charts/instance.ts b/packages/backend/src/server/api/endpoints/charts/instance.ts
index 765bf024ee..e1053d05d8 100644
--- a/packages/backend/src/server/api/endpoints/charts/instance.ts
+++ b/packages/backend/src/server/api/endpoints/charts/instance.ts
@@ -17,11 +17,11 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
- // Burst up to 100, then 2/sec average
+ // Burst up to 200, then 5/sec average
limit: {
type: 'bucket',
- size: 100,
- dripRate: 500,
+ size: 200,
+ dripRate: 200,
},
} as const;
diff --git a/packages/backend/src/server/api/endpoints/charts/notes.ts b/packages/backend/src/server/api/endpoints/charts/notes.ts
index ecac436311..4550e2f17e 100644
--- a/packages/backend/src/server/api/endpoints/charts/notes.ts
+++ b/packages/backend/src/server/api/endpoints/charts/notes.ts
@@ -17,11 +17,11 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
- // Burst up to 100, then 2/sec average
+ // Burst up to 200, then 5/sec average
limit: {
type: 'bucket',
- size: 100,
- dripRate: 500,
+ size: 200,
+ dripRate: 200,
},
} as const;
diff --git a/packages/backend/src/server/api/endpoints/charts/user/drive.ts b/packages/backend/src/server/api/endpoints/charts/user/drive.ts
index 98ec40ade2..9475a8ab0a 100644
--- a/packages/backend/src/server/api/endpoints/charts/user/drive.ts
+++ b/packages/backend/src/server/api/endpoints/charts/user/drive.ts
@@ -17,11 +17,11 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
- // Burst up to 100, then 2/sec average
+ // Burst up to 200, then 5/sec average
limit: {
type: 'bucket',
- size: 100,
- dripRate: 500,
+ size: 200,
+ dripRate: 200,
},
} as const;
diff --git a/packages/backend/src/server/api/endpoints/charts/user/following.ts b/packages/backend/src/server/api/endpoints/charts/user/following.ts
index cb3dd36bab..1d333f9a9b 100644
--- a/packages/backend/src/server/api/endpoints/charts/user/following.ts
+++ b/packages/backend/src/server/api/endpoints/charts/user/following.ts
@@ -8,6 +8,8 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { getJsonSchema } from '@/core/chart/core.js';
import PerUserFollowingChart from '@/core/chart/charts/per-user-following.js';
import { schema } from '@/core/chart/charts/entities/per-user-following.js';
+import { CacheService } from '@/core/CacheService.js';
+import { RoleService } from '@/core/RoleService.js';
export const meta = {
tags: ['charts', 'users', 'following'],
@@ -17,11 +19,11 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
- // Burst up to 100, then 2/sec average
+ // Burst up to 200, then 5/sec average
limit: {
type: 'bucket',
- size: 100,
- dripRate: 500,
+ size: 200,
+ dripRate: 200,
},
} as const;
@@ -40,9 +42,84 @@ export const paramDef = {
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
private perUserFollowingChart: PerUserFollowingChart,
+ private readonly cacheService: CacheService,
+ private readonly roleService: RoleService,
) {
super(meta, paramDef, async (ps, me) => {
- return await this.perUserFollowingChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null, ps.userId);
+ const profile = await this.cacheService.userProfileCache.fetch(ps.userId);
+
+ // These are structured weird to avoid un-necessary calls to roleService and cacheService
+ const iAmModeratorOrTarget = me && (me.id === ps.userId || await this.roleService.isModerator(me));
+ const iAmFollowingOrTarget = me && (me.id === ps.userId || await this.cacheService.isFollowing(me.id, ps.userId));
+
+ const canViewFollowing =
+ profile.followingVisibility === 'public'
+ || iAmModeratorOrTarget
+ || (profile.followingVisibility === 'followers' && iAmFollowingOrTarget);
+
+ const canViewFollowers =
+ profile.followersVisibility === 'public'
+ || iAmModeratorOrTarget
+ || (profile.followersVisibility === 'followers' && iAmFollowingOrTarget);
+
+ if (!canViewFollowing && !canViewFollowers) {
+ return {
+ local: {
+ followings: {
+ total: [],
+ inc: [],
+ dec: [],
+ },
+ followers: {
+ total: [],
+ inc: [],
+ dec: [],
+ },
+ },
+ remote: {
+ followings: {
+ total: [],
+ inc: [],
+ dec: [],
+ },
+ followers: {
+ total: [],
+ inc: [],
+ dec: [],
+ },
+ },
+ };
+ }
+
+ const chart = await this.perUserFollowingChart.getChart(ps.span, ps.limit, ps.offset ? new Date(ps.offset) : null, ps.userId);
+
+ if (!canViewFollowers) {
+ chart.local.followers = {
+ total: [],
+ inc: [],
+ dec: [],
+ };
+ chart.remote.followers = {
+ total: [],
+ inc: [],
+ dec: [],
+ };
+ }
+
+ if (!canViewFollowing) {
+ chart.local.followings = {
+ total: [],
+ inc: [],
+ dec: [],
+ };
+ chart.remote.followings = {
+ total: [],
+ inc: [],
+ dec: [],
+ };
+ }
+
+ return chart;
});
}
}
diff --git a/packages/backend/src/server/api/endpoints/charts/user/notes.ts b/packages/backend/src/server/api/endpoints/charts/user/notes.ts
index 0742a21210..1d24dc2b77 100644
--- a/packages/backend/src/server/api/endpoints/charts/user/notes.ts
+++ b/packages/backend/src/server/api/endpoints/charts/user/notes.ts
@@ -17,11 +17,11 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
- // Burst up to 100, then 2/sec average
+ // Burst up to 200, then 5/sec average
limit: {
type: 'bucket',
- size: 100,
- dripRate: 500,
+ size: 200,
+ dripRate: 200,
},
} as const;
diff --git a/packages/backend/src/server/api/endpoints/charts/user/pv.ts b/packages/backend/src/server/api/endpoints/charts/user/pv.ts
index a220381b00..e0026d5ff3 100644
--- a/packages/backend/src/server/api/endpoints/charts/user/pv.ts
+++ b/packages/backend/src/server/api/endpoints/charts/user/pv.ts
@@ -17,11 +17,11 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
- // Burst up to 100, then 2/sec average
+ // Burst up to 200, then 5/sec average
limit: {
type: 'bucket',
- size: 100,
- dripRate: 500,
+ size: 200,
+ dripRate: 200,
},
} as const;
diff --git a/packages/backend/src/server/api/endpoints/charts/user/reactions.ts b/packages/backend/src/server/api/endpoints/charts/user/reactions.ts
index 3bb33622c2..c15056466f 100644
--- a/packages/backend/src/server/api/endpoints/charts/user/reactions.ts
+++ b/packages/backend/src/server/api/endpoints/charts/user/reactions.ts
@@ -17,11 +17,11 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
- // Burst up to 100, then 2/sec average
+ // Burst up to 200, then 5/sec average
limit: {
type: 'bucket',
- size: 100,
- dripRate: 500,
+ size: 200,
+ dripRate: 200,
},
} as const;
diff --git a/packages/backend/src/server/api/endpoints/charts/users.ts b/packages/backend/src/server/api/endpoints/charts/users.ts
index b5452517ab..0f96fae202 100644
--- a/packages/backend/src/server/api/endpoints/charts/users.ts
+++ b/packages/backend/src/server/api/endpoints/charts/users.ts
@@ -17,11 +17,11 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 60,
- // Burst up to 100, then 2/sec average
+ // Burst up to 200, then 5/sec average
limit: {
type: 'bucket',
- size: 100,
- dripRate: 500,
+ size: 200,
+ dripRate: 200,
},
} as const;
diff --git a/packages/backend/src/server/api/endpoints/clips/notes.ts b/packages/backend/src/server/api/endpoints/clips/notes.ts
index 59513e530d..4758dbad00 100644
--- a/packages/backend/src/server/api/endpoints/clips/notes.ts
+++ b/packages/backend/src/server/api/endpoints/clips/notes.ts
@@ -92,10 +92,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.andWhere('clipNote.clipId = :clipId', { clipId: clip.id });
this.queryService.generateBlockedHostQueryForNote(query);
+ this.queryService.generateVisibilityQuery(query, me);
if (me) {
- this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
}
const notes = await query
diff --git a/packages/backend/src/server/api/endpoints/drive/files/attached-notes.ts b/packages/backend/src/server/api/endpoints/drive/files/attached-notes.ts
index 32c2620915..9d70044db8 100644
--- a/packages/backend/src/server/api/endpoints/drive/files/attached-notes.ts
+++ b/packages/backend/src/server/api/endpoints/drive/files/attached-notes.ts
@@ -81,10 +81,22 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchFile);
}
- const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId);
- query.andWhere(':file <@ note.fileIds', { file: [file.id] });
+ const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
+ .andWhere(':file <@ note.fileIds', { file: [file.id] })
+ .innerJoinAndSelect('note.user', 'user')
+ .leftJoinAndSelect('note.reply', 'reply')
+ .leftJoinAndSelect('note.renote', 'renote')
+ .leftJoinAndSelect('reply.user', 'replyUser')
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .limit(ps.limit);
- const notes = await query.limit(ps.limit).getMany();
+ this.queryService.generateVisibilityQuery(query, me);
+ this.queryService.generateBlockedHostQueryForNote(query);
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
+ this.queryService.generateMutedUserQueryForNotes(query, me);
+ this.queryService.generateBlockedUserQueryForNotes(query, me);
+
+ const notes = await query.getMany();
return await this.noteEntityService.packMany(notes, me, {
detail: true,
diff --git a/packages/backend/src/server/api/endpoints/drive/files/create.ts b/packages/backend/src/server/api/endpoints/drive/files/create.ts
index f4c47d71bf..939eadad9b 100644
--- a/packages/backend/src/server/api/endpoints/drive/files/create.ts
+++ b/packages/backend/src/server/api/endpoints/drive/files/create.ts
@@ -10,6 +10,8 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
import { DriveService } from '@/core/DriveService.js';
import type { Config } from '@/config.js';
+import { ApiLoggerService } from '@/server/api/ApiLoggerService.js';
+import { renderInlineError } from '@/misc/render-inline-error.js';
import { ApiError } from '../../../error.js';
import { MiMeta } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
@@ -95,6 +97,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private driveFileEntityService: DriveFileEntityService,
private driveService: DriveService,
+ private readonly apiLoggerService: ApiLoggerService,
) {
super(meta, paramDef, async (ps, me, _, file, cleanup, ip, headers) => {
// Get 'name' parameter
@@ -130,14 +133,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
return await this.driveFileEntityService.pack(driveFile, { self: true });
} catch (err) {
if (err instanceof Error || typeof err === 'string') {
- console.error(err);
+ this.apiLoggerService.logger.error(`Error saving drive file: ${renderInlineError(err)}`);
}
if (err instanceof IdentifiableError) {
if (err.id === '282f77bf-5816-4f72-9264-aa14d8261a21') throw new ApiError(meta.errors.inappropriate);
if (err.id === 'c6244ed2-a39a-4e1c-bf93-f0fbd7764fa6') throw new ApiError(meta.errors.noFreeSpace);
if (err.id === 'f9e4e5f3-4df4-40b5-b400-f236945f7073') throw new ApiError(meta.errors.maxFileSizeExceeded);
}
- throw new ApiError();
+ throw err;
} finally {
cleanup!();
}
diff --git a/packages/backend/src/server/api/endpoints/fetch-rss.ts b/packages/backend/src/server/api/endpoints/fetch-rss.ts
index 03f35f16a5..11244b30f6 100644
--- a/packages/backend/src/server/api/endpoints/fetch-rss.ts
+++ b/packages/backend/src/server/api/endpoints/fetch-rss.ts
@@ -3,12 +3,12 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import Parser from 'rss-parser';
import { Injectable } from '@nestjs/common';
+import { parseFeed } from 'htmlparser2';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { HttpRequestService } from '@/core/HttpRequestService.js';
-
-const rssParser = new Parser();
+import { ApiError } from '../error.js';
+import type { FeedItem } from 'domutils';
export const meta = {
tags: ['meta'],
@@ -17,52 +17,32 @@ export const meta = {
allowGet: true,
cacheSec: 60 * 3,
+ errors: {
+ fetchFailed: {
+ id: '88f4356f-719d-4715-b4fc-703a10a812d2',
+ code: 'FETCH_FAILED',
+ message: 'Failed to fetch RSS feed',
+ },
+ },
+
res: {
type: 'object',
properties: {
- image: {
- type: 'object',
+ type: {
+ type: 'string',
+ optional: false,
+ },
+ id: {
+ type: 'string',
optional: true,
- properties: {
- link: {
- type: 'string',
- optional: true,
- },
- url: {
- type: 'string',
- optional: false,
- },
- title: {
- type: 'string',
- optional: true,
- },
- },
},
- paginationLinks: {
- type: 'object',
+ updated: {
+ type: 'string',
+ optional: true,
+ },
+ author: {
+ type: 'string',
optional: true,
- properties: {
- self: {
- type: 'string',
- optional: true,
- },
- first: {
- type: 'string',
- optional: true,
- },
- next: {
- type: 'string',
- optional: true,
- },
- last: {
- type: 'string',
- optional: true,
- },
- prev: {
- type: 'string',
- optional: true,
- },
- },
},
link: {
type: 'string',
@@ -94,113 +74,42 @@ export const meta = {
type: 'string',
optional: true,
},
- creator: {
- type: 'string',
- optional: true,
- },
- summary: {
- type: 'string',
- optional: true,
- },
- content: {
- type: 'string',
- optional: true,
- },
- isoDate: {
+ description: {
type: 'string',
optional: true,
},
- categories: {
+ media: {
type: 'array',
- optional: true,
+ optional: false,
items: {
- type: 'string',
- },
- },
- contentSnippet: {
- type: 'string',
- optional: true,
- },
- enclosure: {
- type: 'object',
- optional: true,
- properties: {
- url: {
- type: 'string',
- optional: false,
- },
- length: {
- type: 'number',
- optional: true,
- },
- type: {
- type: 'string',
- optional: true,
+ type: 'object',
+ properties: {
+ medium: {
+ type: 'string',
+ optional: true,
+ },
+ url: {
+ type: 'string',
+ optional: true,
+ },
+ type: {
+ type: 'string',
+ optional: true,
+ },
+ lang: {
+ type: 'string',
+ optional: true,
+ },
},
},
},
},
},
},
- feedUrl: {
- type: 'string',
- optional: true,
- },
description: {
type: 'string',
optional: true,
},
- itunes: {
- type: 'object',
- optional: true,
- additionalProperties: true,
- properties: {
- image: {
- type: 'string',
- optional: true,
- },
- owner: {
- type: 'object',
- optional: true,
- properties: {
- name: {
- type: 'string',
- optional: true,
- },
- email: {
- type: 'string',
- optional: true,
- },
- },
- },
- author: {
- type: 'string',
- optional: true,
- },
- summary: {
- type: 'string',
- optional: true,
- },
- explicit: {
- type: 'string',
- optional: true,
- },
- categories: {
- type: 'array',
- optional: true,
- items: {
- type: 'string',
- },
- },
- keywords: {
- type: 'array',
- optional: true,
- items: {
- type: 'string',
- },
- },
- },
- },
},
},
@@ -224,7 +133,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
constructor(
private httpRequestService: HttpRequestService,
) {
- super(meta, paramDef, async (ps, me) => {
+ super(meta, paramDef, async (ps) => {
const res = await this.httpRequestService.send(ps.url, {
method: 'GET',
headers: {
@@ -234,8 +143,38 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});
const text = await res.text();
+ const feed = parseFeed(text, {
+ xmlMode: true,
+ });
+
+ if (!feed) {
+ throw new ApiError(meta.errors.fetchFailed);
+ }
- return rssParser.parseString(text);
+ return {
+ type: feed.type,
+ id: feed.id,
+ title: feed.title,
+ link: feed.link,
+ description: feed.description,
+ updated: feed.updated?.toISOString(),
+ author: feed.author,
+ items: feed.items
+ .filter((item): item is FeedItem & { link: string, title: string } => !!item.link && !!item.title)
+ .map(item => ({
+ guid: item.id,
+ title: item.title,
+ link: item.link,
+ description: item.description,
+ pubDate: item.pubDate?.toISOString(),
+ media: item.media.map(media => ({
+ medium: media.medium,
+ url: media.url,
+ type: media.type,
+ lang: media.lang,
+ })),
+ })),
+ };
});
}
}
diff --git a/packages/backend/src/server/api/endpoints/following/delete.ts b/packages/backend/src/server/api/endpoints/following/delete.ts
index ba146b6703..442352a4d2 100644
--- a/packages/backend/src/server/api/endpoints/following/delete.ts
+++ b/packages/backend/src/server/api/endpoints/following/delete.ts
@@ -12,6 +12,7 @@ import { UserFollowingService } from '@/core/UserFollowingService.js';
import { DI } from '@/di-symbols.js';
import { GetterService } from '@/server/api/GetterService.js';
import { ApiError } from '../../error.js';
+import { CacheService } from '@/core/CacheService.js';
export const meta = {
tags: ['following', 'users'],
@@ -69,6 +70,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private userEntityService: UserEntityService,
private getterService: GetterService,
private userFollowingService: UserFollowingService,
+ private readonly cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
const follower = me;
@@ -85,12 +87,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});
// Check not following
- const exist = await this.followingsRepository.exists({
- where: {
- followerId: follower.id,
- followeeId: followee.id,
- },
- });
+ const exist = await this.cacheService.userFollowingsCache.fetch(follower.id).then(f => f.has(followee.id));
if (!exist) {
throw new ApiError(meta.errors.notFollowing);
diff --git a/packages/backend/src/server/api/endpoints/following/invalidate.ts b/packages/backend/src/server/api/endpoints/following/invalidate.ts
index b45d21410b..3809bf29b0 100644
--- a/packages/backend/src/server/api/endpoints/following/invalidate.ts
+++ b/packages/backend/src/server/api/endpoints/following/invalidate.ts
@@ -11,6 +11,7 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { UserFollowingService } from '@/core/UserFollowingService.js';
import { DI } from '@/di-symbols.js';
import { GetterService } from '@/server/api/GetterService.js';
+import { CacheService } from '@/core/CacheService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -69,6 +70,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private userEntityService: UserEntityService,
private getterService: GetterService,
private userFollowingService: UserFollowingService,
+ private readonly cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
const followee = me;
@@ -85,12 +87,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});
// Check not following
- const exist = await this.followingsRepository.findOneBy({
- followerId: follower.id,
- followeeId: followee.id,
- });
+ const isFollowing = await this.cacheService.userFollowingsCache.fetch(follower.id).then(f => f.has(followee.id));
- if (exist == null) {
+ if (!isFollowing) {
throw new ApiError(meta.errors.notFollowing);
}
diff --git a/packages/backend/src/server/api/endpoints/following/update-all.ts b/packages/backend/src/server/api/endpoints/following/update-all.ts
index c953feb393..a02b51cc79 100644
--- a/packages/backend/src/server/api/endpoints/following/update-all.ts
+++ b/packages/backend/src/server/api/endpoints/following/update-all.ts
@@ -12,6 +12,7 @@ import { UserFollowingService } from '@/core/UserFollowingService.js';
import { DI } from '@/di-symbols.js';
import { GetterService } from '@/server/api/GetterService.js';
import { ApiError } from '../../error.js';
+import { CacheService } from '@/core/CacheService.js';
export const meta = {
tags: ['following', 'users'],
@@ -39,6 +40,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
constructor(
@Inject(DI.followingsRepository)
private followingsRepository: FollowingsRepository,
+ private readonly cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
await this.followingsRepository.update({
@@ -48,6 +50,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withReplies: ps.withReplies != null ? ps.withReplies : undefined,
});
+ await this.cacheService.refreshFollowRelationsFor(me.id);
+
return;
});
}
diff --git a/packages/backend/src/server/api/endpoints/following/update.ts b/packages/backend/src/server/api/endpoints/following/update.ts
index d62cf210ed..f4ca21856f 100644
--- a/packages/backend/src/server/api/endpoints/following/update.ts
+++ b/packages/backend/src/server/api/endpoints/following/update.ts
@@ -11,6 +11,7 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { UserFollowingService } from '@/core/UserFollowingService.js';
import { DI } from '@/di-symbols.js';
import { GetterService } from '@/server/api/GetterService.js';
+import { CacheService } from '@/core/CacheService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -71,6 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private userEntityService: UserEntityService,
private getterService: GetterService,
private userFollowingService: UserFollowingService,
+ private readonly cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
const follower = me;
@@ -87,10 +89,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});
// Check not following
- const exist = await this.followingsRepository.findOneBy({
- followerId: follower.id,
- followeeId: followee.id,
- });
+ const exist = await this.cacheService.userFollowingsCache.fetch(follower.id).then(f => f.get(followee.id));
if (exist == null) {
throw new ApiError(meta.errors.notFollowing);
@@ -103,6 +102,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withReplies: ps.withReplies != null ? ps.withReplies : undefined,
});
+ await this.cacheService.refreshFollowRelationsFor(follower.id);
+
return await this.userEntityService.pack(follower.id, me);
});
}
diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/create.ts b/packages/backend/src/server/api/endpoints/gallery/posts/create.ts
index 504a9c789e..08abd7fed5 100644
--- a/packages/backend/src/server/api/endpoints/gallery/posts/create.ts
+++ b/packages/backend/src/server/api/endpoints/gallery/posts/create.ts
@@ -72,7 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
))).filter(x => x != null);
if (files.length === 0) {
- throw new Error();
+ throw new Error('no files specified');
}
const post = await this.galleryPostsRepository.insertOne(new MiGalleryPost({
diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/update.ts b/packages/backend/src/server/api/endpoints/gallery/posts/update.ts
index 5243ee9603..d0f9b56863 100644
--- a/packages/backend/src/server/api/endpoints/gallery/posts/update.ts
+++ b/packages/backend/src/server/api/endpoints/gallery/posts/update.ts
@@ -73,7 +73,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
))).filter(x => x != null);
if (files.length === 0) {
- throw new Error();
+ throw new Error('no files');
}
}
diff --git a/packages/backend/src/server/api/endpoints/i/2fa/remove-key.ts b/packages/backend/src/server/api/endpoints/i/2fa/remove-key.ts
index d4098458d7..931c8d69b0 100644
--- a/packages/backend/src/server/api/endpoints/i/2fa/remove-key.ts
+++ b/packages/backend/src/server/api/endpoints/i/2fa/remove-key.ts
@@ -70,7 +70,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
try {
await this.userAuthService.twoFactorAuthenticate(profile, token);
} catch (e) {
- throw new Error('authentication failed');
+ throw new Error('authentication failed', { cause: e });
}
}
diff --git a/packages/backend/src/server/api/endpoints/i/move.ts b/packages/backend/src/server/api/endpoints/i/move.ts
index 7852b5a2e1..e2a14b61af 100644
--- a/packages/backend/src/server/api/endpoints/i/move.ts
+++ b/packages/backend/src/server/api/endpoints/i/move.ts
@@ -17,7 +17,7 @@ import { ApiLoggerService } from '@/server/api/ApiLoggerService.js';
import { GetterService } from '@/server/api/GetterService.js';
import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
-
+import { renderInlineError } from '@/misc/render-inline-error.js';
import * as Acct from '@/misc/acct.js';
import { DI } from '@/di-symbols.js';
import { MiMeta } from '@/models/_.js';
@@ -105,7 +105,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const { username, host } = Acct.parse(ps.moveToAccount);
// retrieve the destination account
let moveTo = await this.remoteUserResolveService.resolveUser(username, host).catch((e) => {
- this.apiLoggerService.logger.warn(`failed to resolve remote user: ${e}`);
+ this.apiLoggerService.logger.warn(`failed to resolve remote user: ${renderInlineError(e)}`);
throw new ApiError(meta.errors.noSuchUser);
});
const destination = await this.getterService.getUser(moveTo.id) as MiLocalUser | MiRemoteUser;
diff --git a/packages/backend/src/server/api/endpoints/i/notifications-grouped.ts b/packages/backend/src/server/api/endpoints/i/notifications-grouped.ts
index b9c41b057d..444734070f 100644
--- a/packages/backend/src/server/api/endpoints/i/notifications-grouped.ts
+++ b/packages/backend/src/server/api/endpoints/i/notifications-grouped.ts
@@ -104,53 +104,88 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
// grouping
- let groupedNotifications = [notifications[0]] as MiGroupedNotification[];
- for (let i = 1; i < notifications.length; i++) {
+ const groupedNotifications : MiGroupedNotification[] = [];
+ // keep track of where reaction / renote notifications are, by note id
+ const reactionIdxByNoteId = new Map<string, number>();
+ const renoteIdxByNoteId = new Map<string, number>();
+
+ // group notifications by type+note; notice that we don't try to
+ // split groups if they span a long stretch of time, because
+ // it's probably overkill: if the user has very few
+ // notifications, there should be very little difference; if the
+ // user has many notifications, the pagination will break the
+ // groups
+
+ // scan `notifications` newest-to-oldest
+ for (let i = 0; i < notifications.length; i++) {
const notification = notifications[i];
- const prev = notifications[i - 1];
- let prevGroupedNotification = groupedNotifications.at(-1)!;
- if (prev.type === 'reaction' && notification.type === 'reaction' && prev.noteId === notification.noteId) {
- if (prevGroupedNotification.type !== 'reaction:grouped') {
- groupedNotifications[groupedNotifications.length - 1] = {
+ if (notification.type === 'reaction') {
+ const reactionIdx = reactionIdxByNoteId.get(notification.noteId);
+ if (reactionIdx === undefined) {
+ // first reaction to this note that we see, add it as-is
+ // and remember where we put it
+ groupedNotifications.push(notification);
+ reactionIdxByNoteId.set(notification.noteId, groupedNotifications.length - 1);
+ continue;
+ }
+
+ let prevReaction = groupedNotifications[reactionIdx] as FilterUnionByProperty<MiGroupedNotification, 'type', 'reaction:grouped'> | FilterUnionByProperty<MiGroupedNotification, 'type', 'reaction'>;
+ // if the previous reaction is not a group, make it into one
+ if (prevReaction.type !== 'reaction:grouped') {
+ prevReaction = groupedNotifications[reactionIdx] = {
type: 'reaction:grouped',
- id: '',
- createdAt: prev.createdAt,
- noteId: prev.noteId!,
+ id: prevReaction.id, // this will be the newest id in this group
+ createdAt: prevReaction.createdAt,
+ noteId: prevReaction.noteId!,
reactions: [{
- userId: prev.notifierId!,
- reaction: prev.reaction!,
+ userId: prevReaction.notifierId!,
+ reaction: prevReaction.reaction!,
}],
};
- prevGroupedNotification = groupedNotifications.at(-1)!;
}
- (prevGroupedNotification as FilterUnionByProperty<MiGroupedNotification, 'type', 'reaction:grouped'>).reactions.push({
+ // add this new reaction to the existing group
+ (prevReaction as FilterUnionByProperty<MiGroupedNotification, 'type', 'reaction:grouped'>).reactions.push({
userId: notification.notifierId!,
reaction: notification.reaction!,
});
- prevGroupedNotification.id = notification.id;
continue;
}
- if (prev.type === 'renote' && notification.type === 'renote' && prev.targetNoteId === notification.targetNoteId) {
- if (prevGroupedNotification.type !== 'renote:grouped') {
- groupedNotifications[groupedNotifications.length - 1] = {
+
+ if (notification.type === 'renote') {
+ const renoteIdx = renoteIdxByNoteId.get(notification.targetNoteId);
+ if (renoteIdx === undefined) {
+ // first renote of this note that we see, add it as-is and
+ // remember where we put it
+ groupedNotifications.push(notification);
+ renoteIdxByNoteId.set(notification.targetNoteId, groupedNotifications.length - 1);
+ continue;
+ }
+
+ let prevRenote = groupedNotifications[renoteIdx] as FilterUnionByProperty<MiGroupedNotification, 'type', 'renote:grouped'> | FilterUnionByProperty<MiGroupedNotification, 'type', 'renote'>;
+ // if the previous renote is not a group, make it into one
+ if (prevRenote.type !== 'renote:grouped') {
+ prevRenote = groupedNotifications[renoteIdx] = {
type: 'renote:grouped',
- id: '',
- createdAt: notification.createdAt,
- noteId: prev.noteId!,
- userIds: [prev.notifierId!],
+ id: prevRenote.id, // this will be the newest id in this group
+ createdAt: prevRenote.createdAt,
+ noteId: prevRenote.noteId!,
+ userIds: [prevRenote.notifierId!],
};
- prevGroupedNotification = groupedNotifications.at(-1)!;
}
- (prevGroupedNotification as FilterUnionByProperty<MiGroupedNotification, 'type', 'renote:grouped'>).userIds.push(notification.notifierId!);
- prevGroupedNotification.id = notification.id;
+ // add this new renote to the existing group
+ (prevRenote as FilterUnionByProperty<MiGroupedNotification, 'type', 'renote:grouped'>).userIds.push(notification.notifierId!);
continue;
}
+ // not a groupable notification, just push it
groupedNotifications.push(notification);
}
- groupedNotifications = groupedNotifications.slice(0, ps.limit);
+ // sort the groups by their id, newest first
+ groupedNotifications.sort(
+ (a, b) => a.id < b.id ? 1 : a.id > b.id ? -1 : 0,
+ );
return await this.notificationEntityService.packGroupedMany(groupedNotifications, me.id);
});
diff --git a/packages/backend/src/server/api/endpoints/i/registry/get.ts b/packages/backend/src/server/api/endpoints/i/registry/get.ts
index dff33016e0..d284334834 100644
--- a/packages/backend/src/server/api/endpoints/i/registry/get.ts
+++ b/packages/backend/src/server/api/endpoints/i/registry/get.ts
@@ -20,9 +20,7 @@ export const meta = {
},
},
- res: {
- type: 'object',
- },
+ res: {},
// 10 calls per 5 seconds
limit: {
diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts
index f35e395841..5767880531 100644
--- a/packages/backend/src/server/api/endpoints/i/update.ts
+++ b/packages/backend/src/server/api/endpoints/i/update.ts
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import * as mfm from '@transfem-org/sfm-js';
+import * as mfm from 'mfm-js';
import { Inject, Injectable } from '@nestjs/common';
import ms from 'ms';
import { extractCustomEmojisFromMfm } from '@/misc/extract-custom-emojis-from-mfm.js';
@@ -34,6 +34,7 @@ import { verifyFieldLinks } from '@/misc/verify-field-link.js';
import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
import { notificationRecieveConfig } from '@/models/json-schema/user.js';
import { userUnsignedFetchOptions } from '@/const.js';
+import { renderInlineError } from '@/misc/render-inline-error.js';
import { ApiLoggerService } from '../../ApiLoggerService.js';
import { ApiError } from '../../error.js';
@@ -263,6 +264,15 @@ export const paramDef = {
enum: userUnsignedFetchOptions,
nullable: false,
},
+ attributionDomains: {
+ type: 'array',
+ items: {
+ type: 'string',
+ minLength: 1,
+ maxLength: 128,
+ },
+ maxItems: 32,
+ },
},
} as const;
@@ -373,6 +383,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
if (ps.mutedInstances !== undefined) profileUpdates.mutedInstances = ps.mutedInstances;
if (ps.notificationRecieveConfig !== undefined) profileUpdates.notificationRecieveConfig = ps.notificationRecieveConfig;
+ if (ps.attributionDomains !== undefined) updates.attributionDomains = ps.attributionDomains;
if (typeof ps.isLocked === 'boolean') updates.isLocked = ps.isLocked;
if (typeof ps.isExplorable === 'boolean') updates.isExplorable = ps.isExplorable;
if (typeof ps.hideOnlineStatus === 'boolean') updates.hideOnlineStatus = ps.hideOnlineStatus;
@@ -506,7 +517,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Retrieve the old account
const knownAs = await this.remoteUserResolveService.resolveUser(username, host).catch((e) => {
- this.apiLoggerService.logger.warn(`failed to resolve dstination user: ${e}`);
+ this.apiLoggerService.logger.warn(`failed to resolve destination user: ${renderInlineError(e)}`);
throw new ApiError(meta.errors.noSuchUser);
});
if (knownAs.id === _user.id) throw new ApiError(meta.errors.forbiddenToSetYourself);
@@ -606,7 +617,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const updatedProfile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id });
- this.cacheService.userProfileCache.set(user.id, updatedProfile);
+ await this.cacheService.userProfileCache.set(user.id, updatedProfile);
// Publish meUpdated event
this.globalEventService.publishMainStream(user.id, 'meUpdated', iObj);
@@ -663,7 +674,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// these two methods need to be kept in sync with
// `ApRendererService.renderPerson`
private userNeedsPublishing(oldUser: MiLocalUser, newUser: Partial<MiUser>): boolean {
- const basicFields: (keyof MiUser)[] = ['avatarId', 'bannerId', 'backgroundId', 'isBot', 'username', 'name', 'isLocked', 'isExplorable', 'isCat', 'noindex', 'speakAsCat', 'movedToUri', 'alsoKnownAs', 'hideOnlineStatus', 'enableRss', 'requireSigninToViewContents', 'makeNotesFollowersOnlyBefore', 'makeNotesHiddenBefore'];
+ const basicFields: (keyof MiUser)[] = ['avatarId', 'bannerId', 'backgroundId', 'isBot', 'username', 'name', 'isLocked', 'isExplorable', 'isCat', 'noindex', 'speakAsCat', 'movedToUri', 'alsoKnownAs', 'hideOnlineStatus', 'enableRss', 'requireSigninToViewContents', 'makeNotesFollowersOnlyBefore', 'makeNotesHiddenBefore', 'attributionDomains'];
for (const field of basicFields) {
if ((field in newUser) && oldUser[field] !== newUser[field]) {
return true;
diff --git a/packages/backend/src/server/api/endpoints/notes.ts b/packages/backend/src/server/api/endpoints/notes.ts
index f6c37023e1..00a88521fd 100644
--- a/packages/backend/src/server/api/endpoints/notes.ts
+++ b/packages/backend/src/server/api/endpoints/notes.ts
@@ -64,7 +64,16 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .limit(ps.limit);
+
+ this.queryService.generateVisibilityQuery(query, me);
+ this.queryService.generateBlockedHostQueryForNote(query);
+ if (me) {
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
+ this.queryService.generateMutedUserQueryForNotes(query, me);
+ this.queryService.generateBlockedUserQueryForNotes(query, me);
+ }
if (ps.local) {
query.andWhere('note.userHost IS NULL');
@@ -75,7 +84,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
if (ps.renote !== undefined) {
- query.andWhere(ps.renote ? 'note.renoteId IS NOT NULL' : 'note.renoteId IS NULL');
+ if (ps.renote) {
+ this.queryService.andIsRenote(query, 'note');
+
+ if (me) {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ }
+ } else {
+ this.queryService.andIsNotRenote(query, 'note');
+ }
}
if (ps.withFiles !== undefined) {
@@ -91,7 +108,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// query.isBot = bot;
//}
- const notes = await query.limit(ps.limit).getMany();
+ const notes = await query.getMany();
return await this.noteEntityService.packMany(notes);
});
diff --git a/packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts b/packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts
index df030d90aa..84d6aa0dc7 100644
--- a/packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/bubble-timeline.ts
@@ -1,13 +1,16 @@
+/*
+ * SPDX-FileCopyrightText: Marie and other Sharkey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
import { Inject, Injectable } from '@nestjs/common';
-import { Brackets } from 'typeorm';
-import type { NotesRepository, MiMeta } from '@/models/_.js';
+import type { NotesRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { QueryService } from '@/core/QueryService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import ActiveUsersChart from '@/core/chart/charts/active-users.js';
import { DI } from '@/di-symbols.js';
import { RoleService } from '@/core/RoleService.js';
-import { CacheService } from '@/core/CacheService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -56,9 +59,6 @@ export const paramDef = {
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
- @Inject(DI.meta)
- private serverSettings: MiMeta,
-
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,
@@ -66,7 +66,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private queryService: QueryService,
private roleService: RoleService,
private activeUsersChart: ActiveUsersChart,
- private cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
const policies = await this.roleService.getUserPolicies(me ? me.id : null);
@@ -74,29 +73,34 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.btlDisabled);
}
- const [
- followings,
- ] = me ? await Promise.all([
- this.cacheService.userFollowingsCache.fetch(me.id),
- ]) : [undefined];
-
//#region Construct query
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
.andWhere('note.visibility = \'public\'')
.andWhere('note.channelId IS NULL')
- .andWhere('note.userHost IN (:...hosts)', { hosts: this.serverSettings.bubbleInstances })
+ .andWhere('note.userHost IS NOT NULL')
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .limit(ps.limit);
+
+ // This subquery mess teaches postgres how to use the right indexes.
+ // Using WHERE or ON conditions causes a fallback to full sequence scan, which times out.
+ // Important: don't use a query builder here or TypeORM will get confused and stop quoting column names! (known, unfixed bug apparently)
+ query
+ .leftJoin('(select "host" from "instance" where "isBubbled" = true)', 'bubbleInstance', '"bubbleInstance"."host" = "note"."userHost"')
+ .andWhere('"bubbleInstance" IS NOT NULL');
+ this.queryService
+ .leftJoinInstance(query, 'note.userInstance', 'userInstance', '"userInstance"."host" = "bubbleInstance"."host"');
- this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
- if (me) this.queryService.generateMutedUserQueryForNotes(query, me);
- if (me) this.queryService.generateBlockedUserQueryForNotes(query, me);
- if (me) this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
+ if (me) {
+ this.queryService.generateMutedUserQueryForNotes(query, me);
+ this.queryService.generateBlockedUserQueryForNotes(query, me);
+ }
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
@@ -104,29 +108,20 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (!ps.withBots) query.andWhere('user.isBot = FALSE');
- if (ps.withRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.where('note.renoteId IS NULL');
- qb.orWhere(new Brackets(qb => {
- qb.where('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- }));
- }));
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else if (me) {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
}
//#endregion
- let timeline = await query.limit(ps.limit).getMany();
-
- timeline = timeline.filter(note => {
- if (note.user?.isSilenced && me && followings && note.userId !== me.id && !followings[note.userId]) return false;
- return true;
- });
+ const timeline = await query.getMany();
- process.nextTick(() => {
- if (me) {
+ if (me) {
+ process.nextTick(() => {
this.activeUsersChart.read(me);
- }
- });
+ });
+ }
return await this.noteEntityService.packMany(timeline, me);
});
diff --git a/packages/backend/src/server/api/endpoints/notes/children.ts b/packages/backend/src/server/api/endpoints/notes/children.ts
index 8f19d534d4..cf8b11ccb5 100644
--- a/packages/backend/src/server/api/endpoints/notes/children.ts
+++ b/packages/backend/src/server/api/endpoints/notes/children.ts
@@ -57,26 +57,22 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
.andWhere(new Brackets(qb => {
- qb
- .where('note.replyId = :noteId', { noteId: ps.noteId });
- if (ps.showQuotes) {
- qb.orWhere(new Brackets(qb => {
- qb
- .where('note.renoteId = :noteId', { noteId: ps.noteId })
- .andWhere(new Brackets(qb => {
- qb
- .where('note.text IS NOT NULL')
- .orWhere('note.fileIds != \'{}\'')
- .orWhere('note.hasPoll = TRUE');
- }));
- }));
- }
+ qb.orWhere('note.replyId = :noteId');
+
+ if (ps.showQuotes) {
+ qb.orWhere(new Brackets(qbb => this.queryService
+ .andIsQuote(qbb, 'note')
+ .andWhere('note.renoteId = :noteId'),
+ ));
+ }
}))
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .setParameters({ noteId: ps.noteId })
+ .limit(ps.limit);
this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
@@ -85,7 +81,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.queryService.generateBlockedUserQueryForNotes(query, me);
}
- const notes = await query.limit(ps.limit).getMany();
+ const notes = await query.getMany();
return await this.noteEntityService.packMany(notes, me);
});
diff --git a/packages/backend/src/server/api/endpoints/notes/create.ts b/packages/backend/src/server/api/endpoints/notes/create.ts
index 3dd90c3dca..461910543f 100644
--- a/packages/backend/src/server/api/endpoints/notes/create.ts
+++ b/packages/backend/src/server/api/endpoints/notes/create.ts
@@ -348,7 +348,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchReplyTarget);
} else if (isRenote(reply) && !isQuote(reply)) {
throw new ApiError(meta.errors.cannotReplyToPureRenote);
- } else if (!await this.noteEntityService.isVisibleForMe(reply, me.id)) {
+ } else if (!await this.noteEntityService.isVisibleForMe(reply, me.id, { me })) {
throw new ApiError(meta.errors.cannotReplyToInvisibleNote);
} else if (reply.visibility === 'specified' && ps.visibility !== 'specified') {
throw new ApiError(meta.errors.cannotReplyToSpecifiedVisibilityNoteWithExtendedVisibility);
diff --git a/packages/backend/src/server/api/endpoints/notes/edit.ts b/packages/backend/src/server/api/endpoints/notes/edit.ts
index 2c01b26584..bd70cb7835 100644
--- a/packages/backend/src/server/api/endpoints/notes/edit.ts
+++ b/packages/backend/src/server/api/endpoints/notes/edit.ts
@@ -402,7 +402,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchReplyTarget);
} else if (isRenote(reply) && !isQuote(reply)) {
throw new ApiError(meta.errors.cannotReplyToPureRenote);
- } else if (!await this.noteEntityService.isVisibleForMe(reply, me.id)) {
+ } else if (!await this.noteEntityService.isVisibleForMe(reply, me.id, { me })) {
throw new ApiError(meta.errors.cannotReplyToInvisibleNote);
} else if (reply.visibility === 'specified' && ps.visibility !== 'specified') {
throw new ApiError(meta.errors.cannotReplyToSpecifiedVisibilityNoteWithExtendedVisibility);
diff --git a/packages/backend/src/server/api/endpoints/notes/following.ts b/packages/backend/src/server/api/endpoints/notes/following.ts
index 5f6ee9f903..0f8c61ab3e 100644
--- a/packages/backend/src/server/api/endpoints/notes/following.ts
+++ b/packages/backend/src/server/api/endpoints/notes/following.ts
@@ -4,7 +4,7 @@
*/
import { Inject, Injectable } from '@nestjs/common';
-import { ObjectLiteral, SelectQueryBuilder } from 'typeorm';
+import { IsNull, ObjectLiteral, SelectQueryBuilder } from 'typeorm';
import { SkLatestNote, MiFollowing } from '@/models/_.js';
import type { NotesRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
@@ -12,6 +12,7 @@ import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { DI } from '@/di-symbols.js';
import { QueryService } from '@/core/QueryService.js';
import { ApiError } from '@/server/api/error.js';
+import ActiveUsersChart from '@/core/chart/charts/active-users.js';
export const meta = {
tags: ['notes'],
@@ -76,8 +77,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,
- private noteEntityService: NoteEntityService,
- private queryService: QueryService,
+ private readonly noteEntityService: NoteEntityService,
+ private readonly queryService: QueryService,
+ private readonly activeUsersChart: ActiveUsersChart,
) {
super(meta, paramDef, async (ps, me) => {
if (ps.includeReplies && ps.filesOnly) throw new ApiError(meta.errors.bothWithRepliesAndWithFiles);
@@ -85,7 +87,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const query = this.notesRepository
.createQueryBuilder('note')
- .setParameter('me', me.id)
+ .setParameters({ meId: me.id })
// Limit to latest notes
.innerJoin(
@@ -130,7 +132,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
.leftJoinAndSelect('renote.user', 'renoteUser')
- .leftJoinAndSelect('note.channel', 'channel')
+
+ // Exclude channel notes
+ .andWhere({ channelId: IsNull() })
;
// Limit to files, if requested
@@ -145,23 +149,26 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Hide blocked users / instances
query.andWhere('"user"."isSuspended" = false');
- query.andWhere('("replyUser" IS NULL OR "replyUser"."isSuspended" = false)');
- query.andWhere('("renoteUser" IS NULL OR "renoteUser"."isSuspended" = false)');
this.queryService.generateBlockedHostQueryForNote(query);
- // Respect blocks and mutes
+ // Respect blocks, mutes, and privacy
+ this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
this.queryService.generateMutedUserQueryForNotes(query, me);
// Support pagination
this.queryService
.makePaginationQuery(query, ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
- .orderBy('note.id', 'DESC')
.take(ps.limit);
// Query and return the next page
const notes = await query.getMany();
- return await this.noteEntityService.packMany(notes, me);
+
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
+
+ return await this.noteEntityService.packMany(notes, me, { skipHide: true });
});
}
}
@@ -170,14 +177,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
* Limit to followers (they follow us)
*/
function addFollower<T extends SelectQueryBuilder<ObjectLiteral>>(query: T): T {
- return query.innerJoin(MiFollowing, 'follower', 'follower."followerId" = latest.user_id AND follower."followeeId" = :me');
+ return query.innerJoin(MiFollowing, 'follower', 'follower."followerId" = latest.user_id AND follower."followeeId" = :meId');
}
/**
* Limit to followees (we follow them)
*/
function addFollowee<T extends SelectQueryBuilder<ObjectLiteral>>(query: T): T {
- return query.innerJoin(MiFollowing, 'followee', 'followee."followerId" = :me AND followee."followeeId" = latest.user_id');
+ return query.innerJoin(MiFollowing, 'followee', 'followee."followerId" = :meId AND followee."followeeId" = latest.user_id');
}
/**
diff --git a/packages/backend/src/server/api/endpoints/notes/global-timeline.ts b/packages/backend/src/server/api/endpoints/notes/global-timeline.ts
index e82d9ca7af..506ea6fcda 100644
--- a/packages/backend/src/server/api/endpoints/notes/global-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/global-timeline.ts
@@ -12,7 +12,6 @@ import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import ActiveUsersChart from '@/core/chart/charts/active-users.js';
import { DI } from '@/di-symbols.js';
import { RoleService } from '@/core/RoleService.js';
-import { CacheService } from '@/core/CacheService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -68,7 +67,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private queryService: QueryService,
private roleService: RoleService,
private activeUsersChart: ActiveUsersChart,
- private cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
const policies = await this.roleService.getUserPolicies(me ? me.id : null);
@@ -76,8 +74,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.gtlDisabled);
}
- const followings = me ? await this.cacheService.userFollowingsCache.fetch(me.id) : {};
-
//#region Construct query
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
@@ -90,11 +86,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('renote.user', 'renoteUser');
this.queryService.generateBlockedHostQueryForNote(query);
-
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
if (me) {
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
- this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
}
if (ps.withFiles) {
@@ -103,29 +98,20 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (!ps.withBots) query.andWhere('user.isBot = FALSE');
- if (ps.withRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.where('note.renoteId IS NULL');
- qb.orWhere(new Brackets(qb => {
- qb.where('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- }));
- }));
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else if (me) {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
}
//#endregion
- let timeline = await query.limit(ps.limit).getMany();
+ const timeline = await query.limit(ps.limit).getMany();
- timeline = timeline.filter(note => {
- if (note.user?.isSilenced && me && followings && note.userId !== me.id && !followings[note.userId]) return false;
- return true;
- });
-
- process.nextTick(() => {
- if (me) {
+ if (me) {
+ process.nextTick(() => {
this.activeUsersChart.read(me);
- }
- });
+ });
+ }
return await this.noteEntityService.packMany(timeline, me);
});
diff --git a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
index 6461a2e33f..a5623d1f03 100644
--- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
@@ -66,9 +66,6 @@ export const paramDef = {
sinceDate: { type: 'integer' },
untilDate: { type: 'integer' },
allowPartial: { type: 'boolean', default: false }, // true is recommended but for compatibility false by default
- includeMyRenotes: { type: 'boolean', default: true },
- includeRenotedMyNotes: { type: 'boolean', default: true },
- includeLocalRenotes: { type: 'boolean', default: true },
withFiles: { type: 'boolean', default: false },
withRenotes: { type: 'boolean', default: true },
withReplies: { type: 'boolean', default: false },
@@ -114,12 +111,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId,
sinceId,
limit: ps.limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withReplies: ps.withReplies,
withBots: ps.withBots,
+ withRenotes: ps.withRenotes,
}, me);
process.nextTick(() => {
@@ -169,7 +164,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
excludeBots: !ps.withBots,
noteFilter: note => {
if (note.reply && note.reply.visibility === 'followers') {
- if (!Object.hasOwn(followings, note.reply.userId) && note.reply.userId !== me.id) return false;
+ if (!followings.has(note.reply.userId) && note.reply.userId !== me.id) return false;
}
return true;
@@ -178,12 +173,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId,
sinceId,
limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withReplies: ps.withReplies,
withBots: ps.withBots,
+ withRenotes: ps.withRenotes,
}, me),
});
@@ -199,103 +192,58 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId: string | null,
sinceId: string | null,
limit: number,
- includeMyRenotes: boolean,
- includeRenotedMyNotes: boolean,
- includeLocalRenotes: boolean,
withFiles: boolean,
withReplies: boolean,
withBots: boolean,
+ withRenotes: boolean,
}, me: MiLocalUser) {
- const followees = await this.userFollowingService.getFollowees(me.id);
- const followingChannels = await this.channelFollowingsRepository.find({
- where: {
- followerId: me.id,
- },
- });
-
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
- .andWhere(new Brackets(qb => {
- if (followees.length > 0) {
- const meOrFolloweeIds = [me.id, ...followees.map(f => f.followeeId)];
- qb.where('note.userId IN (:...meOrFolloweeIds)', { meOrFolloweeIds: meOrFolloweeIds });
- qb.orWhere('(note.visibility = \'public\') AND (note.userHost IS NULL)');
- } else {
- qb.where('note.userId = :meId', { meId: me.id });
- qb.orWhere('(note.visibility = \'public\') AND (note.userHost IS NULL)');
- }
- }))
+ // 1. by a user I follow, 2. a public local post, 3. my own post
+ .andWhere(new Brackets(qb => this.queryService
+ .orFollowingUser(qb, ':meId', 'note.userId')
+ .orWhere(new Brackets(qbb => qbb
+ .andWhere('note.visibility = \'public\'')
+ .andWhere('note.userHost IS NULL')))
+ .orWhere(':meId = note.userId')))
+ // 1. in a channel I follow, 2. not in a channel
+ .andWhere(new Brackets(qb => this.queryService
+ .orFollowingChannel(qb, ':meId', 'note.channelId')
+ .orWhere('note.channelId IS NULL')))
+ .setParameters({ meId: me.id })
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
-
- if (followingChannels.length > 0) {
- const followingChannelIds = followingChannels.map(x => x.followeeId);
-
- query.andWhere(new Brackets(qb => {
- qb.where('note.channelId IN (:...followingChannelIds)', { followingChannelIds });
- qb.orWhere('note.channelId IS NULL');
- }));
- } else {
- query.andWhere('note.channelId IS NULL');
- }
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .limit(ps.limit);
if (!ps.withReplies) {
- query.andWhere(new Brackets(qb => {
- qb
- .where('note.replyId IS NULL') // 返信ではない
- .orWhere(new Brackets(qb => {
- qb // 返信だけど投稿者自身への返信
- .where('note.replyId IS NOT NULL')
- .andWhere('note.replyUserId = note.userId');
- }));
- }));
+ query
+ // 1. Not a reply, 2. a self-reply
+ .andWhere(new Brackets(qb => qb
+ .orWhere('note.replyId IS NULL') // 返信ではない
+ .orWhere('note.replyUserId = note.userId')));
}
this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
- this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
-
- if (ps.includeMyRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.userId != :meId', { meId: me.id });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
-
- if (ps.includeRenotedMyNotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteUserId != :meId', { meId: me.id });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
-
- if (ps.includeLocalRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteUserHost IS NOT NULL');
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
}
if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ }
//#endregion
- return await query.limit(ps.limit).getMany();
+ return await query.getMany();
}
}
diff --git a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts
index f55853f3f3..41b1ee1086 100644
--- a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts
@@ -103,13 +103,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withFiles: ps.withFiles,
withReplies: ps.withReplies,
withBots: ps.withBots,
+ withRenotes: ps.withRenotes,
}, me);
- process.nextTick(() => {
- if (me) {
+ if (me) {
+ process.nextTick(() => {
this.activeUsersChart.read(me);
- }
- });
+ });
+ }
return await this.noteEntityService.packMany(timeline, me);
}
@@ -136,14 +137,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withFiles: ps.withFiles,
withReplies: ps.withReplies,
withBots: ps.withBots,
+ withRenotes: ps.withRenotes,
}, me),
});
- process.nextTick(() => {
- if (me) {
+ if (me) {
+ process.nextTick(() => {
this.activeUsersChart.read(me);
- }
- });
+ });
+ }
return timeline;
});
@@ -156,40 +158,47 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
withFiles: boolean,
withReplies: boolean,
withBots: boolean,
+ withRenotes: boolean,
}, me: MiLocalUser | null) {
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
ps.sinceId, ps.untilId)
- .andWhere('(note.visibility = \'public\') AND (note.userHost IS NULL) AND (note.channelId IS NULL)')
+ .andWhere('note.visibility = \'public\'')
+ .andWhere('note.channelId IS NULL')
+ .andWhere('note.userHost IS NULL')
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .limit(ps.limit);
+
+ if (!ps.withReplies) {
+ query
+ // 1. Not a reply, 2. a self-reply
+ .andWhere(new Brackets(qb => qb
+ .orWhere('note.replyId IS NULL') // 返信ではない
+ .orWhere('note.replyUserId = note.userId')));
+ }
- this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
- if (me) this.queryService.generateMutedUserQueryForNotes(query, me);
- if (me) this.queryService.generateBlockedUserQueryForNotes(query, me);
- if (me) this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
+ if (me) {
+ this.queryService.generateMutedUserQueryForNotes(query, me);
+ this.queryService.generateBlockedUserQueryForNotes(query, me);
+ }
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
}
- if (!ps.withReplies) {
- query.andWhere(new Brackets(qb => {
- qb
- .where('note.replyId IS NULL') // 返信ではない
- .orWhere(new Brackets(qb => {
- qb // 返信だけど投稿者自身への返信
- .where('note.replyId IS NOT NULL')
- .andWhere('note.replyUserId = note.userId');
- }));
- }));
- }
-
if (!ps.withBots) query.andWhere('user.isBot = FALSE');
- return await query.limit(ps.limit).getMany();
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else if (me) {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ }
+
+ return await query.getMany();
}
}
diff --git a/packages/backend/src/server/api/endpoints/notes/mentions.ts b/packages/backend/src/server/api/endpoints/notes/mentions.ts
index 269b57366c..f30e5a583f 100644
--- a/packages/backend/src/server/api/endpoints/notes/mentions.ts
+++ b/packages/backend/src/server/api/endpoints/notes/mentions.ts
@@ -6,10 +6,12 @@
import { Brackets } from 'typeorm';
import { Inject, Injectable } from '@nestjs/common';
import type { NotesRepository, FollowingsRepository } from '@/models/_.js';
+import { MiNote } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { QueryService } from '@/core/QueryService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { DI } from '@/di-symbols.js';
+import ActiveUsersChart from '@/core/chart/charts/active-users.js';
export const meta = {
tags: ['notes'],
@@ -57,42 +59,58 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private noteEntityService: NoteEntityService,
private queryService: QueryService,
+ private readonly activeUsersChart: ActiveUsersChart,
) {
super(meta, paramDef, async (ps, me) => {
- const followingQuery = this.followingsRepository.createQueryBuilder('following')
- .select('following.followeeId')
- .where('following.followerId = :followerId', { followerId: me.id });
-
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
- .andWhere(new Brackets(qb => {
- qb // このmeIdAsListパラメータはqueryServiceのgenerateVisibilityQueryでセットされる
- .where(':meIdAsList <@ note.mentions')
- .orWhere(':meIdAsList <@ note.visibleUserIds');
- }))
- // Avoid scanning primary key index
- .orderBy('CONCAT(note.id)', 'DESC')
+ .innerJoin(qb => {
+ qb
+ .select('note.id', 'id')
+ .from(qbb => qbb
+ .select('note.id', 'id')
+ .from(MiNote, 'note')
+ .where(new Brackets(qbbb => qbbb
+ // DM to me
+ .orWhere(':meIdAsList <@ note.visibleUserIds')
+ // Mentions me
+ .orWhere(':meIdAsList <@ note.mentions'),
+ ))
+ .setParameters({ meIdAsList: [me.id] })
+ , 'source')
+ .innerJoin(MiNote, 'note', 'note.id = source.id');
+
+ this.queryService.generateVisibilityQuery(qb, me);
+ this.queryService.generateBlockedHostQueryForNote(qb);
+ this.queryService.generateMutedUserQueryForNotes(qb, me);
+ this.queryService.generateMutedNoteThreadQuery(qb, me);
+ this.queryService.generateBlockedUserQueryForNotes(qb, me);
+ // A renote can't mention a user, so it will never appear here anyway.
+ //this.queryService.generateMutedUserRenotesQueryForNotes(qb, me);
+
+ if (ps.visibility) {
+ qb.andWhere('note.visibility = :visibility', { visibility: ps.visibility });
+ }
+
+ if (ps.following) {
+ this.queryService
+ .andFollowingUser(qb, ':meId', 'note.userId')
+ .setParameters({ meId: me.id });
+ }
+
+ return qb;
+ }, 'source', 'source.id = note.id')
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
-
- this.queryService.generateVisibilityQuery(query, me);
- this.queryService.generateBlockedHostQueryForNote(query);
- this.queryService.generateMutedUserQueryForNotes(query, me);
- this.queryService.generateMutedNoteThreadQuery(query, me);
- this.queryService.generateBlockedUserQueryForNotes(query, me);
-
- if (ps.visibility) {
- query.andWhere('note.visibility = :visibility', { visibility: ps.visibility });
- }
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .limit(ps.limit);
- if (ps.following) {
- query.andWhere(`((note.userId IN (${ followingQuery.getQuery() })) OR (note.userId = :meId))`, { meId: me.id });
- query.setParameters(followingQuery.getParameters());
- }
+ const mentions = await query.getMany();
- const mentions = await query.limit(ps.limit).getMany();
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
return await this.noteEntityService.packMany(mentions, me);
});
diff --git a/packages/backend/src/server/api/endpoints/notes/polls/recommendation.ts b/packages/backend/src/server/api/endpoints/notes/polls/recommendation.ts
index 33a9c281b3..6f96821a63 100644
--- a/packages/backend/src/server/api/endpoints/notes/polls/recommendation.ts
+++ b/packages/backend/src/server/api/endpoints/notes/polls/recommendation.ts
@@ -9,13 +9,13 @@ import type { NotesRepository, MutingsRepository, PollsRepository, PollVotesRepo
import { Endpoint } from '@/server/api/endpoint-base.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { DI } from '@/di-symbols.js';
+import { QueryService } from '@/core/QueryService.js';
+import { RoleService } from '@/core/RoleService.js';
+import { ApiError } from '@/server/api/error.js';
export const meta = {
tags: ['notes'],
- requireCredential: true,
- kind: 'read:account',
-
res: {
type: 'array',
optional: false, nullable: false,
@@ -26,10 +26,24 @@ export const meta = {
},
},
- // 2 calls per second
+ errors: {
+ ltlDisabled: {
+ message: 'Local timeline has been disabled.',
+ code: 'LTL_DISABLED',
+ id: '45a6eb02-7695-4393-b023-dd3be9aaaefd',
+ },
+ gtlDisabled: {
+ message: 'Global timeline has been disabled.',
+ code: 'GTL_DISABLED',
+ id: '0332fc13-6ab2-4427-ae80-a9fadffd1a6b',
+ },
+ },
+
+ // Up to 10 calls, then 2 per second
limit: {
- duration: 1000,
- max: 2,
+ type: 'bucket',
+ size: 10,
+ dripRate: 500,
},
} as const;
@@ -39,6 +53,8 @@ export const paramDef = {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
offset: { type: 'integer', default: 0 },
excludeChannels: { type: 'boolean', default: false },
+ local: { type: 'boolean', nullable: true, default: null },
+ expired: { type: 'boolean', default: false },
},
required: [],
} as const;
@@ -59,18 +75,54 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private mutingsRepository: MutingsRepository,
private noteEntityService: NoteEntityService,
+ private readonly queryService: QueryService,
+ private readonly roleService: RoleService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.pollsRepository.createQueryBuilder('poll')
- .where('poll.userHost IS NULL')
- .andWhere('poll.userId != :meId', { meId: me.id })
- .andWhere('poll.noteVisibility = \'public\'')
- .andWhere(new Brackets(qb => {
+ .innerJoinAndSelect('poll.note', 'note')
+ .innerJoinAndSelect('note.user', 'user')
+ .leftJoinAndSelect('note.renote', 'renote')
+ .leftJoinAndSelect('note.reply', 'reply')
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .leftJoinAndSelect('reply.user', 'replyUser')
+ .andWhere('user.isExplorable = TRUE')
+ ;
+
+ if (me) {
+ query.andWhere('poll.userId != :meId', { meId: me.id });
+ }
+
+ if (ps.expired) {
+ query.andWhere('poll.expiresAt IS NOT NULL');
+ query.andWhere('poll.expiresAt <= :expiresMax', {
+ expiresMax: new Date(),
+ });
+ query.andWhere('poll.expiresAt >= :expiresMin', {
+ expiresMin: new Date(Date.now() - (1000 * 60 * 60 * 24 * 7)),
+ });
+ } else {
+ query.andWhere(new Brackets(qb => {
qb
.where('poll.expiresAt IS NULL')
.orWhere('poll.expiresAt > :now', { now: new Date() });
}));
+ }
+
+ const policies = await this.roleService.getUserPolicies(me?.id ?? null);
+ if (ps.local != null) {
+ if (ps.local) {
+ if (!policies.ltlAvailable) throw new ApiError(meta.errors.ltlDisabled);
+ query.andWhere('poll.userHost IS NULL');
+ } else {
+ if (!policies.gtlAvailable) throw new ApiError(meta.errors.gtlDisabled);
+ query.andWhere('poll.userHost IS NOT NULL');
+ }
+ } else {
+ if (!policies.gtlAvailable) throw new ApiError(meta.errors.gtlDisabled);
+ }
+ /*
//#region exclude arleady voted polls
const votedQuery = this.pollVotesRepository.createQueryBuilder('vote')
.select('vote.noteId')
@@ -81,16 +133,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
query.setParameters(votedQuery.getParameters());
//#endregion
+ */
- //#region mute
- const mutingQuery = this.mutingsRepository.createQueryBuilder('muting')
- .select('muting.muteeId')
- .where('muting.muterId = :muterId', { muterId: me.id });
-
- query
- .andWhere(`poll.userId NOT IN (${ mutingQuery.getQuery() })`);
-
- query.setParameters(mutingQuery.getParameters());
+ //#region block/mute/vis
+ this.queryService.generateVisibilityQuery(query, me);
+ this.queryService.generateBlockedHostQueryForNote(query);
+ if (me) {
+ this.queryService.generateBlockedUserQueryForNotes(query, me);
+ this.queryService.generateMutedUserQueryForNotes(query, me);
+ }
//#endregion
//#region exclude channels
@@ -107,6 +158,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (polls.length === 0) return [];
+ /*
const notes = await this.notesRepository.find({
where: {
id: In(polls.map(poll => poll.noteId)),
@@ -115,6 +167,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
id: 'DESC',
},
});
+ */
+
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const notes = polls.map(poll => poll.note!);
return await this.noteEntityService.packMany(notes, me, {
detail: true,
diff --git a/packages/backend/src/server/api/endpoints/notes/renotes.ts b/packages/backend/src/server/api/endpoints/notes/renotes.ts
index 0f08cc9cf2..be7cb0320f 100644
--- a/packages/backend/src/server/api/endpoints/notes/renotes.ts
+++ b/packages/backend/src/server/api/endpoints/notes/renotes.ts
@@ -47,7 +47,7 @@ export const paramDef = {
type: 'object',
properties: {
noteId: { type: 'string', format: 'misskey:id' },
- userId: { type: "string", format: "misskey:id" },
+ userId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
@@ -81,19 +81,21 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('renote.user', 'renoteUser');
if (ps.userId) {
- query.andWhere("user.id = :userId", { userId: ps.userId });
+ query.andWhere('user.id = :userId', { userId: ps.userId });
}
if (ps.quote) {
- query.andWhere("note.text IS NOT NULL");
+ this.queryService.andIsQuote(query, 'note');
} else {
- query.andWhere("note.text IS NULL");
+ this.queryService.andIsRenote(query, 'note');
}
this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
- if (me) this.queryService.generateMutedUserQueryForNotes(query, me);
- if (me) this.queryService.generateBlockedUserQueryForNotes(query, me);
+ if (me) {
+ this.queryService.generateMutedUserQueryForNotes(query, me);
+ this.queryService.generateBlockedUserQueryForNotes(query, me);
+ }
const renotes = await query.limit(ps.limit).getMany();
diff --git a/packages/backend/src/server/api/endpoints/notes/replies.ts b/packages/backend/src/server/api/endpoints/notes/replies.ts
index 0882e19182..f79bfaa7df 100644
--- a/packages/backend/src/server/api/endpoints/notes/replies.ts
+++ b/packages/backend/src/server/api/endpoints/notes/replies.ts
@@ -59,14 +59,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .limit(ps.limit);
this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
- if (me) this.queryService.generateMutedUserQueryForNotes(query, me);
- if (me) this.queryService.generateBlockedUserQueryForNotes(query, me);
+ if (me) {
+ this.queryService.generateMutedUserQueryForNotes(query, me);
+ this.queryService.generateBlockedUserQueryForNotes(query, me);
+ }
- const timeline = await query.limit(ps.limit).getMany();
+ const timeline = await query.getMany();
return await this.noteEntityService.packMany(timeline, me);
});
diff --git a/packages/backend/src/server/api/endpoints/notes/search-by-tag.ts b/packages/backend/src/server/api/endpoints/notes/search-by-tag.ts
index 91874a8195..5064144d9c 100644
--- a/packages/backend/src/server/api/endpoints/notes/search-by-tag.ts
+++ b/packages/backend/src/server/api/endpoints/notes/search-by-tag.ts
@@ -12,8 +12,6 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { QueryService } from '@/core/QueryService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { DI } from '@/di-symbols.js';
-import { CacheService } from '@/core/CacheService.js';
-import { UtilityService } from '@/core/UtilityService.js';
export const meta = {
tags: ['notes', 'hashtags'],
@@ -82,26 +80,26 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private noteEntityService: NoteEntityService,
private queryService: QueryService,
- private cacheService: CacheService,
- private utilityService: UtilityService,
) {
super(meta, paramDef, async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
- .andWhere("note.visibility IN ('public', 'home')") // keep in sync with NoteCreateService call to `hashtagService.updateHashtags()`
+ .andWhere(new Brackets(qb => qb
+ .orWhere('note.visibility = \'public\'')
+ .orWhere('note.visibility = \'home\''))) // keep in sync with NoteCreateService call to `hashtagService.updateHashtags()`
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .limit(ps.limit);
- if (!this.serverSettings.enableBotTrending) query.andWhere('user.isBot = FALSE');
-
- this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
if (me) this.queryService.generateMutedUserQueryForNotes(query, me);
if (me) this.queryService.generateBlockedUserQueryForNotes(query, me);
+ if (me) this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
- const followings = me ? await this.cacheService.userFollowingsCache.fetch(me.id) : {};
+ if (!this.serverSettings.enableBotTrending) query.andWhere('user.isBot = FALSE');
try {
if (ps.tag) {
@@ -134,9 +132,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (ps.renote != null) {
if (ps.renote) {
- query.andWhere('note.renoteId IS NOT NULL');
+ this.queryService.andIsRenote(query, 'note');
} else {
- query.andWhere('note.renoteId IS NULL');
+ this.queryService.andIsNotRenote(query, 'note');
}
}
@@ -153,17 +151,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
// Search notes
- let notes = await query.limit(ps.limit).getMany();
-
- notes = notes.filter(note => {
- if (note.user?.isSilenced && me && followings && note.userId !== me.id && !followings[note.userId]) return false;
- if (note.user?.isSuspended) return false;
- if (note.userHost) {
- if (!this.utilityService.isFederationAllowedHost(note.userHost)) return false;
- if (this.utilityService.isSilencedHost(this.serverSettings.silencedHosts, note.userHost)) return false;
- }
- return true;
- });
+ const notes = await query.getMany();
return await this.noteEntityService.packMany(notes, me);
});
diff --git a/packages/backend/src/server/api/endpoints/notes/timeline.ts b/packages/backend/src/server/api/endpoints/notes/timeline.ts
index a2dfa7fdac..44c539eaad 100644
--- a/packages/backend/src/server/api/endpoints/notes/timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/timeline.ts
@@ -49,9 +49,6 @@ export const paramDef = {
sinceDate: { type: 'integer' },
untilDate: { type: 'integer' },
allowPartial: { type: 'boolean', default: false }, // true is recommended but for compatibility false by default
- includeMyRenotes: { type: 'boolean', default: true },
- includeRenotedMyNotes: { type: 'boolean', default: true },
- includeLocalRenotes: { type: 'boolean', default: true },
withFiles: { type: 'boolean', default: false },
withRenotes: { type: 'boolean', default: true },
withBots: { type: 'boolean', default: true },
@@ -88,9 +85,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId,
sinceId,
limit: ps.limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
withBots: ps.withBots,
@@ -121,7 +115,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
excludePureRenotes: !ps.withRenotes,
noteFilter: note => {
if (note.reply && note.reply.visibility === 'followers') {
- if (!Object.hasOwn(followings, note.reply.userId) && note.reply.userId !== me.id) return false;
+ if (!followings.has(note.reply.userId) && note.reply.userId !== me.id) return false;
}
if (!ps.withBots && note.user?.isBot) return false;
@@ -131,9 +125,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId,
sinceId,
limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
withBots: ps.withBots,
@@ -148,113 +139,48 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});
}
- private async getFromDb(ps: { untilId: string | null; sinceId: string | null; limit: number; includeMyRenotes: boolean; includeRenotedMyNotes: boolean; includeLocalRenotes: boolean; withFiles: boolean; withRenotes: boolean; withBots: boolean; }, me: MiLocalUser) {
- const followees = await this.userFollowingService.getFollowees(me.id);
- const followingChannels = await this.channelFollowingsRepository.find({
- where: {
- followerId: me.id,
- },
- });
-
+ private async getFromDb(ps: { untilId: string | null; sinceId: string | null; limit: number; withFiles: boolean; withRenotes: boolean; withBots: boolean; }, me: MiLocalUser) {
//#region Construct query
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
+ // 1. in a channel I follow, 2. my own post, 3. by a user I follow
+ .andWhere(new Brackets(qb => this.queryService
+ .orFollowingChannel(qb, ':meId', 'note.channelId')
+ .orWhere(':meId = note.userId')
+ .orWhere(new Brackets(qb2 => this.queryService
+ .andFollowingUser(qb2, ':meId', 'note.userId')
+ .andWhere('note.channelId IS NULL'))),
+ ))
+ // 1. Not a reply, 2. a self-reply
+ .andWhere(new Brackets(qb => qb
+ .orWhere('note.replyId IS NULL') // 返信ではない
+ .orWhere('note.replyUserId = note.userId')))
+ .setParameters({ meId: me.id })
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
-
- if (followees.length > 0 && followingChannels.length > 0) {
- // ユーザー・チャンネルともにフォローあり
- const meOrFolloweeIds = [me.id, ...followees.map(f => f.followeeId)];
- const followingChannelIds = followingChannels.map(x => x.followeeId);
- query.andWhere(new Brackets(qb => {
- qb
- .where(new Brackets(qb2 => {
- qb2
- .where('note.userId IN (:...meOrFolloweeIds)', { meOrFolloweeIds: meOrFolloweeIds })
- .andWhere('note.channelId IS NULL');
- }))
- .orWhere('note.channelId IN (:...followingChannelIds)', { followingChannelIds });
- }));
- } else if (followees.length > 0) {
- // ユーザーフォローのみ(チャンネルフォローなし)
- const meOrFolloweeIds = [me.id, ...followees.map(f => f.followeeId)];
- query
- .andWhere('note.channelId IS NULL')
- .andWhere('note.userId IN (:...meOrFolloweeIds)', { meOrFolloweeIds: meOrFolloweeIds });
- } else if (followingChannels.length > 0) {
- // チャンネルフォローのみ(ユーザーフォローなし)
- const followingChannelIds = followingChannels.map(x => x.followeeId);
- query.andWhere(new Brackets(qb => {
- qb
- .where('note.channelId IN (:...followingChannelIds)', { followingChannelIds })
- .orWhere('note.userId = :meId', { meId: me.id });
- }));
- } else {
- // フォローなし
- query
- .andWhere('note.channelId IS NULL')
- .andWhere('note.userId = :meId', { meId: me.id });
- }
-
- query.andWhere(new Brackets(qb => {
- qb
- .where('note.replyId IS NULL') // 返信ではない
- .orWhere(new Brackets(qb => {
- qb // 返信だけど投稿者自身への返信
- .where('note.replyId IS NOT NULL')
- .andWhere('note.replyUserId = note.userId');
- }));
- }));
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .limit(ps.limit);
this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
- this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
-
- if (ps.includeMyRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.userId != :meId', { meId: me.id });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
-
- if (ps.includeRenotedMyNotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteUserId != :meId', { meId: me.id });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
-
- if (ps.includeLocalRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteUserHost IS NOT NULL');
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
if (ps.withFiles) {
query.andWhere('note.fileIds != \'{}\'');
}
- if (ps.withRenotes === false) {
- query.andWhere('note.renoteId IS NULL');
- }
-
if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ }
//#endregion
- return await query.limit(ps.limit).getMany();
+ return await query.getMany();
}
}
diff --git a/packages/backend/src/server/api/endpoints/notes/translate.ts b/packages/backend/src/server/api/endpoints/notes/translate.ts
index a97542c063..5ebd5ef362 100644
--- a/packages/backend/src/server/api/endpoints/notes/translate.ts
+++ b/packages/backend/src/server/api/endpoints/notes/translate.ts
@@ -20,11 +20,9 @@ import { ApiError } from '../../error.js';
export const meta = {
tags: ['notes'],
- // TODO allow unauthenticated if default template allows?
- // Maybe a value 'optional' that allows unauthenticated OR a token w/ appropriate role.
- // This will allow unauthenticated requests without leaking post data to restricted clients.
- requireCredential: true,
+ requireCredential: 'optional',
kind: 'read:account',
+ requiredRolePolicy: 'canUseTranslator',
res: {
type: 'object',
@@ -88,17 +86,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private readonly loggerService: ApiLoggerService,
) {
super(meta, paramDef, async (ps, me) => {
- const policies = await this.roleService.getUserPolicies(me.id);
- if (!policies.canUseTranslator) {
- throw new ApiError(meta.errors.unavailable);
- }
-
const note = await this.getterService.getNote(ps.noteId).catch(err => {
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
throw err;
});
- if (!(await this.noteEntityService.isVisibleForMe(note, me.id))) {
+ if (!(await this.noteEntityService.isVisibleForMe(note, me?.id ?? null, { me }))) {
throw new ApiError(meta.errors.cannotTranslateInvisibleNote);
}
@@ -140,7 +133,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (this.serverSettings.deeplAuthKey) params.append('auth_key', this.serverSettings.deeplAuthKey);
params.append('text', note.text);
params.append('target_lang', targetLang);
- const endpoint = deeplFreeInstance ?? this.serverSettings.deeplIsPro ? 'https://api.deepl.com/v2/translate' : 'https://api-free.deepl.com/v2/translate';
+ const endpoint = deeplFreeInstance ?? ( this.serverSettings.deeplIsPro ? 'https://api.deepl.com/v2/translate' : 'https://api-free.deepl.com/v2/translate' );
const res = await this.httpRequestService.send(endpoint, {
method: 'POST',
diff --git a/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts b/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts
index 60f18a09b0..0f038e5541 100644
--- a/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts
@@ -57,9 +57,6 @@ export const paramDef = {
sinceDate: { type: 'integer' },
untilDate: { type: 'integer' },
allowPartial: { type: 'boolean', default: false }, // true is recommended but for compatibility false by default
- includeMyRenotes: { type: 'boolean', default: true },
- includeRenotedMyNotes: { type: 'boolean', default: true },
- includeLocalRenotes: { type: 'boolean', default: true },
withRenotes: { type: 'boolean', default: true },
withFiles: {
type: 'boolean',
@@ -109,14 +106,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId,
sinceId,
limit: ps.limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
}, me);
- this.activeUsersChart.read(me);
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
return await this.noteEntityService.packMany(timeline, me);
}
@@ -135,15 +131,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId,
sinceId,
limit,
- includeMyRenotes: ps.includeMyRenotes,
- includeRenotedMyNotes: ps.includeRenotedMyNotes,
- includeLocalRenotes: ps.includeLocalRenotes,
withFiles: ps.withFiles,
withRenotes: ps.withRenotes,
}, me),
});
- this.activeUsersChart.read(me);
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
return timeline;
});
@@ -153,93 +148,49 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
untilId: string | null,
sinceId: string | null,
limit: number,
- includeMyRenotes: boolean,
- includeRenotedMyNotes: boolean,
- includeLocalRenotes: boolean,
withFiles: boolean,
withRenotes: boolean,
}, me: MiLocalUser) {
//#region Construct query
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
.innerJoin(this.userListMembershipsRepository.metadata.targetName, 'userListMemberships', 'userListMemberships.userId = note.userId')
+ .andWhere('userListMemberships.userListId = :userListId', { userListId: list.id })
+ .andWhere('note.channelId IS NULL') // チャンネルノートではない
+ .andWhere(new Brackets(qb => qb
+ // 返信ではない
+ .orWhere('note.replyId IS NULL')
+ // 返信だけど投稿者自身への返信
+ .orWhere('note.replyUserId = note.userId')
+ // 返信だけど自分宛ての返信
+ .orWhere('note.replyUserId = :meId')
+ // 返信だけどwithRepliesがtrueの場合
+ .orWhere('userListMemberships.withReplies = true'),
+ ))
+ .setParameters({ meId: me.id })
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
.leftJoinAndSelect('renote.user', 'renoteUser')
- .andWhere('userListMemberships.userListId = :userListId', { userListId: list.id })
- .andWhere('note.channelId IS NULL') // チャンネルノートではない
- .andWhere(new Brackets(qb => {
- qb
- .where('note.replyId IS NULL') // 返信ではない
- .orWhere(new Brackets(qb => {
- qb // 返信だけど投稿者自身への返信
- .where('note.replyId IS NOT NULL')
- .andWhere('note.replyUserId = note.userId');
- }))
- .orWhere(new Brackets(qb => {
- qb // 返信だけど自分宛ての返信
- .where('note.replyId IS NOT NULL')
- .andWhere('note.replyUserId = :meId', { meId: me.id });
- }))
- .orWhere(new Brackets(qb => {
- qb // 返信だけどwithRepliesがtrueの場合
- .where('note.replyId IS NOT NULL')
- .andWhere('userListMemberships.withReplies = true');
- }));
- }));
+ .limit(ps.limit);
this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
- this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
-
- if (ps.includeMyRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.userId != :meId', { meId: me.id });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
-
- if (ps.includeRenotedMyNotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteUserId != :meId', { meId: me.id });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
- }
- if (ps.includeLocalRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteUserHost IS NOT NULL');
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
+ if (ps.withFiles) {
+ query.andWhere('note.fileIds != \'{}\'');
}
- if (ps.withRenotes === false) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere(new Brackets(qb => {
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- }));
- }));
+ if (!ps.withRenotes) {
+ this.queryService.generateExcludedRenotesQueryForNotes(query);
+ } else {
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
}
- if (ps.withFiles) {
- query.andWhere('note.fileIds != \'{}\'');
- }
//#endregion
- return await query.limit(ps.limit).getMany();
+ return await query.getMany();
}
}
diff --git a/packages/backend/src/server/api/endpoints/roles/notes.ts b/packages/backend/src/server/api/endpoints/roles/notes.ts
index d1c2e4b686..741bd819ba 100644
--- a/packages/backend/src/server/api/endpoints/roles/notes.ts
+++ b/packages/backend/src/server/api/endpoints/roles/notes.ts
@@ -12,6 +12,7 @@ import { DI } from '@/di-symbols.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { IdService } from '@/core/IdService.js';
import { FanoutTimelineService } from '@/core/FanoutTimelineService.js';
+import ActiveUsersChart from '@/core/chart/charts/active-users.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -74,6 +75,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private noteEntityService: NoteEntityService,
private queryService: QueryService,
private fanoutTimelineService: FanoutTimelineService,
+ private readonly activeUsersChart: ActiveUsersChart,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
@@ -101,19 +103,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const query = this.notesRepository.createQueryBuilder('note')
.where('note.id IN (:...noteIds)', { noteIds: noteIds })
.andWhere('(note.visibility = \'public\')')
+ .orderBy('note.id', 'DESC')
.innerJoinAndSelect('note.user', 'user')
.leftJoinAndSelect('note.reply', 'reply')
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('reply.user', 'replyUser')
.leftJoinAndSelect('renote.user', 'renoteUser');
- this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
+ this.queryService.generateSilencedUserQueryForNotes(query, me);
this.queryService.generateMutedUserQueryForNotes(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
const notes = await query.getMany();
- notes.sort((a, b) => a.id > b.id ? -1 : 1);
+
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
return await this.noteEntityService.packMany(notes, me);
});
diff --git a/packages/backend/src/server/api/endpoints/sw/register.ts b/packages/backend/src/server/api/endpoints/sw/register.ts
index f447b5598b..2f72e6ce1d 100644
--- a/packages/backend/src/server/api/endpoints/sw/register.ts
+++ b/packages/backend/src/server/api/endpoints/sw/register.ts
@@ -104,7 +104,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
sendReadMessage: ps.sendReadMessage,
});
- this.pushNotificationService.refreshCache(me.id);
+ await this.pushNotificationService.refreshCache(me.id);
return {
state: 'subscribed' as const,
diff --git a/packages/backend/src/server/api/endpoints/sw/unregister.ts b/packages/backend/src/server/api/endpoints/sw/unregister.ts
index aa7e03dceb..f43a2cce28 100644
--- a/packages/backend/src/server/api/endpoints/sw/unregister.ts
+++ b/packages/backend/src/server/api/endpoints/sw/unregister.ts
@@ -46,7 +46,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});
if (me) {
- this.pushNotificationService.refreshCache(me.id);
+ await this.pushNotificationService.refreshCache(me.id);
}
});
}
diff --git a/packages/backend/src/server/api/endpoints/sw/update-registration.ts b/packages/backend/src/server/api/endpoints/sw/update-registration.ts
index 78b9323b7b..0cbed273e8 100644
--- a/packages/backend/src/server/api/endpoints/sw/update-registration.ts
+++ b/packages/backend/src/server/api/endpoints/sw/update-registration.ts
@@ -86,7 +86,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
sendReadMessage: swSubscription.sendReadMessage,
});
- this.pushNotificationService.refreshCache(me.id);
+ await this.pushNotificationService.refreshCache(me.id);
return {
userId: swSubscription.userId,
diff --git a/packages/backend/src/server/api/endpoints/users/followers.ts b/packages/backend/src/server/api/endpoints/users/followers.ts
index c1617e14e5..82ce282bfc 100644
--- a/packages/backend/src/server/api/endpoints/users/followers.ts
+++ b/packages/backend/src/server/api/endpoints/users/followers.ts
@@ -12,6 +12,7 @@ import { FollowingEntityService } from '@/core/entities/FollowingEntityService.j
import { UtilityService } from '@/core/UtilityService.js';
import { DI } from '@/di-symbols.js';
import { RoleService } from '@/core/RoleService.js';
+import { CacheService } from '@/core/CacheService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -89,6 +90,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private followingEntityService: FollowingEntityService,
private queryService: QueryService,
private roleService: RoleService,
+ private readonly cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
const user = await this.usersRepository.findOneBy(ps.userId != null
@@ -110,12 +112,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (me == null) {
throw new ApiError(meta.errors.forbidden);
} else if (me.id !== user.id) {
- const isFollowing = await this.followingsRepository.exists({
- where: {
- followeeId: user.id,
- followerId: me.id,
- },
- });
+ const isFollowing = await this.cacheService.userFollowingsCache.fetch(me.id).then(f => f.has(user.id));
if (!isFollowing) {
throw new ApiError(meta.errors.forbidden);
}
diff --git a/packages/backend/src/server/api/endpoints/users/following.ts b/packages/backend/src/server/api/endpoints/users/following.ts
index c292c6d6a3..80f0b0c484 100644
--- a/packages/backend/src/server/api/endpoints/users/following.ts
+++ b/packages/backend/src/server/api/endpoints/users/following.ts
@@ -13,6 +13,7 @@ import { FollowingEntityService } from '@/core/entities/FollowingEntityService.j
import { UtilityService } from '@/core/UtilityService.js';
import { DI } from '@/di-symbols.js';
import { RoleService } from '@/core/RoleService.js';
+import { CacheService } from '@/core/CacheService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -98,6 +99,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private followingEntityService: FollowingEntityService,
private queryService: QueryService,
private roleService: RoleService,
+ private readonly cacheService: CacheService,
) {
super(meta, paramDef, async (ps, me) => {
const user = await this.usersRepository.findOneBy(ps.userId != null
@@ -119,12 +121,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (me == null) {
throw new ApiError(meta.errors.forbidden);
} else if (me.id !== user.id) {
- const isFollowing = await this.followingsRepository.exists({
- where: {
- followeeId: user.id,
- followerId: me.id,
- },
- });
+ const isFollowing = await this.cacheService.userFollowingsCache.fetch(me.id).then(f => f.has(user.id));
if (!isFollowing) {
throw new ApiError(meta.errors.forbidden);
}
diff --git a/packages/backend/src/server/api/endpoints/users/notes.ts b/packages/backend/src/server/api/endpoints/users/notes.ts
index 965baa859a..4602709067 100644
--- a/packages/backend/src/server/api/endpoints/users/notes.ts
+++ b/packages/backend/src/server/api/endpoints/users/notes.ts
@@ -134,7 +134,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (ps.withReplies) redisTimelines.push(`userTimelineWithReplies:${ps.userId}`);
if (ps.withChannelNotes) redisTimelines.push(`userTimelineWithChannel:${ps.userId}`);
- const isFollowing = me && Object.hasOwn(await this.cacheService.userFollowingsCache.fetch(me.id), ps.userId);
+ const isFollowing = me && (await this.cacheService.userFollowingsCache.fetch(me.id)).has(ps.userId);
const timeline = await this.fanoutTimelineEndpointService.timeline({
untilId,
@@ -205,7 +205,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('note.renote', 'renote')
.leftJoinAndSelect('note.channel', 'channel')
.leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .limit(ps.limit);
if (ps.withChannelNotes) {
if (!isSelf) query.andWhere(new Brackets(qb => {
@@ -230,26 +231,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (!ps.withRenotes && !ps.withQuotes) {
query.andWhere('note.renoteId IS NULL');
} else if (!ps.withRenotes) {
- query.andWhere(new Brackets(qb => {
- qb.orWhere('note.userId != :userId', { userId: ps.userId });
- qb.orWhere('note.renoteId IS NULL');
- qb.orWhere('note.text IS NOT NULL');
- qb.orWhere('note.fileIds != \'{}\'');
- qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)');
- }));
+ this.queryService.andIsNotRenote(query, 'note');
} else if (!ps.withQuotes) {
- query.andWhere(`
- (
- note."renoteId" IS NULL
- OR (
- note.text IS NULL
- AND note.cw IS NULL
- AND note."replyId" IS NULL
- AND note."hasPoll" IS FALSE
- AND note."fileIds" = '{}'
- )
- )
- `);
+ this.queryService.andIsNotQuote(query, 'note');
}
if (!ps.withRepliesToOthers && !ps.withRepliesToSelf) {
@@ -268,6 +252,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
query.andWhere('"user"."isBot" = false');
}
- return await query.limit(ps.limit).getMany();
+ return await query.getMany();
}
}
diff --git a/packages/backend/src/server/api/endpoints/users/reactions.ts b/packages/backend/src/server/api/endpoints/users/reactions.ts
index 56f59bd285..553787ad58 100644
--- a/packages/backend/src/server/api/endpoints/users/reactions.ts
+++ b/packages/backend/src/server/api/endpoints/users/reactions.ts
@@ -105,10 +105,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const query = this.queryService.makePaginationQuery(this.noteReactionsRepository.createQueryBuilder('reaction'),
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
.andWhere('reaction.userId = :userId', { userId: ps.userId })
- .leftJoinAndSelect('reaction.note', 'note');
+ .innerJoinAndSelect('reaction.note', 'note');
this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateBlockedHostQueryForNote(query);
+ if (me) {
+ this.queryService.generateMutedUserQueryForNotes(query, me);
+ this.queryService.generateBlockedUserQueryForNotes(query, me);
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ }
const reactions = (await query
.limit(ps.limit)
diff --git a/packages/backend/src/server/api/endpoints/users/recommendation.ts b/packages/backend/src/server/api/endpoints/users/recommendation.ts
index 642d788459..52dd2197b2 100644
--- a/packages/backend/src/server/api/endpoints/users/recommendation.ts
+++ b/packages/backend/src/server/api/endpoints/users/recommendation.ts
@@ -71,6 +71,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.queryService.generateBlockQueryForUsers(query, me);
this.queryService.generateBlockedUserQueryForNotes(query, me);
+ // TODO optimization: replace with exists()
const followingQuery = this.followingsRepository.createQueryBuilder('following')
.select('following.followeeId')
.where('following.followerId = :followerId', { followerId: me.id });
diff --git a/packages/backend/src/server/api/endpoints/users/show.ts b/packages/backend/src/server/api/endpoints/users/show.ts
index 7b1c8adfb8..84eb661742 100644
--- a/packages/backend/src/server/api/endpoints/users/show.ts
+++ b/packages/backend/src/server/api/endpoints/users/show.ts
@@ -13,6 +13,7 @@ import { RemoteUserResolveService } from '@/core/RemoteUserResolveService.js';
import { DI } from '@/di-symbols.js';
import PerUserPvChart from '@/core/chart/charts/per-user-pv.js';
import { RoleService } from '@/core/RoleService.js';
+import { renderInlineError } from '@/misc/render-inline-error.js';
import { ApiError } from '../../error.js';
import { ApiLoggerService } from '../../ApiLoggerService.js';
import type { FindOptionsWhere } from 'typeorm';
@@ -131,7 +132,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Lookup user
if (typeof ps.host === 'string' && typeof ps.username === 'string') {
user = await this.remoteUserResolveService.resolveUser(ps.username, ps.host).catch(err => {
- this.apiLoggerService.logger.warn(`failed to resolve remote user: ${err}`);
+ this.apiLoggerService.logger.warn(`failed to resolve remote user: ${renderInlineError(err)}`);
throw new ApiError(meta.errors.failedToResolveRemoteUser);
});
} else {
diff --git a/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts b/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts
index 74fd9d7d59..072dacf708 100644
--- a/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts
+++ b/packages/backend/src/server/api/mastodon/MastodonApiServerService.ts
@@ -71,6 +71,13 @@ export class MastodonApiServerService {
done();
});
+ // Tell crawlers not to index API endpoints.
+ // https://developers.google.com/search/docs/crawling-indexing/block-indexing
+ fastify.addHook('onRequest', (request, reply, done) => {
+ reply.header('X-Robots-Tag', 'noindex');
+ done();
+ });
+
// External endpoints
this.apiAccountMastodon.register(fastify);
this.apiAppsMastodon.register(fastify);
diff --git a/packages/backend/src/server/api/mastodon/MastodonConverters.ts b/packages/backend/src/server/api/mastodon/MastodonConverters.ts
index 375ea1ef08..df8d68042a 100644
--- a/packages/backend/src/server/api/mastodon/MastodonConverters.ts
+++ b/packages/backend/src/server/api/mastodon/MastodonConverters.ts
@@ -5,7 +5,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { Entity, MastodonEntity, MisskeyEntity } from 'megalodon';
-import mfm from '@transfem-org/sfm-js';
+import mfm from 'mfm-js';
import { MastodonNotificationType } from 'megalodon/lib/src/mastodon/notification.js';
import { NotificationType } from 'megalodon/lib/src/notification.js';
import { DI } from '@/di-symbols.js';
@@ -252,10 +252,10 @@ export class MastodonConverters {
return await this.convertStatus(status, me);
}
- public async convertStatus(status: Entity.Status, me: MiLocalUser | null): Promise<MastodonEntity.Status> {
+ public async convertStatus(status: Entity.Status, me: MiLocalUser | null, hints?: { note?: MiNote, user?: MiUser }): Promise<MastodonEntity.Status> {
const convertedAccount = this.convertAccount(status.account);
- const note = await this.mastodonDataService.requireNote(status.id, me);
- const noteUser = await this.getUser(status.account.id);
+ const note = hints?.note ?? await this.mastodonDataService.requireNote(status.id, me);
+ const noteUser = hints?.user ?? note.user ?? await this.getUser(status.account.id);
const mentionedRemoteUsers = JSON.parse(note.mentionedRemoteUsers);
const emojis = await this.customEmojiService.populateEmojis(note.emojis, noteUser.host ? noteUser.host : this.config.host);
diff --git a/packages/backend/src/server/api/mastodon/MastodonDataService.ts b/packages/backend/src/server/api/mastodon/MastodonDataService.ts
index db257756de..e080cb10bd 100644
--- a/packages/backend/src/server/api/mastodon/MastodonDataService.ts
+++ b/packages/backend/src/server/api/mastodon/MastodonDataService.ts
@@ -7,8 +7,8 @@ import { Inject, Injectable } from '@nestjs/common';
import { IsNull } from 'typeorm';
import { DI } from '@/di-symbols.js';
import { QueryService } from '@/core/QueryService.js';
-import type { MiNote, NotesRepository } from '@/models/_.js';
-import type { MiLocalUser } from '@/models/User.js';
+import type { MiChannel, MiNote, NotesRepository } from '@/models/_.js';
+import type { MiLocalUser, MiUser } from '@/models/User.js';
import { ApiError } from '../error.js';
/**
@@ -27,8 +27,8 @@ export class MastodonDataService {
/**
* Fetches a note in the context of the current user, and throws an exception if not found.
*/
- public async requireNote(noteId: string, me?: MiLocalUser | null): Promise<MiNote> {
- const note = await this.getNote(noteId, me);
+ public async requireNote<Rel extends NoteRelations = NoteRelations>(noteId: string, me: MiLocalUser | null | undefined, relations?: Rel): Promise<NoteWithRelations<Rel>> {
+ const note = await this.getNote(noteId, me, relations);
if (!note) {
throw new ApiError({
@@ -46,12 +46,39 @@ export class MastodonDataService {
/**
* Fetches a note in the context of the current user.
*/
- public async getNote(noteId: string, me?: MiLocalUser | null): Promise<MiNote | null> {
+ public async getNote<Rel extends NoteRelations = NoteRelations>(noteId: string, me: MiLocalUser | null | undefined, relations?: Rel): Promise<NoteWithRelations<Rel> | null> {
// Root query: note + required dependencies
const query = this.notesRepository
.createQueryBuilder('note')
- .where('note.id = :noteId', { noteId })
- .innerJoinAndSelect('note.user', 'user');
+ .where('note.id = :noteId', { noteId });
+
+ // Load relations
+ if (relations) {
+ if (relations.reply) {
+ query.leftJoinAndSelect('note.reply', 'reply');
+ if (typeof(relations.reply) === 'object') {
+ if (relations.reply.reply) query.leftJoinAndSelect('reply.reply', 'replyReply');
+ if (relations.reply.renote) query.leftJoinAndSelect('reply.renote', 'replyRenote');
+ if (relations.reply.user) query.innerJoinAndSelect('reply.user', 'replyUser');
+ if (relations.reply.channel) query.leftJoinAndSelect('reply.channel', 'replyChannel');
+ }
+ }
+ if (relations.renote) {
+ query.leftJoinAndSelect('note.renote', 'renote');
+ if (typeof(relations.renote) === 'object') {
+ if (relations.renote.reply) query.leftJoinAndSelect('renote.reply', 'renoteReply');
+ if (relations.renote.renote) query.leftJoinAndSelect('renote.renote', 'renoteRenote');
+ if (relations.renote.user) query.innerJoinAndSelect('renote.user', 'renoteUser');
+ if (relations.renote.channel) query.leftJoinAndSelect('renote.channel', 'renoteChannel');
+ }
+ }
+ if (relations.user) {
+ query.innerJoinAndSelect('note.user', 'user');
+ }
+ if (relations.channel) {
+ query.leftJoinAndSelect('note.channel', 'channel');
+ }
+ }
// Restrict visibility
this.queryService.generateVisibilityQuery(query, me);
@@ -59,7 +86,7 @@ export class MastodonDataService {
this.queryService.generateBlockedUserQueryForNotes(query, me);
}
- return await query.getOne();
+ return await query.getOne() as NoteWithRelations<Rel> | null;
}
/**
@@ -82,3 +109,41 @@ export class MastodonDataService {
});
}
}
+
+interface NoteRelations {
+ reply?: boolean | {
+ reply?: boolean;
+ renote?: boolean;
+ user?: boolean;
+ channel?: boolean;
+ };
+ renote?: boolean | {
+ reply?: boolean;
+ renote?: boolean;
+ user?: boolean;
+ channel?: boolean;
+ };
+ user?: boolean;
+ channel?: boolean;
+}
+
+type NoteWithRelations<Rel extends NoteRelations> = MiNote & {
+ reply: Rel extends { reply: false }
+ ? null
+ : null | (MiNote & {
+ reply: Rel['reply'] extends { reply: true } ? MiNote | null : null;
+ renote: Rel['reply'] extends { renote: true } ? MiNote | null : null;
+ user: Rel['reply'] extends { user: true } ? MiUser : null;
+ channel: Rel['reply'] extends { channel: true } ? MiChannel | null : null;
+ });
+ renote: Rel extends { renote: false }
+ ? null
+ : null | (MiNote & {
+ reply: Rel['renote'] extends { reply: true } ? MiNote | null : null;
+ renote: Rel['renote'] extends { renote: true } ? MiNote | null : null;
+ user: Rel['renote'] extends { user: true } ? MiUser : null;
+ channel: Rel['renote'] extends { channel: true } ? MiChannel | null : null;
+ });
+ user: Rel extends { user: true } ? MiUser : null;
+ channel: Rel extends { channel: true } ? MiChannel | null : null;
+};
diff --git a/packages/backend/src/server/api/mastodon/endpoints/status.ts b/packages/backend/src/server/api/mastodon/endpoints/status.ts
index 22b8a911ca..7a058a0ed9 100644
--- a/packages/backend/src/server/api/mastodon/endpoints/status.ts
+++ b/packages/backend/src/server/api/mastodon/endpoints/status.ts
@@ -8,6 +8,10 @@ import { Injectable } from '@nestjs/common';
import { emojiRegexAtStartToEnd } from '@/misc/emoji-regex.js';
import { parseTimelineArgs, TimelineArgs, toBoolean, toInt } from '@/server/api/mastodon/argsUtils.js';
import { MastodonClientService } from '@/server/api/mastodon/MastodonClientService.js';
+import { MastodonDataService } from '@/server/api/mastodon/MastodonDataService.js';
+import { getNoteSummary } from '@/misc/get-note-summary.js';
+import type { Packed } from '@/misc/json-schema.js';
+import { isPureRenote } from '@/misc/is-renote.js';
import { convertAttachment, convertPoll, MastodonConverters } from '../MastodonConverters.js';
import type { Entity } from 'megalodon';
import type { FastifyInstance } from 'fastify';
@@ -22,6 +26,7 @@ export class ApiStatusMastodon {
constructor(
private readonly mastoConverters: MastodonConverters,
private readonly clientService: MastodonClientService,
+ private readonly mastodonDataService: MastodonDataService,
) {}
public register(fastify: FastifyInstance): void {
@@ -29,13 +34,24 @@ export class ApiStatusMastodon {
if (!_request.params.id) return reply.code(400).send({ error: 'BAD_REQUEST', error_description: 'Missing required parameter "id"' });
const { client, me } = await this.clientService.getAuthClient(_request);
- const data = await client.getStatus(_request.params.id);
- const response = await this.mastoConverters.convertStatus(data.data, me);
+ const note = await this.mastodonDataService.requireNote(_request.params.id, me, { user: true, renote: { user: true } });
+
+ // Unpack renote for Discord, otherwise the preview breaks
+ const appearNote = (isPureRenote(note) && _request.headers['user-agent']?.match(/\bDiscordbot\//))
+ ? note.renote as NonNullable<typeof note.renote>
+ : note;
+
+ const data = await client.getStatus(appearNote.id);
+ const response = await this.mastoConverters.convertStatus(data.data, me, { note: appearNote, user: appearNote.user });
// Fixup - Discord ignores CWs and renders the entire post.
if (response.sensitive && _request.headers['user-agent']?.match(/\bDiscordbot\//)) {
- response.content = '(preview disabled for sensitive content)';
+ response.content = getNoteSummary(data.data satisfies Packed<'Note'>);
response.media_attachments = [];
+ response.in_reply_to_id = null;
+ response.in_reply_to_account_id = null;
+ response.reblog = null;
+ response.quote = null;
}
return reply.send(response);
@@ -170,7 +186,7 @@ export class ApiStatusMastodon {
const data = await client.deleteEmojiReaction(id, react);
return reply.send(data.data);
}
- if (!body.media_ids) body.media_ids = undefined;
+ body.media_ids ??= undefined;
if (body.media_ids && !body.media_ids.length) body.media_ids = undefined;
if (body.poll && !body.poll.options) {
diff --git a/packages/backend/src/server/api/stream/Connection.ts b/packages/backend/src/server/api/stream/Connection.ts
index e0535a2f14..0ee7078eb2 100644
--- a/packages/backend/src/server/api/stream/Connection.ts
+++ b/packages/backend/src/server/api/stream/Connection.ts
@@ -36,7 +36,7 @@ export default class Connection {
private channels = new Map<string, Channel>();
private subscribingNotes = new Map<string, number>();
public userProfile: MiUserProfile | null = null;
- public following: Record<string, Pick<MiFollowing, 'withReplies'> | undefined> = {};
+ public following: Map<string, Omit<MiFollowing, 'isFollowerHibernated'>> = new Map();
public followingChannels: Set<string> = new Set();
public userIdsWhoMeMuting: Set<string> = new Set();
public userIdsWhoBlockingMe: Set<string> = new Set();
diff --git a/packages/backend/src/server/api/stream/channel.ts b/packages/backend/src/server/api/stream/channel.ts
index 9af816dfbb..40ad454adb 100644
--- a/packages/backend/src/server/api/stream/channel.ts
+++ b/packages/backend/src/server/api/stream/channel.ts
@@ -61,12 +61,30 @@ export default abstract class Channel {
return this.connection.subscriber;
}
+ /**
+ * Checks if a note is visible to the current user *excluding* blocks and mutes.
+ */
+ protected isNoteVisibleToMe(note: Packed<'Note'>): boolean {
+ if (note.visibility === 'public') return true;
+ if (note.visibility === 'home') return true;
+ if (!this.user) return false;
+ if (this.user.id === note.userId) return true;
+ if (note.visibility === 'followers') {
+ return this.following.has(note.userId);
+ }
+ if (!note.visibleUserIds) return false;
+ return note.visibleUserIds.includes(this.user.id);
+ }
+
/*
* ミュートとブロックされてるを処理する
*/
protected isNoteMutedOrBlocked(note: Packed<'Note'>): boolean {
+ // Ignore notes that require sign-in
+ if (note.user.requireSigninToViewContents && !this.user) return true;
+
// 流れてきたNoteがインスタンスミュートしたインスタンスが関わる
- if (isInstanceMuted(note, new Set<string>(this.userProfile?.mutedInstances ?? [])) && !this.following[note.userId]) return true;
+ if (isInstanceMuted(note, this.userMutedInstances) && !this.following.has(note.userId)) return true;
// 流れてきたNoteがミュートしているユーザーが関わる
if (isUserRelated(note, this.userIdsWhoMeMuting)) return true;
@@ -79,6 +97,15 @@ export default abstract class Channel {
// If it's a boost (pure renote) then we need to check the target as well
if (isPackedPureRenote(note) && note.renote && this.isNoteMutedOrBlocked(note.renote)) return true;
+ // Hide silenced notes
+ if (note.user.isSilenced || note.user.instance?.isSilenced) {
+ if (this.user == null) return true;
+ if (this.user.id === note.userId) return false;
+ if (!this.following.has(note.userId)) return true;
+ }
+
+ // TODO muted threads
+
return false;
}
diff --git a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts
index d29101cbc5..72f719b411 100644
--- a/packages/backend/src/server/api/stream/channels/bubble-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/bubble-timeline.ts
@@ -5,13 +5,12 @@
import { Injectable } from '@nestjs/common';
import type { Packed } from '@/misc/json-schema.js';
-import { MetaService } from '@/core/MetaService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
-import type { MiMeta } from '@/models/Meta.js';
import { isRenotePacked, isQuotePacked } from '@/misc/is-renote.js';
import type { JsonObject } from '@/misc/json-value.js';
+import { UtilityService } from '@/core/UtilityService.js';
import Channel, { MiChannelService } from '../channel.js';
class BubbleTimelineChannel extends Channel {
@@ -21,11 +20,10 @@ class BubbleTimelineChannel extends Channel {
private withRenotes: boolean;
private withFiles: boolean;
private withBots: boolean;
- private instance: MiMeta;
constructor(
- private metaService: MetaService,
private roleService: RoleService,
+ private readonly utilityService: UtilityService,
noteEntityService: NoteEntityService,
id: string,
@@ -42,7 +40,6 @@ class BubbleTimelineChannel extends Channel {
this.withRenotes = !!(params.withRenotes ?? true);
this.withFiles = !!(params.withFiles ?? false);
this.withBots = !!(params.withBots ?? true);
- this.instance = await this.metaService.fetch();
// Subscribe events
this.subscriber.on('notesStream', this.onNote);
@@ -50,20 +47,36 @@ class BubbleTimelineChannel extends Channel {
@bindThis
private async onNote(note: Packed<'Note'>) {
+ const isMe = this.user?.id === note.userId;
+
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
if (!this.withBots && note.user.isBot) return;
if (note.visibility !== 'public') return;
if (note.channelId != null) return;
- if (note.user.host == null) return;
- if (!this.instance.bubbleInstances.includes(note.user.host)) return;
- if (note.user.requireSigninToViewContents && this.user == null) return;
+ if (!this.utilityService.isBubbledHost(note.user.host)) return;
- if (isRenotePacked(note) && !isQuotePacked(note) && !this.withRenotes) return;
+ if (this.isNoteMutedOrBlocked(note)) return;
- if (note.user.isSilenced && !this.following[note.userId] && note.userId !== this.user!.id) return;
+ if (note.reply) {
+ const reply = note.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following.get(note.userId)?.withReplies) {
+ // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
+ if (reply.userId !== this.user?.id && !isMe && reply.userId !== note.userId) return;
+ }
+ }
- if (this.isNoteMutedOrBlocked(note)) return;
+ // 純粋なリノート(引用リノートでないリノート)の場合
+ if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
+ if (!this.withRenotes) return;
+ if (note.renote.reply) {
+ const reply = note.renote.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ }
+ }
const clonedNote = await this.assignMyReaction(note);
await this.hideNote(clonedNote);
@@ -85,17 +98,17 @@ export class BubbleTimelineChannelService implements MiChannelService<false> {
public readonly kind = BubbleTimelineChannel.kind;
constructor(
- private metaService: MetaService,
private roleService: RoleService,
private noteEntityService: NoteEntityService,
+ private readonly utilityService: UtilityService,
) {
}
@bindThis
public create(id: string, connection: Channel['connection']): BubbleTimelineChannel {
return new BubbleTimelineChannel(
- this.metaService,
this.roleService,
+ this.utilityService,
this.noteEntityService,
id,
connection,
diff --git a/packages/backend/src/server/api/stream/channels/global-timeline.ts b/packages/backend/src/server/api/stream/channels/global-timeline.ts
index c899ad9490..5c73f637c7 100644
--- a/packages/backend/src/server/api/stream/channels/global-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/global-timeline.ts
@@ -48,20 +48,36 @@ class GlobalTimelineChannel extends Channel {
@bindThis
private async onNote(note: Packed<'Note'>) {
+ const isMe = this.user?.id === note.userId;
+
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
if (!this.withBots && note.user.isBot) return;
if (note.visibility !== 'public') return;
if (note.channelId != null) return;
- if (note.user.requireSigninToViewContents && this.user == null) return;
- if (note.renote && note.renote.user.requireSigninToViewContents && this.user == null) return;
- if (note.reply && note.reply.user.requireSigninToViewContents && this.user == null) return;
- if (isRenotePacked(note) && !isQuotePacked(note) && !this.withRenotes) return;
+ if (this.isNoteMutedOrBlocked(note)) return;
+ if (!this.isNoteVisibleToMe(note)) return;
- if (note.user.isSilenced && !this.following[note.userId] && note.userId !== this.user!.id) return;
+ if (note.reply) {
+ const reply = note.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following.get(note.userId)?.withReplies) {
+ // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
+ if (reply.userId !== this.user?.id && !isMe && reply.userId !== note.userId) return;
+ }
+ }
- if (this.isNoteMutedOrBlocked(note)) return;
+ // 純粋なリノート(引用リノートでないリノート)の場合
+ if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
+ if (!this.withRenotes) return;
+ if (note.renote.reply) {
+ const reply = note.renote.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ }
+ }
const clonedNote = await this.assignMyReaction(note);
await this.hideNote(clonedNote);
diff --git a/packages/backend/src/server/api/stream/channels/home-timeline.ts b/packages/backend/src/server/api/stream/channels/home-timeline.ts
index dfdb491113..c7062c0394 100644
--- a/packages/backend/src/server/api/stream/channels/home-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/home-timeline.ts
@@ -47,40 +47,32 @@ class HomeTimelineChannel extends Channel {
if (!this.followingChannels.has(note.channelId)) return;
} else {
// その投稿のユーザーをフォローしていなかったら弾く
- if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
+ if (!isMe && !this.following.has(note.userId)) return;
}
- if (note.visibility === 'followers') {
- if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
- } else if (note.visibility === 'specified') {
- if (!isMe && !note.visibleUserIds!.includes(this.user!.id)) return;
- }
+ if (this.isNoteMutedOrBlocked(note)) return;
+ if (!this.isNoteVisibleToMe(note)) return;
if (note.reply) {
const reply = note.reply;
- if (this.following[note.userId]?.withReplies) {
- // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
- if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId) && reply.userId !== this.user!.id) return;
- } else {
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following.get(note.userId)?.withReplies) {
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
if (reply.userId !== this.user!.id && !isMe && reply.userId !== note.userId) return;
}
}
- if (note.user.isSilenced && !this.following[note.userId] && note.userId !== this.user!.id) return;
-
// 純粋なリノート(引用リノートでないリノート)の場合
if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
if (!this.withRenotes) return;
if (note.renote.reply) {
const reply = note.renote.reply;
// 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
- if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId) && reply.userId !== this.user!.id) return;
+ if (!this.isNoteVisibleToMe(reply)) return;
}
}
- if (this.isNoteMutedOrBlocked(note)) return;
-
const clonedNote = await this.assignMyReaction(note);
await this.hideNote(clonedNote);
diff --git a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
index 6cb425ff81..7cb64c9f89 100644
--- a/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/hybrid-timeline.ts
@@ -62,39 +62,31 @@ class HybridTimelineChannel extends Channel {
// フォローしているチャンネルの投稿 の場合だけ
if (!(
(note.channelId == null && isMe) ||
- (note.channelId == null && Object.hasOwn(this.following, note.userId)) ||
+ (note.channelId == null && this.following.has(note.userId)) ||
(note.channelId == null && (note.user.host == null && note.visibility === 'public')) ||
(note.channelId != null && this.followingChannels.has(note.channelId))
)) return;
- if (note.visibility === 'followers') {
- if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
- } else if (note.visibility === 'specified') {
- if (!isMe && !note.visibleUserIds!.includes(this.user!.id)) return;
- }
-
if (this.isNoteMutedOrBlocked(note)) return;
+ if (!this.isNoteVisibleToMe(note)) return;
if (note.reply) {
const reply = note.reply;
- if ((this.following[note.userId]?.withReplies ?? false) || this.withReplies) {
- // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
- if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId) && reply.userId !== this.user!.id) return;
- } else {
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following.get(note.userId)?.withReplies && !this.withReplies) {
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
if (reply.userId !== this.user!.id && !isMe && reply.userId !== note.userId) return;
}
}
- if (note.user.isSilenced && !this.following[note.userId] && note.userId !== this.user!.id) return;
-
// 純粋なリノート(引用リノートでないリノート)の場合
if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
if (!this.withRenotes) return;
if (note.renote.reply) {
const reply = note.renote.reply;
// 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
- if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId) && reply.userId !== this.user!.id) return;
+ if (!this.isNoteVisibleToMe(reply)) return;
}
}
diff --git a/packages/backend/src/server/api/stream/channels/local-timeline.ts b/packages/backend/src/server/api/stream/channels/local-timeline.ts
index 82b128eae0..4869d871d6 100644
--- a/packages/backend/src/server/api/stream/channels/local-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/local-timeline.ts
@@ -50,28 +50,37 @@ class LocalTimelineChannel extends Channel {
@bindThis
private async onNote(note: Packed<'Note'>) {
+ const isMe = this.user?.id === note.userId;
+
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
if (!this.withBots && note.user.isBot) return;
if (note.user.host !== null) return;
if (note.visibility !== 'public') return;
if (note.channelId != null) return;
- if (note.user.requireSigninToViewContents && this.user == null) return;
- if (note.renote && note.renote.user.requireSigninToViewContents && this.user == null) return;
- if (note.reply && note.reply.user.requireSigninToViewContents && this.user == null) return;
+
+ if (this.isNoteMutedOrBlocked(note)) return;
+ if (!this.isNoteVisibleToMe(note)) return;
// 関係ない返信は除外
- if (note.reply && this.user && !this.following[note.userId]?.withReplies && !this.withReplies) {
+ if (note.reply) {
const reply = note.reply;
- // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
- if (reply.userId !== this.user.id && note.userId !== this.user.id && reply.userId !== note.userId) return;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following.get(note.userId)?.withReplies) {
+ // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
+ if (reply.userId !== this.user?.id && !isMe && reply.userId !== note.userId) return;
+ }
}
- if (note.user.isSilenced && !this.following[note.userId] && note.userId !== this.user!.id) return;
-
- if (isRenotePacked(note) && !isQuotePacked(note) && !this.withRenotes) return;
-
- if (this.isNoteMutedOrBlocked(note)) return;
+ if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
+ if (!this.withRenotes) return;
+ if (note.renote.reply) {
+ const reply = note.renote.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ }
+ }
const clonedNote = await this.assignMyReaction(note);
await this.hideNote(clonedNote);
diff --git a/packages/backend/src/server/api/stream/channels/main.ts b/packages/backend/src/server/api/stream/channels/main.ts
index 6194bb78dd..193907504a 100644
--- a/packages/backend/src/server/api/stream/channels/main.ts
+++ b/packages/backend/src/server/api/stream/channels/main.ts
@@ -32,10 +32,12 @@ class MainChannel extends Channel {
switch (data.type) {
case 'notification': {
// Ignore notifications from instances the user has muted
- if (isUserFromMutedInstance(data.body, new Set<string>(this.userProfile?.mutedInstances ?? []))) return;
+ if (isUserFromMutedInstance(data.body, this.userMutedInstances)) return;
if (data.body.userId && this.userIdsWhoMeMuting.has(data.body.userId)) return;
if (data.body.note && data.body.note.isHidden) {
+ if (this.isNoteMutedOrBlocked(data.body.note)) return;
+ if (!this.isNoteVisibleToMe(data.body.id)) return;
const note = await this.noteEntityService.pack(data.body.note.id, this.user, {
detail: true,
});
@@ -44,9 +46,7 @@ class MainChannel extends Channel {
break;
}
case 'mention': {
- if (isInstanceMuted(data.body, new Set<string>(this.userProfile?.mutedInstances ?? []))) return;
-
- if (this.userIdsWhoMeMuting.has(data.body.userId)) return;
+ if (this.isNoteMutedOrBlocked(data.body)) return;
if (data.body.isHidden) {
const note = await this.noteEntityService.pack(data.body.id, this.user, {
detail: true,
diff --git a/packages/backend/src/server/api/stream/channels/role-timeline.ts b/packages/backend/src/server/api/stream/channels/role-timeline.ts
index 78cd9bf868..a3886618f1 100644
--- a/packages/backend/src/server/api/stream/channels/role-timeline.ts
+++ b/packages/backend/src/server/api/stream/channels/role-timeline.ts
@@ -9,6 +9,7 @@ import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
import type { GlobalEvents } from '@/core/GlobalEventService.js';
import type { JsonObject } from '@/misc/json-value.js';
+import { isQuotePacked, isRenotePacked } from '@/misc/is-renote.js';
import Channel, { type MiChannelService } from '../channel.js';
class RoleTimelineChannel extends Channel {
@@ -40,7 +41,9 @@ class RoleTimelineChannel extends Channel {
private async onEvent(data: GlobalEvents['roleTimeline']['payload']) {
if (data.type === 'note') {
const note = data.body;
+ const isMe = this.user?.id === note.userId;
+ // TODO this should be cached
if (!(await this.roleservice.isExplorable({ id: this.roleId }))) {
return;
}
@@ -48,6 +51,25 @@ class RoleTimelineChannel extends Channel {
if (this.isNoteMutedOrBlocked(note)) return;
+ if (note.reply) {
+ const reply = note.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following.get(note.userId)?.withReplies) {
+ // 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
+ if (reply.userId !== this.user?.id && !isMe && reply.userId !== note.userId) return;
+ }
+ }
+
+ // 純粋なリノート(引用リノートでないリノート)の場合
+ if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
+ if (note.renote.reply) {
+ const reply = note.renote.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ }
+ }
+
const clonedNote = await this.assignMyReaction(note);
await this.hideNote(clonedNote);
diff --git a/packages/backend/src/server/api/stream/channels/user-list.ts b/packages/backend/src/server/api/stream/channels/user-list.ts
index 8a7c2b2633..4dae24a696 100644
--- a/packages/backend/src/server/api/stream/channels/user-list.ts
+++ b/packages/backend/src/server/api/stream/channels/user-list.ts
@@ -16,7 +16,8 @@ import Channel, { type MiChannelService } from '../channel.js';
class UserListChannel extends Channel {
public readonly chName = 'userList';
public static shouldShare = false;
- public static requireCredential = false as const;
+ public static requireCredential = true as const;
+ public static kind = 'read:account';
private listId: string;
private membershipsMap: Record<string, Pick<MiUserListMembership, 'withReplies'> | undefined> = {};
private listUsersClock: NodeJS.Timeout;
@@ -81,7 +82,7 @@ class UserListChannel extends Channel {
@bindThis
private async onNote(note: Packed<'Note'>) {
- const isMe = this.user!.id === note.userId;
+ const isMe = this.user?.id === note.userId;
// チャンネル投稿は無視する
if (note.channelId) return;
@@ -90,26 +91,28 @@ class UserListChannel extends Channel {
if (!Object.hasOwn(this.membershipsMap, note.userId)) return;
- if (note.visibility === 'followers') {
- if (!isMe && !Object.hasOwn(this.following, note.userId)) return;
- } else if (note.visibility === 'specified') {
- if (!note.visibleUserIds!.includes(this.user!.id)) return;
- }
+ if (this.isNoteMutedOrBlocked(note)) return;
+ if (!this.isNoteVisibleToMe(note)) return;
if (note.reply) {
const reply = note.reply;
- if (this.membershipsMap[note.userId]?.withReplies) {
- // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
- if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId)) return;
- } else {
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ if (!this.following.get(note.userId)?.withReplies) {
// 「チャンネル接続主への返信」でもなければ、「チャンネル接続主が行った返信」でもなければ、「投稿者の投稿者自身への返信」でもない場合
if (reply.userId !== this.user!.id && !isMe && reply.userId !== note.userId) return;
}
}
- if (isRenotePacked(note) && !isQuotePacked(note) && !this.withRenotes) return;
-
- if (this.isNoteMutedOrBlocked(note)) return;
+ // 純粋なリノート(引用リノートでないリノート)の場合
+ if (isRenotePacked(note) && !isQuotePacked(note) && note.renote) {
+ if (!this.withRenotes) return;
+ if (note.renote.reply) {
+ const reply = note.renote.reply;
+ // 自分のフォローしていないユーザーの visibility: followers な投稿への返信のリノートは弾く
+ if (!this.isNoteVisibleToMe(reply)) return;
+ }
+ }
const clonedNote = await this.assignMyReaction(note);
await this.hideNote(clonedNote);
@@ -128,7 +131,7 @@ class UserListChannel extends Channel {
}
@Injectable()
-export class UserListChannelService implements MiChannelService<false> {
+export class UserListChannelService implements MiChannelService<true> {
public readonly shouldShare = UserListChannel.shouldShare;
public readonly requireCredential = UserListChannel.requireCredential;
public readonly kind = UserListChannel.kind;
diff --git a/packages/backend/src/server/web/FeedService.ts b/packages/backend/src/server/web/FeedService.ts
index dcd4d80303..a622ae7e34 100644
--- a/packages/backend/src/server/web/FeedService.ts
+++ b/packages/backend/src/server/web/FeedService.ts
@@ -15,7 +15,7 @@ import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.j
import { bindThis } from '@/decorators.js';
import { IdService } from '@/core/IdService.js';
import { MfmService } from "@/core/MfmService.js";
-import { parse as mfmParse } from '@transfem-org/sfm-js';
+import { parse as mfmParse } from 'mfm-js';
@Injectable()
export class FeedService {
diff --git a/packages/backend/src/server/web/UrlPreviewService.ts b/packages/backend/src/server/web/UrlPreviewService.ts
index 203bc908a8..71a142fc6f 100644
--- a/packages/backend/src/server/web/UrlPreviewService.ts
+++ b/packages/backend/src/server/web/UrlPreviewService.ts
@@ -20,6 +20,7 @@ import { RedisKVCache } from '@/misc/cache.js';
import { UtilityService } from '@/core/UtilityService.js';
import { ApDbResolverService } from '@/core/activitypub/ApDbResolverService.js';
import type { MiAccessToken, NotesRepository } from '@/models/_.js';
+import { RemoteUserResolveService } from '@/core/RemoteUserResolveService.js';
import { ApUtilityService } from '@/core/activitypub/ApUtilityService.js';
import { ApRequestService } from '@/core/activitypub/ApRequestService.js';
import { SystemAccountService } from '@/core/SystemAccountService.js';
@@ -30,14 +31,19 @@ import { BucketRateLimit, Keyed, sendRateLimitHeaders } from '@/misc/rate-limit-
import type { MiLocalUser } from '@/models/User.js';
import { getIpHash } from '@/misc/get-ip-hash.js';
import { isRetryableError } from '@/misc/is-retryable-error.js';
+import * as Acct from '@/misc/acct.js';
+import { isNote } from '@/core/activitypub/type.js';
import type { FastifyRequest, FastifyReply } from 'fastify';
export type LocalSummalyResult = SummalyResult & {
haveNoteLocally?: boolean;
+ linkAttribution?: {
+ userId: string,
+ }
};
// Increment this to invalidate cached previews after a major change.
-const cacheFormatVersion = 3;
+const cacheFormatVersion = 4;
type PreviewRoute = {
Querystring: {
@@ -82,6 +88,7 @@ export class UrlPreviewService {
private readonly utilityService: UtilityService,
private readonly apUtilityService: ApUtilityService,
private readonly apDbResolverService: ApDbResolverService,
+ private readonly remoteUserResolveService: RemoteUserResolveService,
private readonly apRequestService: ApRequestService,
private readonly systemAccountService: SystemAccountService,
private readonly apNoteService: ApNoteService,
@@ -117,26 +124,49 @@ export class UrlPreviewService {
request: FastifyRequest<PreviewRoute>,
reply: FastifyReply,
): Promise<void> {
+ if (!this.meta.urlPreviewEnabled) {
+ // Tell crawlers not to index URL previews.
+ // https://developers.google.com/search/docs/crawling-indexing/block-indexing
+ reply.header('X-Robots-Tag', 'noindex');
+
+ return reply.code(403).send({
+ error: {
+ message: 'URL preview is disabled',
+ code: 'URL_PREVIEW_DISABLED',
+ id: '58b36e13-d2f5-0323-b0c6-76aa9dabefb8',
+ },
+ });
+ }
+
const url = request.query.url;
if (typeof url !== 'string' || !URL.canParse(url)) {
reply.code(400);
return;
}
+ // Enforce HTTP(S) for input URLs
+ const urlScheme = this.utilityService.getUrlScheme(url);
+ if (urlScheme !== 'http:' && urlScheme !== 'https:') {
+ reply.code(400);
+ return;
+ }
+
const lang = request.query.lang;
if (Array.isArray(lang)) {
reply.code(400);
return;
}
- if (!this.meta.urlPreviewEnabled) {
- return reply.code(403).send({
- error: {
- message: 'URL preview is disabled',
- code: 'URL_PREVIEW_DISABLED',
- id: '58b36e13-d2f5-0323-b0c6-76aa9dabefb8',
- },
- });
+ // Strip out hash (anchor)
+ const urlObj = new URL(url);
+ if (urlObj.hash) {
+ urlObj.hash = '';
+ const params = new URLSearchParams({ url: urlObj.href });
+ if (lang) params.set('lang', lang);
+ const newUrl = `/url?${params.toString()}`;
+
+ reply.redirect(newUrl, 301);
+ return;
}
// Check rate limit
@@ -145,7 +175,7 @@ export class UrlPreviewService {
return;
}
- if (this.utilityService.isBlockedHost(this.meta.blockedHosts, new URL(url).host)) {
+ if (this.utilityService.isBlockedHost(this.meta.blockedHosts, urlObj.host)) {
return reply.code(403).send({
error: {
message: 'URL is blocked',
@@ -160,7 +190,7 @@ export class UrlPreviewService {
return;
}
- const cacheKey = `${url}@${lang}@${cacheFormatVersion}`;
+ const cacheKey = getCacheKey(url, lang);
if (await this.sendCachedPreview(cacheKey, reply, fetch)) {
return;
}
@@ -206,9 +236,23 @@ export class UrlPreviewService {
}
}
+ await this.validateLinkAttribution(summary);
+
// Await this to avoid hammering redis when a bunch of URLs are fetched at once
await this.previewCache.set(cacheKey, summary);
+ // Also cache the response URL in case of redirects
+ if (summary.url !== url) {
+ const responseCacheKey = getCacheKey(summary.url, lang);
+ await this.previewCache.set(responseCacheKey, summary);
+ }
+
+ // Also cache the ActivityPub URL, if different from the others
+ if (summary.activityPub && summary.activityPub !== summary.url) {
+ const apCacheKey = getCacheKey(summary.activityPub, lang);
+ await this.previewCache.set(apCacheKey, summary);
+ }
+
// Cache 1 day (matching redis), but only once we finalize the result
if (!summary.activityPub || summary.haveNoteLocally) {
reply.header('Cache-Control', 'public, max-age=86400');
@@ -370,7 +414,7 @@ export class UrlPreviewService {
// Finally, attempt a signed GET in case it's a direct link to an instance with authorized fetch.
const instanceActor = await this.systemAccountService.getInstanceActor();
const remoteObject = await this.apRequestService.signedGet(summary.url, instanceActor).catch(() => null);
- if (remoteObject && this.apUtilityService.haveSameAuthority(remoteObject.id, summary.url)) {
+ if (remoteObject && isNote(remoteObject) && this.apUtilityService.haveSameAuthority(remoteObject.id, summary.url)) {
summary.activityPub = remoteObject.id;
return;
}
@@ -426,6 +470,30 @@ export class UrlPreviewService {
}
}
+ private async validateLinkAttribution(summary: LocalSummalyResult) {
+ if (!summary.fediverseCreator) return;
+ if (!URL.canParse(summary.url)) return;
+
+ const url = URL.parse(summary.url);
+
+ const acct = Acct.parse(summary.fediverseCreator);
+ if (acct.host?.toLowerCase() === this.config.host) {
+ acct.host = null;
+ }
+ try {
+ const user = await this.remoteUserResolveService.resolveUser(acct.username, acct.host);
+
+ const attributionDomains = user.attributionDomains;
+ if (attributionDomains.some(x => `.${url?.host.toLowerCase()}`.endsWith(`.${x}`))) {
+ summary.linkAttribution = {
+ userId: user.id,
+ };
+ }
+ } catch {
+ this.logger.debug('User not found: ' + summary.fediverseCreator);
+ }
+ }
+
// Adapted from ApiCallService
private async checkFetchPermissions(auth: AuthArray, reply: FastifyReply): Promise<boolean> {
const [user, app] = auth;
@@ -501,3 +569,7 @@ export class UrlPreviewService {
return true;
}
}
+
+function getCacheKey(url: string, lang = 'none') {
+ return `${url}@${lang}@${cacheFormatVersion}`;
+}