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';
|
|
|
|
import { makePaginationQuery } from '../../common/make-pagination-query.js';
|
|
|
|
import { Notes } from '@/models/index.js';
|
|
|
|
import { generateMutedUserQuery } from '../../common/generate-muted-user-query.js';
|
|
|
|
import { generateMutedInstanceQuery } from '../../common/generate-muted-instance-query.js';
|
|
|
|
import { activeUsersChart } from '@/services/chart/index.js';
|
|
|
|
import { generateRepliesQuery } from '../../common/generate-replies-query.js';
|
|
|
|
import { generateMutedNoteQuery } from '../../common/generate-muted-note-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: {
|
|
|
|
gtlDisabled: {
|
|
|
|
message: 'Global timeline has been disabled.',
|
|
|
|
code: 'GTL_DISABLED',
|
2021-12-09 14:58:30 +00:00
|
|
|
id: '0332fc13-6ab2-4427-ae80-a9fadffd1a6b',
|
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: {
|
|
|
|
withFiles: { type: 'boolean' },
|
|
|
|
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.disableGlobalTimeline) {
|
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.gtlDisabled);
|
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\'')
|
2020-08-18 13:44:21 +00:00
|
|
|
.andWhere('note.channelId 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');
|
2018-07-15 08:50:24 +00:00
|
|
|
|
2020-02-15 12:39:38 +00:00
|
|
|
generateRepliesQuery(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);
|
2021-12-09 12:38:56 +00:00
|
|
|
if (user) generateMutedInstanceQuery(query, user);
|
2018-05-28 12:59:57 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
if (ps.withFiles) {
|
|
|
|
query.andWhere('note.fileIds != \'{}\'');
|
2018-05-28 12:59:57 +00:00
|
|
|
}
|
2019-04-07 12:50:36 +00:00
|
|
|
//#endregion
|
2018-04-17 05:52:28 +00:00
|
|
|
|
2022-02-19 05:05:32 +00:00
|
|
|
const timeline = await query.take(ps.limit).getMany();
|
2018-09-05 14:55:51 +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
|
|
|
}
|
|
|
|
});
|
2018-06-06 21:13:57 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
return await Notes.packMany(timeline, user);
|
2019-02-22 02:46:58 +00:00
|
|
|
});
|