summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/src/server/api/endpoints')
-rw-r--r--packages/backend/src/server/api/endpoints/admin/avatar-decorations/create.ts44
-rw-r--r--packages/backend/src/server/api/endpoints/admin/avatar-decorations/delete.ts38
-rw-r--r--packages/backend/src/server/api/endpoints/admin/avatar-decorations/list.ts101
-rw-r--r--packages/backend/src/server/api/endpoints/admin/avatar-decorations/update.ts50
-rw-r--r--packages/backend/src/server/api/endpoints/admin/meta.ts9
-rw-r--r--packages/backend/src/server/api/endpoints/admin/update-meta.ts5
-rw-r--r--packages/backend/src/server/api/endpoints/channels/follow.ts16
-rw-r--r--packages/backend/src/server/api/endpoints/channels/unfollow.ts12
-rw-r--r--packages/backend/src/server/api/endpoints/fetch-external-resources.ts72
-rw-r--r--packages/backend/src/server/api/endpoints/following/update-all.ts54
-rw-r--r--packages/backend/src/server/api/endpoints/get-avatar-decorations.ts82
-rw-r--r--packages/backend/src/server/api/endpoints/i/revoke-token.ts29
-rw-r--r--packages/backend/src/server/api/endpoints/i/update.ts34
-rw-r--r--packages/backend/src/server/api/endpoints/notes/create.ts5
-rw-r--r--packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts341
-rw-r--r--packages/backend/src/server/api/endpoints/notes/local-timeline.ts211
-rw-r--r--packages/backend/src/server/api/endpoints/notes/timeline.ts305
-rw-r--r--packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts154
-rw-r--r--packages/backend/src/server/api/endpoints/notifications/create.ts4
19 files changed, 1150 insertions, 416 deletions
diff --git a/packages/backend/src/server/api/endpoints/admin/avatar-decorations/create.ts b/packages/backend/src/server/api/endpoints/admin/avatar-decorations/create.ts
new file mode 100644
index 0000000000..ec143fcb53
--- /dev/null
+++ b/packages/backend/src/server/api/endpoints/admin/avatar-decorations/create.ts
@@ -0,0 +1,44 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import { Injectable } from '@nestjs/common';
+import { Endpoint } from '@/server/api/endpoint-base.js';
+import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
+
+export const meta = {
+ tags: ['admin'],
+
+ requireCredential: true,
+ requireRolePolicy: 'canManageAvatarDecorations',
+} as const;
+
+export const paramDef = {
+ type: 'object',
+ properties: {
+ name: { type: 'string', minLength: 1 },
+ description: { type: 'string' },
+ url: { type: 'string', minLength: 1 },
+ roleIdsThatCanBeUsedThisDecoration: { type: 'array', items: {
+ type: 'string',
+ } },
+ },
+ required: ['name', 'description', 'url'],
+} as const;
+
+@Injectable()
+export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
+ constructor(
+ private avatarDecorationService: AvatarDecorationService,
+ ) {
+ super(meta, paramDef, async (ps, me) => {
+ await this.avatarDecorationService.create({
+ name: ps.name,
+ description: ps.description,
+ url: ps.url,
+ roleIdsThatCanBeUsedThisDecoration: ps.roleIdsThatCanBeUsedThisDecoration,
+ }, me);
+ });
+ }
+}
diff --git a/packages/backend/src/server/api/endpoints/admin/avatar-decorations/delete.ts b/packages/backend/src/server/api/endpoints/admin/avatar-decorations/delete.ts
new file mode 100644
index 0000000000..6f1f386871
--- /dev/null
+++ b/packages/backend/src/server/api/endpoints/admin/avatar-decorations/delete.ts
@@ -0,0 +1,38 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import { Inject, Injectable } from '@nestjs/common';
+import { Endpoint } from '@/server/api/endpoint-base.js';
+import { DI } from '@/di-symbols.js';
+import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
+import { ApiError } from '../../../error.js';
+
+export const meta = {
+ tags: ['admin'],
+
+ requireCredential: true,
+ requireRolePolicy: 'canManageAvatarDecorations',
+ errors: {
+ },
+} as const;
+
+export const paramDef = {
+ type: 'object',
+ properties: {
+ id: { type: 'string', format: 'misskey:id' },
+ },
+ required: ['id'],
+} as const;
+
+@Injectable()
+export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
+ constructor(
+ private avatarDecorationService: AvatarDecorationService,
+ ) {
+ super(meta, paramDef, async (ps, me) => {
+ await this.avatarDecorationService.delete(ps.id, me);
+ });
+ }
+}
diff --git a/packages/backend/src/server/api/endpoints/admin/avatar-decorations/list.ts b/packages/backend/src/server/api/endpoints/admin/avatar-decorations/list.ts
new file mode 100644
index 0000000000..d9c669377d
--- /dev/null
+++ b/packages/backend/src/server/api/endpoints/admin/avatar-decorations/list.ts
@@ -0,0 +1,101 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import { Inject, Injectable } from '@nestjs/common';
+import type { AnnouncementsRepository, AnnouncementReadsRepository } from '@/models/_.js';
+import type { MiAnnouncement } from '@/models/Announcement.js';
+import { Endpoint } from '@/server/api/endpoint-base.js';
+import { QueryService } from '@/core/QueryService.js';
+import { DI } from '@/di-symbols.js';
+import { IdService } from '@/core/IdService.js';
+import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
+
+export const meta = {
+ tags: ['admin'],
+
+ requireCredential: true,
+ requireRolePolicy: 'canManageAvatarDecorations',
+
+ res: {
+ type: 'array',
+ optional: false, nullable: false,
+ items: {
+ type: 'object',
+ optional: false, nullable: false,
+ properties: {
+ id: {
+ type: 'string',
+ optional: false, nullable: false,
+ format: 'id',
+ example: 'xxxxxxxxxx',
+ },
+ createdAt: {
+ type: 'string',
+ optional: false, nullable: false,
+ format: 'date-time',
+ },
+ updatedAt: {
+ type: 'string',
+ optional: false, nullable: true,
+ format: 'date-time',
+ },
+ name: {
+ type: 'string',
+ optional: false, nullable: false,
+ },
+ description: {
+ type: 'string',
+ optional: false, nullable: false,
+ },
+ url: {
+ type: 'string',
+ optional: false, nullable: false,
+ },
+ roleIdsThatCanBeUsedThisDecoration: {
+ type: 'array',
+ optional: false, nullable: false,
+ items: {
+ type: 'string',
+ optional: false, nullable: false,
+ format: 'id',
+ },
+ },
+ },
+ },
+ },
+} as const;
+
+export const paramDef = {
+ type: 'object',
+ properties: {
+ limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
+ sinceId: { type: 'string', format: 'misskey:id' },
+ untilId: { type: 'string', format: 'misskey:id' },
+ userId: { type: 'string', format: 'misskey:id', nullable: true },
+ },
+ required: [],
+} as const;
+
+@Injectable()
+export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
+ constructor(
+ private avatarDecorationService: AvatarDecorationService,
+ private idService: IdService,
+ ) {
+ super(meta, paramDef, async (ps, me) => {
+ const avatarDecorations = await this.avatarDecorationService.getAll(true);
+
+ return avatarDecorations.map(avatarDecoration => ({
+ id: avatarDecoration.id,
+ createdAt: this.idService.parse(avatarDecoration.id).date.toISOString(),
+ updatedAt: avatarDecoration.updatedAt?.toISOString() ?? null,
+ name: avatarDecoration.name,
+ description: avatarDecoration.description,
+ url: avatarDecoration.url,
+ roleIdsThatCanBeUsedThisDecoration: avatarDecoration.roleIdsThatCanBeUsedThisDecoration,
+ }));
+ });
+ }
+}
diff --git a/packages/backend/src/server/api/endpoints/admin/avatar-decorations/update.ts b/packages/backend/src/server/api/endpoints/admin/avatar-decorations/update.ts
new file mode 100644
index 0000000000..5ea9a40762
--- /dev/null
+++ b/packages/backend/src/server/api/endpoints/admin/avatar-decorations/update.ts
@@ -0,0 +1,50 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import { Inject, Injectable } from '@nestjs/common';
+import { Endpoint } from '@/server/api/endpoint-base.js';
+import { DI } from '@/di-symbols.js';
+import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
+import { ApiError } from '../../../error.js';
+
+export const meta = {
+ tags: ['admin'],
+
+ requireCredential: true,
+ requireRolePolicy: 'canManageAvatarDecorations',
+
+ errors: {
+ },
+} as const;
+
+export const paramDef = {
+ type: 'object',
+ properties: {
+ id: { type: 'string', format: 'misskey:id' },
+ name: { type: 'string', minLength: 1 },
+ description: { type: 'string' },
+ url: { type: 'string', minLength: 1 },
+ roleIdsThatCanBeUsedThisDecoration: { type: 'array', items: {
+ type: 'string',
+ } },
+ },
+ required: ['id'],
+} as const;
+
+@Injectable()
+export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
+ constructor(
+ private avatarDecorationService: AvatarDecorationService,
+ ) {
+ super(meta, paramDef, async (ps, me) => {
+ await this.avatarDecorationService.update(ps.id, {
+ name: ps.name,
+ description: ps.description,
+ url: ps.url,
+ roleIdsThatCanBeUsedThisDecoration: ps.roleIdsThatCanBeUsedThisDecoration,
+ }, me);
+ });
+ }
+}
diff --git a/packages/backend/src/server/api/endpoints/admin/meta.ts b/packages/backend/src/server/api/endpoints/admin/meta.ts
index a6e483254c..f737a75972 100644
--- a/packages/backend/src/server/api/endpoints/admin/meta.ts
+++ b/packages/backend/src/server/api/endpoints/admin/meta.ts
@@ -110,11 +110,11 @@ export const meta = {
optional: false, nullable: false,
},
silencedHosts: {
- type: "array",
+ type: 'array',
optional: true,
nullable: false,
items: {
- type: "string",
+ type: 'string',
optional: false,
nullable: false,
},
@@ -303,6 +303,10 @@ export const meta = {
type: 'object',
optional: false, nullable: false,
},
+ enableFanoutTimeline: {
+ type: 'boolean',
+ optional: false, nullable: false,
+ },
perLocalUserUserTimelineCacheMax: {
type: 'number',
optional: false, nullable: false,
@@ -434,6 +438,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
enableIdenticonGeneration: instance.enableIdenticonGeneration,
policies: { ...DEFAULT_POLICIES, ...instance.policies },
manifestJsonOverride: instance.manifestJsonOverride,
+ enableFanoutTimeline: instance.enableFanoutTimeline,
perLocalUserUserTimelineCacheMax: instance.perLocalUserUserTimelineCacheMax,
perRemoteUserUserTimelineCacheMax: instance.perRemoteUserUserTimelineCacheMax,
perUserHomeTimelineCacheMax: instance.perUserHomeTimelineCacheMax,
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 2276eb0b18..915021601a 100644
--- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts
+++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts
@@ -123,6 +123,7 @@ export const paramDef = {
serverRules: { type: 'array', items: { type: 'string' } },
preservedUsernames: { type: 'array', items: { type: 'string' } },
manifestJsonOverride: { type: 'string' },
+ enableFanoutTimeline: { type: 'boolean' },
perLocalUserUserTimelineCacheMax: { type: 'integer' },
perRemoteUserUserTimelineCacheMax: { type: 'integer' },
perUserHomeTimelineCacheMax: { type: 'integer' },
@@ -495,6 +496,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.manifestJsonOverride = ps.manifestJsonOverride;
}
+ if (ps.enableFanoutTimeline !== undefined) {
+ set.enableFanoutTimeline = ps.enableFanoutTimeline;
+ }
+
if (ps.perLocalUserUserTimelineCacheMax !== undefined) {
set.perLocalUserUserTimelineCacheMax = ps.perLocalUserUserTimelineCacheMax;
}
diff --git a/packages/backend/src/server/api/endpoints/channels/follow.ts b/packages/backend/src/server/api/endpoints/channels/follow.ts
index 76ec6be805..bb5a477eb8 100644
--- a/packages/backend/src/server/api/endpoints/channels/follow.ts
+++ b/packages/backend/src/server/api/endpoints/channels/follow.ts
@@ -5,9 +5,9 @@
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
-import type { ChannelFollowingsRepository, ChannelsRepository } from '@/models/_.js';
-import { IdService } from '@/core/IdService.js';
+import type { ChannelsRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
+import { ChannelFollowingService } from '@/core/ChannelFollowingService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -41,11 +41,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
constructor(
@Inject(DI.channelsRepository)
private channelsRepository: ChannelsRepository,
-
- @Inject(DI.channelFollowingsRepository)
- private channelFollowingsRepository: ChannelFollowingsRepository,
-
- private idService: IdService,
+ private channelFollowingService: ChannelFollowingService,
) {
super(meta, paramDef, async (ps, me) => {
const channel = await this.channelsRepository.findOneBy({
@@ -56,11 +52,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchChannel);
}
- await this.channelFollowingsRepository.insert({
- id: this.idService.gen(),
- followerId: me.id,
- followeeId: channel.id,
- });
+ await this.channelFollowingService.follow(me, channel);
});
}
}
diff --git a/packages/backend/src/server/api/endpoints/channels/unfollow.ts b/packages/backend/src/server/api/endpoints/channels/unfollow.ts
index 46883dd548..c95332c7f8 100644
--- a/packages/backend/src/server/api/endpoints/channels/unfollow.ts
+++ b/packages/backend/src/server/api/endpoints/channels/unfollow.ts
@@ -5,8 +5,9 @@
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
-import type { ChannelFollowingsRepository, ChannelsRepository } from '@/models/_.js';
+import type { ChannelsRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
+import { ChannelFollowingService } from '@/core/ChannelFollowingService.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -40,9 +41,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
constructor(
@Inject(DI.channelsRepository)
private channelsRepository: ChannelsRepository,
-
- @Inject(DI.channelFollowingsRepository)
- private channelFollowingsRepository: ChannelFollowingsRepository,
+ private channelFollowingService: ChannelFollowingService,
) {
super(meta, paramDef, async (ps, me) => {
const channel = await this.channelsRepository.findOneBy({
@@ -53,10 +52,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.noSuchChannel);
}
- await this.channelFollowingsRepository.delete({
- followerId: me.id,
- followeeId: channel.id,
- });
+ await this.channelFollowingService.unfollow(me, channel);
});
}
}
diff --git a/packages/backend/src/server/api/endpoints/fetch-external-resources.ts b/packages/backend/src/server/api/endpoints/fetch-external-resources.ts
new file mode 100644
index 0000000000..d7b46cc666
--- /dev/null
+++ b/packages/backend/src/server/api/endpoints/fetch-external-resources.ts
@@ -0,0 +1,72 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import { createHash } from 'crypto';
+import ms from 'ms';
+import { Injectable } from '@nestjs/common';
+import { Endpoint } from '@/server/api/endpoint-base.js';
+import { HttpRequestService } from '@/core/HttpRequestService.js';
+import { ApiError } from '../error.js';
+
+export const meta = {
+ tags: ['meta'],
+
+ requireCredential: true,
+
+ limit: {
+ duration: ms('1hour'),
+ max: 50,
+ },
+
+ errors: {
+ invalidSchema: {
+ message: 'External resource returned invalid schema.',
+ code: 'EXT_RESOURCE_RETURNED_INVALID_SCHEMA',
+ id: 'bb774091-7a15-4a70-9dc5-6ac8cf125856',
+ },
+ hashUnmached: {
+ message: 'Hash did not match.',
+ code: 'EXT_RESOURCE_HASH_DIDNT_MATCH',
+ id: '693ba8ba-b486-40df-a174-72f8279b56a4',
+ },
+ },
+} as const;
+
+export const paramDef = {
+ type: 'object',
+ properties: {
+ url: { type: 'string' },
+ hash: { type: 'string' },
+ },
+ required: ['url', 'hash'],
+} as const;
+
+@Injectable()
+export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
+ constructor(
+ private httpRequestService: HttpRequestService,
+ ) {
+ super(meta, paramDef, async (ps) => {
+ const res = await this.httpRequestService.getJson<{
+ type: string;
+ data: string;
+ }>(ps.url);
+
+ if (!res.data || !res.type) {
+ throw new ApiError(meta.errors.invalidSchema);
+ }
+
+ const resHash = createHash('sha512').update(res.data.replace(/\r\n/g, '\n')).digest('hex');
+ if (resHash !== ps.hash) {
+ throw new ApiError(meta.errors.hashUnmached);
+ }
+
+ return {
+ type: res.type,
+ data: res.data,
+ };
+ });
+ }
+}
diff --git a/packages/backend/src/server/api/endpoints/following/update-all.ts b/packages/backend/src/server/api/endpoints/following/update-all.ts
new file mode 100644
index 0000000000..28734cfdbd
--- /dev/null
+++ b/packages/backend/src/server/api/endpoints/following/update-all.ts
@@ -0,0 +1,54 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import ms from 'ms';
+import { Inject, Injectable } from '@nestjs/common';
+import { Endpoint } from '@/server/api/endpoint-base.js';
+import type { FollowingsRepository } from '@/models/_.js';
+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 { ApiError } from '../../error.js';
+
+export const meta = {
+ tags: ['following', 'users'],
+
+ limit: {
+ duration: ms('1hour'),
+ max: 10,
+ },
+
+ requireCredential: true,
+
+ kind: 'write:following',
+} as const;
+
+export const paramDef = {
+ type: 'object',
+ properties: {
+ notify: { type: 'string', enum: ['normal', 'none'] },
+ withReplies: { type: 'boolean' },
+ },
+} as const;
+
+@Injectable()
+export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
+ constructor(
+ @Inject(DI.followingsRepository)
+ private followingsRepository: FollowingsRepository,
+ ) {
+ super(meta, paramDef, async (ps, me) => {
+ await this.followingsRepository.update({
+ followerId: me.id,
+ }, {
+ notify: ps.notify != null ? (ps.notify === 'none' ? null : ps.notify) : undefined,
+ withReplies: ps.withReplies != null ? ps.withReplies : undefined,
+ });
+
+ return;
+ });
+ }
+}
diff --git a/packages/backend/src/server/api/endpoints/get-avatar-decorations.ts b/packages/backend/src/server/api/endpoints/get-avatar-decorations.ts
new file mode 100644
index 0000000000..dbe1626149
--- /dev/null
+++ b/packages/backend/src/server/api/endpoints/get-avatar-decorations.ts
@@ -0,0 +1,82 @@
+/*
+ * SPDX-FileCopyrightText: syuilo and other misskey contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+import { IsNull } from 'typeorm';
+import { Inject, Injectable } from '@nestjs/common';
+import { Endpoint } from '@/server/api/endpoint-base.js';
+import { DI } from '@/di-symbols.js';
+import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
+import { RoleService } from '@/core/RoleService.js';
+
+export const meta = {
+ tags: ['users'],
+
+ requireCredential: false,
+
+ res: {
+ type: 'array',
+ optional: false, nullable: false,
+ items: {
+ type: 'object',
+ optional: false, nullable: false,
+ properties: {
+ id: {
+ type: 'string',
+ optional: false, nullable: false,
+ format: 'id',
+ example: 'xxxxxxxxxx',
+ },
+ name: {
+ type: 'string',
+ optional: false, nullable: false,
+ },
+ description: {
+ type: 'string',
+ optional: false, nullable: false,
+ },
+ url: {
+ type: 'string',
+ optional: false, nullable: false,
+ },
+ roleIdsThatCanBeUsedThisDecoration: {
+ type: 'array',
+ optional: false, nullable: false,
+ items: {
+ type: 'string',
+ optional: false, nullable: false,
+ format: 'id',
+ },
+ },
+ },
+ },
+ },
+} as const;
+
+export const paramDef = {
+ type: 'object',
+ properties: {},
+ required: [],
+} as const;
+
+@Injectable()
+export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
+ constructor(
+ private avatarDecorationService: AvatarDecorationService,
+ private roleService: RoleService,
+ ) {
+ super(meta, paramDef, async (ps, me) => {
+ const decorations = await this.avatarDecorationService.getAll(true);
+ const allRoles = await this.roleService.getRoles();
+
+ return decorations.map(decoration => ({
+ id: decoration.id,
+ name: decoration.name,
+ description: decoration.description,
+ url: decoration.url,
+ roleIdsThatCanBeUsedThisDecoration: decoration.roleIdsThatCanBeUsedThisDecoration.filter(roleId => allRoles.some(role => role.id === roleId)),
+ }));
+ });
+ }
+}
diff --git a/packages/backend/src/server/api/endpoints/i/revoke-token.ts b/packages/backend/src/server/api/endpoints/i/revoke-token.ts
index 8e2f271005..e8bb282533 100644
--- a/packages/backend/src/server/api/endpoints/i/revoke-token.ts
+++ b/packages/backend/src/server/api/endpoints/i/revoke-token.ts
@@ -18,8 +18,12 @@ export const paramDef = {
type: 'object',
properties: {
tokenId: { type: 'string', format: 'misskey:id' },
+ token: { type: 'string' },
},
- required: ['tokenId'],
+ anyOf: [
+ { required: ['tokenId'] },
+ { required: ['token'] },
+ ],
} as const;
@Injectable()
@@ -29,13 +33,24 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private accessTokensRepository: AccessTokensRepository,
) {
super(meta, paramDef, async (ps, me) => {
- const tokenExist = await this.accessTokensRepository.exist({ where: { id: ps.tokenId } });
+ if (ps.tokenId) {
+ const tokenExist = await this.accessTokensRepository.exist({ where: { id: ps.tokenId } });
- if (tokenExist) {
- await this.accessTokensRepository.delete({
- id: ps.tokenId,
- userId: me.id,
- });
+ if (tokenExist) {
+ await this.accessTokensRepository.delete({
+ id: ps.tokenId,
+ userId: me.id,
+ });
+ }
+ } else if (ps.token) {
+ const tokenExist = await this.accessTokensRepository.exist({ where: { token: ps.token } });
+
+ if (tokenExist) {
+ await this.accessTokensRepository.delete({
+ token: ps.token,
+ userId: me.id,
+ });
+ }
}
});
}
diff --git a/packages/backend/src/server/api/endpoints/i/update.ts b/packages/backend/src/server/api/endpoints/i/update.ts
index 1011a8d31a..ec2d5d6579 100644
--- a/packages/backend/src/server/api/endpoints/i/update.ts
+++ b/packages/backend/src/server/api/endpoints/i/update.ts
@@ -32,6 +32,7 @@ import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.j
import { HttpRequestService } from '@/core/HttpRequestService.js';
import type { Config } from '@/config.js';
import { safeForSql } from '@/misc/safe-for-sql.js';
+import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
import { ApiLoggerService } from '../../ApiLoggerService.js';
import { ApiError } from '../../error.js';
@@ -144,6 +145,15 @@ export const paramDef = {
listenbrainz: { ...listenbrainzSchema, nullable: true },
lang: { type: 'string', enum: [null, ...Object.keys(langmap)] as string[], nullable: true },
avatarId: { type: 'string', format: 'misskey:id', nullable: true },
+ avatarDecorations: { type: 'array', maxItems: 1, items: {
+ type: 'object',
+ properties: {
+ id: { type: 'string', format: 'misskey:id' },
+ angle: { type: 'number', nullable: true, maximum: 0.5, minimum: -0.5 },
+ flipH: { type: 'boolean', nullable: true },
+ },
+ required: ['id'],
+ } },
bannerId: { type: 'string', format: 'misskey:id', nullable: true },
backgroundId: { type: 'string', format: 'misskey:id', nullable: true },
fields: {
@@ -222,6 +232,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private roleService: RoleService,
private cacheService: CacheService,
private httpRequestService: HttpRequestService,
+ private avatarDecorationService: AvatarDecorationService,
) {
super(meta, paramDef, async (ps, _user, token) => {
const user = await this.usersRepository.findOneByOrFail({ id: _user.id }) as MiLocalUser;
@@ -327,6 +338,21 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
updates.backgroundUrl = null;
updates.backgroundBlurhash = null;
}
+
+ if (ps.avatarDecorations) {
+ const decorations = await this.avatarDecorationService.getAll(true);
+ const myRoles = await this.roleService.getUserRoles(user.id);
+ const allRoles = await this.roleService.getRoles();
+ const decorationIds = decorations
+ .filter(d => d.roleIdsThatCanBeUsedThisDecoration.filter(roleId => allRoles.some(r => r.id === roleId)).length === 0 || myRoles.some(r => d.roleIdsThatCanBeUsedThisDecoration.includes(r.id)))
+ .map(d => d.id);
+
+ updates.avatarDecorations = ps.avatarDecorations.filter(d => decorationIds.includes(d.id)).map(d => ({
+ id: d.id,
+ angle: d.angle ?? 0,
+ flipH: d.flipH ?? false,
+ }));
+ }
if (ps.pinnedPageId) {
const page = await this.pagesRepository.findOneBy({ id: ps.pinnedPageId });
@@ -453,9 +479,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const myLink = `${this.config.url}/@${user.username}`;
- const includesMyLink = Array.from(doc.getElementsByTagName('a')).some(a => a.href === myLink);
+ const aEls = Array.from(doc.getElementsByTagName('a'));
+ const linkEls = Array.from(doc.getElementsByTagName('link'));
+
+ const includesMyLink = aEls.some(a => a.href === myLink);
+ const includesRelMeLinks = [...aEls, ...linkEls].some(link => link.rel === 'me' && link.href === myLink);
- if (includesMyLink) {
+ if (includesMyLink || includesRelMeLinks) {
await this.userProfilesRepository.createQueryBuilder('profile').update()
.where('userId = :userId', { userId: user.id })
.set({
diff --git a/packages/backend/src/server/api/endpoints/notes/create.ts b/packages/backend/src/server/api/endpoints/notes/create.ts
index 3ae4ac044a..649068fb20 100644
--- a/packages/backend/src/server/api/endpoints/notes/create.ts
+++ b/packages/backend/src/server/api/endpoints/notes/create.ts
@@ -17,6 +17,7 @@ import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { NoteCreateService } from '@/core/NoteCreateService.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '../../error.js';
+import { isPureRenote } from '@/misc/is-pure-renote.js';
export const meta = {
tags: ['notes'],
@@ -221,7 +222,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (renote == null) {
throw new ApiError(meta.errors.noSuchRenoteTarget);
- } else if (renote.renoteId && !renote.text && !renote.fileIds && !renote.hasPoll) {
+ } else if (isPureRenote(renote)) {
throw new ApiError(meta.errors.cannotReRenote);
}
@@ -254,7 +255,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (reply == null) {
throw new ApiError(meta.errors.noSuchReplyTarget);
- } else if (reply.renoteId && !reply.text && !reply.fileIds && !reply.hasPoll) {
+ } else if (isPureRenote(reply)) {
throw new ApiError(meta.errors.cannotReplyToPureRenote);
}
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 ada88ea4f2..47dda846a7 100644
--- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts
@@ -5,7 +5,7 @@
import { Brackets } from 'typeorm';
import { Inject, Injectable } from '@nestjs/common';
-import type { NotesRepository, FollowingsRepository, MiNote } from '@/models/_.js';
+import type { NotesRepository, FollowingsRepository, MiNote, ChannelFollowingsRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import ActiveUsersChart from '@/core/chart/charts/active-users.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
@@ -17,6 +17,8 @@ import { CacheService } from '@/core/CacheService.js';
import { FunoutTimelineService } from '@/core/FunoutTimelineService.js';
import { QueryService } from '@/core/QueryService.js';
import { UserFollowingService } from '@/core/UserFollowingService.js';
+import { MetaService } from '@/core/MetaService.js';
+import { MiLocalUser } from '@/models/User.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -68,6 +70,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,
+ @Inject(DI.channelFollowingsRepository)
+ private channelFollowingsRepository: ChannelFollowingsRepository,
+
private noteEntityService: NoteEntityService,
private roleService: RoleService,
private activeUsersChart: ActiveUsersChart,
@@ -76,6 +81,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private funoutTimelineService: FunoutTimelineService,
private queryService: QueryService,
private userFollowingService: UserFollowingService,
+ private metaService: MetaService,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
@@ -86,171 +92,224 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.stlDisabled);
}
- const [
- followings,
- userIdsWhoMeMuting,
- userIdsWhoMeMutingRenotes,
- userIdsWhoBlockingMe,
- ] = await Promise.all([
- this.cacheService.userFollowingsCache.fetch(me.id),
- this.cacheService.userMutingsCache.fetch(me.id),
- this.cacheService.renoteMutingsCache.fetch(me.id),
- this.cacheService.userBlockedCache.fetch(me.id),
- ]);
+ const serverSettings = await this.metaService.fetch();
- let noteIds: string[];
- let shouldFallbackToDb = false;
+ if (serverSettings.enableFanoutTimeline) {
+ const [
+ userIdsWhoMeMuting,
+ userIdsWhoMeMutingRenotes,
+ userIdsWhoBlockingMe,
+ ] = await Promise.all([
+ this.cacheService.userMutingsCache.fetch(me.id),
+ this.cacheService.renoteMutingsCache.fetch(me.id),
+ this.cacheService.userBlockedCache.fetch(me.id),
+ ]);
- if (ps.withFiles) {
- const [htlNoteIds, ltlNoteIds] = await this.funoutTimelineService.getMulti([
- `homeTimelineWithFiles:${me.id}`,
- 'localTimelineWithFiles',
- ], untilId, sinceId);
- noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds]));
- } else if (ps.withReplies) {
- const [htlNoteIds, ltlNoteIds, ltlReplyNoteIds] = await this.funoutTimelineService.getMulti([
- `homeTimeline:${me.id}`,
- 'localTimeline',
- 'localTimelineWithReplies',
- ], untilId, sinceId);
- noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds, ...ltlReplyNoteIds]));
- } else {
- const [htlNoteIds, ltlNoteIds] = await this.funoutTimelineService.getMulti([
- `homeTimeline:${me.id}`,
- 'localTimeline',
- ], untilId, sinceId);
- noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds]));
- shouldFallbackToDb = htlNoteIds.length === 0;
- }
+ let noteIds: string[];
+ let shouldFallbackToDb = false;
- noteIds.sort((a, b) => a > b ? -1 : 1);
- noteIds = noteIds.slice(0, ps.limit);
+ if (ps.withFiles) {
+ const [htlNoteIds, ltlNoteIds] = await this.funoutTimelineService.getMulti([
+ `homeTimelineWithFiles:${me.id}`,
+ 'localTimelineWithFiles',
+ ], untilId, sinceId);
+ noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds]));
+ } else if (ps.withReplies) {
+ const [htlNoteIds, ltlNoteIds, ltlReplyNoteIds] = await this.funoutTimelineService.getMulti([
+ `homeTimeline:${me.id}`,
+ 'localTimeline',
+ 'localTimelineWithReplies',
+ ], untilId, sinceId);
+ noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds, ...ltlReplyNoteIds]));
+ } else {
+ const [htlNoteIds, ltlNoteIds] = await this.funoutTimelineService.getMulti([
+ `homeTimeline:${me.id}`,
+ 'localTimeline',
+ ], untilId, sinceId);
+ noteIds = Array.from(new Set([...htlNoteIds, ...ltlNoteIds]));
+ shouldFallbackToDb = htlNoteIds.length === 0;
+ }
- if (!shouldFallbackToDb) {
- const query = this.notesRepository.createQueryBuilder('note')
- .where('note.id IN (:...noteIds)', { noteIds: noteIds })
- .innerJoinAndSelect('note.user', 'user')
- .leftJoinAndSelect('note.reply', 'reply')
- .leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser')
- .leftJoinAndSelect('note.channel', 'channel');
+ noteIds.sort((a, b) => a > b ? -1 : 1);
+ noteIds = noteIds.slice(0, ps.limit);
- if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+ shouldFallbackToDb = shouldFallbackToDb || (noteIds.length === 0);
- let timeline = await query.getMany();
+ let redisTimeline: MiNote[] = [];
- timeline = timeline.filter(note => {
- if (note.userId === me.id) {
- return true;
- }
- if (isUserRelated(note, userIdsWhoBlockingMe)) return false;
- if (isUserRelated(note, userIdsWhoMeMuting)) return false;
- if (note.renoteId) {
- if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) {
- if (isUserRelated(note, userIdsWhoMeMutingRenotes)) return false;
- if (ps.withRenotes === false) return false;
- }
- }
- if (note.user?.isSilenced && note.userId !== me.id && !followings[note.userId]) return false;
+ if (!shouldFallbackToDb) {
+ const query = this.notesRepository.createQueryBuilder('note')
+ .where('note.id IN (:...noteIds)', { noteIds: noteIds })
+ .innerJoinAndSelect('note.user', 'user')
+ .leftJoinAndSelect('note.reply', 'reply')
+ .leftJoinAndSelect('note.renote', 'renote')
+ .leftJoinAndSelect('reply.user', 'replyUser')
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .leftJoinAndSelect('note.channel', 'channel');
- return true;
- });
+ redisTimeline = await query.getMany();
- // TODO: フィルタした結果件数が足りなかった場合の対応
+ redisTimeline = redisTimeline.filter(note => {
+ if (note.userId === me.id) {
+ return true;
+ }
+ if (isUserRelated(note, userIdsWhoBlockingMe)) return false;
+ if (isUserRelated(note, userIdsWhoMeMuting)) return false;
+ if (note.renoteId) {
+ if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) {
+ if (isUserRelated(note, userIdsWhoMeMutingRenotes)) return false;
+ if (ps.withRenotes === false) return false;
+ }
+ }
+ if (!ps.withBots && note.user?.isBot) return false;
- timeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ return true;
+ });
- process.nextTick(() => {
- this.activeUsersChart.read(me);
- });
+ redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ }
- return await this.noteEntityService.packMany(timeline, me);
- } else { // fallback to db
- const followees = await this.userFollowingService.getFollowees(me.id);
+ if (redisTimeline.length > 0) {
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
- const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
- .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)');
- }
- }))
- .innerJoinAndSelect('note.user', 'user')
- .leftJoinAndSelect('note.reply', 'reply')
- .leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ return await this.noteEntityService.packMany(redisTimeline, me);
+ } else { // fallback to db
+ return await this.getFromDb({
+ untilId,
+ sinceId,
+ limit: ps.limit,
+ includeMyRenotes: ps.includeMyRenotes,
+ includeRenotedMyNotes: ps.includeRenotedMyNotes,
+ includeLocalRenotes: ps.includeLocalRenotes,
+ withFiles: ps.withFiles,
+ withReplies: ps.withReplies,
+ withBots: ps.withBots,
+ }, me);
+ }
+ } else {
+ return await this.getFromDb({
+ untilId,
+ sinceId,
+ limit: ps.limit,
+ includeMyRenotes: ps.includeMyRenotes,
+ includeRenotedMyNotes: ps.includeRenotedMyNotes,
+ includeLocalRenotes: ps.includeLocalRenotes,
+ withFiles: ps.withFiles,
+ withReplies: ps.withReplies,
+ withBots: ps.withBots,
+ }, me);
+ }
+ });
+ }
- if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+ private async getFromDb(ps: {
+ untilId: string | null,
+ sinceId: string | null,
+ limit: number,
+ includeMyRenotes: boolean,
+ includeRenotedMyNotes: boolean,
+ includeLocalRenotes: boolean,
+ withFiles: boolean,
+ withReplies: boolean,
+ withBots: boolean,
+ }, me: MiLocalUser) {
+ const followees = await this.userFollowingService.getFollowees(me.id);
+ const followingChannels = await this.channelFollowingsRepository.find({
+ where: {
+ followerId: 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');
- }));
- }));
+ 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)');
+ }
+ }))
+ .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.generateMutedUserQuery(query, me);
- this.queryService.generateBlockedUserQuery(query, me);
- this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ if (followingChannels.length > 0) {
+ const followingChannelIds = followingChannels.map(x => x.followeeId);
- 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)');
- }));
- }
+ 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');
+ }
- 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.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.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)');
- }));
- }
+ this.queryService.generateVisibilityQuery(query, me);
+ this.queryService.generateMutedUserQuery(query, me);
+ this.queryService.generateBlockedUserQuery(query, me);
+ this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
- if (ps.withFiles) {
- query.andWhere('note.fileIds != \'{}\'');
- }
- //#endregion
+ 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)');
+ }));
+ }
- let timeline = await query.limit(ps.limit).getMany();
+ 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)');
+ }));
+ }
- timeline = timeline.filter(note => {
- if (note.user?.isSilenced && note.userId !== me.id && !followings[note.userId]) return false;
- return true;
- });
+ 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)');
+ }));
+ }
- process.nextTick(() => {
- this.activeUsersChart.read(me);
- });
+ if (ps.withFiles) {
+ query.andWhere('note.fileIds != \'{}\'');
+ }
- return await this.noteEntityService.packMany(timeline, me);
- }
+ if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+ //#endregion
+
+ const timeline = await query.limit(ps.limit).getMany();
+
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
});
+
+ return await this.noteEntityService.packMany(timeline, me);
}
}
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 85560f12ca..dec34860b5 100644
--- a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts
@@ -16,6 +16,8 @@ import { CacheService } from '@/core/CacheService.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import { FunoutTimelineService } from '@/core/FunoutTimelineService.js';
import { QueryService } from '@/core/QueryService.js';
+import { MetaService } from '@/core/MetaService.js';
+import { MiLocalUser } from '@/models/User.js';
import { ApiError } from '../../error.js';
export const meta = {
@@ -70,6 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private cacheService: CacheService,
private funoutTimelineService: FunoutTimelineService,
private queryService: QueryService,
+ private metaService: MetaService,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
@@ -80,112 +83,148 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.ltlDisabled);
}
- const [
- followings,
- userIdsWhoMeMuting,
- userIdsWhoMeMutingRenotes,
- userIdsWhoBlockingMe,
- ] = me ? await Promise.all([
- this.cacheService.userFollowingsCache.fetch(me.id),
- this.cacheService.userMutingsCache.fetch(me.id),
- this.cacheService.renoteMutingsCache.fetch(me.id),
- this.cacheService.userBlockedCache.fetch(me.id),
- ]) : [undefined, new Set<string>(), new Set<string>(), new Set<string>()];
+ const serverSettings = await this.metaService.fetch();
- let noteIds: string[];
+ if (serverSettings.enableFanoutTimeline) {
+ const [
+ userIdsWhoMeMuting,
+ userIdsWhoMeMutingRenotes,
+ userIdsWhoBlockingMe,
+ ] = me ? await Promise.all([
+ this.cacheService.userMutingsCache.fetch(me.id),
+ this.cacheService.renoteMutingsCache.fetch(me.id),
+ this.cacheService.userBlockedCache.fetch(me.id),
+ ]) : [new Set<string>(), new Set<string>(), new Set<string>()];
- if (ps.withFiles) {
- noteIds = await this.funoutTimelineService.get('localTimelineWithFiles', untilId, sinceId);
- } else {
- const [nonReplyNoteIds, replyNoteIds] = await this.funoutTimelineService.getMulti([
- 'localTimeline',
- 'localTimelineWithReplies',
- ], untilId, sinceId);
- noteIds = Array.from(new Set([...nonReplyNoteIds, ...replyNoteIds]));
- noteIds.sort((a, b) => a > b ? -1 : 1);
- }
+ let noteIds: string[];
- noteIds = noteIds.slice(0, ps.limit);
+ if (ps.withFiles) {
+ noteIds = await this.funoutTimelineService.get('localTimelineWithFiles', untilId, sinceId);
+ } else {
+ const [nonReplyNoteIds, replyNoteIds] = await this.funoutTimelineService.getMulti([
+ 'localTimeline',
+ 'localTimelineWithReplies',
+ ], untilId, sinceId);
+ noteIds = Array.from(new Set([...nonReplyNoteIds, ...replyNoteIds]));
+ noteIds.sort((a, b) => a > b ? -1 : 1);
+ }
- if (noteIds.length > 0) {
- const query = this.notesRepository.createQueryBuilder('note')
- .where('note.id IN (:...noteIds)', { noteIds: noteIds })
- .innerJoinAndSelect('note.user', 'user')
- .leftJoinAndSelect('note.reply', 'reply')
- .leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser')
- .leftJoinAndSelect('note.channel', 'channel');
+ noteIds = noteIds.slice(0, ps.limit);
- if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+ let redisTimeline: MiNote[] = [];
- let timeline = await query.getMany();
+ if (noteIds.length > 0) {
+ const query = this.notesRepository.createQueryBuilder('note')
+ .where('note.id IN (:...noteIds)', { noteIds: noteIds })
+ .innerJoinAndSelect('note.user', 'user')
+ .leftJoinAndSelect('note.reply', 'reply')
+ .leftJoinAndSelect('note.renote', 'renote')
+ .leftJoinAndSelect('reply.user', 'replyUser')
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .leftJoinAndSelect('note.channel', 'channel');
- timeline = timeline.filter(note => {
- if (me && (note.userId === me.id)) {
- return true;
- }
- if (!ps.withReplies && note.replyId && (me == null || note.replyUserId !== me.id)) return false;
- if (me && isUserRelated(note, userIdsWhoBlockingMe)) return false;
- if (me && isUserRelated(note, userIdsWhoMeMuting)) return false;
- if (note.renoteId) {
- if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) {
- if (me && isUserRelated(note, userIdsWhoMeMutingRenotes)) return false;
- if (ps.withRenotes === false) return false;
- }
- }
- if (note.user?.isSilenced && me && followings && note.userId !== me.id && !followings[note.userId]) return false;
+ redisTimeline = await query.getMany();
- return true;
- });
+ redisTimeline = redisTimeline.filter(note => {
+ if (me && (note.userId === me.id)) {
+ return true;
+ }
+ if (!ps.withReplies && note.replyId && note.replyUserId !== note.userId && (me == null || note.replyUserId !== me.id)) return false;
+ if (!ps.withBots && note.user?.isBot) return false;
+ if (me && isUserRelated(note, userIdsWhoBlockingMe)) return false;
+ if (me && isUserRelated(note, userIdsWhoMeMuting)) return false;
+ if (note.renoteId) {
+ if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) {
+ if (me && isUserRelated(note, userIdsWhoMeMutingRenotes)) return false;
+ if (ps.withRenotes === false) return false;
+ }
+ }
- // TODO: フィルタした結果件数が足りなかった場合の対応
+ return true;
+ });
- timeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ }
- process.nextTick(() => {
- if (me) {
- this.activeUsersChart.read(me);
- }
- });
+ if (redisTimeline.length > 0) {
+ process.nextTick(() => {
+ if (me) {
+ this.activeUsersChart.read(me);
+ }
+ });
- return await this.noteEntityService.packMany(timeline, me);
- } else { // fallback to db
- const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'),
- ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
- .andWhere('(note.visibility = \'public\') AND (note.userHost IS NULL)')
- .innerJoinAndSelect('note.user', 'user')
- .leftJoinAndSelect('note.reply', 'reply')
- .leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ return await this.noteEntityService.packMany(redisTimeline, me);
+ } else { // fallback to db
+ return await this.getFromDb({
+ untilId,
+ sinceId,
+ limit: ps.limit,
+ withFiles: ps.withFiles,
+ withReplies: ps.withReplies,
+ withBots: ps.withBots,
+ }, me);
+ }
+ } else {
+ return await this.getFromDb({
+ untilId,
+ sinceId,
+ limit: ps.limit,
+ withFiles: ps.withFiles,
+ withReplies: ps.withReplies,
+ withBots: ps.withBots,
+ }, me);
+ }
+ });
+ }
- if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+ private async getFromDb(ps: {
+ sinceId: string | null,
+ untilId: string | null,
+ limit: number,
+ withFiles: boolean,
+ withReplies: boolean,
+ withBots: 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)')
+ .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);
- if (me) this.queryService.generateMutedUserQuery(query, me);
- if (me) this.queryService.generateBlockedUserQuery(query, me);
- if (me) this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ this.queryService.generateVisibilityQuery(query, me);
+ if (me) this.queryService.generateMutedUserQuery(query, me);
+ if (me) this.queryService.generateBlockedUserQuery(query, me);
+ if (me) this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
- if (ps.withFiles) {
- query.andWhere('note.fileIds != \'{}\'');
- }
+ if (ps.withFiles) {
+ query.andWhere('note.fileIds != \'{}\'');
+ }
- let timeline = await query.limit(ps.limit).getMany();
+ 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');
+ }));
+ }));
+ }
- timeline = timeline.filter(note => {
- if (note.user?.isSilenced && me && followings && note.userId !== me.id && !followings[note.userId]) return false;
- return true;
- });
+ if (!ps.withBots) query.andWhere('user.isBot = FALSE');
- process.nextTick(() => {
- if (me) {
- this.activeUsersChart.read(me);
- }
- });
+ const timeline = await query.limit(ps.limit).getMany();
- return await this.noteEntityService.packMany(timeline, me);
+ process.nextTick(() => {
+ if (me) {
+ this.activeUsersChart.read(me);
}
});
+
+ return await this.noteEntityService.packMany(timeline, me);
}
}
diff --git a/packages/backend/src/server/api/endpoints/notes/timeline.ts b/packages/backend/src/server/api/endpoints/notes/timeline.ts
index b98d1d9f91..e58e524988 100644
--- a/packages/backend/src/server/api/endpoints/notes/timeline.ts
+++ b/packages/backend/src/server/api/endpoints/notes/timeline.ts
@@ -5,7 +5,7 @@
import { Brackets } from 'typeorm';
import { Inject, Injectable } from '@nestjs/common';
-import type { NotesRepository } from '@/models/_.js';
+import type { MiNote, NotesRepository, ChannelFollowingsRepository } from '@/models/_.js';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { QueryService } from '@/core/QueryService.js';
import ActiveUsersChart from '@/core/chart/charts/active-users.js';
@@ -16,6 +16,8 @@ import { CacheService } from '@/core/CacheService.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import { FunoutTimelineService } from '@/core/FunoutTimelineService.js';
import { UserFollowingService } from '@/core/UserFollowingService.js';
+import { MiLocalUser } from '@/models/User.js';
+import { MetaService } from '@/core/MetaService.js';
export const meta = {
tags: ['notes'],
@@ -57,6 +59,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,
+ @Inject(DI.channelFollowingsRepository)
+ private channelFollowingsRepository: ChannelFollowingsRepository,
+
private noteEntityService: NoteEntityService,
private activeUsersChart: ActiveUsersChart,
private idService: IdService,
@@ -64,154 +69,214 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private funoutTimelineService: FunoutTimelineService,
private userFollowingService: UserFollowingService,
private queryService: QueryService,
+ private metaService: MetaService,
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.gen(ps.sinceDate!) : null);
- const [
- followings,
- userIdsWhoMeMuting,
- userIdsWhoMeMutingRenotes,
- userIdsWhoBlockingMe,
- ] = await Promise.all([
- this.cacheService.userFollowingsCache.fetch(me.id),
- this.cacheService.userMutingsCache.fetch(me.id),
- this.cacheService.renoteMutingsCache.fetch(me.id),
- this.cacheService.userBlockedCache.fetch(me.id),
- ]);
-
- let noteIds = await this.funoutTimelineService.get(ps.withFiles ? `homeTimelineWithFiles:${me.id}` : `homeTimeline:${me.id}`, untilId, sinceId);
- noteIds = noteIds.slice(0, ps.limit);
+ const serverSettings = await this.metaService.fetch();
- if (noteIds.length > 0) {
- const query = this.notesRepository.createQueryBuilder('note')
- .where('note.id IN (:...noteIds)', { noteIds: noteIds })
- .innerJoinAndSelect('note.user', 'user')
- .leftJoinAndSelect('note.reply', 'reply')
- .leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser')
- .leftJoinAndSelect('note.channel', 'channel');
+ if (serverSettings.enableFanoutTimeline) {
+ const [
+ followings,
+ userIdsWhoMeMuting,
+ userIdsWhoMeMutingRenotes,
+ userIdsWhoBlockingMe,
+ ] = await Promise.all([
+ this.cacheService.userFollowingsCache.fetch(me.id),
+ this.cacheService.userMutingsCache.fetch(me.id),
+ this.cacheService.renoteMutingsCache.fetch(me.id),
+ this.cacheService.userBlockedCache.fetch(me.id),
+ ]);
- if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+ let noteIds = await this.funoutTimelineService.get(ps.withFiles ? `homeTimelineWithFiles:${me.id}` : `homeTimeline:${me.id}`, untilId, sinceId);
+ noteIds = noteIds.slice(0, ps.limit);
- let timeline = await query.getMany();
+ let redisTimeline: MiNote[] = [];
- timeline = timeline.filter(note => {
- if (note.userId === me.id) {
- return true;
- }
- if (isUserRelated(note, userIdsWhoBlockingMe)) return false;
- if (isUserRelated(note, userIdsWhoMeMuting)) return false;
- if (note.renoteId) {
- if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) {
- if (isUserRelated(note, userIdsWhoMeMutingRenotes)) return false;
- if (ps.withRenotes === false) return false;
- }
- }
- if (note.reply && note.reply.visibility === 'followers') {
- if (!Object.hasOwn(followings, note.reply.userId)) return false;
- }
- if (note.user?.isSilenced && note.userId !== me.id && !followings[note.userId]) return false;
+ if (noteIds.length > 0) {
+ const query = this.notesRepository.createQueryBuilder('note')
+ .where('note.id IN (:...noteIds)', { noteIds: noteIds })
+ .innerJoinAndSelect('note.user', 'user')
+ .leftJoinAndSelect('note.reply', 'reply')
+ .leftJoinAndSelect('note.renote', 'renote')
+ .leftJoinAndSelect('reply.user', 'replyUser')
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .leftJoinAndSelect('note.channel', 'channel');
- return true;
- });
+ redisTimeline = await query.getMany();
- // TODO: フィルタした結果件数が足りなかった場合の対応
+ redisTimeline = redisTimeline.filter(note => {
+ if (note.userId === me.id) {
+ return true;
+ }
+ if (isUserRelated(note, userIdsWhoBlockingMe)) return false;
+ if (isUserRelated(note, userIdsWhoMeMuting)) return false;
+ if (note.renoteId) {
+ if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) {
+ if (isUserRelated(note, userIdsWhoMeMutingRenotes)) return false;
+ if (ps.withRenotes === false) return false;
+ }
+ }
+ if (note.reply && note.reply.visibility === 'followers') {
+ if (!Object.hasOwn(followings, note.reply.userId)) return false;
+ }
+ if (!ps.withBots && note.user?.isBot) return false;
- timeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ return true;
+ });
- process.nextTick(() => {
- this.activeUsersChart.read(me);
- });
+ redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ }
- return await this.noteEntityService.packMany(timeline, me);
- } else { // fallback to db
- const followees = await this.userFollowingService.getFollowees(me.id);
+ if (redisTimeline.length > 0) {
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
+ });
- //#region Construct query
- const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
- .andWhere('note.channelId IS NULL')
- .innerJoinAndSelect('note.user', 'user')
- .leftJoinAndSelect('note.reply', 'reply')
- .leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser');
+ return await this.noteEntityService.packMany(redisTimeline, me);
+ } else { // fallback to db
+ return await this.getFromDb({
+ untilId,
+ sinceId,
+ limit: ps.limit,
+ includeMyRenotes: ps.includeMyRenotes,
+ includeRenotedMyNotes: ps.includeRenotedMyNotes,
+ includeLocalRenotes: ps.includeLocalRenotes,
+ withFiles: ps.withFiles,
+ withRenotes: ps.withRenotes,
+ withBots: ps.withBots,
+ }, me);
+ }
+ } else {
+ return await this.getFromDb({
+ untilId,
+ sinceId,
+ limit: ps.limit,
+ includeMyRenotes: ps.includeMyRenotes,
+ includeRenotedMyNotes: ps.includeRenotedMyNotes,
+ includeLocalRenotes: ps.includeLocalRenotes,
+ withFiles: ps.withFiles,
+ withRenotes: ps.withRenotes,
+ withBots: ps.withBots,
+ }, me);
+ }
+ });
+ }
- if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+ 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,
+ },
+ });
- if (followees.length > 0) {
- const meOrFolloweeIds = [me.id, ...followees.map(f => f.followeeId)];
+ //#region Construct query
+ const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
+ .innerJoinAndSelect('note.user', 'user')
+ .leftJoinAndSelect('note.reply', 'reply')
+ .leftJoinAndSelect('note.renote', 'renote')
+ .leftJoinAndSelect('reply.user', 'replyUser')
+ .leftJoinAndSelect('renote.user', 'renoteUser');
- query.andWhere('note.userId IN (:...meOrFolloweeIds)', { meOrFolloweeIds: meOrFolloweeIds });
- } else {
- query.andWhere('note.userId = :meId', { meId: me.id });
- }
+ 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');
- }));
+ 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');
}));
+ }));
- this.queryService.generateVisibilityQuery(query, me);
- this.queryService.generateMutedUserQuery(query, me);
- this.queryService.generateBlockedUserQuery(query, me);
- this.queryService.generateMutedUserRenotesQueryForNotes(query, me);
+ this.queryService.generateVisibilityQuery(query, me);
+ this.queryService.generateMutedUserQuery(query, me);
+ this.queryService.generateBlockedUserQuery(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.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.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.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 != \'{}\'');
- }
- //#endregion
+ if (ps.withFiles) {
+ query.andWhere('note.fileIds != \'{}\'');
+ }
- let timeline = await query.limit(ps.limit).getMany();
+ if (ps.withRenotes === false) {
+ query.andWhere('note.renoteId IS NULL');
+ }
- timeline = timeline.filter(note => {
- if (note.user?.isSilenced && note.userId !== me.id && !followings[note.userId]) return false;
- return true;
- });
+ if (!ps.withBots) query.andWhere('user.isBot = FALSE');
+ //#endregion
- process.nextTick(() => {
- this.activeUsersChart.read(me);
- });
+ const timeline = await query.limit(ps.limit).getMany();
- return await this.noteEntityService.packMany(timeline, me);
- }
+ process.nextTick(() => {
+ this.activeUsersChart.read(me);
});
+
+ return await this.noteEntityService.packMany(timeline, me);
}
}
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 2b31e6169c..9ead1410c2 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
@@ -3,12 +3,9 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import { Brackets } from 'typeorm';
import { Inject, Injectable } from '@nestjs/common';
-import * as Redis from 'ioredis';
-import type { NotesRepository, UserListsRepository, UserListMembershipsRepository, MiNote } from '@/models/_.js';
+import type { MiNote, NotesRepository, UserListMembershipsRepository, UserListsRepository } 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';
@@ -16,7 +13,9 @@ import { CacheService } from '@/core/CacheService.js';
import { IdService } from '@/core/IdService.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import { FunoutTimelineService } from '@/core/FunoutTimelineService.js';
+import { QueryService } from '@/core/QueryService.js';
import { ApiError } from '../../error.js';
+import { Brackets } from 'typeorm';
export const meta = {
tags: ['notes', 'lists'],
@@ -67,20 +66,22 @@ export const paramDef = {
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
- @Inject(DI.redisForTimelines)
- private redisForTimelines: Redis.Redis,
-
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,
@Inject(DI.userListsRepository)
private userListsRepository: UserListsRepository,
+ @Inject(DI.userListMembershipsRepository)
+ private userListMembershipsRepository: UserListMembershipsRepository,
+
private noteEntityService: NoteEntityService,
private activeUsersChart: ActiveUsersChart,
private cacheService: CacheService,
private idService: IdService,
private funoutTimelineService: FunoutTimelineService,
+ private queryService: QueryService,
+
) {
super(meta, paramDef, async (ps, me) => {
const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null);
@@ -108,44 +109,129 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
let noteIds = await this.funoutTimelineService.get(ps.withFiles ? `userListTimelineWithFiles:${list.id}` : `userListTimeline:${list.id}`, untilId, sinceId);
noteIds = noteIds.slice(0, ps.limit);
- if (noteIds.length === 0) {
- return [];
- }
+ let redisTimeline: MiNote[] = [];
+
+ if (noteIds.length > 0) {
+ const query = this.notesRepository.createQueryBuilder('note')
+ .where('note.id IN (:...noteIds)', { noteIds: noteIds })
+ .innerJoinAndSelect('note.user', 'user')
+ .leftJoinAndSelect('note.reply', 'reply')
+ .leftJoinAndSelect('note.renote', 'renote')
+ .leftJoinAndSelect('reply.user', 'replyUser')
+ .leftJoinAndSelect('renote.user', 'renoteUser')
+ .leftJoinAndSelect('note.channel', 'channel');
- const query = this.notesRepository.createQueryBuilder('note')
- .where('note.id IN (:...noteIds)', { noteIds: noteIds })
- .innerJoinAndSelect('note.user', 'user')
- .leftJoinAndSelect('note.reply', 'reply')
- .leftJoinAndSelect('note.renote', 'renote')
- .leftJoinAndSelect('reply.user', 'replyUser')
- .leftJoinAndSelect('renote.user', 'renoteUser')
- .leftJoinAndSelect('note.channel', 'channel');
+ redisTimeline = await query.getMany();
- let timeline = await query.getMany();
+ redisTimeline = redisTimeline.filter(note => {
+ if (note.userId === me.id) {
+ return true;
+ }
+ if (isUserRelated(note, userIdsWhoBlockingMe)) return false;
+ if (isUserRelated(note, userIdsWhoMeMuting)) return false;
+ if (note.renoteId) {
+ if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) {
+ if (isUserRelated(note, userIdsWhoMeMutingRenotes)) return false;
+ if (ps.withRenotes === false) return false;
+ }
+ }
- timeline = timeline.filter(note => {
- if (note.userId === me.id) {
return true;
+ });
+
+ redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ }
+
+ if (redisTimeline.length > 0) {
+ this.activeUsersChart.read(me);
+ return await this.noteEntityService.packMany(redisTimeline, me);
+ } else { // fallback to db
+ //#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')
+ .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');
+ }));
+ }));
+
+ this.queryService.generateVisibilityQuery(query, me);
+ this.queryService.generateMutedUserQuery(query, me);
+ this.queryService.generateBlockedUserQuery(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 (isUserRelated(note, userIdsWhoBlockingMe)) return false;
- if (isUserRelated(note, userIdsWhoMeMuting)) return false;
- if (note.renoteId) {
- if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) {
- if (isUserRelated(note, userIdsWhoMeMutingRenotes)) return false;
- if (ps.withRenotes === false) return false;
- }
+
+ 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)');
+ }));
}
- return true;
- });
+ 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.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 != \'{}\'');
+ }));
+ }));
+ }
- // TODO: フィルタした結果件数が足りなかった場合の対応
+ if (ps.withFiles) {
+ query.andWhere('note.fileIds != \'{}\'');
+ }
+ //#endregion
- timeline.sort((a, b) => a.id > b.id ? -1 : 1);
+ const timeline = await query.limit(ps.limit).getMany();
- this.activeUsersChart.read(me);
+ this.activeUsersChart.read(me);
- return await this.noteEntityService.packMany(timeline, me);
+ return await this.noteEntityService.packMany(timeline, me);
+ }
});
}
}
diff --git a/packages/backend/src/server/api/endpoints/notifications/create.ts b/packages/backend/src/server/api/endpoints/notifications/create.ts
index 268628cf76..19bc6fa8d7 100644
--- a/packages/backend/src/server/api/endpoints/notifications/create.ts
+++ b/packages/backend/src/server/api/endpoints/notifications/create.ts
@@ -42,8 +42,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
this.notificationService.createNotification(user.id, 'app', {
appAccessTokenId: token ? token.id : null,
customBody: ps.body,
- customHeader: ps.header,
- customIcon: ps.icon,
+ customHeader: ps.header ?? token?.name,
+ customIcon: ps.icon ?? token?.iconUrl,
});
});
}