タイムライン取得処理への組み込み

This commit is contained in:
samunohito 2024-06-11 21:13:31 +09:00
parent 94ededa68d
commit 7d7c2d4daf
18 changed files with 512 additions and 43 deletions

View file

@ -124,6 +124,9 @@ import * as ep___channels_favorite from './endpoints/channels/favorite.js';
import * as ep___channels_unfavorite from './endpoints/channels/unfavorite.js';
import * as ep___channels_myFavorites from './endpoints/channels/my-favorites.js';
import * as ep___channels_search from './endpoints/channels/search.js';
import * as ep___channels_mute_create from './endpoints/channels/mute/create.js';
import * as ep___channels_mute_delete from './endpoints/channels/mute/delete.js';
import * as ep___channels_mute_list from './endpoints/channels/mute/list.js';
import * as ep___charts_activeUsers from './endpoints/charts/active-users.js';
import * as ep___charts_apRequest from './endpoints/charts/ap-request.js';
import * as ep___charts_drive from './endpoints/charts/drive.js';
@ -507,6 +510,9 @@ const $channels_favorite: Provider = { provide: 'ep:channels/favorite', useClass
const $channels_unfavorite: Provider = { provide: 'ep:channels/unfavorite', useClass: ep___channels_unfavorite.default };
const $channels_myFavorites: Provider = { provide: 'ep:channels/my-favorites', useClass: ep___channels_myFavorites.default };
const $channels_search: Provider = { provide: 'ep:channels/search', useClass: ep___channels_search.default };
const $channels_mute_create: Provider = { provide: 'ep:channels/mute/create', useClass: ep___channels_mute_create.default };
const $channels_mute_delete: Provider = { provide: 'ep:channels/mute/delete', useClass: ep___channels_mute_delete.default };
const $channels_mute_list: Provider = { provide: 'ep:channels/mute/list', useClass: ep___channels_mute_list.default };
const $charts_activeUsers: Provider = { provide: 'ep:charts/active-users', useClass: ep___charts_activeUsers.default };
const $charts_apRequest: Provider = { provide: 'ep:charts/ap-request', useClass: ep___charts_apRequest.default };
const $charts_drive: Provider = { provide: 'ep:charts/drive', useClass: ep___charts_drive.default };
@ -894,6 +900,9 @@ const $reversi_verify: Provider = { provide: 'ep:reversi/verify', useClass: ep__
$channels_unfavorite,
$channels_myFavorites,
$channels_search,
$channels_mute_create,
$channels_mute_delete,
$channels_mute_list,
$charts_activeUsers,
$charts_apRequest,
$charts_drive,
@ -1275,6 +1284,9 @@ const $reversi_verify: Provider = { provide: 'ep:reversi/verify', useClass: ep__
$channels_unfavorite,
$channels_myFavorites,
$channels_search,
$channels_mute_create,
$channels_mute_delete,
$channels_mute_list,
$charts_activeUsers,
$charts_apRequest,
$charts_drive,

View file

@ -130,6 +130,9 @@ import * as ep___channels_favorite from './endpoints/channels/favorite.js';
import * as ep___channels_unfavorite from './endpoints/channels/unfavorite.js';
import * as ep___channels_myFavorites from './endpoints/channels/my-favorites.js';
import * as ep___channels_search from './endpoints/channels/search.js';
import * as ep___channels_mute_create from './endpoints/channels/mute/create.js';
import * as ep___channels_mute_delete from './endpoints/channels/mute/delete.js';
import * as ep___channels_mute_list from './endpoints/channels/mute/list.js';
import * as ep___charts_activeUsers from './endpoints/charts/active-users.js';
import * as ep___charts_apRequest from './endpoints/charts/ap-request.js';
import * as ep___charts_drive from './endpoints/charts/drive.js';
@ -511,6 +514,9 @@ const eps = [
['channels/unfavorite', ep___channels_unfavorite],
['channels/my-favorites', ep___channels_myFavorites],
['channels/search', ep___channels_search],
['channels/mute/create', ep___channels_mute_create],
['channels/mute/delete', ep___channels_mute_delete],
['channels/mute/list', ep___channels_mute_list],
['charts/active-users', ep___charts_activeUsers],
['charts/ap-request', ep___charts_apRequest],
['charts/drive', ep___charts_drive],

View file

@ -0,0 +1,90 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { ChannelsRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '@/server/api/error.js';
import { ChannelMutingService } from '@/core/ChannelMutingService.js';
export const meta = {
tags: ['channels', 'mute'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:channels',
errors: {
noSuchChannel: {
message: 'No such Channel.',
code: 'NO_SUCH_CHANNEL',
id: '7174361e-d58f-31d6-2e7c-6fb830786a3f',
},
alreadyMuting: {
message: 'You are already muting that user.',
code: 'ALREADY_MUTING_CHANNEL',
id: '5a251978-769a-da44-3e89-3931e43bb592',
},
expiresAtIsPast: {
message: 'Cannot set past date to "expiresAt".',
code: 'EXPIRES_AT_IS_PAST',
id: '42b32236-df2c-a45f-fdbf-def67268f749',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
channelId: { type: 'string', format: 'misskey:id' },
expiresAt: {
type: 'integer',
nullable: true,
description: 'A Unix Epoch timestamp that must lie in the future. `null` means an indefinite mute.',
},
},
required: ['channelId'],
} as const;
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
@Inject(DI.channelsRepository)
private channelsRepository: ChannelsRepository,
private channelMutingService: ChannelMutingService,
) {
super(meta, paramDef, async (ps, me) => {
// Check if exists the channel
const targetChannel = await this.channelsRepository.findOneBy({ id: ps.channelId });
if (!targetChannel) {
throw new ApiError(meta.errors.noSuchChannel);
}
// Check if already muting
const exist = await this.channelMutingService.isMuted({
requestUserId: me.id,
targetChannelId: targetChannel.id,
});
if (exist) {
throw new ApiError(meta.errors.alreadyMuting);
}
// Check if expiresAt is past
if (ps.expiresAt && ps.expiresAt <= Date.now()) {
throw new ApiError(meta.errors.expiresAtIsPast);
}
await this.channelMutingService.mute({
requestUserId: me.id,
targetChannelId: targetChannel.id,
expiresAt: ps.expiresAt ? new Date(ps.expiresAt) : null,
});
});
}
}

View file

@ -0,0 +1,73 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { ChannelsRepository } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
import { ChannelMutingService } from '@/core/ChannelMutingService.js';
import { ApiError } from '@/server/api/error.js';
export const meta = {
tags: ['channels', 'mute'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:channels',
errors: {
noSuchChannel: {
message: 'No such Channel.',
code: 'NO_SUCH_CHANNEL',
id: 'e7998769-6e94-d9c2-6b8f-94a527314aba',
},
notMuting: {
message: 'You are not muting that channel.',
code: 'NOT_MUTING_CHANNEL',
id: '14d55962-6ea8-d990-1333-d6bef78dc2ab',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
channelId: { type: 'string', format: 'misskey:id' },
},
required: ['channelId'],
} as const;
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
@Inject(DI.channelsRepository)
private channelsRepository: ChannelsRepository,
private channelMutingService: ChannelMutingService,
) {
super(meta, paramDef, async (ps, me) => {
// Check if exists the channel
const targetChannel = await this.channelsRepository.findOneBy({ id: ps.channelId });
if (!targetChannel) {
throw new ApiError(meta.errors.noSuchChannel);
}
// Check if already muting
const exist = await this.channelMutingService.isMuted({
requestUserId: me.id,
targetChannelId: targetChannel.id,
});
if (exist) {
throw new ApiError(meta.errors.notMuting);
}
await this.channelMutingService.unmute({
requestUserId: me.id,
targetChannelId: targetChannel.id,
});
});
}
}

View file

@ -0,0 +1,49 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { ChannelMutingService } from '@/core/ChannelMutingService.js';
import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js';
export const meta = {
tags: ['channels', 'mute'],
requireCredential: true,
prohibitMoved: true,
kind: 'read:channels',
res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'Channel',
},
},
} 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 channelMutingService: ChannelMutingService,
private channelEntityService: ChannelEntityService,
) {
super(meta, paramDef, async (ps, me) => {
const mutings = await this.channelMutingService.list({
requestUserId: me.id,
});
return await this.channelEntityService.packMany(mutings, me);
});
}
}

View file

@ -19,6 +19,7 @@ import { UserFollowingService } from '@/core/UserFollowingService.js';
import { MetaService } from '@/core/MetaService.js';
import { MiLocalUser } from '@/models/User.js';
import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js';
import { ChannelMutingService } from '@/core/ChannelMutingService.js';
import { ApiError } from '../../error.js';
export const meta = {
@ -47,7 +48,7 @@ export const meta = {
bothWithRepliesAndWithFiles: {
message: 'Specifying both withReplies and withFiles is not supported',
code: 'BOTH_WITH_REPLIES_AND_WITH_FILES',
id: 'dfaa3eb7-8002-4cb7-bcc4-1095df46656f'
id: 'dfaa3eb7-8002-4cb7-bcc4-1095df46656f',
},
},
} as const;
@ -87,6 +88,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private cacheService: CacheService,
private queryService: QueryService,
private userFollowingService: UserFollowingService,
private channelMutingService: ChannelMutingService,
private metaService: MetaService,
private fanoutTimelineEndpointService: FanoutTimelineEndpointService,
) {
@ -152,6 +154,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
useDbFallback: serverSettings.enableFanoutTimelineDbFallback,
alwaysIncludeMyNotes: true,
excludePureRenotes: !ps.withRenotes,
excludeMutedChannels: true,
dbFallback: async (untilId, sinceId, limit) => await this.getFromDb({
untilId,
sinceId,
@ -188,6 +191,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
followerId: me.id,
},
});
const mutingChannelIds = (followingChannels.length > 0)
? await this.channelMutingService.list({ requestUserId: me.id }).then(x => x.map(x => x.id))
: [];
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
.andWhere(new Brackets(qb => {
@ -217,6 +223,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
query.andWhere('note.channelId IS NULL');
}
if (mutingChannelIds.length > 0) {
// ミュートしてるチャンネルは含めない
query.andWhere(new Brackets(qb => {
qb
.andWhere('note.channelId NOT IN (:...mutingChannelIds)', { mutingChannelIds })
.andWhere('note.renoteChannelId NOT IN (:...mutingChannelIds)', { mutingChannelIds });
}));
}
if (!ps.withReplies) {
query.andWhere(new Brackets(qb => {
qb

View file

@ -5,7 +5,7 @@
import { Brackets } from 'typeorm';
import { Inject, Injectable } from '@nestjs/common';
import type { NotesRepository, ChannelFollowingsRepository } from '@/models/_.js';
import type { NotesRepository, ChannelFollowingsRepository, ChannelMutingRepository } 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';
@ -17,6 +17,7 @@ import { UserFollowingService } from '@/core/UserFollowingService.js';
import { MiLocalUser } from '@/models/User.js';
import { MetaService } from '@/core/MetaService.js';
import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js';
import { ChannelMutingService } from '@/core/ChannelMutingService.js';
export const meta = {
tags: ['notes'],
@ -68,6 +69,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private cacheService: CacheService,
private fanoutTimelineEndpointService: FanoutTimelineEndpointService,
private userFollowingService: UserFollowingService,
private channelMutingService: ChannelMutingService,
private queryService: QueryService,
private metaService: MetaService,
) {
@ -112,6 +114,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
redisTimelines: ps.withFiles ? [`homeTimelineWithFiles:${me.id}`] : [`homeTimeline:${me.id}`],
alwaysIncludeMyNotes: true,
excludePureRenotes: !ps.withRenotes,
excludeMutedChannels: true,
noteFilter: note => {
if (note.reply && note.reply.visibility === 'followers') {
if (!Object.hasOwn(followings, note.reply.userId)) return false;
@ -146,6 +149,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
followerId: me.id,
},
});
const mutingChannelIds = (followingChannels.length > 0)
? await this.channelMutingService.list({ requestUserId: me.id }).then(x => x.map(x => x.id))
: [];
//#region Construct query
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
@ -163,7 +169,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
qb
.where(new Brackets(qb2 => {
qb2
.where('note.userId IN (:...meOrFolloweeIds)', { meOrFolloweeIds: meOrFolloweeIds })
.andWhere('note.userId IN (:...meOrFolloweeIds)', { meOrFolloweeIds: meOrFolloweeIds })
.andWhere('note.channelId IS NULL');
}))
.orWhere('note.channelId IN (:...followingChannelIds)', { followingChannelIds });
@ -171,9 +177,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
} 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 });
query.andWhere(new Brackets(qb => {
qb
.andWhere('note.channelId IS NULL')
.andWhere('note.userId IN (:...meOrFolloweeIds)', { meOrFolloweeIds: meOrFolloweeIds });
}));
} else if (followingChannels.length > 0) {
// チャンネルフォローのみ(ユーザーフォローなし)
const followingChannelIds = followingChannels.map(x => x.followeeId);
@ -184,9 +192,20 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}));
} else {
// フォローなし
query
.andWhere('note.channelId IS NULL')
.andWhere('note.userId = :meId', { meId: me.id });
query.andWhere(new Brackets(qb => {
qb
.andWhere('note.channelId IS NULL')
.andWhere('note.userId = :meId', { meId: me.id });
}));
}
if (mutingChannelIds.length > 0) {
// ミュートしてるチャンネルは含めない
query.andWhere(new Brackets(qb => {
qb
.andWhere('note.channelId NOT IN (:...mutingChannelIds)', { mutingChannelIds })
.andWhere('note.renoteChannelId NOT IN (:...mutingChannelIds)', { mutingChannelIds });
}));
}
query.andWhere(new Brackets(qb => {

View file

@ -8,6 +8,7 @@ import type { Packed } from '@/misc/json-schema.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import { isRenotePacked, isQuotePacked } from '@/misc/is-renote.js';
import { isChannelRelated } from '@/misc/is-channel-related.js';
import Channel, { type MiChannelService } from '../channel.js';
class HomeTimelineChannel extends Channel {
@ -43,7 +44,10 @@ class HomeTimelineChannel extends Channel {
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
if (note.channelId) {
if (!this.followingChannels.has(note.channelId)) return;
// そのチャンネルをフォローしていない or そのチャンネル(リノート・引用リノート含む)はミュートしている
if (!this.followingChannels.has(note.channelId) || isChannelRelated(note, this.mutingChannels)) {
return;
}
} else {
// その投稿のユーザーをフォローしていなかったら弾く
if (!isMe && !Object.hasOwn(this.following, note.userId)) return;

View file

@ -10,6 +10,7 @@ import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { bindThis } from '@/decorators.js';
import { RoleService } from '@/core/RoleService.js';
import { isRenotePacked, isQuotePacked } from '@/misc/is-renote.js';
import { isChannelRelated } from '@/misc/is-channel-related.js';
import Channel, { type MiChannelService } from '../channel.js';
class HybridTimelineChannel extends Channel {
@ -55,12 +56,14 @@ class HybridTimelineChannel extends Channel {
// チャンネルの投稿ではなく、自分自身の投稿 または
// チャンネルの投稿ではなく、その投稿のユーザーをフォローしている または
// チャンネルの投稿ではなく、全体公開のローカルの投稿 または
// フォローしているチャンネルの投稿 の場合だけ
// フォローしているチャンネルの投稿 または
// ミュートしていないチャンネルの投稿(リノート・引用リノートもチェック対象)の場合だけ
if (!(
(note.channelId == null && isMe) ||
(note.channelId == null && Object.hasOwn(this.following, note.userId)) ||
(note.channelId == null && (note.user.host == null && note.visibility === 'public')) ||
(note.channelId != null && this.followingChannels.has(note.channelId))
(note.channelId != null && this.followingChannels.has(note.channelId)) ||
(note.channelId != null && !isChannelRelated(note, this.mutingChannels))
)) return;
if (note.visibility === 'followers') {
@ -82,7 +85,10 @@ class HybridTimelineChannel extends Channel {
}
}
if (isRenotePacked(note) && !isQuotePacked(note) && !this.withRenotes) return;
// 純粋なリノート(引用リノートでないリノート)の場合
if (isRenotePacked(note) && !isQuotePacked(note) && !this.withRenotes) {
return;
}
if (this.user && note.renoteId && !note.text) {
if (note.renote && Object.keys(note.renote.reactions).length > 0) {