2022-02-27 02:07:39 +00:00
|
|
|
import define from '../../define.js';
|
|
|
|
import { fetchMeta } from '@/misc/fetch-meta.js';
|
|
|
|
import { ApiError } from '../../error.js';
|
2022-03-25 07:27:41 +00:00
|
|
|
import { Notes, Users } from '@/models/index.js';
|
2022-02-27 02:07:39 +00:00
|
|
|
import { generateMutedUserQuery } from '../../common/generate-muted-user-query.js';
|
|
|
|
import { makePaginationQuery } from '../../common/make-pagination-query.js';
|
|
|
|
import { generateVisibilityQuery } from '../../common/generate-visibility-query.js';
|
|
|
|
import { activeUsersChart } from '@/services/chart/index.js';
|
2019-04-07 12:50:36 +00:00
|
|
|
import { Brackets } from 'typeorm';
|
2022-02-27 02:07:39 +00:00
|
|
|
import { generateRepliesQuery } from '../../common/generate-replies-query.js';
|
|
|
|
import { generateMutedNoteQuery } from '../../common/generate-muted-note-query.js';
|
|
|
|
import { generateChannelQuery } from '../../common/generate-channel-query.js';
|
|
|
|
import { generateBlockedUserQuery } from '../../common/generate-block-query.js';
|
2018-04-17 05:52:28 +00:00
|
|
|
|
2018-09-05 14:55:51 +00:00
|
|
|
export const meta = {
|
2019-02-23 02:20:58 +00:00
|
|
|
tags: ['notes'],
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'array',
|
|
|
|
optional: false, nullable: false,
|
2019-02-23 02:20:58 +00:00
|
|
|
items: {
|
2022-01-18 13:27:10 +00:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-04-23 13:35:26 +00:00
|
|
|
ref: 'Note',
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2019-02-23 02:20:58 +00:00
|
|
|
},
|
|
|
|
|
2019-02-22 02:46:58 +00:00
|
|
|
errors: {
|
|
|
|
ltlDisabled: {
|
|
|
|
message: 'Local timeline has been disabled.',
|
|
|
|
code: 'LTL_DISABLED',
|
2021-12-09 14:58:30 +00:00
|
|
|
id: '45a6eb02-7695-4393-b023-dd3be9aaaefd',
|
2019-02-22 02:46:58 +00:00
|
|
|
},
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2018-04-17 05:52:28 +00:00
|
|
|
|
2022-02-20 04:15:40 +00:00
|
|
|
export const paramDef = {
|
2022-02-19 05:05:32 +00:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
2022-04-02 06:04:36 +00:00
|
|
|
withFiles: {
|
|
|
|
type: 'boolean',
|
|
|
|
default: false,
|
|
|
|
description: 'Only show notes that have attached files.',
|
|
|
|
},
|
2022-02-19 05:05:32 +00:00
|
|
|
fileType: { type: 'array', items: {
|
|
|
|
type: 'string',
|
|
|
|
} },
|
|
|
|
excludeNsfw: { type: 'boolean', default: false },
|
|
|
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
|
|
|
sinceId: { type: 'string', format: 'misskey:id' },
|
|
|
|
untilId: { type: 'string', format: 'misskey:id' },
|
|
|
|
sinceDate: { type: 'integer' },
|
|
|
|
untilDate: { type: 'integer' },
|
|
|
|
},
|
|
|
|
required: [],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 17:12:50 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 05:05:32 +00:00
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2019-02-22 02:46:58 +00:00
|
|
|
const m = await fetchMeta();
|
|
|
|
if (m.disableLocalTimeline) {
|
2019-01-15 17:30:55 +00:00
|
|
|
if (user == null || (!user.isAdmin && !user.isModerator)) {
|
2019-02-22 02:46:58 +00:00
|
|
|
throw new ApiError(meta.errors.ltlDisabled);
|
2019-01-15 17:30:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 05:52:28 +00:00
|
|
|
//#region Construct query
|
2019-04-07 12:50:36 +00:00
|
|
|
const query = makePaginationQuery(Notes.createQueryBuilder('note'),
|
|
|
|
ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate)
|
|
|
|
.andWhere('(note.visibility = \'public\') AND (note.userHost IS NULL)')
|
2021-03-21 03:33:37 +00:00
|
|
|
.innerJoinAndSelect('note.user', 'user')
|
2022-02-27 04:59:10 +00:00
|
|
|
.leftJoinAndSelect('user.avatar', 'avatar')
|
|
|
|
.leftJoinAndSelect('user.banner', 'banner')
|
2021-03-21 03:31:56 +00:00
|
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
2022-02-27 04:59:10 +00:00
|
|
|
.leftJoinAndSelect('replyUser.avatar', 'replyUserAvatar')
|
|
|
|
.leftJoinAndSelect('replyUser.banner', 'replyUserBanner')
|
|
|
|
.leftJoinAndSelect('renote.user', 'renoteUser')
|
|
|
|
.leftJoinAndSelect('renoteUser.avatar', 'renoteUserAvatar')
|
|
|
|
.leftJoinAndSelect('renoteUser.banner', 'renoteUserBanner');
|
2019-01-20 04:14:31 +00:00
|
|
|
|
2020-08-18 13:44:21 +00:00
|
|
|
generateChannelQuery(query, user);
|
2020-02-15 12:39:38 +00:00
|
|
|
generateRepliesQuery(query, user);
|
2019-12-11 15:49:30 +00:00
|
|
|
generateVisibilityQuery(query, user);
|
2020-07-28 00:38:41 +00:00
|
|
|
if (user) generateMutedUserQuery(query, user);
|
2020-07-27 04:34:20 +00:00
|
|
|
if (user) generateMutedNoteQuery(query, user);
|
2021-08-17 12:48:59 +00:00
|
|
|
if (user) generateBlockedUserQuery(query, user);
|
2018-04-17 05:52:28 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
if (ps.withFiles) {
|
|
|
|
query.andWhere('note.fileIds != \'{}\'');
|
2018-06-06 21:13:57 +00:00
|
|
|
}
|
|
|
|
|
2019-04-12 16:43:22 +00:00
|
|
|
if (ps.fileType != null) {
|
2019-04-07 12:50:36 +00:00
|
|
|
query.andWhere('note.fileIds != \'{}\'');
|
|
|
|
query.andWhere(new Brackets(qb => {
|
2019-04-12 16:43:22 +00:00
|
|
|
for (const type of ps.fileType!) {
|
|
|
|
const i = ps.fileType!.indexOf(type);
|
2019-04-07 12:50:36 +00:00
|
|
|
qb.orWhere(`:type${i} = ANY(note.attachedFileTypes)`, { [`type${i}`]: type });
|
|
|
|
}
|
|
|
|
}));
|
2018-09-25 12:09:38 +00:00
|
|
|
|
|
|
|
if (ps.excludeNsfw) {
|
2019-08-27 08:33:07 +00:00
|
|
|
query.andWhere('note.cw IS NULL');
|
|
|
|
query.andWhere('0 = (SELECT COUNT(*) FROM drive_file df WHERE df.id = ANY(note."fileIds") AND df."isSensitive" = TRUE)');
|
2018-09-25 12:09:38 +00:00
|
|
|
}
|
2018-09-05 19:28:22 +00:00
|
|
|
}
|
2018-04-17 05:52:28 +00:00
|
|
|
//#endregion
|
|
|
|
|
2022-02-19 05:05:32 +00:00
|
|
|
const timeline = await query.take(ps.limit).getMany();
|
2019-01-17 08:16:08 +00:00
|
|
|
|
2019-04-27 02:17:03 +00:00
|
|
|
process.nextTick(() => {
|
|
|
|
if (user) {
|
2022-02-08 18:46:58 +00:00
|
|
|
activeUsersChart.read(user);
|
2019-04-27 02:17:03 +00:00
|
|
|
}
|
|
|
|
});
|
2019-02-22 02:46:58 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
return await Notes.packMany(timeline, user);
|
2019-02-22 02:46:58 +00:00
|
|
|
});
|